Run Buildroot in a Docker Container

This post explores how you can run Buildroot in a Docker container. Follow the getting started to install Docker. I prefer using Docker with the PowerShell prompt on Windows 10.


To download and run the ubuntu image in a new container

docker run -it ubuntu bash

From another command prompt, run the following to find container id

docker ps -l

Use the -a option to see all containers

docker ps -a

Type exit to exit bash shell and stop container.

To return to container created earlier

docker start -ai container_id

Update apt-get package cache so that you can search and install additional packages

apt-get update

You should now be able to search

apt-cache search wget

And install your favorite tools

apt-get install wget

Obtain Buildroot


Untar Buildroot

tar xvzf buildroot-2016.11.2.tar.gz

Install dependencies required to run Buildroot

apt-get install patch cpio python unzip rsync bc bzip2 ncurses-dev git make g++

Go ahead and build your Linux system.


Enable Debugging on Raspberry Pi with Buildroot

This is a quick post that shows how to enable gdb and/or gdbserver on the Raspberry Pi when using Buildroot.

Enable option Build packages with debugging symbols, under Build Options

debugging symbols

Enable the following options under Toolchain

  • Build cross gdb for the host – to facilitate remote debugging
  • Thread library debugging – to enable adding gdb and gdbserver packages to the device’s root file system

cross gdb on host

Thread library debugging

Select gdb and gdbserver (useful for remote debugging), under Target packages, “Debugging, profiling and benchmark”

gdb and gdbserver

Wireless Router with Buildroot and Raspberry Pi

This post shows how to build a basic wireless router, using the Raspberry Pi. It is driven by a custom Linux system built with Buildroot 2014.08, that boots up in no time at all.

Add all appropriate Kernel modules and Buildroot packages referenced in the following posts, before proceeding

Kernel Configuration

I’m using a different USB Wi-Fi adapter in this post. It has the RTL8188CUS chipset that supports access point mode. The Kernel driver is Realtek 8192C USB WiFi, available under Device Drivers, Network device support, Wireless LAN

Realtek 8192C USB WiFi

Package Configuration

Invoke make menuconfig within the buildroot folder from a command prompt. Under Target Packages, select option Show packages that are also provided by busybox


Under Target packages, Networking application, select dhcp and its sub-packages


If you’re using a different wireless adapter, select hostapd and its sub-packages


Perform build by invoking make, copy the newly minted system to an SD card, and use it to boot up your Raspberry Pi.

Custom hostapd

The hostapd built by Buildroot does not work with the chosen Wi-Fi adapter. We need to build the hostapd module provided by Realtek for RTL8188CUS.

Download the driver package from Realtek. It contains the GPL source code for hostapd. In my case, I expanded, then expanded wpa_supplicant_hostapd-0.8_rtw_r7475.20130812.tar.gz under folder wpa_supplicant_hostapd.

Proceed to folder hostapd from the command line, and use the toolchain built by Buildroot to build hostapd

export PATH=/home/parallels/buildroot-2014.08/output/host/usr/bin:$PATH
make CC=arm-buildroot-linux-uclibcgnueabi-gcc

Copy hostapd binary to SD card.

Router Setup

Bring up wireless interface with a static IP address

ifconfig wlan0 up netmask

Or, when using iproute2

ip addr add dev wlan0
ip link set wlan0 up

Configure and bring up dhcpd. Edit /etc/dhcp/dhcpd.conf. Edit following lines so that they are commented (as shown)

#option domain-name "";
#option domain-name-servers,;

Edit following line so that it is uncommented (as shown)


Add following lines at the end

