Buildroot
Buildroot
Buildroot: a nice,
simple and efficient
embedded Linux build
system
Thomas Petazzoni
Free Electrons
thomas.petazzoni@free-electrons.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1/50
Thomas Petazzoni
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 2/50
Building embedded Linux systems
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 3/50
Buildroot main characteristics
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 4/50
Buildroot vs. OpenEmbedded/Yocto
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 5/50
Context: quick Buildroot history
December 2001
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 6/50
Context: quick Buildroot history
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 7/50
Context: quick Buildroot history
January 2009
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 8/50
Context: quick Buildroot history
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 10/50
Buildroot: general principle
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 11/50
Using Buildroot
$ wget http://buildroot.org/downloads/buildroot-2012.05.tar.bz2
$ tar xjf buildroot-2012.05.tar.bz2
$ cd buildroot-2012.05
$ make [menu|x|n|g]config
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 12/50
Buildroot menuconfig
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 13/50
Target architecture
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 14/50
Build options
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 15/50
Toolchain
Buildroot provides three toolchain back-ends:
I An internal Buildroot toolchain back-end, which has been
available since Buildroot’s creation. Buildroot will directly
build a uClibc toolchain and use it for cross-compiling all
packages.
I An external toolchain back-end, which allows use existing
pre-built uClibc, glibc or eglibc toolchains, such as Sourcery
CodeBench toolchains, Linaro toolchains, or toolchains that
have previously been built using Crosstool-NG or Buildroot.
Using an external toolchain removes the toolchain build time.
I A Crosstool-NG back-end, which tells Buildroot to build a
cross-compiling toolchain with Crosstool-NG. This allows to
benefit from all Crosstool-NG advantages, such as support for
glibc or eglibc.
→ Buildroot often had the reputation of being limited to uClibc,
but it is no longer the case, for several years now.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 16/50
System configuration
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 17/50
Packages
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 18/50
Packages
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 19/50
Filesystem images
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 20/50
Kernel and bootloader
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 21/50
Building
$ make
...
$ ls output/images/
dataflash_at91sam9m10g45ek.bin rootfs.tar
rootfs.ubi rootfs.ubifs
u-boot.bin u-boot-env.bin
uImage
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 22/50
Build output (1/2)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 23/50
Build output (2/2)
I ...
I stamps, a few stamp files used internally by Buildroot to keep
track of what has been built
I target, the target root filesystem (but with an empty /dev
and invalid permissions, those are fixed using fakeroot in the
final image)
I toolchain, where the different toolchain components are built
in the case of the internal back-end. Otherwise unused.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 24/50
Build-time: basic examples
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 25/50
Build time: real-world example 1
ALL
pppd picocom logrotate rootfs-jffs2 rootfs-tar busybox dropbear my-application strace linux26
libxml2 host-libxslt qt
host-mtd host-libxml2
host-automake
host-autoconf
host-m4 host-libtool
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 27/50
Build time: real-world example 2
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 28/50
Dependencies: real-world example 2
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 29/50
Overall logic: preparation
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 30/50
Overall logic: toolchain
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 31/50
Overall logic: packages (1/2)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 32/50
Overall logic: packages (2/2)
I ...
I The package source code is extracted in
build/<pkg>-<version>/, and stamp files are created after
each step to let Buildroot know of what has already been
done. Commands like make <foo>-reconfigure and
make <foo>-rebuild allow to restart the build of a package
if needed.
I Host packages are installed in host/, while target packages
are installed in target/ (usually stripped, no headers).
Target libraries are also installed in
host/usr/<tuple>/sysroot so that they are found by the
cross-compiler (unstripped, with headers and static libraries)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 33/50
Overall logic: root filesystem image
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 34/50
Source code organization
I board, board-specific
patches and configuration
I package, all user-space
files packages (for the host and
the target)
I boot, bootloaders recipes
I support, misc scripts and
I configs, default tools
configuration files for various
platforms. Same concept as
I target, legacy, almost
kernel defconfigs empty directory
I docs
I toolchain, toolchain
handling code (build recipes
I fs, recipes for generating for internal and
root filesystem images in Crosstool-NG back-ends,
various formats, and also integration recipes for
root filesystem skeleton in external toolchains)
fs/skeleton
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 35/50
Adding packages: configuration
http://foo-project.org
source "package/foo/Config.in"
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 36/50
Adding packages: writing the recipe
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 37/50
Adding packages: minimal recipe
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 38/50
Adding packages: various source methods
From Git
FOO_VERSION = this-branch
FOO_SITE = git://git.foo-project.org/foo.git
From Subversion
FOO_VERSION = 12345
FOO_SITE = http://foo-project.org/svn/foo/trunk/
FOO_SITE_METHOD = svn
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 39/50
Packages: GENTARGETS
For packages that use a special build system (not autotools, not
CMake).
FOO_VERSION = 1.3
FOO_SOURCE = foo-$(FOO_VERSION).tar.bz2
FOO_SITE = http://foo-project.org/downloads
FOO_DEPENDENCIES = zlib
define FOO_CONFIGURE_CMDS
echo "HAS_ZLIB=YES" >> $(@D)/config
endef
define FOO_BUILD_CMDS
$(MAKE) -C $(@D) \
CC="$(TARGET_CC)" CFLAGS="$(TARGET_CFLAGS)" \
all
endef
define FOO_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/foo $(TARGET_DIR)/usr/bin
endef
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 40/50
Packages: other important mechanisms
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 41/50
Buildroot simplicity
I After a configuration modification, Buildroot does not even
try to apply the configuration changes during the next
make invocation.
I Tracking the consequences of configuration modifications is
very complicated (when a toolchain setting is changed
everything need to be rebuilt; when a library is removed, all
reverse dependencies needs to be rebuilt)
I Buildroot remains simple: it simply executes the build
procedure of the selected packages, and does not try to
track the files installed by each package.
I Relies on the user’s knowledge about the configuration
change to know what needs to be done. Since building is very
fast, full rebuilds are not problematic.
I This focus on simplicity is a very strong design decision of
Buildroot. Some features, such as binary packages generation,
are not implemented in order to keep the build system simple.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 42/50
Customizing for a project
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 44/50
autobuild.buildroot.org
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 45/50
Future directions
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 46/50
References
I Website: http://buildroot.org
I Mailing-list: buildroot@uclibc.org
http://buildroot.org/lists.html
I IRC channel: #buildroot on Freenode
I Bug tracker: https://bugs.uclibc.org
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 47/50
Buildroot tutorial at Libre Software Meeting
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 48/50
Conclusion
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 49/50
Questions?
Thomas Petazzoni
thomas.petazzoni@free-electrons.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 50/50