Getting Started with Buildroot
Total Page:16
File Type:pdf, Size:1020Kb
Embedded Apprentice Linux Engineer Getting started with Buildroot Thomas Petazzoni [email protected] ľ Copyright 2004-2018, Bootlin. Creative Commons BY-SA 3.0 license. Formerly Free Electrons Corrections, suggestions, contributions and translations are welcome! - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/1 Thomas Petazzoni I Embedded Linux engineer at Free Electrons → Bootlin I Embedded Linux expertise I Development, consulting and training I Strong open-source focus I Freely available training materials I Open-source contributor I Living in Toulouse, France - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/1 Building an embedded Linux system + Readily available - Large, usually 100+ MB - Not available for all architectures - Not easy to customize - Generally require native compilation - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/1 Building an embedded Linux system + Smaller and flexible - Very hard to handle cross-compilation and dependencies - Not reproducible - No benefit from other people’s work - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/1 Building an embedded Linux system + Small and flexible + Reproducible, handles cross-compilation and dependencies + Available for virtually all architectures - One tool to learn - Build time - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/1 I Cross-compilation → leveraging fast build machines I Recipes for building components → easy Embedded Linux build system: principle I Building from source → lot of flexibility - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/1 I Recipes for building components → easy Embedded Linux build system: principle I Building from source → lot of flexibility I Cross-compilation → leveraging fast build machines - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/1 Embedded Linux build system: principle I Building from source → lot of flexibility I Cross-compilation → leveraging fast build machines I Recipes for building components → easy - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/1 Buildroot at a glance I Is an embedded Linux build system, builds from source: I cross-compilation toolchain I root filesystem with many libraries/applications, cross-built I kernel and bootloader images I Fast, simple root filesystem in minutes I Easy to use and understand: kconfig and make I Small root filesystem, default 2 MB I More than 2300 packages available I Generates filesystem images, not a distribution I Vendor neutral I Active community, stable releases every 3 months I Started in 2001, oldest still maintained build system I http://buildroot.org - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/1 Getting started $ git clone git://git.busybox.net/buildroot $ cd buildroot $ make menuconfig - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/1 2. Build options 3. Toolchain 4. System configuration 5. Kernel 6. Target packages 7. Filesystem images 8. Bootloaders 9. Host utilities Buildroot configuration 1. Target architecture I Architecture ARC, ARM, AArch64, Blackfin, csky, m68k, Microblaze, MIPS(64), NIOS II, OpenRisc, PowerPC(64), SuperH, SPARC, x86, x86 64, Xtensa I Specific processor I ABI I Floating point strategy - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 3. Toolchain 4. System configuration 5. Kernel 6. Target packages 7. Filesystem images 8. Bootloaders 9. Host utilities Buildroot configuration 1. Target architecture 2. Build options I Download directory I Number of parallel jobs I Use of ccache I Shared or static libraries I etc. - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 4. System configuration 5. Kernel 6. Target packages 7. Filesystem images 8. Bootloaders 9. Host utilities Buildroot configuration 1. Target architecture 2. Build options I Buildroot toolchain 3. Toolchain I Buildroot builds the toolchain I uClibc, glibc, musl I External toolchain I Uses a pre-built toolchain I Profiles for existing popular toolchains Linaro, Sourcery CodeBench, etc. I Custom toolchains - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 5. Kernel 6. Target packages 7. Filesystem images 8. Bootloaders 9. Host utilities Buildroot configuration 1. Target architecture 2. Build options I Init system to use: BusyBox, Sysvinit, Systemd 3. Toolchain I /dev management solution: static, devtmpfs, 4. System configuration mdev, udev I Hostname, password, getty terminal, etc. I Root filesystem overlay I Custom post build and post image scripts I etc. - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 6. Target packages 7. Filesystem images 8. Bootloaders 9. Host utilities Buildroot configuration 1. Target architecture 2. Build options 3. Toolchain I Kernel source (stable version, Git tree, patches) 4. System configuration I Kernel configuration 5. Kernel I Support for kernel extensions: RTAI, Xenomai, aufs, etc. - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 7. Filesystem images 8. Bootloaders 9. Host utilities Buildroot configuration 1. Target architecture I More than 2300 packages 2. Build options I Qt4, Qt5, X.org, Gtk, EFL 3. Toolchain I GStreamer, ffmpeg 4. System configuration I Python, Perl, Ruby, Lua, Erlang 5. Kernel I Samba, OpenSSL, OpenSSH, dropbear, 6. Target packages lighttpd I OpenGL support for various platforms I And many, many more libraries and utilities - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 8. Bootloaders 9. Host utilities Buildroot configuration I Major filesystem formats supported 1. Target architecture I cloop 2. Build options I cpio, for kernel initramfs 3. Toolchain I cramfs 4. System configuration I ext2/3/4 5. Kernel I jffs2 6. Target packages I romfs 7. Filesystem images I squashfs I tar I ubifs - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 9. Host utilities Buildroot configuration 1. Target architecture 2. Build options I Grub2 3. Toolchain I Syslinux 4. System configuration I U-Boot 5. Kernel I Barebox 6. Target packages I and more platform-specific bootloaders: 7. Filesystem images imx-bootlets, at91bootstrap, etc. 8. Bootloaders - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 Buildroot configuration 1. Target architecture 2. Build options 3. Toolchain 4. System configuration I Allows to build some native tools, useful for 5. Kernel development. 6. Target packages 7. Filesystem images 8. Bootloaders 9. Host utilities - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1 Building and using I To start the build: make I Results in output/images: I rootfs.ext4, root filesystem in ext4 format I zImage, Linux kernel image I am335x-pocketbeagle.dtb, Linux kernel Device Tree blob I u-boot.img, U-Boot bootloader image I MLO, U-Boot bootloader image I Ready to be flashed on your embedded system. - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/1 Exploring the build output I All the output produced by Buildroot is stored in output/ I Can be customized using O= for out-of-tree build I output/ contains I output/build, with one sub-directory for the source code of each component I output/host, which contains all native utilities needed for the build, including the cross-compiler I output/host/<tuple>/sysroot, which contains all the headers and libraries built for the target I output/target, which contains almost the target root filesystem I output/images, the final images - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/1 Summarized build process 1. Check core dependencies 2. For each selected package, after taking care of its dependencies: download, extract, patch, configure, build, install I To target/ for target apps and libs I To host/<tuple>/sysroot for target libs I To host/ for native apps and libs I Filesystem skeleton and toolchain are handled as regular packages 3. Copy rootfs overlay 4. Call post build scripts 5. Generate the root filesystem image 6. Call post image scripts - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/1 Customizing the build Besides the existing packages and options, there are multiple ways to customize the generated root filesystem: I Create custom post-build and/or post-image scripts I Use a root filesystem overlay, recommended to add all your config files I Add your own packages - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/1 Adding a new package: Config.in package/libmicrohttpd/Config.in config BR2_PACKAGE_LIBMICROHTTPD bool "libmicrohttpd" depends on BR2_TOOLCHAIN_HAS_THREADS