Home » Development and Build » Yocto Embedded Linux » Modifying bitbake/yocto initscripts to start wifi during boot

Modifying bitbake/yocto initscripts to start wifi during boot

We will need to change the wpa-supplicant.conf file as below, by modifying poky/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/wpa_supplicant.conf-sane

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1

network={
        ssid="MYSSID"
        psk="MY-SECURE-PASSKEY"
        proto=RSN
        key_mgmt=WPA-PSK
}

Now, once we modified wpa_supplicant configuration files, we need to create an script which will start the wpa_supplicant application which uses this conf file to connect to WiFi access point.

$ vim poky/meta/recipes-core/initscripts/initscripts-1.0/start-wifi.sh
#!/bin/sh
ifconfig wlan0 192.168.1.150
route add default gw 192.168.1.1

wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
: exit 0

As you can see above, if you don’t have DHCP enabled and server is unable to assign IP address to wifi device wlan0 , we have assigned free IP address manually i.e. 192.168.1.150 in your case it may be different.

Now, we need to modify initscript bitbake recipe to start the above script during the boot, modify initscripts.bb SRC_URI so bitbake build system considers this as source file from local files folder and then we modify install function “do_install” to copy this start-wifi.sh to filesystem etc initscripts directory.

$ vim poky/meta/recipes-core/initscripts/initscripts_1.0.bb
SRC_URI = "
file://start-wifi.sh \
"
do_install () {
install -m 0755    ${WORKDIR}/start-wifi.sh     ${D}${sysconfdir}/init.d

update-rc.d -r ${D} start-wifi.sh start 99 2 3 4 5 .
}

MASKED_SCRIPTS = " \
start-wifi \
"

Now if you compile the root file system which contains initscripts and boot the board with this new file system, you can see start-wifi.sh script is executed during initial booting which starts wpa_supplication and WiFi is already connected.

1 thought on “Modifying bitbake/yocto initscripts to start wifi during boot”

Leave a Comment