Wireless network for Raspberry Pi 4 with Buildroot

Enable wireless network (and SSH access) on a minimal Linux for the Raspberry Pi 4.

Introduction

On each board Buildroot ships configuration for, only eth0 is configured by default. The Raspberry Pi boards, on the other hand, are generally capable of wireless connectivity.
Trying to enable wlan0 proved not to be so straight forward, as many of the articles I’ve found are now a bit outdated. But eventually it boils down to few little settings.

TL;DR

Jump to the configuration file already: rpi4_wifi_defconfig

RPI firmware

TODO: On top of the default buildroot (2023.11) config, the following settings enabled the wifi:

BR2_PACKAGE_BRCMFMAC_SDIO_FIRMWARE_RPI=y
BR2_PACKAGE_BRCMFMAC_SDIO_FIRMWARE_RPI_WIFI=y
BR2_PACKAGE_RPI_FIRMWARE=y
BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y

The brcmfmac drivers alone however, will not get us quite there. If you try to build and run the system now, it will show no dmesg about the driver.

Enable MDEV

As described in this post the WiFi components on the Pi come up a little late, so we need to modprobe the WiFi driver brcmfmac, manually, or use an hotplug mechanism that would automate that: enter MDEV.

  • System Configurations -> /dev management -> Dynamic using Devtmpfs + mdev

will set the following value:

BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y

For some more insights refer to 6.2. /dev management.

Network packages

# network interfaces manager
BR2_PACKAGE_IWD=y

# SSH support
BR2_PACKAGE_DROPBEAR=y

Here iwd is preferred to the wpa_supplicant, since it works pretty much out-of-the-box with a simple rootfs overlay:

# /var/lib/iwd/<MyWifiSSID>.psk

[Security]
Passphrase=<MyWifiPassword>

Custom user

The Buildroot manual describes how to add custom users, besides “root”, in 9.6. Adding custom user accounts. A user(table) file that defines the standard Raspberry Pi user looks like this:

pi -1 pi -1 =raspberry /home/pi /bin/sh -

Then the user file must be added to the configuration:

BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL)/board/users.txt"

Watch out! Each line MUST be terminated and MUST be terminated right, which is each line having a trailing \n, and the last line being an empty one.

Watch out! The user home folder like for example /home/pi is created automatically by Buildroot.

Watch out! To make sure the format is correct and no other character are injected, use nano, vi or another basic editor.

References