subnet netmask {
  option broadcast-address;
  option routers;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name "local";
  option domain-name-servers,;

Create leases file

touch /var/lib/dhcp/dhcpd.leases

Instantiate dhcpd

dhcpd -cf /etc/dhcp/dhcpd.conf

Configure and bring up hostapd. Create file /etc/hostapd/hostapd.conf with


Run hostapd

hostapd -B /etc/hostapd/hostapd.conf

Try driver=nl80211 if you’re using a new netlink interface compatible driver. If you get the following error when starting hostapd, you probably need a different driver

Configuration file: /etc/hostapd/hostapd.conf
Line 2: invalid/unknown driver 'nl80211'
1 errors found in configuration file '/etc/hostapd/hostapd.conf'

If you get the following error using the Wi-Fi adapter mentioned earlier, you need to use the Realtek hostapd compiled above, with driver=rtl871xdrv in hostapd.conf

rfkill: Cannot open RFKILL control device
nl80211: Could not configure driver mode
nl80211 driver initialization failed.
hostapd_free_hapd_data: Interface wlan0 wasn't started

Join the pi network from any other device using password raspberry, and you’re good to go. Configure NAT routing, if you want to access internet over the wired ethernet interface like so

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
iptables -A FORWARD -i usb0 -o wlan0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i wlan0 -o usb0 -j ACCEPT

Change usb0 to eth0 if that is where your ISP link is at.

Check where your default route is configured for with

netstat -nr



If default route is set for usb0 (or eth0) add route through wlan0 for subnet thus

route add -net dev wlan0

Bluetooth on Raspberry Pi with Buildroot

This post shows how to build Bluetooth support with Buildroot for a Raspberry Pi. You’ll need a Bluetooth adapter such as the Bluetooth 4.0 USB Module from Adafruit. That adapter is also Bluetooth Smart (LE) ready.

I recommend using Buildroot 2014.08 because bluez-tools such as bt-adapter and bt-agent work with its version of Bluez.

Kernel Configuration

Enable Bluetooth subsystem support under Networking support

Bluetooth subsystem support

Enable RFCOMM  protocol support under Bluetooth subsystem support, if you want Bluetooth SPP support. Enable BNEP protocol support, if you want support for networking over Bluetooth. Enable HIDP protocol support, if you want support for Bluetooth enabled keyboard and mice.

RFCOMM and BNEP support

Since we’re using a USB adapter, enable HCI USB driver under Bluetooth subsystem support, Bluetooth device drivers

HCI USB driver

Buildroot Packages

The Kernel Bluetooth stack is called BlueZ. BlueZ also provides a set of utilities that can be used from the command line. To add those, select bluez-utils under Target packages, Networking applications


If using Buildroot 2014.08, select bluez-utils 5.x package instead


make the Linux system and copy to SD card.

Useful commands

Look for interfaces

hciconfig -a

Bring up HCI interface

hciconfig hci0 up

Make the device discoverable

hciconfig hci0 piscan

Scan available devices

hcitool scan

Ping a device

l2ping C8:3E:99:C6:1B:F8

Browse capabilities of a device

sdptool browse C8:3E:99:C6:1B:F8

Run bluetooth daemon


If using Buildroot 2014.08

/usr/libexec/bluetooth/bluetoothd &

Browse local capabilities

sdptool browse local

Another means to discover available devices, using bluez-tools

bt-adapter -d

Connect and pair with a device listed by the command above

bt-device -c 5C:0E:8B:03:6E:4E

Create a network connection and obtain IP address

bt-network -c C8:3E:99:C6:1B:F8 nap
sudo dhclient bnep0

Create a serial port

sdptool add --channel=7 SP
rfcomm connect /dev/rfcomm0 C8:3E:99:C6:1B:F8 7

Use screen with the above serial port

screen /dev/rfcomm0 115200

Bluetooth LE commands

Scan for Bluetooth LE devices

hcitool lescan

Access services and characteristics provided by an LE peripheral

gatttool -b 7F:AE:48:2B:00:0C -t random -I

gatttool prompt supports a set of commands to interact with the peripheral

char-read-hnd handle
char-write-req handle data

Enable advertising as an iBeacon

hciconfig hci0 leadv
hciconfig hci0 noscan
hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00

Bluetooth is big. Go ahead and do something with it.

Wireless on Raspberry Pi with Buildroot

Raspberry Pi does not have Wi-Fi on board. You’ll need to use a Wi-Fi dongle and discover the driver to build into the kernel. One way to find the driver is to plug the dongle into a Raspberry Pi running Raspbian, and perform an lsmod to see which module gets loaded. The following text assumes you’re building a custom embedded Linux system using Buildroot.

Kernel Configuration

Invoke the Kernel configuration utility using make linux-menuconfig.

Enable Wireless Networking support under Networking support


Enable cfg80211 – wireless configuration API, and Generic IEEE 802.11 Networking Stack (mac80211), under Networking Support, Wireless

cfg80211 and mac80211

Enable EEPROM 93CX6 support under Device Drivers, Misc devices, EEPROM support. Required for RTL8187 module in my Wi-Fi dongle, may not be needed for your particular adapter

EEPROM 93CX6 support

Enable Wireless LAN driver support under Device Drivers, Network device support

Wireless LAN

Enable Realtek 8187 and 8187B USB support under Device Drivers, Network device support, Wireless LAN. Select the driver appropriate for your adapter

Realtek 8187 and 8187B USB support

Package Configuration

Invoke make menuconfig within the buildroot folder from a command prompt.

Select package iw required to configure wireless networking, under Target packages, Networking applications. Enable iproute2 if you want to use the ip utility instead of ifconfig.


Select package wpa_supplicant and its sub-packages for WPA/WPA2 support


Perform the build by invoking make, copy the newly minted system to an SD card, and use it to boot up your Raspberry Pi.

Configure Wireless Networking

List your wireless interfaces

iw list

If you’ve selected the iproute2 package above, the following should list all network interfaces

ip link

Bring up the wlan0 interface

ip link set wlan0 up


ifconfig wlan0 up

Find the access point you want to connect to

iw dev wlan0 scan

Assuming you’re using WPA/WPA2, invoke wpa_passphrase to create config file, and wpa_supplicant to connect to network

wpa_passphrase your_SSID your_passphrase > your_SSID.conf
wpa_supplicant -B -i wlan0 -c your_SSID.conf

Instead, if you want to connect to an open network

iw dev wlan0 connect your_SSID

Request IP address using DHCP

dhcpcd wlan0

Check link status

iw dev wlan0 link

Add nameserver entries to /etc/resolv.conf e.g.


Test internet connectivity using ping


Linux NAT routing on Raspberry Pi with Buildroot

This post documents the kernel modules and other packages required to build an embedded Linux NAT router using buildroot, for Raspberry Pi.

Modify Linux kernel configuration

Invoke make linux-menuconfig in buildroot folder to initiate kernel configuration utility. Select modules shown in the figures below.

Networking Options

Network packet filtering framework

Ensure that the following is enabled under Networking Options

  • Network packet filtering framework (Netfilter)

Core Netfilter Configuration

Ensure that the following are enabled under Core Netfilter Configuration

  • Netfilter connection tracking support
  • Netfilter Xtables support (required for ip_tables)
  • “conntrack” connection tracking match support
  • “state” match support

IP: Netfilter Configuration

Ensure following is enabled under Network packet filtering framework (Netfilter)

  • Advanced netfilter configuration

IPv4 packet filtering and NAT

Ensure the following modules are selected under IP: Netfilter Configuration

  • IPv4 connection tracking support (required for NAT)
  • IP tables support (required for filtering/masq/NAT)
  • Packet filtering
  • IPv4 NAT
    • MASQUERADE target support
    • NETMAP target support
    • REDIRECT target support

Enable other targets if you want to do sophisticated filtering.

Modify Buildroot Configuration

Include iptables utility package shown in the figure below, using the configuration utility invoked by executing make menuconfig. Include tcpdump if you want to sniff network data.

Buildroot iptables

Now, just execute make to build the system, and copy the kernel image and root file system to SD card.

Perform NAT routing

I use the following commands to bring up the network interfaces and setup NAT forwarding. Any packets received on interface eth0 are forwarded to usb0. Only packets for connections already established are forwarded back to eth0. usb0 is a USB CDC ethernet interface of the kind seen in modems.

ifconfig usb0 up
ifconfig eth0 up
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
iptables -A FORWARD -i usb0 -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o usb0 -j ACCEPT

If you get any of the following error messages with iptables, you are probably missing one of the kernel modules mentioned above

iptables v1.4.21: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
iptables v1.4.21: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
iptables: No chain/target/match by that name.

If the NAT router is not the default gateway on downstream hosts and routers, you’ll have to setup static routes to relay packets upstream. This can be done using a command such as the following on Mac OS X

sudo route -n add -net

Or, on Linux

route add -net gw

Finally, a couple of useful commands to troubleshoot IP routing and forwarding.

List all rules in iptables

iptables -L -v

Flush all rules in iptables

iptables --flush

A basic packet sniffer

tcpdump -A -i usb0

List all routes

netstat -nr

Network Connection Bridging on Raspberry Pi with Buildroot

This post shows how I add network connection bridging to my custom embedded Linux system for Raspberry Pi. This allows me to experiment with bridging network connections for internet sharing, robustness testing, packet capture, and so on.

Modify Linux kernel configuration

Execute the following in the buildroot folder to get Linux Kernel configuration menu

make linux-menuconfig

Select the 802.1d Ethernet Bridging module shown in the following screenshot

Ethernet Bridging

Modify Buildroot configuration

Execute the following in the buildroot folder to get the configuration menu

make menuconfig

Select the bridge-utils package, shown in the screenshot below. This package contains the brctl utility required to configure bridging.


Then, just execute make to build the system. Once that is done, copy the new kernel image and root file system over to the SD card.

Perform bridging

These are the sequence of commands I typically use to bring up the bridge manually. I use a regular ethernet interface and a USB CDC ethernet interface for testing.

ifconfig eth0 promisc up
ifconfig usb0 promisc up
brctl addbr br0
brctl addif br0 eth0 usb0
ifconfig br0 up

If you need the bridge interface to have an IP address, you can assign one manually, or by invoking the DHCP client daemon as shown below. This is useful if you need to have access to your Pi over the network.

dhcpcd br0

To wrap it up, here’s how you can tear everything down.

ifconfig eth0 down
ifconfig usb0 down
ifconfig br0 down
brctl delbr br0