Navigating networking on a minimal Linux distribution can sometimes feel like solving a puzzle. If you are running a custom Yocto image on a Raspberry Pi 5 and trying to get your Wi-Fi working without the luxury of NetworkManager, you might run into a few roadblocks.
When you check your network interfaces using networkctl and see that wlan0 is sitting stubbornly in an “off” and “unmanaged” state, it’s a clear sign that the default networking mechanisms aren’t kicking in as expected. Here is a comprehensive guide to understanding why this happens and how to fix it using wpa_supplicant and systemd-networkd.
The Problem: The “Yocto Factor”
In a standard Raspberry Pi OS setup, NetworkManager typically handles everything seamlessly out of the box. However, in a custom, minimal Yocto build, wpa_supplicant might be running via D-Bus (often denoted by the -u flag in its process string) but without a dedicated configuration file or a defined control interface.
Because of this missing link between the hardware and the daemon, running wpa_cli -i wlan0 to interactively connect to a network results in an error like:
Could not connect to wpa_supplicant: wlan0 - re-tryingThis means wpa_cli is essentially shouting into a void. Let’s manually bridge that gap.
1. Create the Missing Configuration
We need to provide wpa_supplicant with a configuration file that explicitly defines the control interface socket required by wpa_cli.
Create the directory and the configuration file:
sudo mkdir -p /etc/wpa_supplicantsudo tee /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null <<EOFctrl_interface=/var/run/wpa_supplicantctrl_interface_group=0update_config=1EOFctrl_interface: Creates the socket thatwpa_cliuses to connect.update_config=1: Allowswpa_clito save new networks directly back to this file.
2. Bind wpa_supplicant to the Interface
The existing wpa_supplicant service, managed by systemd, is likely running generally without being bound to the wlan0 interface. We need to kill that process, bring the wireless interface up at the kernel level, and restart the daemon manually.
# Stop the D-Bus version from runningsudo systemctl stop wpa_supplicant
# Force wlan0 up at the kernel levelsudo ip link set wlan0 up
# Start wpa_supplicant manually, linking it to the config and interfacesudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.confTip
The -B flag runs the process in the background, -i specifies the interface, and -c points to the new configuration file we just made.
3. Connect via wpa_cli
Now that the daemon is explicitly watching wlan0 and has a control socket at /var/run/wpa_supplicant, wpa_cli will work as expected:
sudo wpa_cli -i wlan0Once inside the interactive prompt (>), you can scan and connect to your network:
> scan> scan_results> add_network0> set_network 0 ssid "Your_Network_Name"> set_network 0 psk "Your_Password"> enable_network 0> save_config> quit4. Make it Persistent with systemd-networkd
Even after successfully connecting to your Wi-Fi network, networkctl may still report the interface as unmanaged. This happens because systemd-networkd doesn’t automatically know it should manage IP assignment for this link.
To fix this and ensure the lifecycle is managed correctly on subsequent reboots, create a .network profile to handle DHCP:
sudo tee /etc/systemd/network/25-wlan0.network > /dev/null <<EOF[Match]Name=wlan0
[Network]DHCP=yesEOFRestart the network manager to apply the changes:
sudo systemctl restart systemd-networkdYour wlan0 interface should now be properly configured, connected, and assigned an IP address!
Troubleshooting: “Failed to initiate sched scan”
While working through these steps, checking your systemctl logs (sudo systemctl status wpa_supplicant) might reveal the following error:
wlan0: Failed to initiate sched scanThis commonly occurs if the interface is soft-blocked by a software switch or if there are issues with power saving modes affecting the Wi-Fi chip.
To resolve this:
- Try disabling power management for the interface to see if scanning resumes:
Terminal window sudo iw dev wlan0 set power_save off - Double-check that your radio is not blocked using
rfkill:Terminal window sudo rfkill listsudo rfkill unblock wifi
By manually defining the control interface for wpa_supplicant and tying IP configuration to systemd-networkd, you can successfully tame the Wi-Fi on a custom Yocto build for the Raspberry Pi 5. Happy tinkering!