Buildroot stm32 Slides
Buildroot stm32 Slides
Corrections, suggestions, contributions and translations are welcome! embedded Linux and kernel engineering
Send them to [email protected]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/340
Buildroot system development training
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/340
About Bootlin
About Bootlin
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/340
Bootlin introduction
▶ Engineering company
• In business since 2004
• Before 2018: Free Electrons
▶ Team based in France and Italy
▶ Serving customers worldwide
▶ Highly focused and recognized expertise
• Embedded Linux
• Linux kernel
• Embedded Linux build systems
▶ Strong open-source contributor
▶ Activities
• Engineering services
• Training courses
▶ https://bootlin.com
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/340
Bootlin engineering services
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/340
Bootlin training courses
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/340
Bootlin, an open-source contributor
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/340
Bootlin on-line resources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/340
Generic course information
Generic course
information
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/340
Supported hardware
Discovery Kits from STMicroelectronics: STM32MP157A-DK1, STM32MP157D-DK1,
STM32MP157C-DK2 or STM32MP157F-DK2
▶ STM32MP157 (Dual Cortex-A7 + Cortex-M4) CPU
from STMicroelectronics
▶ 512 MB DDR3L RAM
▶ Gigabit Ethernet port
▶ 4 USB 2.0 host ports, 1 USB-C OTG port
▶ 1 Micro SD slot
▶ On-board ST-LINK/V2-1 debugger
▶ Misc: buttons, LEDs, audio codec
▶ LCD touchscreen (DK2 only)
▶ Currently sold at 72 EUR + VAT (DK1) and 113 EUR DK1 Discovery Kit
+ VAT (DK2) at Mouser
Board and CPU documentation, design files, software: A-DK1, D-DK1, C-DK2, F-DK2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/340
Shopping list: hardware for this course
▶ MicroSD card
1
https://www.olimex.com/Products/Modules/Sensors/MOD-WII/MOD-Wii-UEXT-NUNCHUCK/
2
https://www.olimex.com/Products/Breadboarding/JUMPER-WIRES/JW-110x10/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/340
Training quiz and certificate
▶ You have been given a quiz to test your knowledge on the topics covered by the
course. That’s not too late to take it if you haven’t done it yet!
▶ At the end of the course, we will submit this quiz to you again. That time, you
will see the correct answers.
▶ It allows Bootlin to assess your progress thanks to the course. That’s also a kind
of challenge, to look for clues throughout the lectures and labs / demos, as all the
answers are in the course!
▶ Another reason is that we only give training certificates to people who achieve at
least a 50% score in the final quiz and who attended all the sessions.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/340
Participate!
During the lectures...
▶ Don’t hesitate to ask questions. Other people in the audience may have similar
questions too.
▶ Don’t hesitate to share your experience too, for example to compare Linux with
other operating systems you know.
▶ Your point of view is most valuable, because it can be similar to your colleagues’
and different from the trainer’s.
▶ In on-line sessions
• Please keep your camera on too if you have one.
• Also make sure your name is properly filled.
• If Jitsi Meet is used, you can also use the ”Raise your hand” button when you wish
to ask a question but don’t want to interrupt.
▶ All this helps the trainer to engage with participants, see when something needs
clarifying and make the session more interactive, enjoyable and useful for everyone.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 13/340
Collaborate!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/340
Practical lab - Training Setup
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/340
Introduction to Embedded Linux
Introduction to
Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/340
Simplified Linux system architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/340
Overall Linux boot sequence
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/340
Embedded Linux work
▶ BSP work: porting the bootloader and Linux kernel, developing Linux device
drivers.
▶ system integration work: assembling all the user space components needed for
the system, configure them, develop the upgrade and recovery mechanisms, etc.
▶ application development: write the company-specific applications and libraries.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/340
Complexity of user space integration
ALL
xlib_libXrandr harfbuzz xlib_libXcursor xlib_libXdamage xlib_libXi xlib_libXinerama xproto_xcmiscproto xlib_libXres xlib_libXxf86vm xproto_xf86dgaproto mcookie xdata_xbitmaps xproto_bigreqsproto xproto_compositeproto xproto_glproto xkeyboard-config xproto_videoproto xlib_libxkbfile
xproto_randrproto cairo xproto_damageproto xlib_libXfixes xlib_libXft xproto_xineramaproto xproto_resourceproto xproto_xf86vidmodeproto host-xapp_xkbcomp xfont_font-cursor-misc xfont_font-misc-misc xfont_font-alias
xlib_libXrender xproto_fixesproto gdk-pixbuf fontconfig xlib_libXext host-xlib_libxkbfile host-xapp_mkfontdir host-xapp_bdftopcf host-xfont_font-util xfont_font-util
glibc host-gdk-pixbuf xproto_xf86bigfontproto xproto_xextproto xproto_inputproto xproto_kbproto freetype libxcb xlib_xtrans host-libxcb xfont_encodings xproto_fontsproto host-xproto_xf86bigfontproto host-xproto_inputproto host-xproto_kbproto host-xproto_xextproto host-xlib_xtrans host-xfont_encodings host-xproto_fontsproto
linux-headers host-gcc-initial host-gawk host-libglib2 libpng libpthread-stubs xcb-proto host-xcb-proto host-intltool xlib_libfontenc xlib_libXdmcp xlib_libXau host-libxslt host-libpthread-stubs host-xapp_mkfontscale xproto_presentproto
host-binutils libffi host-libffi host-gettext host-libpng zlib host-python host-libxml-parser-perl xproto_xproto xutil_util-macros host-libxml2 host-freetype host-xlib_libfontenc host-xlib_libXau host-xlib_libXdmcp
host-gmp host-libtool
host-m4
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/340
System integration: several possibilities
Pros Cons
Building everything manually Full flexibility Dependency hell
Learning experience Need to understand a lot of details
Version compatibility
Lack of reproducibility
Binary distribution Easy to create and extend Hard to customize
Debian, Ubuntu, Fedora, etc. Hard to optimize (boot time, size)
Hard to rebuild the full system from source
Large system
Uses native compilation (slow)
No well-defined mechanism to generate an
image
Lots of mandatory dependencies
Not available for all architectures
Build systems Nearly full flexibility Not as easy as a binary distribution
Buildroot, Yocto, PTXdist, etc. Built from source: customization and op- Build time
timization are easy
Fully reproducible
Uses cross-compilation
Have embedded specific packages not nec-
essarily in desktop distros
Make more features optional
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/340
Embedded Linux build system: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/340
Embedded Linux build system: tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/340
Introduction to Buildroot
Introduction to
Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/340
Buildroot at a glance
▶ Can build a toolchain, a rootfs, a kernel, a bootloader
▶ Easy to configure: menuconfig, xconfig, etc.
▶ Fast: builds a simple root filesystem in a few minutes
▶ Easy to understand: written in make, extensive documentation
▶ Small root filesystem, starting at 2 MB
▶ 2800+ packages for user space libraries/apps available
▶ Many architectures supported
▶ Well-known technologies: make and kconfig
▶ Vendor neutral
▶ Active community, regular releases
• The present slides cover Buildroot 2022.02. There may be some differences if you
use older or newer Buildroot versions.
▶ https://buildroot.org
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/340
Buildroot design goals
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/340
Who’s using Buildroot?
▶ System makers
• SpaceX
• Tesla
• GoPro
• Barco
• Rockwell Collins
▶ Processor vendors
• Marvell
• Microchip
• Rockchip
▶ SoM and board vendors
▶ Many companies when doing R&D on products
▶ Many, many hobbyists on development
boards: Raspberry Pi, BeagleBone Black, etc.
Getting Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/340
Using Buildroot
▶ Implemented in make
• With a few helper shell scripts
▶ All interaction happens by calling make in the main Buildroot sources directory.
$ cd buildroot/
$ make help
▶ No need to run as root, Buildroot is designed to be executed with normal user
privileges.
• Running as root is even strongly discouraged!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 29/340
Configuring Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 30/340
Main menuconfig menu
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 31/340
Running the build
▶ As simple as:
$ make
▶ Often useful to keep a log of the build output, for analysis or investigation:
$ ./utils/brmake
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 32/340
Build results
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 33/340
Practical lab - Basic Buildroot usage
▶ Get Buildroot
▶ Configure a minimal system with Buildroot for
the target hardware
▶ Do the build
▶ Prepare the target hardware for usage
▶ Flash and test the generated system
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 34/340
Managing the build and the configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 35/340
Default build organization
▶ All the build output goes into a directory called output/ within the top-level
Buildroot source directory.
• O = output
▶ The configuration file is stored as .config in the top-level Buildroot source
directory.
• CONFIG_DIR = $(TOPDIR)
• TOPDIR = $(shell pwd)
▶ buildroot/
• .config
• arch/
• package/
• output/
• fs/
• ...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 36/340
Out of tree build: introduction
▶ Out of tree build allows to use an output directory different than output/
▶ Useful to build different Buildroot configurations from the same source tree.
▶ Customization of the output directory done by passing O=/path/to/directory on
the command line.
▶ Configuration file stored inside the $(O) directory, as opposed to inside the
Buildroot sources for the in-tree build case.
▶ project/
• buildroot/, Buildroot sources
• foo-output/, output of a first project
.config
• bar-output/, output of a second project
.config
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 37/340
Out of tree build: using
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 38/340
Out of tree build: example
1. You are in your Buildroot source tree:
$ ls
arch board boot ... Makefile ... package ...
4. Start the build (passing O= and -C no longer needed thanks to the wrapper):
$ make
5. Adjust the configuration again, restart the build, clean the build:
$ make menuconfig
$ make
$ make clean
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 39/340
Full config file vs. defconfig
▶ The .config file is a full config file: it contains the value for all options (except
those having unmet dependencies)
▶ The default .config, without any customization, has 4467 lines (as of Buildroot
2021.02)
• Not very practical for reading and modifying by humans.
▶ A defconfig stores only the values for options for which the non-default value is
chosen.
• Much easier to read
• Can be modified by humans
• Can be used for automated construction of configurations
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 40/340
defconfig: example
▶ For the default Buildroot configuration, the defconfig is empty: everything is the
default.
▶ If you change the architecture to be ARM, the defconfig is just one line:
BR2_arm=y
▶ If then you also enable the stress package, the defconfig will be just two lines:
BR2_arm=y
BR2_PACKAGE_STRESS=y
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 41/340
Using and creating a defconfig
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 42/340
Existing defconfigs
▶ Buildroot comes with a number of existing defconfigs for various publicly available
hardware platforms:
• RaspberryPi, BeagleBone Black, CubieBoard, Microchip evaluation boards,
Minnowboard, various i.MX6 boards
• QEMU emulated platforms
▶ List them using make list-defconfigs
▶ Most built-in defconfigs are minimal: only build a toolchain, bootloader, kernel
and minimal root filesystem.
$ make qemu_arm_vexpress_defconfig
$ make
▶ Additional instructions often available in board/<boardname>, e.g.:
board/qemu/arm-vexpess/readme.txt.
▶ Your own defconfigs can obviously be more featureful
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 43/340
Assembling a defconfig (1/2)
▶ defconfigs are trivial text files, one can use simple concatenation to assemble them
from fragments.
platform1.frag
BR2_arm=y
BR2_TOOLCHAIN_BUILDROOT_WCHAR=y
BR2_GCC_VERSION_7_X=y
platform2.frag
BR2_mipsel=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS=y
packages.frag
BR2_PACKAGE_STRESS=y
BR2_PACKAGE_MTD=y
BR2_PACKAGE_LIBCONFIG=y
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 44/340
Assembling a defconfig (2/2)
debug.frag
BR2_ENABLE_DEBUG=y
BR2_PACKAGE_STRACE=y
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 45/340
Other building tips
▶ Cleaning targets
• Cleaning all the build output, but keeping the configuration file:
$ make clean
• Cleaning everything, including the configuration file, and downloaded file if at the
default location:
$ make distclean
▶ Verbose build
• By default, Buildroot hides a number of commands it runs during the build, only
showing the most important ones.
• To get a fully verbose build, pass V=1:
$ make V=1
• Passing V=1 also applies to packages, like the Linux kernel, busybox...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 46/340
Buildroot source and build trees
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 47/340
Buildroot source and build trees
Source tree
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 48/340
Source tree (1/5)
▶ Makefile
• top-level Makefile, handles the configuration and general orchestration of the build
▶ Config.in
• top-level Config.in, main/general options. Includes many other Config.in files
▶ arch/
• Config.in.* files defining the architecture variants (processor type, ABI, floating
point, etc.)
• Config.in, Config.in.arm, Config.in.x86, Config.in.microblaze, etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 49/340
Source tree (2/5)
▶ toolchain/
• packages for generating or using toolchains
• toolchain/ virtual package that depends on either toolchain-buildroot or
toolchain-external
• toolchain-buildroot/ virtual package to build the internal toolchain
• toolchain-external/ virtual package to download/import the external toolchain
▶ system/
• skeleton/ the rootfs skeleton
• Config.in, options for system-wide features like init system, /dev handling, etc.
▶ linux/
• linux.mk, the Linux kernel package
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 50/340
Source tree (3/5)
▶ package/
• all the user space packages (2800+)
• busybox/, gcc/, qt5/, etc.
• pkg-generic.mk, core package infrastructure
• pkg-cmake.mk, pkg-autotools.mk, pkg-perl.mk, etc. Specialized package
infrastructures
▶ fs/
• logic to generate filesystem images in various formats
• common.mk, common logic
• cpio/, ext2/, squashfs/, tar/, ubifs/, etc.
▶ boot/
• bootloader packages
• at91bootstrap3/, barebox/, grub2/, syslinux/, uboot/, etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 51/340
Source tree (4/5)
▶ configs/
• default configuration files for various platforms
• similar to kernel defconfigs
• atmel_xplained_defconfig, beaglebone_defconfig, raspberrypi_defconfig,
etc.
▶ board/
• board-specific files (kernel configuration files, kernel patches, image flashing scripts,
etc.)
• typically go together with a defconfig in configs/
▶ support/
• misc utilities (kconfig code, libtool patches, download helpers, and more.)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 52/340
Source tree (5/5)
▶ utils/
• Various utilities useful to Buildroot developers
• brmake, make wrapper, with logging
• get-developers, to know to whom patches should be sent
• test-pkg, to validate that a package builds properly
• scanpipy, scancpan to generate Python/Perl package .mk files
• ...
▶ docs/
• Buildroot documentation
• Written in AsciiDoc, can generate HTML, PDF, TXT versions: make manual
• ≈135 pages PDF document
• Also available pre-generated online.
• https://buildroot.org/downloads/manual/manual.html
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 53/340
Buildroot source and build trees
Build tree
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 54/340
Build tree: $(O)
▶ output/
▶ Global output directory
▶ Can be customized for out-of-tree build by passing O=<dir>
▶ Variable: O (as passed on the command line)
▶ Variable: BASE_DIR (as an absolute path)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 55/340
Build tree: $(O)/build
▶ output/
• build/
buildroot-config/
busybox-1.22.1/
host-pkgconf-0.8.9/
kmod-1.18/
build-time.log
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 56/340
Build tree: $(O)/host
▶ output/
• host/
lib
bin
sbin
<tuple>/sysroot/bin
<tuple>/sysroot/lib
<tuple>/sysroot/usr/lib
<tuple>/sysroot/usr/bin
• Contains both the tools built for the host (cross-compiler, etc.) and the sysroot of
the toolchain
• Variable: HOST_DIR
• Host tools are directly in host/
• The sysroot is in host/<tuple>/sysroot/usr
• <tuple> is an identifier of the architecture, vendor, operating system, C library and
ABI. E.g: arm-unknown-linux-gnueabihf.
• Variable for the sysroot: STAGING_DIR
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 57/340
Build tree: $(O)/staging
▶ output/
• staging/
• Just a symbolic link to the sysroot, i.e. to host/<tuple>/sysroot/.
• Available for convenience
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 58/340
Build tree: $(O)/target
▶ output/
• target/
bin/
etc/
lib/
usr/bin/
usr/lib/
usr/share/
usr/sbin/
THIS_IS_NOT_YOUR_ROOT_FILESYSTEM
...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 59/340
Build tree: $(O)/images
▶ output/
• images/
zImage
armada-370-mirabox.dtb
rootfs.tar
rootfs.ubi
• Contains the final images: kernel image, bootloader image, root filesystem image(s)
• Variable: BINARIES_DIR
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 60/340
Build tree: $(O)/graphs
▶ output/
• graphs/
• Visualization of Buildroot operation: dependencies between packages, time to build
the different packages
• make graph-depends
• make graph-build
• make graph-size
• Variable: GRAPHS_DIR
• See the section Analyzing the build later in this training.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 61/340
Build tree: $(O)/legal-info
▶ output/
• legal-info/
manifest.csv
host-manifest.csv
licenses.txt
licenses/
sources/
...
• Legal information: license of all packages, and their source code, plus a licensing
manifest
• Useful for license compliance
• make legal-info
• Variable: LEGAL_INFO_DIR
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 62/340
Toolchains in Buildroot
Toolchains in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 63/340
What is a cross-compilation toolchain?
▶ A set of tools to build and debug code for a target architecture, from a machine
running a different architecture.
▶ Example: building code for ARM from a x86-64 PC.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 64/340
Two possibilities for the toolchain
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 65/340
Internal toolchain backend
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 66/340
Internal toolchain backend: result
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 67/340
External toolchain backend possibilities
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 68/340
Existing external toolchain profile
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 69/340
Existing external toolchains: Bootlin toolchains
▶ https://toolchains.bootlin.com
▶ A set of 169 pre-built toolchains, freely
available
• 41 different CPU architecture variants
• All possible C libraries supported: glibc,
uClibc-ng, musl
• Toolchains built with Buildroot!
▶ Two versions for each toolchain
• stable, which uses the default version of gcc,
binutils and gdb in Buildroot
• bleeding-edge, which uses the latest version of
gcc, binutils and gdb in Buildroot
▶ Directly integrated in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 70/340
Custom external toolchains
▶ If you have a custom external toolchain, for example from your vendor, select
Custom toolchain in Toolchain.
▶ Buildroot can download and extract it for you
• Convenient to share toolchains between several developers
• Option Toolchain to be downloaded and installed in Toolchain origin
• The URL of the toolchain tarball is needed
▶ Or Buildroot can use an already installed toolchain
• Option Pre-installed toolchain in Toolchain origin
• The local path to the toolchain is needed
▶ In both cases, you will have to tell Buildroot the configuration of the toolchain: C
library, kernel headers version, etc.
• Buildroot needs this information to know which packages can be built with this
toolchain
• Buildroot will check those values at the beginning of the build
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 71/340
Custom external toolchain example configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 72/340
External toolchain: result
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 73/340
Kernel headers version
▶ One option in the toolchain menu is particularly important: the kernel headers
version.
▶ When building user space programs, libraries or the C library, kernel headers are
used to know how to interface with the kernel.
▶ This kernel/user space interface is backward compatible, but can introduce new
features.
▶ It is therefore important to use kernel headers that have a version equal or older
than the kernel version running on the target.
▶ With the internal toolchain backend, choose an appropriate kernel headers version.
▶ With the external toolchain backend, beware when choosing your toolchain.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 74/340
Other toolchain menu options
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 75/340
Managing the Linux kernel configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 76/340
Introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 77/340
Defining the configuration
▶ In the Kernel menu in menuconfig, 3 possibilities to configure the kernel:
1. Use a defconfig
Will use a defconfig provided within the kernel sources
Available in arch/<ARCH>/configs in the kernel sources
Used unmodified by Buildroot
Good starting point
2. Use a custom config file
Allows to give the path to either a full .config, or a minimal defconfig
Usually what you will use, so that you can have a custom configuration
3. Use the architecture default configuration
Use the defconfig provided by the architecture in the kernel source tree. Some
architectures (e.g ARM64) have a single defconfig.
▶ Configuration can be further tweaked with Additional fragments
• Allows to pass a list of configuration file fragments.
• They can complement or override configuration options specified in a defconfig or a
full configuration file.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 78/340
Examples of kernel configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 79/340
Changing the configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 80/340
Typical flow
1. make menuconfig
• Start with a defconfig from the kernel, say mvebu_v7_defconfig
2. Run make linux-menuconfig to customize the configuration
3. Do the build, test, tweak the configuration as needed.
4. You cannot do make linux-update-{config,defconfig}, since the Buildroot
configuration points to a kernel defconfig
5. make menuconfig
• Change to a custom configuration file. There’s no need for the file to exist, it will be
created by Buildroot.
6. make linux-update-defconfig
• Will create your custom configuration file, as a minimal defconfig
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 81/340
Root filesystem in Buildroot
Root filesystem in
Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 82/340
Overall rootfs construction steps
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 83/340
Root filesystem skeleton
▶ The base of a Linux root filesystem: UNIX directory hierarchy, a few configuration
files and scripts in /etc. No programs or libraries.
▶ All target packages depend on the skeleton package, so it is essentially the first
thing copied to $(TARGET_DIR) at the beginning of the build.
▶ skeleton is a virtual package that will depend on:
• skeleton-init-{sysv,systemd,openrc,none} depending on the init system being
selected
• skeleton-custom when a custom skeleton is selected
▶ All of skeleton-init-{sysv,systemd,openrc,none} depend on
skeleton-init-common
• Copies system/skeleton/* to $(TARGET_DIR)
▶ skeleton-init-{sysv,systemd,openrc} install additional files specific to those
init systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 84/340
Skeleton packages dependencies
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 85/340
Custom root filesystem skeleton
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 86/340
Installation of packages
▶ All the selected target packages will be built (can be BusyBox, Qt, OpenSSH,
lighttpd, and many more)
▶ Most of them will install files in $(TARGET_DIR): programs, libraries, fonts, data
files, configuration files, etc.
▶ This is really the step that will bring the vast majority of the files in the root
filesystem.
▶ Covered in more details in the section about creating your own Buildroot
packages.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 87/340
Cleanup step
▶ Once all packages have been installed, a cleanup step is executed to reduce the
size of the root filesystem.
▶ It mainly involves:
• Removing header files, pkg-config files, CMake files, static libraries, man pages,
documentation.
• Stripping all the programs and libraries using strip, to remove unneeded
information. Depends on BR2_ENABLE_DEBUG and BR2_STRIP_* options.
• Additional specific clean up steps: clean up unneeded Python files when Python is
used, etc. See TARGET_FINALIZE_HOOKS in the Buildroot code.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 88/340
Root filesystem overlay
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 89/340
Post-build scripts
▶ Sometimes a root filesystem overlay is not sufficient: you can use post-build
scripts.
▶ Can be used to customize existing files, remove unneeded files to save space,
add new files that are generated dynamically (build date, etc.)
▶ Executed before the root filesystem image is created. Can be written in any
language, shell scripts are often used.
▶ BR2_ROOTFS_POST_BUILD_SCRIPT contains a space-separated list of post-build
script paths.
▶ $(TARGET_DIR) path passed as first argument, additional arguments can be
passed in the BR2_ROOTFS_POST_SCRIPT_ARGS option.
▶ Various environment variables are available:
• BR2_CONFIG, path to the Buildroot .config file
• HOST_DIR, STAGING_DIR, TARGET_DIR, BUILD_DIR, BINARIES_DIR, BASE_DIR
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 90/340
Post-build script: example
board/myproject/post-build.sh
#!/bin/sh
# Generate a file identifying the build (git commit and build date)
echo $(git describe) $(date +%Y-%m-%d-%H:%M:%S) > \
$TARGET_DIR/etc/build-id
Buildroot configuration
BR2_ROOTFS_POST_BUILD_SCRIPT="board/myproject/post-build.sh"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 91/340
Generating the filesystem images
▶ In the Filesystem images menu, you can select which filesystem image formats
to generate.
▶ To generate those images, Buildroot will generate a shell script that:
• Changes the owner of all files to 0:0 (root user)
• Takes into account the global permission and device tables, as well as the
per-package ones.
• Takes into account the global and per-package users tables.
• Runs the filesystem image generation utility, which depends on each filesystem
type (genext2fs, mkfs.ubifs, tar, etc.)
▶ This script is executed using a tool called fakeroot
• Allows to fake being root so that permissions and ownership can be modified, device
files can be created, etc.
• Advanced: possibility of running a custom script inside fakeroot, see
BR2_ROOTFS_POST_FAKEROOT_SCRIPT.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 92/340
Permission table
▶ By default, all files are owned by the root user, and the permissions with which
they are installed in $(TARGET_DIR) are preserved.
▶ To customize the ownership or the permission of installed files, one can create one
or several permission tables
▶ BR2_ROOTFS_DEVICE_TABLE contains a space-separated list of permission table
files. The option name contains device for backward compatibility reasons only.
▶ The system/device_table.txt file is used by default.
▶ Packages can also specify their own permissions. See the Advanced package
aspects section for details.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 93/340
Device table
▶ When the system is using a static /dev, one may need to create additional device
nodes
▶ Done using one or several device tables
▶ BR2_ROOTFS_STATIC_DEVICE_TABLE contains a space-separated list of device table
files.
▶ The system/device_table_dev.txt file is used by default.
▶ Packages can also specify their own device files. See the Advanced package
aspects section for details.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 94/340
Users table
▶ One may need to add specific UNIX users and groups in addition to the ones
available in the default skeleton.
▶ BR2_ROOTFS_USERS_TABLES is a space-separated list of user tables.
▶ Packages can also specify their own users. See the Advanced package aspects
section for details.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 95/340
Post-image scripts
▶ Once all the filesystem images have been created, at the very end of the build,
post-image scripts are called.
▶ They allow to do any custom action at the end of the build. For example:
• Extract the root filesystem to do NFS booting
• Generate a final firmware image
• Start the flashing process
▶ BR2_ROOTFS_POST_IMAGE_SCRIPT is a space-separated list of post-image scripts to
call.
▶ Post-image scripts are called:
• from the Buildroot source directory
• with the $(BINARIES_DIR) path as first argument
• with the contents of the BR2_ROOTFS_POST_SCRIPT_ARGS as other arguments
• with a number of available environment variables: BR2_CONFIG, HOST_DIR,
STAGING_DIR, TARGET_DIR, BUILD_DIR, BINARIES_DIR and BASE_DIR.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 96/340
Init mechanism
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 97/340
/dev management method
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 98/340
Other customization options
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 99/340
Deploying the images
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 100/340
Deploying the images: genimage
▶ genimage allows to create the complete image of a block device (SD card, USB
key, hard drive), including multiple partitions and filesystems.
▶ For example, allows to create an image with two partitions: one FAT partition for
bootloader and kernel, one ext4 partition for the root filesystem.
▶ Also allows to place the bootloader at a fixed offset in the image if required.
▶ The helper script support/scripts/genimage.sh can be used as a post-image
script to call genimage
▶ More and more widely used in Buildroot default configurations
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 101/340
Deploying the images: genimage example
genimage-raspberrypi.cfg
image sdcard.img {
hdimage {
image boot.vfat {
}
vfat {
files = {
partition boot {
"bcm2708-rpi-b.dtb",
partition-type = 0xC
"rpi-firmware/bootcode.bin",
bootable = "true"
"rpi-firmware/cmdline.txt",
image = "boot.vfat"
"kernel-marked/zImage"
}
[...]
}
partition rootfs {
}
partition-type = 0x83
image = "rootfs.ext4"
size = 32M
}
}
}
defconfig
BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/raspberrypi/genimage-raspberrypi.cfg"
flash
dd if=output/images/sdcard.img of=/dev/sdb
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 102/340
Deploying the image: NFS booting
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 103/340
Deploying the image: initramfs
▶ Another common use case is to use an initramfs, i.e. a root filesystem fully in
RAM.
• Convenient for small filesystems, fast booting or kernel development
▶ Two solutions:
• BR2_TARGET_ROOTFS_CPIO=y to generate a cpio archive, that you can load from your
bootloader next to the kernel image.
• BR2_TARGET_ROOTFS_INITRAMFS=y to directly include the initramfs inside the kernel
image. Only available when the kernel is built by Buildroot.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 104/340
Practical lab - Root filesystem construction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 105/340
Download infrastructure in Buildroot
Download infrastructure
in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 106/340
Introduction
▶ One important aspect of Buildroot is to fetch source code or binary files from
third party projects.
▶ Download supported from HTTP(S), FTP, Git, Subversion, CVS, Mercurial, etc.
▶ Being able to do reproducible builds over a long period of time requires
understanding the download infrastructure.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 107/340
Download location
▶ Each Buildroot package indicates in its .mk file which files it needs to be
downloaded.
▶ Can be a tarball, one or several patches, binary files, etc.
▶ When downloading a file, Buildroot will successively try the following locations:
1. The local $(DL_DIR) directory where downloaded files are kept
2. The primary site, as indicated by BR2_PRIMARY_SITE
3. The original site, as indicated by the package .mk file
4. The backup Buildroot mirror, as indicated by BR2_BACKUP_SITE
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 108/340
DL_DIR
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 109/340
Primary site
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 110/340
Backup Buildroot mirror
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 111/340
Special case of VCS download
▶ When a package uses the source code from Git, Subversion or another VCS,
Buildroot cannot directly download a tarball.
▶ It uses a VCS-specific method to fetch the specified version of the source from the
VCS repository
▶ The source code is checked-out/cloned inside DL_DIR and kept to speed-up
further downloads of the same project (caching only implemented for Git)
▶ Finally a tarball containing only the source code (and not the version control
history or metadata) is created and stored in DL_DIR
• Example: avrdude-eabe067c4527bc2eedc5db9288ef5cf1818ec720.tar.gz
▶ This tarball will be re-used for the next builds, and attempts are made to
download it from the primary and backup sites.
▶ Due to this, always use a tag name or a full commit id, and never a branch name:
the code will never be re-downloaded when the branch is updated.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 112/340
File integrity checking
▶ Buildroot packages can provide a .hash file to provide hashes for the downloaded
files.
▶ The download infrastructure uses this hash file when available to check the
integrity of the downloaded files.
▶ Hashs are checked every time a downloaded file is used, even if it is already
cached in $(DL_DIR).
▶ If the hash is incorrect, the download infrastructure attempts to re-download the
file once. If that still fails, the build aborts with an error.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 113/340
Download-related make targets
▶ make source
• Triggers the download of all the files needed to build the current configuration.
• All files are stored in $(DL_DIR)
• Allows to prepare a fully offline build
▶ make external-deps
• Lists the files from $(DL_DIR) that are needed for the current configuration to build.
• Does not guarantee that all files are in $(DL_DIR), a make source is required
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 114/340
GNU Make 101
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 115/340
Introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 116/340
Basics of make rules
▶ At their core, Makefiles are simply defining rules to create targets from
prerequisites using recipe commands
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 117/340
Rule example
Makefile
clean:
rm -rf $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) \
$(BUILD_DIR) $(BASE_DIR)/staging \
$(LEGAL_INFO_DIR)
distclean: clean
[...]
rm -rf $(BR2_CONFIG) $(CONFIG_DIR)/.config.old \
$(CONFIG_DIR)/.auto.deps
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 118/340
Defining and referencing variables
define FOOBAR
line 1
line 2
endef
▶ Make variables are referenced using the $(FOOBAR) syntax.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 119/340
Conditions
distclean: clean
ifeq ($(DL_DIR),$(TOPDIR)/dl)
rm -rf $(DL_DIR)
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 120/340
Defining and using functions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 121/340
Useful make functions
▶ subst and patsubst to replace text
ICU_SOURCE = icu4c-$(subst .,_,$(ICU_VERSION))-src.tgz
IMAGEMAGICK_CONFIG_SCRIPTS = \
$(addsuffix -config,Magick MagickCore MagickWand Wand)
▶ And many more, see the GNU Make manual for details.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 122/340
Writing recipes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 123/340
Integrating new packages in Buildroot
Integrating new
packages in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 124/340
Why adding new packages in Buildroot?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 125/340
Basic elements of a Buildroot package
▶ A directory, package/foo
▶ A Config.in file, written in kconfig language, describing the configuration options
for the package.
▶ A <pkg>.mk file, written in make, describing where to fetch the source, how to
build and install it, etc.
▶ An optional <pkg>.hash file, providing hashes to check the integrity of the
downloaded tarballs and license files.
▶ Optionally, .patch files, that are applied on the package source code before
building.
▶ Optionally, any additional file that might be useful for the package: init script,
example configuration file, etc.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 126/340
Integrating new packages in Buildroot
Config.in file
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 127/340
package/<pkg>/Config.in: basics
▶ Describes the configuration options for the package.
▶ Written in the kconfig language.
▶ One option is mandatory to enable/disable the package, it must be named
BR2_PACKAGE_<PACKAGE>.
config BR2_PACKAGE_STRACE
bool "strace"
help
A useful diagnostic, instructional, and debugging tool.
Allows you to track what system calls a program makes
while it is running.
http://sourceforge.net/projects/strace/
▶ The main package option is a bool with the package name as the prompt. Will
be visible in menuconfig.
▶ The help text give a quick description, and the homepage of the project.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 128/340
package/<pkg>/Config.in: inclusion
package/Config.in
menu "Target packages"
menu "Audio and video applications"
source "package/alsa-utils/Config.in"
...
endmenu
...
menu "Libraries"
menu "Audio/Sound"
source "package/alsa-lib/Config.in"
...
endmenu
...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 129/340
package/<pkg>/Config.in: dependencies
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 130/340
package/<pkg>/Config.in: dependency example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 131/340
Dependency propagation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 132/340
Config.in.host for host packages?
▶ Most of the packages in Buildroot are target packages, i.e. they are cross-compiled
for the target architecture, and meant to be run on the target platform.
▶ Some packages have a host variant, built to be executed on the build machine.
Such packages are needed for the build process of other packages.
▶ The majority of host packages are not visible in menuconfig: they are just
dependencies of other packages, the user doesn’t really need to know about them.
▶ A few of them are potentially directly useful to the user (flashing tools, etc.), and
can be shown in the Host utilities section of menuconfig.
▶ In this case, the configuration option is in a Config.in.host file, included from
package/Config.in.host, and the option must be named
BR2_PACKAGE_HOST_<PACKAGE>.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 133/340
Config.in.host example
package/Config.in.host
menu "Host utilities"
source "package/genimage/Config.in.host"
source "package/lpc3250loader/Config.in.host"
source "package/openocd/Config.in.host"
source "package/qemu/Config.in.host"
endmenu
package/openocd/Config.in.host
config BR2_PACKAGE_HOST_OPENOCD
bool "host openocd"
help
OpenOCD - Open On-Chip Debugger
http://openocd.org
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 134/340
Config.in sub-options
package/pppd/Config.in
▶ Additional sub-options can be config BR2_PACKAGE_PPPD
bool "pppd"
defined to further configure depends on !BR2_STATIC_LIBS
depends on BR2_USE_MMU
the package, to enable or ...
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 135/340
Integrating new packages in Buildroot
Package infrastructures
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 136/340
Package infrastructures: what is it?
▶ Each software component to be built by Buildroot comes with its own build
system.
▶ Buildroot does not re-invent the build system of each component, it simply uses it.
▶ Numerous build systems available: hand-written Makefiles or shell scripts,
autotools, Meson, CMake and also some specific to languages: Python, Perl, Lua,
Erlang, etc.
▶ In order to avoid duplicating code, Buildroot has package infrastructures for
well-known build systems.
▶ And a generic package infrastructure for software components with non-standard
build systems.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 137/340
Package infrastructures
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 138/340
generic-package infrastructure
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 139/340
generic-package: steps
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 140/340
Other package infrastructures
▶ The other package infrastructures are meant to be used when the software
component uses a well-known build system.
▶ They inherit all the behavior of the generic-package infrastructure:
downloading, extracting, patching, etc.
▶ And in addition to that, they typically implement a default behavior for the
configuration, compilation and installation steps.
▶ For example, autotools-package will implement the configuration step as a call
to the ./configure script with the right arguments.
▶ pkg-kconfig is an exception, it only provides some helpers for packages using
Kconfig, but does not implement the configure, build and installation steps.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 141/340
Integrating new packages in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 142/340
The <pkg>.mk file
▶ The .mk file of a package does not look like a normal Makefile.
▶ It is a succession of variable definitions, which must be prefixed by the uppercase
package name.
• FOOBAR_SITE = https://foobar.com/downloads/
• define FOOBAR_BUILD_CMDS
$(MAKE) -C $(@D)
endef
▶ And ends with a call to the desired package infrastructure macro.
• $(eval $(generic-package))
• $(eval $(autotools-package))
• $(eval $(host-autotools-package))
▶ The variables tell the package infrastructure what to do for this specific package.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 143/340
Naming conventions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 144/340
Naming conventions: global namespace
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 145/340
Behind the scenes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 146/340
.mk file: accessing the configuration
▶ Hint: use the make qstrip function to remove double quotes on string options:
NODEJS_MODULES_LIST = $(call qstrip,$(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 147/340
Download related variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 148/340
Available download methods
▶ Buildroot can fetch the source code using different methods:
• wget, for FTP/HTTP downloads
• scp, to fetch the tarball using SSH/SCP
• svn, for Subversion
• cvs, for CVS
• git, for Git
• hg, for Mercurial
• bzr, for Bazaar
• file, for a local tarball
• local, for a local directory
▶ In most cases, the fetching method is guessed by Buildroot using the <pkg>_SITE
variable.
▶ Exceptions:
• Git, Subversion or Mercurial repositories accessed over HTTP or SSH.
• file and local methods
▶ In such cases, use <pkg>_SITE_METHOD explicitly.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 149/340
Download methods examples
CJSON_VERSION = 58
CJSON_SITE_METHOD = svn
CJSON_SITE = http://svn.code.sf.net/p/cjson/code
▶ Source code available in a local directory:
MYAPP_SITE = $(TOPDIR)/../apps/myapp
MYAPP_SITE_METHOD = local
• The ”download” will consist in copying the source code from the designated
directory to the Buildroot per-package build directory.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 150/340
Downloading more elements
perl.mk
PERL_CROSS_SITE = http://raw.github.com/arsv/perl-cross/releases
PERL_CROSS_SOURCE = perl-$(PERL_CROSS_BASE_VERSION)-cross-$(PERL_CROSS_VERSION).tar.gz
PERL_EXTRA_DOWNLOADS = $(PERL_CROSS_SITE)/$(PERL_CROSS_SOURCE)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 151/340
Hash file
▶ In order to validate the integrity of downloaded files and license files, and make
sure the user uses the version which was tested by the Buildroot developers,
cryptographic hashes are used
▶ Each package may contain a file named <package>.hash, which gives the hashes
of the files downloaded by the package.
▶ When present, the hashes for all files downloaded by the package must be
documented.
▶ The hash file can also contain the hashes for the license files listed in
<pkg>_LICENSE_FILES. This allows to detect changes in the license files.
▶ The syntax of the file is:
<hashtype> <hash> <file>
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 152/340
Hash file examples
package/perl/perl.hash
# Hashes from: https://www.cpan.org/src/5.0/perl-5.32.1.tar.xz.{md5,sha1,sha256}.txt
md5 7f104064b906ad8c7329ca5e409a32d7 perl-5.32.1.tar.xz
sha1 1fb4f710d139da1e1a3e1fa4eaba201fcaa8e18e perl-5.32.1.tar.xz
sha256 57cc47c735c8300a8ce2fa0643507b44c4ae59012bfdad0121313db639e02309 perl-5.32.1.tar.xz
# Locally calculated
sha256 dd90d4f42e4dcadf5a7c09eea0189d93c7b37ae560c91f0f6d5233ed3b9292a2 Artistic
sha256 d77d235e41d54594865151f4751e835c5a82322b0e87ace266567c3391a4b912 Copying
sha256 df6ad59aefea68676c38325f25f6707f026ddde6c71291b2ca231b6247859907 README
package/ipset/ipset.hash
# From http://ipset.netfilter.org/ipset-7.6.tar.bz2.md5sum.txt
md5 e107b679c3256af795261cece864d6d9 ipset-7.6.tar.bz2
# Calculated based on the hash above
sha256 0e7d44caa9c153d96a9b5f12644fbe35a632537a5a7f653792b72e53d9d5c2db ipset-7.6.tar.bz2
# Locally calculated
sha256 231f7edcc7352d7734a96eef0b8030f77982678c516876fcb81e25b32d68564c COPYING
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 153/340
Describing dependencies
python.mk
PYTHON_DEPENDENCIES = host-python libffi
ifeq ($(BR2_PACKAGE_PYTHON_READLINE),y)
PYTHON_DEPENDENCIES += readline
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 154/340
Mandatory vs. optional dependencies
▶ Very often, software components have some mandatory dependencies and some
optional dependencies, only needed for optional features.
▶ Handling mandatory dependencies in Buildroot consists in:
• Using a select or depends on on the main package option in Config.in
• Adding the dependency in <pkg>_DEPENDENCIES
▶ For optional dependencies, there are two possibilities:
• Handle it automatically: in the .mk file, if the optional dependency is available, use
it.
• Handle it explicitly: add a package sub-option in the Config.in file.
▶ Automatic handling is usually preferred as it reduces the number of Config.in
options, but it makes the possible dependency less visible to the user.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 155/340
Dependencies: ntp example
▶ Mandatory dependency: libevent
▶ Optional dependency handled automatically: openssl
package/ntp/Config.in
config BR2_PACKAGE_NTP
bool "ntp"
select BR2_PACKAGE_LIBEVENT
[...]
package/ntp/ntp.mk
[...]
NTP_DEPENDENCIES = host-pkgconf libevent
[...]
ifeq ($(BR2_PACKAGE_OPENSSL),y)
NTP_CONF_OPTS += --with-crypto --enable-openssl-random
NTP_DEPENDENCIES += openssl
else
NTP_CONF_OPTS += --without-crypto --disable-openssl-random
endif
[...]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 156/340
Dependencies: mpd example (1/2)
package/mpd/Config.in
menuconfig BR2_PACKAGE_MPD
bool "mpd"
depends on BR2_INSTALL_LIBSTDCPP
[...]
select BR2_PACKAGE_BOOST
select BR2_PACKAGE_LIBGLIB2
select BR2_PACKAGE_LIBICONV if !BR2_ENABLE_LOCALE
[...]
config BR2_PACKAGE_MPD_FLAC
bool "flac"
select BR2_PACKAGE_FLAC
help
Enable flac input/streaming support.
Select this if you want to play back FLAC files.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 157/340
Dependencies: mpd example (2/2)
package/mpd/mpd.mk
MPD_DEPENDENCIES = host-pkgconf boost libglib2
[...]
ifeq ($(BR2_PACKAGE_MPD_FLAC),y)
MPD_DEPENDENCIES += flac
MPD_CONF_OPTS += --enable-flac
else
MPD_CONF_OPTS += --disable-flac
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 158/340
Defining where to install (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 159/340
Defining where to install (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 160/340
Defining where to install (3)
libyaml.mk
LIBYAML_INSTALL_STAGING = YES
eigen.mk
EIGEN_INSTALL_STAGING = YES
EIGEN_INSTALL_TARGET = NO
linux.mk
LINUX_INSTALL_IMAGES = YES
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 161/340
Describing actions for generic-package
▶ In a package using generic-package, only the download, extract and patch steps
are implemented by the package infrastructure.
▶ The other steps should be described by the package .mk file:
• <pkg>_CONFIGURE_CMDS, always called
• <pkg>_BUILD_CMDS, always called
• <pkg>_INSTALL_TARGET_CMDS, called when <pkg>_INSTALL_TARGET = YES, for
target packages
• <pkg>_INSTALL_STAGING_CMDS, called when <pkg>_INSTALL_STAGING = YES, for
target packages
• <pkg>_INSTALL_IMAGES_CMDS, called when <pkg>_INSTALL_IMAGES = YES, for
target packages
• <pkg>_INSTALL_CMDS, always called for host packages
▶ Packages are free to not implement any of these variables: they are all optional.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 162/340
Describing actions: useful variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 163/340
Describing actions: iostat.mk example
IOSTAT_VERSION = 2.2
IOSTAT_SITE = http://linuxinsight.com/sites/default/files
IOSTAT_LICENSE = GPL
IOSTAT_LICENSE_FILES = LICENSE
define IOSTAT_BUILD_CMDS
$(MAKE) -C $(@D) $(TARGET_CONFIGURE_OPTS) \
CFLAGS="$(TARGET_CFLAGS) -DHZ=100"
endef
define IOSTAT_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(IOSTAT_DIR)/iostat \
$(TARGET_DIR)/usr/bin/iostat
endef
$(eval $(generic-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 164/340
Describing actions: libzlib.mk example
LIBZLIB_VERSION = 1.2.11
LIBZLIB_SOURCE = zlib-$(LIBZLIB_VERSION).tar.xz
LIBZLIB_SITE = http://www.zlib.net
LIBZLIB_INSTALL_STAGING = YES
define LIBZLIB_CONFIGURE_CMDS
(cd $(@D); rm -rf config.cache; \
$(TARGET_CONFIGURE_ARGS) \
$(TARGET_CONFIGURE_OPTS) \
CFLAGS="$(TARGET_CFLAGS) $(LIBZLIB_PIC)" \
./configure \
$(LIBZLIB_SHARED) \
--prefix=/usr \
)
endef
define LIBZLIB_BUILD_CMDS
$(TARGET_MAKE_ENV) $(MAKE1) -C $(@D)
endef
define LIBZLIB_INSTALL_STAGING_CMDS
$(TARGET_MAKE_ENV) $(MAKE1) -C $(@D) DESTDIR=$(STAGING_DIR) LDCONFIG=true install
endef
define LIBZLIB_INSTALL_TARGET_CMDS
$(TARGET_MAKE_ENV) $(MAKE1) -C $(@D) DESTDIR=$(TARGET_DIR) LDCONFIG=true install
endef
$(eval $(generic-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 165/340
List of package infrastructures (1/2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 166/340
List of package infrastructures (2/2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 167/340
Integrating new packages in Buildroot
autotools-package infrastructure
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 168/340
The autotools-package infrastructure: basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 169/340
The autotools-package: steps
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 170/340
The autotools-package infrastructure: variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 171/340
Canonical autotools-package example
libyaml.mk
################################################################################
#
# libyaml
#
################################################################################
LIBYAML_VERSION = 0.2.5
LIBYAML_SOURCE = yaml-$(LIBYAML_VERSION).tar.gz
LIBYAML_SITE = http://pyyaml.org/download/libyaml
LIBYAML_INSTALL_STAGING = YES
LIBYAML_LICENSE = MIT
LIBYAML_LICENSE_FILES = License
LIBYAML_CPE_ID_VENDOR = pyyaml
$(eval $(autotools-package))
$(eval $(host-autotools-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 172/340
More complicated autotools-package example
GNUPG2_VERSION = 2.2.25
GNUPG2_SOURCE = gnupg-$(GNUPG2_VERSION).tar.bz2
GNUPG2_SITE = https://gnupg.org/ftp/gcrypt/gnupg
[...]
GNUPG2_LICENSE = GPL-3.0+
GNUPG2_LICENSE_FILES = COPYING
ifeq ($(BR2_PACKAGE_LIBUSB),y)
GNUPG2_CPE_ID_VENDOR = gnupg
GNUPG2_CONF_ENV += CPPFLAGS="$(TARGET_CPPFLAGS)
GNUPG2_CPE_ID_PRODUCT = gnupg
-I$(STAGING_DIR)/usr/include/libusb-1.0"
GNUPG2_DEPENDENCIES = zlib libgpg-error libgcrypt libassuan \
GNUPG2_CONF_OPTS += --enable-ccid-driver
libksba libnpth host-pkgconf \
GNUPG2_DEPENDENCIES += libusb
$(if $(BR2_PACKAGE_LIBICONV),libiconv)
else
GNUPG2_CONF_OPTS += --disable-ccid-driver
ifeq ($(BR2_PACKAGE_BZIP2),y)
endif
GNUPG2_CONF_OPTS += --enable-bzip2 --with-bzip2=$(STAGING_DIR)
GNUPG2_DEPENDENCIES += bzip2
ifeq ($(BR2_PACKAGE_READLINE),y)
else
GNUPG2_CONF_OPTS += --with-readline=$(STAGING_DIR)
GNUPG2_CONF_OPTS += --disable-bzip2
GNUPG2_DEPENDENCIES += readline
endif
else
GNUPG2_CONF_OPTS += --without-readline
ifeq ($(BR2_PACKAGE_GNUTLS),y)
endif
GNUPG2_CONF_OPTS += --enable-gnutls
GNUPG2_DEPENDENCIES += gnutls
$(eval $(autotools-package))
else
GNUPG2_CONF_OPTS += --disable-gnutls
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 173/340
Integrating new packages in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 174/340
Host packages
▶ As explained earlier, most packages in Buildroot are cross-compiled for the target.
They are called target packages.
▶ Some packages however may need to be built natively for the build machine, they
are called host packages. They can be needed for a variety of reasons:
• Needed as a tool to build other things for the target. Buildroot wants to limit the
number of host utilities required to be installed on the build machine, and wants to
ensure the proper version is used. So it builds some host utilities by itself.
• Needed as a tool to interact, debug, reflash, generate images, or other activities
around the build itself.
• Version dependencies: building a Python interpreter for the target needs a Python
interpreter of the same version on the host.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 175/340
Target vs. host: package name and variable prefixes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 176/340
Target vs. host: variable inheritance
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 177/340
Example 1: a pure build utility
package/bison/bison.mk
BISON_VERSION = 3.7.1
BISON_SOURCE = bison-$(BISON_VERSION).tar.xz
BISON_SITE = $(BR2_GNU_MIRROR)/bison
BISON_LICENSE = GPL-3.0+
BISON_LICENSE_FILES = COPYING
BISON_CPE_ID_VENDOR = gnu
# parallel build issue in examples/c/reccalc/
BISON_MAKE = $(MAKE1)
HOST_BISON_DEPENDENCIES = host-m4
HOST_BISON_CONF_OPTS = --enable-relocatable
HOST_BISON_CONF_ENV = ac_cv_libtextstyle=no
$(eval $(host-autotools-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 178/340
Example 2: filesystem manipulation tool
▶ fatcat, is designed to manipulate FAT filesystems, in order to explore, extract,
repair, recover and forensic them.
▶ Not used as a build dependency of another package → visible in menuconfig.
package/fatcat/Config.in.host
config BR2_PACKAGE_HOST_FATCAT
bool "host fatcat"
help
Fatcat is designed to manipulate FAT filesystems, in order
to explore, extract, repair, recover and forensic them. It
currently supports FAT12, FAT16 and FAT32.
https://github.com/Gregwar/fatcat
package/fatcat/fatcat.mk
FATCAT_VERSION = 1.1.0
FATCAT_SITE = $(call github,Gregwar,fatcat,v$(FATCAT_VERSION))
FATCAT_LICENSE = MIT
FATCAT_LICENSE_FILES = LICENSE
$(eval $(host-cmake-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 179/340
Example 3: target and host of the same package
package/e2tools/e2tools.mk
E2TOOLS_VERSION = 0.0.16.4
E2TOOLS_SITE = $(call github,ndim,e2tools,v$(E2TOOLS_VERSION))
$(eval $(autotools-package))
$(eval $(host-autotools-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 180/340
Practical lab - New packages in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 181/340
Advanced package aspects
Advanced package
aspects
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 182/340
Advanced package aspects
Licensing report
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 183/340
Licensing report: introduction
$ make legal-info
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 184/340
Licensing report: contents of legal-info
▶ sources/ and host-sources/, all the source files that are redistributable
(tarballs, patches, etc.)
▶ manifest.csv and host-manifest.csv, CSV files with the list of target and host
packages, their version, license, etc.
▶ licenses/ and host-licenses/<pkg>/, the full license text of all target and host
packages, per package
▶ buildroot.config, the Buildroot .config file
▶ legal-info.sha256 hashes of all legal-info files
▶ README
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 185/340
Including licensing information in packages
▶ <pkg>_LICENSE
• Comma-separated list of license(s) under which the package is distributed.
• Must use SPDX license codes, see https://spdx.org/licenses/
• Can indicate which part is under which license (programs, tests, libraries, etc.)
▶ <pkg>_LICENSE_FILES
• Space-separated list of file paths from the package source code containing the
license text and copyright information
• Paths relative to the package top-level source directory
▶ <pkg>_REDISTRIBUTE
• Boolean indicating whether the package source code can be redistributed or not
(part of the legal-info output)
• Defaults to YES, can be overridden to NO
• If NO, source code is not copied when generating the licensing report
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 186/340
Licensing information examples
linux.mk
LINUX_LICENSE = GPL-2.0
LINUX_LICENSE_FILES = COPYING
acl.mk
ACL_LICENSE = GPL-2.0+ (programs), LGPL-2.1+ (libraries)
ACL_LICENSE_FILES = doc/COPYING doc/COPYING.LGPL
owl-linux.mk
OWL_LINUX_LICENSE = PROPRIETARY
OWL_LINUX_LICENSE_FILES = LICENSE
OWL_LINUX_REDISTRIBUTE = NO
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 187/340
Advanced package aspects
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 188/340
Security vulnerability tracking
▶ Security has obviously become a key issue in embedded systems that are more and
more commonly connected.
▶ Embedded Linux systems typically integrate 10-100+ open-source components →
not easy to keep track of their potential security vulnerabilities
▶ Industry relies on Common Vulnerability Exposure (CVE) reports to document
known security issues
▶ Buildroot is able to identify if packages are affected by known CVEs, by using the
National Vulnerability Database
• make pkg-stats
• Produces $(O)/pkg-stats.html, $(O)/pkg-stats.json
▶ Note: this is limited to known CVEs. It does not guarantee the absence of
security vulnerabilities.
▶ Only applies to open-source packages, not to your own custom code.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 189/340
Example pkg-stats output
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 190/340
CPE: Common Platform Enumeration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 191/340
NVD CVE-2020-35492 example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 192/340
CPE information in packages
package/bash/bash.mk
BASH_CPE_ID_VENDOR = gnu
package/audit/audit.mk
AUDIT_CPE_ID_VENDOR = linux_audit_project
AUDIT_CPE_ID_PRODUCT = linux_audit
linux/linux.mk
LINUX_CPE_ID_VENDOR = linux
LINUX_CPE_ID_PRODUCT = linux_kernel
LINUX_CPE_ID_PREFIX = cpe:2.3:o
package/libffi/libffi.mk
LIBFFI_CPE_ID_VERSION = 3.3
LIBFFI_CPE_ID_UPDATE = rc0
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 193/340
Advanced package aspects
Patching packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 194/340
Patching packages: why?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 195/340
Patch application ordering
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 196/340
Patch conventions
▶ There are a few conventions and best practices that the Buildroot project
encourages to use when managing patches
▶ Their name should start with a sequence number that indicates the ordering in
which they should be applied.
ls package/nginx/*.patch
0001-auto-type-sizeof-rework-autotest-to-be-cross-compila.patch
0002-auto-feature-add-mechanism-allowing-to-force-feature.patch
0003-auto-set-ngx_feature_run_force_result-for-each-featu.patch
0004-auto-lib-libxslt-conf-allow-to-override-ngx_feature_.patch
0005-auto-unix-make-sys_nerr-guessing-cross-friendly.patch
▶ Each patch should contain a description of what the patch does, and if possible
its upstream status.
▶ Each patch should contain a Signed-off-by that identifies the author of the
patch.
▶ Patches should be generated using git format-patch when possible.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 197/340
Patch example
ngx_size=
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 198/340
Global patch directories
▶ You can include patches for the different packages in their package directory,
package/<pkg>/.
▶ However, doing this involves changing the Buildroot sources themselves, which
may not be appropriate for some highly specific patches.
▶ The global patch directories mechanism allows to specify additional locations
where Buildroot will look for patches to apply on packages.
▶ BR2_GLOBAL_PATCH_DIR specifies a space-separated list of directories containing
patches.
▶ These directories must contain sub-directories named after the packages,
themselves containing the patches to be applied.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 199/340
Global patch directory example
Patching strace
$ ls package/strace/*.patch
0001-linux-aarch64-add-missing-header.patch
$ find ~/patches/
~/patches/
~/patches/strace/
~/patches/strace/0001-Demo-strace-change.patch
$ make strace
[...]
>>> strace 4.10 Patching
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 200/340
Generating patches
▶ To generate the patches against a given package source code, there are typically
two possibilities.
▶ Use the upstream version control system, often Git
▶ Use a tool called quilt
• Useful when there is no version control system provided by the upstream project
• https://savannah.nongnu.org/projects/quilt
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 201/340
Generating patches: with Git
Needs to be done outside of Buildroot: you cannot use the Buildroot package build
directory.
1. Clone the upstream Git repository
git clone https://...
2. Create a branch starting on the tag marking the stable release of the software as
packaged in Buildroot
git checkout -b buildroot-changes v3.2
3. Import existing Buildroot patches (if any)
git am /path/to/buildroot/package/<foo>/*.patch
4. Make your changes and commit them
git commit -s -m ``this is a change''
5. Generate the patches
git format-patch v3.2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 202/340
Generating patches: with Quilt
1. Extract the package source code:
tar xf /path/to/dl/<foo>-<version>.tar.gz
2. Inside the package source code, create a directory for patches
mkdir patches
3. Import existing Buildroot patches
quilt import /path/to/buildroot/package/<foo>/*.patch
4. Apply existing Buildroot patches
quilt push -a
5. Create a new patch
quilt new 0001-fix-header-inclusion.patch
6. Edit a file
quilt edit main.c
7. Refresh the patch
quilt refresh
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 203/340
Advanced package aspects
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 204/340
Package-specific users
define AVAHI_USERS
avahi -1 avahi -1 * - - -
endef
define MYSQL_USERS
mysql -1 nogroup -1 * /var/mysql - - MySQL daemon
endef
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 205/340
File permissions and ownership
▶ By default, before creating the root filesystem images, Buildroot changes the
ownership of all files to 0:0, i.e. root:root
▶ Permissions are preserved as is, but since the build is executed as non-root, it is
not possible to install setuid applications.
▶ A default set of permissions for certain files or directories is defined in
system/device_table.txt.
▶ The <pkg>_PERMISSIONS variable allows packages to define special ownership and
permissions for files and directories:
define <pkg>_PERMISSIONS
name type mode uid gid major minor start inc count
endef
▶ The major, minor, start, inc and count fields are not used.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 206/340
File permissions and ownership: examples
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 207/340
Devices
▶ Defining devices only applies when the chosen /dev management strategy is
Static using a device table. In other cases, device files are created dynamically.
▶ A default set of device files is described in system/device_table_dev.txt and
created by Buildroot in the root filesystem images.
▶ When packages need some additional custom devices, they can use the
<pkg>_DEVICES variable:
define <pkg>_DEVICES
name type mode uid gid major minor start inc count
endef
▶ Becoming less useful, since most people are using a dynamic /dev nowadays.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 208/340
Devices: example
xenomai.mk
define XENOMAI_DEVICES
/dev/rtheap c 666 0 0 10 254 0 0 -
/dev/rtscope c 666 0 0 10 253 0 0 -
/dev/rtp c 666 0 0 150 0 0 1 32
endef
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 209/340
Advanced package aspects
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 210/340
Init scripts, systemd unit files
▶ Buildroot supports several main init systems: sysvinit, BusyBox, systemd, OpenRC
▶ When packages want to install a program to be started at boot time, they need to
install a startup script (sysvinit/BusyBox), a systemd service file, etc.
▶ They can do so using the following variables, which contain a list of shell
commands.
• <pkg>_INSTALL_INIT_SYSV
• <pkg>_INSTALL_INIT_SYSTEMD
• <pkg>_INSTALL_INIT_OPENRC
▶ Buildroot will execute the appropriate <pkg>_INSTALL_INIT_xyz commands of all
enabled packages depending on the selected init system.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 211/340
Init scripts, systemd unit files: example
bind.mk
define BIND_INSTALL_INIT_SYSV
$(INSTALL) -m 0755 -D package/bind/S81named \
$(TARGET_DIR)/etc/init.d/S81named
endef
define BIND_INSTALL_INIT_SYSTEMD
$(INSTALL) -D -m 644 package/bind/named.service \
$(TARGET_DIR)/usr/lib/systemd/system/named.service
endef
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 212/340
Advanced package aspects
Config scripts
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 213/340
Config scripts: introduction
▶ Libraries not using pkg-config often install a small shell script that allows
applications to query the compiler and linker flags to use the library.
▶ Examples: curl-config, freetype-config, etc.
▶ Such scripts will:
• generally return results that are not appropriate for cross-compilation
• be used by other cross-compiled Buildroot packages that use those libraries
▶ By listing such scripts in the <pkg>_CONFIG_SCRIPTS variable, Buildroot will
adapt the prefix, header and library paths to make them suitable for
cross-compilation.
▶ Paths in <pkg>_CONFIG_SCRIPTS are relative to $(STAGING_DIR)/usr/bin.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 214/340
Config scripts: examples
libpng.mk
LIBPNG_CONFIG_SCRIPTS = \
libpng$(LIBPNG_SERIES)-config libpng-config
imagemagick.mk
IMAGEMAGICK_CONFIG_SCRIPTS = \
$(addsuffix -config,Magick MagickCore MagickWand Wand)
ifeq ($(BR2_INSTALL_LIBSTDCPP)$(BR2_USE_WCHAR),yy)
IMAGEMAGICK_CONFIG_SCRIPTS += Magick++-config
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 215/340
Config scripts: effect
Without <pkg>_CONFIG_SCRIPTS
$ ./output/staging/usr/bin/libpng-config --cflags --ldflags
-I/usr/include/libpng16
-L/usr/lib -lpng16
With <pkg>_CONFIG_SCRIPTS
$ ./output/staging/usr/bin/libpng-config --cflags --ldflags
-I.../buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/libpng16
-L.../buildroot/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib -lpng16
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 216/340
Advanced package aspects
Hooks
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 217/340
Hooks: principle (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 218/340
Hooks: principle (2)
▶ There are pre and post hooks available for all steps of the package compilation
process:
• download, extract, rsync, patch, configure, build, install, install staging, install
target, install images, legal info
• <pkg>_(PRE|POST)_<step>_HOOKS
• Example: CMAKE_POST_INSTALL_TARGET_HOOKS, CVS_POST_PATCH_HOOKS,
BINUTILS_PRE_PATCH_HOOKS
▶ Hook variables contain a list of make macros to call at the appropriate time.
• Use += to register an additional hook to a hook point
▶ Those make macros contain a list of commands to execute.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 219/340
Hooks: examples
BIND_POST_INSTALL_TARGET_HOOKS += BIND_TARGET_REMOVE_TOOLS
ifeq ($(BR2_PACKAGE_OPENSSL),y)
VSFTPD_DEPENDENCIES += openssl host-pkgconf
VSFTPD_LIBS += `$(PKG_CONFIG_HOST_BINARY) --libs libssl libcrypto`
VSFTPD_POST_CONFIGURE_HOOKS += VSFTPD_ENABLE_SSL
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 220/340
Advanced package aspects
Overriding commands
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 221/340
Overriding commands: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 222/340
Overriding commands: examples
define JQUERY_EXTRACT_CMDS
cp $(DL_DIR)/$(JQUERY_SOURCE) $(@D)
endef
$(eval $(autotools-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 223/340
Advanced package aspects
Legacy handling
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 224/340
Legacy handling: Config.in.legacy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 225/340
Advanced package aspects
DEVELOPERS file
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 226/340
DEVELOPERS file: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 227/340
DEVELOPERS file: extract
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 228/340
Advanced package aspects
Virtual packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 229/340
Virtual packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 230/340
Virtual packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 231/340
Virtual package definition: Config.in
libgles/Config.in
config BR2_PACKAGE_HAS_LIBGLES
bool
config BR2_PACKAGE_PROVIDES_LIBGLES
depends on BR2_PACKAGE_HAS_LIBGLES
string
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 232/340
Virtual package definition: .mk
libgles/libgles.mk
$(eval $(virtual-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 233/340
Virtual package provider
sunxi-mali-mainline/Config.in
config BR2_PACKAGE_SUNXI_MALI_MAINLINE
bool "sunxi-mali-mainline"
select BR2_PACKAGE_HAS_LIBEGL
select BR2_PACKAGE_HAS_LIBGLES
config BR2_PACKAGE_PROVIDES_LIBGLES
default "sunxi-mali-mainline"
sunxi-mali-mainline/sunxi-mali-mainline.mk
[...]
SUNXI_MALI_MAINLINE_PROVIDES = libegl libgles
[...]
▶ The variable <pkg>_PROVIDES is only used to detect if two providers for the same
virtual package are enabled.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 234/340
Virtual package user
qt5/qt5base/Config.in
config BR2_PACKAGE_QT5BASE_OPENGL_ES2
bool "OpenGL ES 2.0+"
depends on BR2_PACKAGE_HAS_LIBGLES
help
Use OpenGL ES 2.0 and later versions.
qt5/qt5base/qt5base.mk
ifeq ($(BR2_PACKAGE_QT5BASE_OPENGL_DESKTOP),y)
QT5BASE_CONFIGURE_OPTS += -opengl desktop
QT5BASE_DEPENDENCIES += libgl
else ifeq ($(BR2_PACKAGE_QT5BASE_OPENGL_ES2),y)
QT5BASE_CONFIGURE_OPTS += -opengl es2
QT5BASE_DEPENDENCIES += libgles
else
QT5BASE_CONFIGURE_OPTS += -no-opengl
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 235/340
Practical lab - Advanced packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 236/340
Analyzing the build
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 237/340
Analyzing the build: available tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 238/340
Dependency graphing
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 239/340
Dependency graph example
ALL
host-mpfr host-libtool
host-gmp
host-m4
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 240/340
Build time graphing
▶ When the generated embedded Linux system grows bigger and bigger, the build
time also increases.
▶ It is sometimes useful to analyze this build time, and see if certain packages are
particularly problematic.
▶ Buildroot collects build duration data in the file $(O)/build/build-time.log
▶ make graph-build generates several graphs in $(O)/graphs/:
• build.hist-build.pdf, build time in build order
• build.hist-duration.pdf, build time by duration
• build.hist-name.pdf, build time by package name
• build.pie-packages.pdf, pie chart of the per-package build time
• build.pie-steps.pdf, pie chart of the per-step build time
▶ Note: only works properly after a complete clean rebuild.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 241/340
Build time graphing: example
60
40
20
gett
too
too
bus
cup
hos
hos
hos
hos
ijs
zlib
lcm
hos
hos
hos
hos
libff
pcre
libg
exp
pop
hos
free
fon
qpd
lcha
lcha
tco
s2
lib2
ybo
t-m
t-lib
t-au
t-au
t-ge
t-lib
t-zli
t-lib
at
t-
ext
pler
f
ty
pkg
pe
nfig
4
b
in-e
in
to
ff
glib
toco
tom
ttex
con
ol
2
xtern
t
ake
n
f
f
al
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 242/340
Filesystem size graphing
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 243/340
Filesystem size graphing: example
21.8%
ncurses (198 kB) 8.3%
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 244/340
Advanced topics
Advanced topics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 245/340
BR2_EXTERNAL: principle
▶ Storing your custom packages, custom configuration files and custom defconfigs
inside the Buildroot tree may not be the most practical solution
• Doesn’t cleanly separate open-source parts from proprietary parts
• Makes it harder to upgrade Buildroot
▶ The BR2_EXTERNAL mechanism allows to store your own package recipes,
defconfigs and other artefacts outside of the Buildroot source tree.
▶ It is possible to use several BR2_EXTERNAL trees, to further separate various
aspects of your project.
▶ Note: can only be used to add new packages, not to override existing Buildroot
packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 246/340
BR2_EXTERNAL: example organization
▶ project/
• buildroot/
The Buildroot source code, cloned from Git, or extracted from a release tarball.
• external1/
• external2/
Two external trees
• output-build1/
• output-build2/
Several output directories, to build various configurations
• custom-app/
• custom-lib/
The source code of your custom applications and libraries.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 247/340
BR2_EXTERNAL: mechanism
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 248/340
BR2_EXTERNAL: recommended structure
+-- board/
| +-- <company>/
| +-- <boardname>/
| +-- linux.config
| +-- busybox.config
| +-- <other configuration files>
| +-- post_build.sh +-- package/
| +-- post_image.sh | +-- <company>/
| +-- rootfs_overlay/ | +-- package1/
| | +-- etc/ | | +-- Config.in
| | +-- <some file> | | +-- package1.mk
| +-- patches/ | +-- package2/
| +-- libbar/ | +-- Config.in
| +-- <some patches> | +-- package2.mk
| |
+-- configs/ +-- Config.in
| +-- <boardname>_defconfig +-- external.mk
| +-- external.desc
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 249/340
BR2_EXTERNAL: external.desc
name: FOOBAR
desc: Foobar Company
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 250/340
BR2_EXTERNAL: main Config.in
Example Config.in
source "$BR2_EXTERNAL_<NAME>_PATH/package/package1/Config.in"
source "$BR2_EXTERNAL_<NAME>_PATH/package/package2/Config.in"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 251/340
BR2_EXTERNAL: external.mk
Example external.mk
include $(sort $(wildcard $(BR2_EXTERNAL_<NAME>_PATH)/package/*/*.mk))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 252/340
Using BR2_EXTERNAL
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 253/340
Use BR2_EXTERNAL in your configuration
▶ In your Buildroot configuration, don’t use absolute paths for the rootfs overlay,
the post-build scripts, global patch directories, etc.
▶ If they are located in an external tree, you can use
$(BR2_EXTERNAL_<NAME>_PATH) in your Buildroot configuration options.
▶ With the recommended structure shown before, a Buildroot configuration would
look like:
BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_<NAME>_PATH)/board/<company>/<boardname>/patches/"
...
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_<NAME>_PATH)/board/<company>/<boardname>/rootfs_overlay/"
...
BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL_<NAME>_PATH)/board/<company>/<boardname>/post_build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_<NAME>_PATH)/board/<company>/<boardname>/post_image.sh"
...
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_<NAME>_PATH)/board/<company>/<boardname>/linux.config"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 254/340
Examples of BR2_EXTERNAL trees
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 255/340
Package-specific targets: basics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 256/340
Package-specific targets: example (1)
$ make strace
>>> strace 4.10 Extracting
>>> strace 4.10 Patching
>>> strace 4.10 Updating config.sub and config.guess
>>> strace 4.10 Patching libtool
>>> strace 4.10 Configuring
>>> strace 4.10 Building
>>> strace 4.10 Installing to target
$ make strace-build
... nothing ...
$ make ltrace-patch
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Extracting
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Patching
$ make ltrace
>>> argp-standalone 1.3 Extracting
>>> argp-standalone 1.3 Patching
>>> argp-standalone 1.3 Updating config.sub and config.guess
>>> argp-standalone 1.3 Patching libtool
[...]
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Configuring
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Autoreconfiguring
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Patching libtool
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Building
>>> ltrace 0896ce554f80afdcba81d9754f6104f863dea803 Installing to target
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 257/340
Package-specific targets: advanced
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 258/340
Package-specific targets: example (2)
$ make strace
>>> strace 4.10 Extracting
>>> strace 4.10 Patching
>>> strace 4.10 Updating config.sub and config.guess
>>> strace 4.10 Patching libtool
>>> strace 4.10 Configuring
>>> strace 4.10 Building
>>> strace 4.10 Installing to target
$ ls output/build/
strace-4.10 [...]
$ make strace-dirclean
rm -Rf /home/thomas/projets/buildroot/output/build/strace-4.10
$ ls output/build/
[... no strace-4.10 directory ...]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 259/340
Package-specific targets: example (3)
$ make strace
>>> strace 4.10 Extracting
>>> strace 4.10 Patching
>>> strace 4.10 Updating config.sub and config.guess
>>> strace 4.10 Patching libtool
>>> strace 4.10 Configuring
>>> strace 4.10 Building
>>> strace 4.10 Installing to target
$ make strace-rebuild
>>> strace 4.10 Building
>>> strace 4.10 Installing to target
$ make strace-reconfigure
>>> strace 4.10 Configuring
>>> strace 4.10 Building
>>> strace 4.10 Installing to target
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 260/340
make show-info
$ make show-info | jq .
{
"busybox": {
"type": "target",
"virtual": false,
"version": "1.31.1",
"licenses": "GPL-2.0",
▶ make show-info outputs JSON text "dl_dir": "busybox",
"install_target": true,
that describes the current "install_staging": false,
"install_images": false,
configuration: enabled packages, in "downloads": [
{
which version, their license, tarball, "source": "busybox-1.31.1.tar.bz2",
"uris": [
dependencies, etc. "http+http://www.busybox.net/downloads",
"http|urlencode+http://sources.buildroot.net/busybox",
▶ Can be useful for post-processing, }
]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 261/340
Understanding rebuilds (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 262/340
Understanding rebuilds (2)
▶ When a package has been built by Buildroot, Buildroot keeps a hidden file telling
that the package has been built.
• Buildroot will therefore never rebuild that package, unless a full rebuild is done, or
this specific package is explicitly rebuilt.
• Buildroot does not recurse into each package at each make invocation, it would be
too time-consuming. So if you change one source file in a package, Buildroot does
not know it.
▶ When make is invoked, Buildroot will always:
• Build the packages that have not been built in a previous build and install them to
the target
• Cleanup the target root filesystem from useless files
• Run post-build scripts, copy rootfs overlays
• Generate the root filesystem images
• Run post-image scripts
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 263/340
Understanding rebuilds: scenarios (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 264/340
Understanding rebuilds: scenarios (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 265/340
Tips for building faster
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 266/340
Support for top-level parallel build (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 267/340
Support for top-level parallel build (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 268/340
Reproducible builds
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 269/340
Practical lab - Advanced aspects
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 270/340
Application development
Application
development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 271/340
Building during development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 272/340
Building code for Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 273/340
Building code for Buildroot: C program
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 274/340
Building code for Buildroot: pkg-config
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 275/340
Building code for Buildroot: autotools
$ export PATH=.../buildroot/output/host/bin/:$PATH
$ ./configure --host=arm-linux
▶ Passing --host=arm-linux tells the configure script to use the cross-compilation
tools prefixed by arm-linux-.
▶ In more complex cases, some additional CFLAGS or LDFLAGS might be needed in
the environment.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 276/340
Building code for Buildroot: CMake
$ cmake -DCMAKE_TOOLCHAIN_FILE=.../buildroot/output/host/share/buildroot/toolchainfile.cmake .
$ make
$ file app
app: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 277/340
Building code for Buildroot: Meson
$ mkdir build
$ meson --cross-file=.../buildroot/output/host/etc/meson/cross-compilation.conf ..
$ ninja
$ file app
app: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 278/340
Building code for Buildroot: environment-setup
▶ Enable BR2_PACKAGE_HOST_ENVIRONMENT_SETUP
▶ Installs an helper shell script output/host/environment-setup that can be
sourced in the shell to define a number of useful environment variables and aliases.
▶ Defines: CC, LD, AR, AS, CFLAGS, LDFLAGS, ARCH, etc.
▶ Defines configure as an alias to run a configure script with the right arguments,
cmake as an alias to run cmake with the right arguments
▶ Drawback: once sourced, the shell environment is really only suitable for
cross-compiling with Buildroot.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 279/340
Building code for Buildroot: environment-setup
$ source output/host/environment-setup
_ _ _ _ _
| |__ _ _(_) | __| |_ __ ___ ___ | |_
| '_ \| | | | | |/ _` | '__/ _ \ / _ \| __|
| |_) | |_| | | | (_| | | | (_) | (_) | |_
|_.__/ \__,_|_|_|\__,_|_| \___/ \___/ \__|
Some tips:
* PATH now contains the SDK utilities
* Standard autotools variables (CC, LD, CFLAGS) are exported
* Kernel compilation variables (ARCH, CROSS_COMPILE, KERNELDIR) are exported
* To configure do "./configure $CONFIGURE_FLAGS" or use
the "configure" alias
* To build CMake-based projects, use the "cmake" alias
$ echo $CC
/home/thomas/projets/buildroot/output/host/bin/arm-linux-gcc
$ echo $CFLAGS
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -D_FORTIFY_SOURCE=1
$ echo $CROSS_COMPILE
/home/thomas/projets/buildroot/output/host/bin/arm-linux-
$ alias configure
alias configure='./configure --target=arm-buildroot-linux-gnueabihf --host=arm-buildroot-linux-gnueabihf \
--build=x86_64-pc-linux-gnu --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --localstatedir=/var \
--program-prefix='
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 280/340
local site method
▶ Allows to tell Buildroot that the source code for a package is already available
locally
▶ Allows to keep your source code under version control, separately, and have
Buildroot always build your latest changes.
▶ Typical project organization:
• buildroot/, the Buildroot source code
• external/, your BR2_EXTERNAL tree
• custom-app/, your custom application code
• custom-lib/, your custom library
▶ In your package .mk file, use:
<pkg>_SITE = $(TOPDIR)/../custom-app
<pkg>_SITE_METHOD = local
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 281/340
Effect of local site method
▶ For the first build, the source code of your package is rsync’ed from <pkg>_SITE
to the build directory, and built there.
▶ After making changes to the source code, you can run:
• make <pkg>-reconfigure
• make <pkg>-rebuild
• make <pkg>-reinstall
▶ Buildroot will first rsync again the package source code (copying only the
modified files) and restart the build from the requested step.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 282/340
local site method workflow
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 283/340
<pkg>_OVERRIDE_SRCDIR
▶ The local site method solution is appropriate when the package uses this method
for all developers
• Requires that all developers fetch locally the source code for all custom applications
and libraries
▶ An alternate solution is that packages for custom applications and libraries fetch
their source code from version control systems
• Using the git, svn, cvs, etc. fetching methods
▶ Then, locally, a user can override how the package is fetched using
<pkg>_OVERRIDE_SRCDIR
• It tells Buildroot to not download the package source code, but to copy it from a
local directory.
▶ The package then behaves as if it was using the local site method.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 284/340
Passing <pkg>_OVERRIDE_SRCDIR
Example local.mk
LIBPNG_OVERRIDE_SRCDIR = $(HOME)/projects/libpng
LINUX_OVERRIDE_SRCDIR = $(HOME)/projects/linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 285/340
Debugging: debugging symbols and stripping
▶ To use debuggers, you need the programs and libraries to be built with debugging
symbols.
▶ The BR2_ENABLE_DEBUG option controls whether programs and libraries are built
with debugging symbols
• Disabled by default.
• Sub-options allow to control the amount of debugging symbols (i.e. gcc options -g1,
-g2 and -g3).
▶ The BR2_STRIP_strip option allows to disable or enable stripping of binaries on
the target.
• Enabled by default.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 286/340
Debugging: debugging symbols and stripping
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 287/340
Debugging: remote debugging requirements
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 288/340
Debugging: remote debugging setup
▶ On the target, start gdbserver
• Use a TCP socket, network connectivity needed
• The multi mode is quite convenient
• $ gdbserver --multi localhost:2345
▶ On the host, start <tuple>-gdb
• $ ./output/host/bin/<tuple>-gdb <program>
• <program> is the path to the program to debug, with debugging symbols
▶ Inside gdb, you need to:
• Connect to the target:
(gdb) target extended-remote <ip>:2345
• Tell the target which program to run:
(gdb) set remote exec-file myapp
• Set the path to the sysroot so that gdb can find debugging symbols for libraries:
(gdb) set sysroot ./output/staging/
• Start the program:
(gdb) run
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 289/340
Debugging tools available in Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 290/340
Generating a SDK for application developers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 291/340
Practical lab - Application development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 292/340
Understanding Buildroot internals
Understanding
Buildroot internals
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 293/340
Configuration system
▶ Uses, almost unchanged, the kconfig code from the kernel, in support/kconfig
(variable CONFIG)
▶ kconfig tools are built in $(BUILD_DIR)/buildroot-config/
▶ The main Config.in file, passed to *config, is at the top-level of the Buildroot
source tree
CONFIG_CONFIG_IN = Config.in
CONFIG = support/kconfig
BR2_CONFIG = $(CONFIG_DIR)/.config
-include $(BR2_CONFIG)
$(BUILD_DIR)/buildroot-config/%onf:
mkdir -p $(@D)/lxdialog
... $(MAKE) ... -C $(CONFIG) -f Makefile.br $(@F)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 294/340
Configuration hierarchy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 295/340
When you run make...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 296/340
Where is $(PACKAGES) filled?
Part of package/pkg-generic.mk
# argument 1 is the lowercase package name
# argument 2 is the uppercase package name, including a HOST_ prefix
# for host packages
define inner-generic-package
...
$(2)_KCONFIG_VAR = BR2_PACKAGE_$(2)
...
ifeq ($$($$($(2)_KCONFIG_VAR)),y)
PACKAGES += $(1)
endif # $(2)_KCONFIG_VAR
endef # inner-generic-package
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 297/340
Diving into pkg-generic.mk
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 298/340
Definition of the actions: code
$(BUILD_DIR)/%/.stamp_downloaded: $(BUILD_DIR)/%/.stamp_host_installed:
# Do some stuff here # Do some stuff here
$(Q)touch $@ $(Q)touch $@
$(BUILD_DIR)/%/.stamp_extracted: $(BUILD_DIR)/%/.stamp_staging_installed:
# Do some stuff here # Do some stuff here
$(Q)touch $@ $(Q)touch $@
$(BUILD_DIR)/%/.stamp_patched: $(BUILD_DIR)/%/.stamp_images_installed:
# Do some stuff here # Do some stuff here
$(Q)touch $@ $(Q)touch $@
$(BUILD_DIR)/%/.stamp_configured: $(BUILD_DIR)/%/.stamp_target_installed:
# Do some stuff here # Do some stuff here
$(Q)touch $@ $(Q)touch $@
$(BUILD_DIR)/%/.stamp_built: $(BUILD_DIR)/%/.stamp_installed:
# Do some stuff here # Do some stuff here
$(Q)touch $@ $(Q)touch $@
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 299/340
Action example 1: download
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 300/340
Action example 2: build
# Build
$(BUILD_DIR)/%/.stamp_built::
@$(call step_start,build)
@$(call MESSAGE,"Building")
$(foreach hook,$($(PKG)_PRE_BUILD_HOOKS),$(call $(hook))$(sep))
+$($(PKG)_BUILD_CMDS)
$(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
@$(call step_end,build)
$(Q)touch $@
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 301/340
The generic-package macro
▶ Packages built for the target:
generic-package = $(call inner-generic-package,
$(pkgname),$(call UPPERCASE,$(pkgname)),
$(call UPPERCASE,$(pkgname)),target)
▶ In package/libzlib/libzlib.mk:
LIBZLIB_... = ...
$(eval $(generic-package))
$(eval $(host-generic-package))
▶ Leads to:
$(call inner-generic-package,libzlib,LIBZLIB,LIBZLIB,target)
$(call inner-generic-package,host-libzlib,HOST_LIBZLIB,LIBZLIB,host)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 302/340
inner-generic-package: defining variables
... ...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 303/340
inner-generic-package: dependencies
ifeq ($(4),target)
ifeq ($$($(2)_ADD_SKELETON_DEPENDENCY),YES)
$(2)_DEPENDENCIES += skeleton
endif
ifeq ($$($(2)_ADD_TOOLCHAIN_DEPENDENCY),YES)
$(2)_DEPENDENCIES += toolchain
endif
endif
...
ifeq ($$(BR2_CCACHE),y)
ifeq ($$(filter host-tar host-skeleton host-xz host-lzip host-fakedate host-ccache,$(1)),)
$(2)_DEPENDENCIES += host-ccache
endif
endif
▶ Adding the skeleton and toolchain dependencies to target packages. Except for
some specific packages (e.g. C library).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 304/340
inner-generic-package: stamp files
$(2)_TARGET_INSTALL = $$($(2)_DIR)/.stamp_installed
$(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
$(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
$(2)_TARGET_INSTALL_IMAGES = $$($(2)_DIR)/.stamp_images_installed
$(2)_TARGET_INSTALL_HOST = $$($(2)_DIR)/.stamp_host_installed
$(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
$(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
$(2)_TARGET_RSYNC = $$($(2)_DIR)/.stamp_rsynced
$(2)_TARGET_RSYNC_SOURCE = $$($(2)_DIR)/.stamp_rsync_sourced
$(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
$(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
$(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
$(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
$$($(2)_TARGET_INSTALL): PKG=$(2)
$$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
$$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
$$($(2)_TARGET_INSTALL_IMAGES): PKG=$(2)
$$($(2)_TARGET_INSTALL_HOST): PKG=$(2)
[...]
$(1): $(1)-install
$(1)-install: $$($(2)_TARGET_INSTALL) $(1)-build: $$($(2)_TARGET_BUILD)
$$($(2)_TARGET_BUILD): $$($(2)_TARGET_CONFIGURE)
ifeq ($$($(2)_INSTALL_TARGET),YES)
$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_TARGET) $(1)-configure: $$($(2)_TARGET_CONFIGURE)
endif $$($(2)_TARGET_CONFIGURE): | $$($(2)_FINAL_DEPENDENCIES)
ifeq ($$($(2)_INSTALL_STAGING),YES) $$($(2)_TARGET_CONFIGURE): $$($(2)_TARGET_PATCH)
$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_STAGING)
endif $(1)-patch: $$($(2)_TARGET_PATCH)
ifeq ($$($(2)_INSTALL_IMAGES),YES) $$($(2)_TARGET_PATCH): $$($(2)_TARGET_EXTRACT)
$$($(2)_TARGET_INSTALL): $$($(2)_TARGET_INSTALL_IMAGES)
endif $(1)-extract: $$($(2)_TARGET_EXTRACT)
$$($(2)_TARGET_EXTRACT): $$($(2)_TARGET_SOURCE)
$(1)-install-target: $$($(2)_TARGET_INSTALL_TARGET) $$($(2)_TARGET_EXTRACT): | $$($(2)_FINAL_EXTRACT_DEPENDENCIES)
$$($(2)_TARGET_INSTALL_TARGET): $$($(2)_TARGET_BUILD)
$(1)-source: $$($(2)_TARGET_SOURCE)
$(1)-install-staging: $$($(2)_TARGET_INSTALL_STAGING) $$($(2)_TARGET_SOURCE): | $$($(2)_FINAL_DOWNLOAD_DEPENDENCIES)
$$($(2)_TARGET_INSTALL_STAGING): $$($(2)_TARGET_BUILD)
$$($(2)_TARGET_SOURCE): | prepare
$(1)-install-images: $$($(2)_TARGET_INSTALL_IMAGES) $$($(2)_TARGET_SOURCE): | dependencies
$$($(2)_TARGET_INSTALL_IMAGES): $$($(2)_TARGET_BUILD)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 306/340
inner-generic-package: sequencing diagram
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 307/340
Preparation work: prepare, dependencies
pkg-generic.mk
$$($(2)_TARGET_SOURCE): | prepare
$$($(2)_TARGET_SOURCE): | dependencies
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 308/340
Rebuilding packages?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 309/340
Specialized package infrastructures
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 310/340
CMake package example: flann
package/flann/flann.mk
FLANN_VERSION = 1.9.1
FLANN_SITE = $(call github,mariusmuja,flann,$(FLANN_VERSION))
FLANN_INSTALL_STAGING = YES
FLANN_LICENSE = BSD-3-Clause
FLANN_LICENSE_FILES = COPYING
FLANN_CONF_OPTS = \
-DBUILD_C_BINDINGS=ON \
-DBUILD_PYTHON_BINDINGS=OFF \
-DBUILD_MATLAB_BINDINGS=OFF \
-DBUILD_EXAMPLES=$(if $(BR2_PACKAGE_FLANN_EXAMPLES),ON,OFF) \
-DUSE_OPENMP=$(if $(BR2_GCC_ENABLE_OPENMP),ON,OFF) \
-DPYTHON_EXECUTABLE=OFF \
-DCMAKE_DISABLE_FIND_PACKAGE_HDF5=TRUE
$(eval $(cmake-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 311/340
CMake package infrastructure (1/2)
define inner-cmake-package
$(2)_CONF_ENV ?=
$(2)_CONF_OPTS ?=
...
$(2)_SRCDIR = $$($(2)_DIR)/$$($(2)_SUBDIR)
$(2)_BUILDDIR = $$($(2)_SRCDIR)
ifndef $(2)_CONFIGURE_CMDS
ifeq ($(4),target)
define $(2)_CONFIGURE_CMDS
(cd $$($$(PKG)_BUILDDIR) && \
$$($$(PKG)_CONF_ENV) $$(HOST_DIR)/bin/cmake $$($$(PKG)_SRCDIR) \
-DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/share/buildroot/toolchainfile.cmake" \
...
$$($$(PKG)_CONF_OPTS) \
)
endef
else
define $(2)_CONFIGURE_CMDS
... host case ...
endef
endif
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 312/340
CMake package infrastructure (2/2)
$(2)_DEPENDENCIES += host-cmake
ifndef $(2)_BUILD_CMDS
ifeq ($(4),target)
define $(2)_BUILD_CMDS
$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS)
-C $$($$(PKG)_BUILDDIR)
endef
else
... host case ...
endif
endif
ifndef $(2)_INSTALL_TARGET_CMDS
define $(2)_INSTALL_TARGET_CMDS
$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS)
$$($$(PKG)_INSTALL_TARGET_OPT) -C $$($$(PKG)_BUILDDIR)
endef
endif
$(call inner-generic-package,$(1),$(2),$(3),$(4))
endef
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 313/340
Autoreconf in pkg-autotools.mk
ifeq ($$($(2)_AUTORECONF),YES)
...
$(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK
$(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
endif
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 314/340
Toolchain support
▶ One virtual package, toolchain, with two implementations in the form of two
packages: toolchain-buildroot and toolchain-external
▶ toolchain-buildroot implements the internal toolchain back-end, where
Buildroot builds the cross-compilation toolchain from scratch. This package
simply depends on host-gcc-final to trigger the entire build process
▶ toolchain-external implements the external toolchain back-end, where
Buildroot uses an existing pre-built toolchain
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 315/340
Internal toolchain back-end
ALL
▶ Build starts with utility host tools and libraries needed for gcc
toolchain
(host-m4, host-mpc, host-mpfr, host-gmp). Installed in
$(HOST_DIR)/{bin,include,lib} toolchain-buildroot
$(STAGING_DIR)/usr/include
▶ We build the C library, uclibc in this example. Installed in host-binutils host-mpc
course $(TARGET_DIR)/lib
▶ We build the final compiler host-gcc-final, installed in host-gmp
$(HOST_DIR)/bin host-m4
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 316/340
External toolchain back-end
▶ toolchain-external-package infrastructure,
implementing the common logic for all external ALL
toolchains
• Implemented in toolchain/toolchain-
toolchain
external/pkg-toolchain-external.mk
▶ Packages in toolchain/toolchain-external/
are using this infrastructure toolchain-external
• E.g. toolchain-external-arm-aarch64,
toolchain-external-bootlin toolchain-external-arm-aarch64
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 317/340
External toolchain example
toolchain/toolchain-external/toolchain-external-arm-aarch64/toolchain-external-arm-aarch64.mk
TOOLCHAIN_EXTERNAL_ARM_AARCH64_VERSION = 2020.11
TOOLCHAIN_EXTERNAL_ARM_AARCH64_SITE = \
https://developer.arm.com/-/media/Files/downloads/
gnu-a/10.2-$(TOOLCHAIN_EXTERNAL_ARM_AARCH64_VERSION)/binrel
TOOLCHAIN_EXTERNAL_ARM_AARCH64_SOURCE = \
gcc-arm-10.2-$(TOOLCHAIN_EXTERNAL_ARM_AARCH64_VERSION)-x86_64-aarch64-none-linux-gnu.tar.xz
$(eval $(toolchain-external-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 318/340
toolchain-external-package logic
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 319/340
Root filesystem image generation
▶ Once all the targets in $(PACKAGES) have been built, it’s time to create the root
filesystem images
▶ First, the target-finalize target does some cleanup of $(TARGET_DIR) by
removing documentation, headers, static libraries, etc.
▶ Then the root filesystem image targets listed in $(ROOTFS_TARGETS) are processed
▶ These targets are added by the common filesystem image generation
infrastructure rootfs, in fs/common.mk
▶ The purpose of this infrastructure is to:
• Collect the users, permissions and device tables
• Make a copy of TARGET_DIR per filesystem image
• Generate a shell script that assigns users, permissions and invokes the filesystem
image creation utility
• Invoke the shell script under fakeroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 320/340
fs/common.mk, dependencies and table generation
ROOTFS_COMMON_DEPENDENCIES = \
host-fakeroot host-makedevs \
$(BR2_TAR_HOST_DEPENDENCY) \
$(if $(PACKAGES_USERS)$(ROOTFS_USERS_TABLES),host-mkpasswd)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 321/340
fs/common.mk, rootfs infrastructure 1
define inner-rootfs
ROOTFS_$(2)_IMAGE_NAME ?= rootfs.$(1)
ROOTFS_$(2)_FINAL_IMAGE_NAME = $$(strip $$(ROOTFS_$(2)_IMAGE_NAME))
ROOTFS_$(2)_DIR = $$(FS_DIR)/$(1)
ROOTFS_$(2)_TARGET_DIR = $$(ROOTFS_$(2)_DIR)/target
ROOTFS_$(2)_DEPENDENCIES += rootfs-common
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 322/340
fs/common.mk, rootfs infrastructure 2
$$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES)
@$$(call MESSAGE,"Generating filesystem image $$(ROOTFS_$(2)_FINAL_IMAGE_NAME)")
[...]
mkdir -p $$(ROOTFS_$(2)_DIR)
rsync -auH \
--exclude=/$$(notdir $$(TARGET_DIR_WARNING_FILE)) \
$$(BASE_TARGET_DIR)/ \
$$(TARGET_DIR)
echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
echo "set -e" >> $$(FAKEROOT_SCRIPT)
echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(ROOTFS_FULL_USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT)
echo "$$(HOST_DIR)/bin/makedevs -d $$(ROOTFS_FULL_DEVICES_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
[...]
$$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
chmod a+x $$(FAKEROOT_SCRIPT)
PATH=$$(BR_PATH) $$(HOST_DIR)/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
[...]
ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
TARGETS_ROOTFS += rootfs-$(1)
endif
endef
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 323/340
fs/ubifs/ubifs.mk
UBIFS_OPTS := -e $(BR2_TARGET_ROOTFS_UBIFS_LEBSIZE) \
-c $(BR2_TARGET_ROOTFS_UBIFS_MAXLEBCNT) \
-m $(BR2_TARGET_ROOTFS_UBIFS_MINIOSIZE)
ifeq ($(BR2_TARGET_ROOTFS_UBIFS_RT_ZLIB),y)
UBIFS_OPTS += -x zlib
endif
...
ROOTFS_UBIFS_DEPENDENCIES = host-mtd
define ROOTFS_UBIFS_CMD
$(HOST_DIR)/sbin/mkfs.ubifs -d $(TARGET_DIR) $(UBIFS_OPTS) -o $@
endef
$(eval $(rootfs))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 324/340
Final example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 325/340
Buildroot community: support and contribution
Buildroot community:
support and
contribution
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 326/340
Documentation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 327/340
Getting support
▶ Free support
• The mailing list for e-mail discussion
http://lists.busybox.net/mailman/listinfo/buildroot
1400+ subscribers, quite heavy traffic.
• The IRC channel, #buildroot on the OFTC network, for interactive discussion
60+ people, most available during European daylight hours
• Bug tracker
https://bugs.busybox.net/buglist.cgi?product=buildroot
▶ Commercial support
• A number of embedded Linux services companies, including Bootlin, can provide
commercial services around Buildroot.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 328/340
Tips to get free support
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 329/340
Release schedule
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 330/340
Contribution process
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 331/340
Patchwork
▶ Tool that records all patches sent on the mailing list
▶ Allows the community to see which patches need review/testing, and the
maintainers which patches can be applied.
▶ Everyone can create an account to manage his own patches
▶ https://patchwork.ozlabs.org/project/buildroot/list/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 332/340
Automated build testing
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 333/340
autobuild.buildroot.org
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 334/340
Autobuild daily reports
Subject: [Buildroot] [autobuild.buildroot.net] Build results for 2019-03-19
unknown | 22
angularjs-legal-info | 15
host-uboot-tools-2019.01 | 11
[...]
Detail of failures
------------------
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 335/340
Additional testing effort
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 336/340
Acknowledgements
▶ Bootlin would like to thank the following members of the Buildroot community for
their useful comments and reviews during the development of these training
materials:
• Thomas De Schampheleire
• Peter Korsgaard
• Yann E. Morin
• Arnout Vandecappelle
• Gustavo Zacarias
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 337/340
Last slides
Last slides
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 338/340
Last slide
Thank you!
And may the Source be with you
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 339/340
Rights to copy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 340/340