Raspberry Pi / Wi-Fi

Wi-Fi on Raspberry Pi: the cywfm driver

cywfm drives the Broadcom/Cypress radio soldered to the Pi 4, Pi 5 and Zero 2 W. WPA2, access point mode, monitor mode, and it survives kldunload.

A raspberry with horns holds an antenna sending out blue radio waves and says wlan0 up.

works Version 0.22.11-t88, tested on FreeBSD 15.1-RELEASE-p7. Source: spagu/freebsd-rpi-wifi.

Boards and chips

BoardChipBandsStatus
Pi 4 Model B Rev 1.4CYW434552.4 + 5 GHztested
Pi 5 Model B (UEFI firmware v0.3)CYW434552.4 + 5 GHztested
Pi Zero 2 W Rev 1.043430 family2.4 GHztested
Other Pi 4 revisions, Pi 400, CM4, Pi 3 B+/A+, CM5, Pi 500CYW43455 / 43456expected to work, report wanted
Pi 3 Model Bneeds a board profile first

The module creates the net80211 device cywfm0; a wlan0 goes on top of it as with any other FreeBSD wireless card. It speaks SDIO through its own layer on the classic MMC stack, so kernels built with options MMCCAM are not supported.

Option A: prepare a fresh SD card

The tools/prepare-card.sh script copies the module, firmware and network settings onto a card freshly written with the FreeBSD image.

  1. Write the FreeBSD 15.1 RPI image to the card (see Before starting).

  2. From a FreeBSD computer, mount both partitions and run the script. The board then joins the network on first boot.

    mkdir -p /mnt/fat /mnt/root
    mount -t msdosfs /dev/da0s1 /mnt/fat
    mount /dev/da0s2a /mnt/root
    tools/prepare-card.sh -b zero2w -m /mnt/fat -r /mnt/root -s "network name" -c GB
    umount /mnt/fat /mnt/root
    

    Use -b pi4 or -b pi5 for the other boards and the two-letter country code after -c.

  3. From Windows the PowerShell version can only reach the FAT partition:

    powershell -ExecutionPolicy Bypass -File tools\prepare-card.ps1 -Board pi4 -Drive E: -Ssid "network name" -Country GB
    

    Boot the board, log in once and finish the install with sh /boot/efi/cywfm/install.sh.

Option B: install on a running board

This needs /usr/src/sys on the board.

  1. Pi Zero 2 W only: remove dtoverlay=mmc from config.txt and reboot. That overlay switches the Wi-Fi bus off.

  2. Install the firmware into /boot/firmware and build the module:

    make install-firmware        # Zero 2 W: tools/fetch-firmware.sh -i -c 43436s
                                 # Pi 5:     tools/fetch-firmware.sh -i -b raspberrypi,5-model-b
    make module
    make load
    

    The firmware files (brcmfmac43455-sdio.*, brcmfmac43456-sdio.*, brcmfmac43436s-sdio.*) are vendor binaries under the Cypress/Synaptics licence. The repository fetches them; it does not ship them.

  3. Bring the interface up by hand:

    ifconfig wlan0 create wlandev cywfm0
    wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
    dhclient wlan0
    
  4. Make it permanent. make install copies the module to /boot/modules and runs kldxref. Then add to /etc/rc.conf:

    kld_list="cywfm"
    wlans_cywfm0="wlan0"
    create_args_wlan0="country XX"
    ifconfig_wlan0="WPA DHCP"
    

    Load it from kld_list, not from loader.conf. A module the loader brings in before the SDIO controller is ready logs "loaded at boot, bring-up skipped" and does nothing. Keep /etc/wpa_supplicant.conf at mode 0600.

To remove it again: sysrc -x wlans_cywfm0 ifconfig_wlan0 create_args_wlan0 and sysrc kld_list-=cywfm.

Is it working?

sysctl hw.cywfm.stage      # "net80211" means the radio is up
dmesg | grep cywfm:
ifconfig wlan0
wpa_cli status

What it can do

  • Station mode with WPA2-PSK and open networks, 802.11w (management frame protection).
  • Access point mode with hostapd.
  • Monitor mode with radiotap headers (hw.cywfm.monitor).
  • Firmware offloads: ARP, IPv6 neighbour discovery, packet filters, keepalive.
  • Automatic recovery after a firmware crash (hw.cywfm.recover, 0 to 10 restarts).
  • kldunload and kldload without a reboot.

What it cannot do (yet)

  • WPA3-SAE: net80211 has no external authentication for FullMAC drivers. A write-up for the FreeBSD wireless list is drafted (see Upstream reports).
  • Wi-Fi Direct (P2P), scheduled scans, wake on wireless.
  • 5 GHz on the Zero 2 W: its radio has no 5 GHz.
  • On the Pi 4 and Pi 5 the first join after loading often fails and the retry succeeds. Each load restarts the firmware's 802.11 sequence counter, so the first authentication frame is almost always number 38 with the Retry bit set. An access point that saw number 38 last time stays quiet, and the result is a neat ok/fail/ok/fail pattern. Two attempted fixes did not change it.
  • Untested: AP with a client on the Pi 4, 40/80 MHz and DFS channels for the AP, several virtual interfaces at once.

Tunables

Set them in /boot/loader.conf as hw.cywfm.<name>="value". The full list (more than 60) is in docs/sysctl.md and the cywfm(4) man page. The ones most often changed:

NameWhat it does
countryRegulatory country code
pmPower save on or off
irq_fixPi 4 shared-interrupt workaround (on by default, see below)
bus_hsHigh-speed SDIO bus
mfp802.11w management frame protection
recoverHow many times to restart after a fatal firmware fault
debugExtra logging, for example hw.cywfm.debug="1"

A bug in the Pi 4 kernel

On the Pi 4 the Wi-Fi SDIO controller and the SD card controller share one interrupt line. If the Wi-Fi controller interrupts while the SD card is in the middle of a DMA write, the SD driver loses its "buffer ready" event. The board keeps answering ping for 9 to 10 seconds and then reboots. That is a FreeBSD kernel bug, not a driver bug, so cywfm patches the sdhci_bcm method table at runtime (irq_fix) until the kernel is fixed. The kernel patch and the report are on the Kernel bugs page.

Two smaller surprises from the same board: the Pi 4's radio reports the SDIO card ID of a 43430 (0xa9a6), so the driver reads the chip ID register instead, which says 0x4345 rev 6. And make -j4 on a Pi 4 once killed the compiler with "illegal instruction". The power supply was sagging, so builds now run with one job.

Report a board

Reports from boards in the "expected to work" row are welcome. Two scripts collect what a report needs:

sh tools/board-report.sh -d dump.txt > report.md
sh tools/self-test.sh -m driver/cywfm.ko > test.md

Built with ssg