Using Buildroot For Real Projects: Thomas Petazzoni Free Electrons Thomas - Petazzoni@free
Using Buildroot For Real Projects: Thomas Petazzoni Free Electrons Thomas - Petazzoni@free
Using Buildroot For Real Projects: Thomas Petazzoni Free Electrons Thomas - Petazzoni@free
Using Buildroot
for real projects
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
Thomas Petazzoni
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Agenda
I What is Buildroot ?
I How does it work ?
I Example systems generated by Buildroot
I Recommendations for real projects
I Toolchain recommendations
I Project specific configuration and files
I Project specific packages
I Enabling application developers
I Misc best practices
I Features in 2011.11 making things better
I Conclusion
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
What is Buildroot ? (1/2)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
What is Buildroot ? (2/2)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Basic usage (1/2)
$ make menuconfig
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Basic usage (2/2)
$ make
...
...
...
$ ls output/images/
dataflash_at91sam9m10g45ek.bin rootfs.tar
rootfs.ubi rootfs.ubifs
u-boot.bin u-boot-env.bin
uImage
Ready to use !
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
How does it work ?
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Top-level source code organization (1/2)
I board/
contains hardware-specific and project-specific files. Covered
later.
I boot/
contains config options and recipes for various bootloaders
I configs/
the default configurations. Covered later.
I docs/
Yes, we have some documentation.
I fs/
contains config options and makefiles to generate the various
filesystem images (jffs2, ubifs, ext2, iso9660, initramfs, tar
and more). Also contains the root filesystem skeleton
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Top-level source code organization (2/2)
I linux/
contains the config options and makefile to generate the Linux
kernel, and also the kernel part of real-time extensions
(Xenomai, RTAI, etc.)
I package/
contains the config options and makefiles for all userspace
packages
I support/
various misc stuff needed for the build (kconfig code, etc.)
I target/
mostly historic directory. No longer contains anything useful
besides the default device table.
I toolchain/
config options and makefiles to build or import the toolchain
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
What does it generate?
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Example 1: Multi-function device
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Toolchain
Three choices:
I Buildroot builds a toolchain. This is limited to uClibc based
toolchains, and the toolchain is rebuilt completely at every
complete Buildroot rebuild.
I Buildroot uses crosstool-NG as a back-end to generate the
toolchain. More choices available (glibc, eglibc, uClibc
supported, more gcc versions, etc.). However, requires
toolchain rebuild at every complete Buildroot rebuild.
I Buildroot can import external toolchains. This is definitely
the mechanism I recommend.
I Allows to re-use CodeSourcery toolchains, or custom
toolchains built with crosstool-NG or Buildroot
I Importing the toolchain into Buildroot takes just a few
seconds, which saves the toolchain build time at every
Buildroot rebuild
I The toolchain rarely needs to be changed compared to the
root filesystem, so this mechanism makes sense
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
External toolchains: toolchain profile
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
External toolchains: custom toolchain
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
External toolchains HOWTO
I As a custom toolchain
I Or by adding a new profile so that the toolchain gets
downloaded automatically and all its configuration is already
known to Buildroot
I This way, users of the Buildroot environment don’t have to
worry about the toolchain and don’t have to wait for it to
build.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Project specific files
board/<company>/<project>/
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Kernel and bootloader changes
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Kernel and bootloaders example (1/2)
$ ls board/<company>/<project>/
linux-2.6.39.config samba-script.tcl
linux-2.6.39-patches/ u-boot-1.3.4-patches/
at91bootstrap-1.16-patches/
$ ls board/<company>/<project>/linux-2.6.39-patches/
linux-0001-foobar.patch linux-0002-barfoo.patch
$ ls board/<company>/<project>/u-boot-1.3.4-patches/
u-boot-0001-barfoo.patch u-boot-0002-foobar.patch
$ ls board/<company>/<project>/at91bootstrap-1.16-patches/
at91bootstrap-0001-bleh.patch at91bootstrap-0002-blah.patch
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Kernel and bootloaders example (2/2)
BR2_TARGET_UBOOT=y
BR2_TARGET_UBOOT_BOARDNAME="company_project"
BR2_TARGET_UBOOT_1_3_4=y
BR2_TARGET_UBOOT_CUSTOM_PATCH_DIR=
"board/company/project/u-boot-1.3.4-patches/"
# BR2_TARGET_UBOOT_NETWORK is not set
BR2_TARGET_AT91BOOTSTRAP=y
BR2_TARGET_AT91BOOTSTRAP_BOARD="at91sam9m10g45ek"
BR2_TARGET_AT91BOOTSTRAP_CUSTOM_PATCH_DIR=
"board/company/project/at91bootstrap-1.16-patches/"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="2.6.39"
BR2_LINUX_KERNEL_PATCH=
"board/company/project/linux-2.6.39-patches/"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=
"board/company/project/linux-2.6.39.config"
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Root filesystem customization (1/3)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Root filesystem customization (2/3)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Root filesystem customization (3/3)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Root filesystem customization: example script
TARGETDIR=$1
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
/dev managament
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Project-specific packages (1/5)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Project-specific packages (3/5)
To create the .mk file, three infrastructures are available:
I The AUTOTARGETS infrastructure, for autotools-based
packages.
You describe the tarball URL and version, the dependencies
and configuration options, and Buildroot does all the rest.
I The CMAKETARGETS infrastructure, for CMake-based
packages.
Here as well, Buildroot does most of the work.
I The GENTARGETS infrastructure, for other packages not
using a well-known build system.
Here, Buildroot has no knowledge of the build system, so you
have to specify what needs to be done to configure, build and
install the component.
See the Buildroot documentation for more details on using these
package infrastructures.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Project-specific packages (4/5)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Project-specific packages (5/5)
MY_APPLICATION_VERSION = 1.0
MY_APPLICATION_DEPENDENCIES = \
qextserialport host-pkg-config
define MY_APPLICATION_EXTRACT_CMDS
cp -a $(TOPDIR)/../company-application/* $(@D)/
endef
define MY_APPLICATION_INSTALL_TARGET_CMDS
cp $(@D)/myapp $(BINARIES_DIR)
endef
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
During application development
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Using Buildroot to build external components
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Using Buildroot to build external components
A simple application
BRPATH/output/host/usr/bin/arm-unknown-linux-gcc -o prog prog.c
$(BRPATH/output/host/usr/bin/pkg-config --libs --cflags glib-2.0)
Autotools component
export PATH=$PATH:BRPATH/output/host/usr/bin/
./configure --host=arm-unknown-linux
CMake component
cmake -DCMAKE_TOOLCHAIN_FILE=BRPATH/output/toolchainfile.cmake
make
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Forcing Buildroot to rebuild a package
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Using NFS during application development
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Storing the project configuration
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Summarizing the project-specific bits
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Be prepared for offline builds
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
In 2011.11: local method
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
In 2011.11: source directory override
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
In 2011.11: other features
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Conclusion
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Questions?
Thomas Petazzoni
[email protected]
Special thanks to the Buildroot community, including Peter Korsgaard, Baruch Siach,
Thomas de Schampheleire, Arnout Vandecappelle and Will Moore for their comments
and suggestions on this presentation.
Slides under CC-BY-SA 3.0.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com