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

Getting Started with Bluetooth Low Energy by Kevin Townsend et al; O’Reilly Media

Getting Started with Bluetooth Low Energy, Tools and Techniques for Low-Power Networking

Bluetooth LE, or Bluetooth Smart as it is officially known, has generated a lot of interest for all the good reasons. Getting Started with Bluetooth Low Energy by Kevin Townsend et al is a solid guide to the topic, along with other good books such as Bluetooth Low Energy: The Developer’s Handbook.

The book begins by discussing the key characteristics, limitations, and use cases of Bluetooth LE technology, in chapter 1. The following four chapters take a deep dive into the protocols that comprise Bluetooth LE, beginning with an overview in Chapter 2. Chapter 3 delves into the Generic Attribute Profile or GAP (advertising and connections). Chapter 4 delves into Generic Attribute Profile or GATT (services and characteristics).

Makers need to select hardware to leverage Bluetooth LE. It may come in the form of a module that you program to act as a peripheral, or a USB dongle that you may plug into a USB host. Chapter 5 discusses several such options. Chapters 6 and 7 delve into debugging and design tools that aid developers during development and troubleshooting.

Chapter 8 shows how to leverage Bluetooth LE on Android using the Bluetooth Application Accelerator library from the Bluetooth SIG. You’ll learn how to establish connection and communicate with a remote device. Chapter 9 delves into Bluetooth LE programming on iOS by demonstrating several practical applications.

Chapter 10, the concluding chapter, shows how to leverage Bluetooth LE on embedded devices. It uses a hardware module introduced in chapter 5, in conjunction with ARM’s mbed platform, to build a peripheral that can be used with Android and iOS devices.

All source code shown in the book can be forked from the author’s GitHub repo. The text has occasional spelling mistakes that don’t affect readability.

I’d like to thank O’Reilly Media for providing an e-book for review.

Wireless Router with Buildroot and Raspberry Pi

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

I refer you to the following posts

Add all appropriate Kernel modules and Buildroot packages mentioned in these posts before proceeding.

Kernel Configuration

I’m using a different USB Wi-Fi adapter here. 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 RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911.zip, 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 "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

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.

Customize Buildroot to build bluez-tools

I am building Bluetooth support into my custom embedded Linux system with Buildroot, but couldn’t find basic command line tools that work with newer versions of BlueZ. That is when I came across bluez-tools, a GSoC project that is able to fill the gap.

To build bluez-tools requires adding my own package to Buildroot. What follows is a brief description of how to do that.

Download source code of bluez-tools. I did this outside of the buildroot folder, by cloning from the author’s GitHub repo

git clone https://github.com/khvzak/bluez-tools.git

Add an override rule to file local.mk, in the root folder of buildroot. That tells buildroot not to download package source from the internet, but to copy the source from the folder created above

BLUEZ_TOOLS_OVERRIDE_SRCDIR = /home/parallels/github/bluez-tools/

Create a folder for bluez-tools package

mkdir package/bluez-tools

Create package/bluez-tools/bluez-tools.mk file for the package with

# bluez-tools

BLUEZ_TOOLS_DEPENDENCIES = dbus libglib2 readline

$(eval $(autotools-package))

BLUEZ_TOOLS_AUTORECONF tells buildroot to generate configure script and Makefile.in by invoking autoconf et al.

Create configuration file package/bluez-tools/Config.in for the package with

	bool "bluez-tools"
	  This is a GSoC'10 project to implement a new command line tools for bluez (bluetooth stack for linux). The project implemented in C and uses the D-Bus interface of bluez. 


Add the package to package/Config.in

source "package/bluez-tools/Config.in"

Enter configuration menu and select the package

make menuconfig


Note that bluez-tools package is under Networking applications because I added it to menu “Networking applications” in package/Config.in

Invoke make to perform the build


If you get any build errors try

make clean

make clean will delete Linux kernel config. Either save the config, or do it all over again.

With Buildroot 2015.05, a command such as

bt-adapter -l

Fails with

bt-adapter: bluez service is not found
Did you forget to run bluetoothd?

bluetoothd is running just fine. Got to figure that one out.

It works all right with Buildroot 2014.08, but have noted the following issue with bt-device

# bt-device -c 5C:0E:8B:03:6E:4E
Connecting to: 5C:0E:8B:03:6E:4E
Device: CS3070:10172522500886 (5C:0E:8B:03:6E:4E)
Enter passkey: 1234
Segmentation fault

Debugging with gdb reveals the following backtrace

#0  0xb6e77d00 in g_utf8_validate () from /usr/lib/libglib-2.0.so.0
#1  0xb6e7b5c8 in g_variant_new_string () from /usr/lib/libglib-2.0.so.0
#2  0x0000c0b8 in _bt_agent_method_call_func (connection=<optimized out>,
    sender=<optimized out>, object_path=<optimized out>,
    interface_name=<optimized out>, method_name=0x18fc228 "RequestPinCode",
    parameters=0x1905f00, invocation=0x18fdab0, user_data=0x0)
    at lib/agent-helper.c:310

Analyzing lib/agent-helper.c indicates a possible cause, passkey is being read into an uninitialized gchar pointer

            g_print("Enter passkey: ");
            errno = 0;
            if (scanf("%s", &ret) == EOF && errno)
                g_warning("%s\n", strerror(errno));
            g_dbus_method_invocation_return_value(invocation, g_variant_new_string(ret));

Should not be hard to fix.

bt-network crashes when used thus

bt-network -c C8:3E:99:C6:1B:F8 panu

Backtrace with gdb appears thus

#0  0xb6ec7ec8 in g_bit_lock () from /usr/lib/libglib-2.0.so.0
#1  0xb6f240a0 in g_variant_n_children () from /usr/lib/libglib-2.0.so.0
#2  0xb6f24100 in g_variant_get_child_value () from /usr/lib/libglib-2.0.so.0
#3  0x000192e8 in network_connect (self=self@entry=0x14d3470, 
    uuid=0xbef76e9e "panu", error=error@entry=0xbef76be4)
    at lib/bluez/network.c:178
#4  0x0000a3bc in main (argc=0, argv=0x14e5128) at bt-network.c:186

Analyzing the source code reveals another possible bug

        GVariant *proxy_ret = g_dbus_proxy_call_sync(self->priv->proxy, "Connect", g_variant_new ("(s)", uuid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
        if (proxy_ret != NULL)
                return NULL;
        proxy_ret = g_variant_get_child_value(proxy_ret, 0);

Python on Raspberry Pi with Buildroot

I’m in need of python on my custom embedded Linux system for Raspberry Pi. This post shows how I enable it. For some reason python build was failing with errors such as

build error: unknown type name ‘wchar_t’

A clean build, as follows, resolved it

make clean

To add python to your Buildroot config, invoke

make menuconfig

Enable WCHAR support, under Toolchain

WCHAR support

Enable python or python3, under Target packages, Interpreter languages and scripting


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

ping www.google.com