Buildroot

The Buildroot project website is at http://buildroot.org.

Current versions of Buildroot are capable of building a toolchain, a bootloader (U-Boot, Barebox, GRUB2, or Gummiboot), a kernel, and a root filesystem. It uses GNU make as the principal build tool.

There is good online documentation at http://buildroot.org/docs.html, including The Buildroot User Manual.

Buildroot was one of the first build systems. It began as part of the uClinux and uClibc projects as a way of generating a small root filesystem for testing. It became a separate project in late 2001 and continued to evolve through to 2006, after which it went into a rather dormant phase. However, since 2009, when Peter Korsgaard took over stewardship, it has been developing rapidly, adding support for glibc-based toolchains and the ability to build a bootloader and a kernel.

Buildroot is also the foundation of another popular build system, OpenWrt (http://wiki.openwrt.org) which forked from Buildroot around 2004. The primary focus of OpenWrt is to produce software for wireless routers and so the package mix is oriented towards networking infrastructure. It also has a runtime package manager using the .ipk format so that a device can be updated or upgraded without a complete re-flash of the image.

The Buildroot developers produce stable releases four times a year, in February, May, August, and November. They are marked by git tags of the form <year>.02, <year>.05, <year>.08, and <year>.11. Typically, when you start your project, you will be using the latest stable release. However, the stable releases are seldom updated after release. To get security fixes and other bug fixes you will have to either continually update to the next stable release as they become available or backport the fixes into your version.

As usual, you can install Buildroot either by cloning the repository or downloading an archive. Here is an example of obtaining version 2015.08.1, which was the latest stable version at the time of writing:

The equivalent TAR archive is available from http://buildroot.org/downloads.

Next, you should read the section titled System Requirement from The Buildroot User Manual, available at http://buildroot.org/downloads/manual/manual.html and make sure that you have installed all the packages listed there.

Buildroot uses the Kconfig and Kbuild mechanisms as the kernel, which I described in the section Understanding kernel configuration in Chapter 4, Porting and Configuring the Kernel. You can configure it from scratch directly using make menuconfig (or xconfig or gconfig), or you can choose one of the 90 or so configurations for various development boards and the QEMU emulator which you can find stored in the directory configs/. Typing make help lists all the targets including the default configurations.

Let's begin by building a default configuration that you can run on the ARM QEMU emulator:

$ cd buildroot
$ make qemu_arm_versatile_defconfig
$ make

The build will take half an hour to an hour, depending on the capabilities of your host system and the speed of your link to the Internet. When it is complete, you will find that two new directories have been created:

You will see the following in output/:

Some of the sample configurations have a corresponding entry in the directory boards/, which contains custom configuration files and information about installing the results on the target. In the case of the system you have just built, the relevant file is board/qemu/arm-vexpress/readme.txt, which tells you how to start QEMU with this target.

Assuming that you have already installed qemu-system-arm as described in Chapter 1, Starting Out, you can run it using this command:

$ qemu-system-arm -M vexpress-a9 -m 256 \
-kernel output/images/zImage \
-dtb output/images/vexpress-v2p-ca9.dtb \
-drive file=output/images/rootfs.ext2,if=sd \
-append "console=ttyAMA0,115200 root=/dev/mmcblk0" \
-serial stdio -net nic,model=lan9118 -net user

You should see the kernel boot messages appear in the same terminal window where you started QEMU, followed by a login prompt:

Log in as root, no password.

You will see that QEMU launches a black window in addition to the one with the kernel boot messages. It is there to display the graphics frame buffer of the target. In this case, the target never writes to the framebuffer, which is why it appears black. To close QEMU, either type poweroff at the root prompt or just close the framebuffer window. This works with QEMU 2.0 (default on Ubuntu 14.04), but fails with earlier versions including QEMU 1.0.50 (default on Ubuntu 12.04) because of problems with the SCSI emulation.

Next, let's use Buildroot to create a BSP for our Nova board, using the same versions of U-Boot and Linux from earlier chapters. The recommended places to store your changes are:

We can use the BeagleBone configuration file as a base, since Nova is a close cousin:

Now the .config file is set for BeagleBone. Next, create a directory for the board configuration:

Suppose that there are some programs that you have developed that you want to include in the build. You have two options: firstly to build them separately, using their own build systems, and then roll the binary into the final build as an overlay. Secondly you could create a Buildroot package that can be selected from the menu and built like any other.

Buildroot packages are stored in the package directory, over 1,000 of them, each in its own subdirectory. A package consists of at least two files: Config.in, containing the snippet of Kconfig code required to make the package visible in the configuration menu, and a makefile named <package_name>.mk. Note that the package does not contain the code, just the instructions to get the code by downloading a tarball, doing a git pull, and so on.

The makefile is written in a format expected by Buildroot and contains directives that allow Buildroot to download, configure, compile, and install the program. Writing a new package makefile is a complex operation which is covered in detail in the Buildroot User Manual. Here is an example which shows you how to create a package for a simple program stored locally, such as our helloworld program.

Begin by creating the subdirectory package/helloworld with a configuration file, Config.in, that looks like this:

The first line must be of the format BR2_PACKAGE_<uppercase package name>. That is followed by a Boolean and the package name as it will appear in the configuration menu and which will allow a user to select this package. The Help section is optional (but hopefully useful).

Next, link the new package into the Target Packages menu by editing package/Config.in and sourcing the configuration file as mentioned in the preceding section. You could append this to an existing sub-menu but, in this case, it seems neater to create a new sub-menu which only contains our package:

Then, create a makefile, package/helloworld/helloworld.mk, to supply the data needed by Buildroot:

The location of the code is hard-coded to a local path name. In a more realistic case, you would get the code from a source code system or from a central server of some kind: there are details of how to do this in the Buildroot User Guide and plenty of examples in other packages.

Buildroot is based on open source software, as are the packages it compiles. At some point during the project, you should check the licenses, which you can do by running:

The information is gathered into output/legal-info. There are summaries of the licenses used to compile the host tools in host-manifest.csv and, on the target, in manifest.csv. There is more information in the README file and in the Buildroot User Manual.