Embedded Apprentice Linux Engineer
Getting started with
Buildroot
Thomas Petazzoni
[Link]@[Link]
© Copyright 2004-2018, Bootlin.
Creative Commons BY-SA 3.0 license.
embedded Linux and kernel engineering
Corrections, suggestions, contributions and translations are welcome!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 1/1
Thomas Petazzoni
▶ Embedded Linux engineer at Bootlin
▶ Embedded Linux expertise
▶ Development, consulting and training
▶ Strong open-source focus
▶ Freely available training materials
▶ Open-source contributor
▶ Living in Toulouse, France
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 2/1
Building an embedded Linux system
+ Readily available
- Large, usually 100+ MB
- Not available for all architectures
- Not easy to customize
- Generally require native compilation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 3/1
Building an embedded Linux system
+ Smaller and flexible
- Very hard to handle cross-compilation and dependencies
- Not reproducible
- No benefit from other people’s work
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 3/1
Building an embedded Linux system
+ Small and flexible
+ Reproducible, handles cross-compilation and dependencies
+ Available for virtually all architectures
- One tool to learn
- Build time
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 3/1
Embedded Linux build system: principle
▶ Building from source → lot of flexibility
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 4/1
Embedded Linux build system: principle
▶ Building from source → lot of flexibility
▶ Cross-compilation → leveraging fast build machines
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 4/1
Embedded Linux build system: principle
▶ Building from source → lot of flexibility
▶ Cross-compilation → leveraging fast build machines
▶ Recipes for building components → easy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 4/1
Buildroot at a glance
▶ Is an embedded Linux build system, builds from source:
▶ cross-compilation toolchain
▶ root filesystem with many libraries/applications, cross-built
▶ kernel and bootloader images
▶ Fast, simple root filesystem in minutes
▶ Easy to use and understand: kconfig and make
▶ Small root filesystem, default 2 MB
▶ More than 2300 packages available
▶ Generates filesystem images, not a distribution
▶ Vendor neutral
▶ Active community, stable releases every 3 months
▶ Started in 2001, oldest still maintained build system
▶ [Link]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 5/1
Getting started
$ git clone git://[Link]/buildroot
$ cd buildroot
$ make menuconfig
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 6/1
Buildroot configuration
1. Target architecture
▶ Architecture
ARC, ARM, AArch64, Blackfin, csky, m68k,
Microblaze, MIPS(64), NIOS II, OpenRisc,
PowerPC(64), SuperH, SPARC, x86, x86_64,
Xtensa
▶ Specific processor
▶ ABI
▶ Floating point strategy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
2. Build options
▶ Download directory
▶ Number of parallel jobs
▶ Use of ccache
▶ Shared or static libraries
▶ etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
2. Build options ▶ Buildroot toolchain
3. Toolchain ▶ Buildroot builds the toolchain
▶ uClibc, glibc, musl
▶ External toolchain
▶ Uses a pre-built toolchain
▶ Profiles for existing popular toolchains
Linaro, Sourcery CodeBench, etc.
▶ Custom toolchains
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
2. Build options ▶ Init system to use: BusyBox, Sysvinit, Systemd
3. Toolchain ▶ /dev management solution: static, devtmpfs,
4. System configuration mdev, udev
▶ Hostname, password, getty terminal, etc.
▶ Root filesystem overlay
▶ Custom post build and post image scripts
▶ etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
2. Build options
3. Toolchain
▶ Kernel source (stable version, Git tree, patches)
4. System configuration
▶ Kernel configuration
5. Kernel
▶ Support for kernel extensions: RTAI, Xenomai,
aufs, etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
▶ More than 2300 packages
2. Build options
▶ Qt4, Qt5, [Link], Gtk, EFL
3. Toolchain
▶ GStreamer, ffmpeg
4. System configuration
▶ Python, Perl, Ruby, Lua, Erlang
5. Kernel
▶ Samba, OpenSSL, OpenSSH, dropbear,
6. Target packages
lighttpd
▶ OpenGL support for various platforms
▶ And many, many more libraries and utilities
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
▶ Major filesystem formats supported
1. Target architecture
▶ cloop
2. Build options
▶ cpio, for kernel initramfs
3. Toolchain
▶ cramfs
4. System configuration
▶ ext2/3/4
5. Kernel
▶ jffs2
6. Target packages
▶ romfs
7. Filesystem images
▶ squashfs
▶ tar
▶ ubifs
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
2. Build options
▶ Grub2
3. Toolchain
▶ Syslinux
4. System configuration
▶ U-Boot
5. Kernel
▶ Barebox
6. Target packages
▶ and more platform-specific bootloaders:
7. Filesystem images
imx-bootlets, at91bootstrap, etc.
8. Bootloaders
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Buildroot configuration
1. Target architecture
2. Build options
3. Toolchain
4. System configuration
▶ Allows to build some native tools, useful for
5. Kernel
development.
6. Target packages
7. Filesystem images
8. Bootloaders
9. Host utilities
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 7/1
Building and using
▶ To start the build: make
▶ Results in output/images:
▶ rootfs.ext4, root filesystem in ext4 format
▶ zImage, Linux kernel image
▶ [Link], Linux kernel Device Tree blob
▶ [Link], U-Boot bootloader image
▶ MLO, U-Boot bootloader image
▶ Ready to be flashed on your embedded system.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 8/1
Exploring the build output
▶ All the output produced by Buildroot is stored in output/
▶ Can be customized using O= for out-of-tree build
▶ output/ contains
▶ output/build, with one sub-directory for the source code of each component
▶ output/host, which contains all native utilities needed for the build, including the
cross-compiler
▶ output/host/<tuple>/sysroot, which contains all the headers and libraries built
for the target
▶ output/target, which contains almost the target root filesystem
▶ output/images, the final images
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 9/1
Summarized build process
1. Check core dependencies
2. For each selected package, after taking care of its dependencies: download,
extract, patch, configure, build, install
▶ To target/ for target apps and libs
▶ To host/<tuple>/sysroot for target libs
▶ To host/ for native apps and libs
▶ Filesystem skeleton and toolchain are handled as regular packages
3. Copy rootfs overlay
4. Call post build scripts
5. Generate the root filesystem image
6. Call post image scripts
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 10/1
Customizing the build
Besides the existing packages and options, there are multiple ways to customize the
generated root filesystem:
▶ Create custom post-build and/or post-image scripts
▶ Use a root filesystem overlay, recommended to add all your config files
▶ Add your own packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 11/1
Adding a new package: [Link]
package/libmicrohttpd/[Link]
config BR2_PACKAGE_LIBMICROHTTPD
bool "libmicrohttpd"
depends on BR2_TOOLCHAIN_HAS_THREADS
help
GNU libmicrohttpd is a small C library that makes it easy to
run an HTTP server as part of another application.
[Link]
comment "libmicrohttpd needs a toolchain w/ threads"
depends on !BR2_TOOLCHAIN_HAS_THREADS
package/[Link]
[...]
source "package/libmicrohttpd/[Link]"
[...]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 12/1
Adding a new package: <pkg>.mk, <pkg>.hash
package/libmicrohttpd/[Link]
LIBMICROHTTPD_VERSION = 0.9.59
LIBMICROHTTPD_SITE = $(BR2_GNU_MIRROR)/libmicrohttpd
LIBMICROHTTPD_LICENSE = LGPL-2.1+
LIBMICROHTTPD_LICENSE_FILES = COPYING
LIBMICROHTTPD_INSTALL_STAGING = YES
LIBMICROHTTPD_CONF_OPT = --disable-curl --disable-examples
$(eval $(autotools-package))
package/libmicrohttpd/[Link]
# Locally calculated
sha256 9b9ccd7d0b11b0e17... [Link]
sha256 70e12e2a60151b9ed... COPYING
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 13/1
Adding a new package: infrastructures
▶ In order to factorize similar behavior between packages using the same build
mechanism, Buildroot has package infrastructures
▶ autotools-package for autoconf/automake based packages
▶ cmake-package for CMake based packages
▶ python-package for Python Distutils and Setuptools based packages
▶ generic-package for non-standard build systems
▶ And more: luarocks-package, perl-package, rebar-package,
kconfig-package, etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 14/1
Defconfigs
▶ Pre-defined configurations for popular platforms
▶ They build a minimal system for the platform
▶ make <foobar>_defconfig to load one of them
▶ Some of the configs
▶ Raspberry
▶ BeagleBone
▶ CubieBoard
▶ PandaBoard
▶ Many Atmel development boards
▶ Several Freescale i.MX6 boards
▶ Many QEMU configurations
▶ and more...
▶ make list-defconfigs for the full list
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 15/1
Buildroot design principles
▶ Cross-compilation only: no support for doing development on the target.
▶ No package management system: Buildroot doesn’t generate a distribution,
but a firmware
▶ Don’t be smart: if you do a change in the configuration and restarts the build,
Buildroot doesn’t try to be smart. Only a full rebuild will guarantee the correct
result.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 16/1
Documentation and support
▶ Extensive manual: [Link]
▶ 3-day training course, with freely available materials:
[Link]
▶ Mailing list: [Link]
▶ IRC channel: buildroot on Freenode
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 17/1
Today’s lab
▶ Step 1: do a minimal build for the PocketBeagle, with just a bootloader, Linux
kernel and minimal root filesystem. Generate a ready-to-use SD card image.
▶ Step 2: enable network over USB and SSH connectivity using Dropbear. Shows
how to use a rootfs overlay and how to add packages.
▶ Step 3: customize the Linux kernel configuration, compile a small application
that uses the GPIO, first manually, and then using a new Buildroot package
▶ Follow the instructions at [Link]
ale/Slides/blob/master/buildroot/[Link]
▶ Don’t hesitate to request help and ask questions!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - [Link] 18/1