Beginner’s Guide to Buildroot: An Easy Start

Using Buildroot makes building embedded Linux systems more convenient.

What is Buildroot?

Buildroot is an open-source embedded Linux system automatic build framework on the Linux platform. The entire Buildroot consists of Makefile scripts and Kconfig configuration files. You can configure Buildroot and modify it using menuconfig to compile a complete Linux system software that can be directly flashed onto the machine (including boot, kernel, rootfs, and various libraries and applications in rootfs), just like compiling the Linux kernel.

Buildroot Usage Demonstration

Taking the classic mini2440 development board project maintained by the Buildroot official open-source community as an example, this section demonstrates its usage.
1) First, download the latest stable version compressed package from the Buildroot official website and extract it under the Ubuntu system.
2) Enter the extracted Buildroot main directory, the directory structure is as follows.
Beginner's Guide to Buildroot: An Easy Start
3) make mini2440_defconfig
4) make all
5) After compilation, the generated writable image file can be found in the output/images/ folder in the main directory, as shown in the screenshot:
Beginner's Guide to Buildroot: An Easy Start
It seems that as long as you execute the commands make *config and make all, u-boot/linux kernel/rootfs can be compiled at once, and the generated image can be directly flashed into the mini2440 development board for operation. In the future, the tedious tasks of making uboot, compiling the kernel, compiling various apps, and creating rootfs can all be automated in one go. My mom no longer has to worry about me making mistakes during the build process. Buildroot truly deserves the title of an automatic building artifact.
Advantages of Buildroot
Buildroot has the following advantages:
a). After using make *config, you can configure the software packages to be compiled through make menuconfig, as shown in the menuconfig directory below:
Beginner's Guide to Buildroot: An Easy Start
Beginner's Guide to Buildroot: An Easy Start
In fact, applications like uboot, linux kernel, and ffmpeg are not necessarily compiled by default; they can be selected for compilation and building through make menuconfig. Buildroot is primarily an automatic build framework; what packages to compile are entirely up to the user.
b). Support for a rich variety of open-source application packages. Who says embedded software engineers only work on kernel drivers? With Buildroot, so many open-source applications can be ported and built onto your development board. Below is a screenshot of the supported automatic build open-source projects in the Buildroot/package/ directory:
boost, python, ffmpeg, redis, opencv, opengl, webkit… Aren’t these open-source application packages familiar? That’s right, these open-source applications can be automatically downloaded, extracted, configured, compiled, and installed into the root filesystem through your configuration script in Buildroot.
You no longer have to ask around in QQ groups and forums about how to port certain open-source software to your Linux development board. Even if you need to develop new software packages in the future, all the tedious porting work can be written into an automatic build script using Makefile. Once the porting work is done, it doesn’t need to be repeated; just let Buildroot handle it automatically.
Beginner's Guide to Buildroot: An Easy Start
Beginner's Guide to Buildroot: An Easy Start
Beginner's Guide to Buildroot: An Easy Start
c). A single development board can be reused multiple times. One board can be configured as a phone, set-top box, monitor, router, or various interesting applications. That’s right, as long as you add the corresponding configuration file to the configs/ directory, the next time you compile, select that configuration, and execute make all. You can immediately build the corresponding writable image, flash it into the development board, and instantly transform your board from a phone to a router without the need for tedious porting and modifications each time.
Beginner's Guide to Buildroot: An Easy Start
d). A tool for team collaboration. You no longer have to explain to your colleagues or partners how to rebuild a certain system’s entire software package from scratch. Just give them your configured Buildroot, and everything will be completed automatically. If there are any unclear steps, they can refer to the build scripts of each software package for instant clarity.

How Buildroot Works

Buildroot is essentially an automatic build framework. Although the official community has implemented build scripts for classic open-source packages like u-boot and linux kernel, you may still need to add your unique app_pkg software package to build your applications.
Buildroot provides a function framework and a variable command framework (details will be introduced in the next article). The app_pkg.mk automatic build script written using its framework will be expanded and filled into the Makefile in the Buildroot main directory by the core script package/pkg-generic.mk. Finally, executing make all runs the Makefile in the Buildroot main directory to generate the desired image.
In package/pkg-generic.mk, by calling pkg-download.mk and pkg-utils.mk files in the same directory, it has already automated a series of mechanized processes such as downloading, extracting, and compiling dependency packages. You only need to write the Makefile script app_pkg.mk according to the format, filling in the download address, linking the names of dependent libraries, and other specific build details.
In summary, Buildroot provides the framework for the build process. Developers write scripts according to the format, provide the necessary build details, configure the entire system, and finally automatically build their system.
Beginner's Guide to Buildroot: An Easy Start

Introduction to Buildroot Directory Structure

The screenshot of the Buildroot main directory is shown below, along with a brief introduction to the scripts stored in each directory.
Beginner's Guide to Buildroot: An Easy Start
arch/ Directory stores CPU architecture-related configuration scripts, such as arm/mips/x86. These CPU-related configurations are crucial when creating toolchains, compiling boot and kernel.
board/ Directory stores various board-specific configuration scripts. During system construction, the default boot and Linux kernel configuration files for the board, as well as some special build process scripts related to the board, are all in this directory, waiting to be called during automatic building.
boot/ Directory contains automatic build scripts for various boot software, not just u-boot, but also grub, which can also be built using Buildroot.
configs/ Directory stores global configuration files for each solution. The previous make mini2440_defconfig actually called the configuration of the mini2440 solution in this directory. The configuration files in this directory record the toolchain, boot, kernel, and various application package configurations and their compilation selection statuses for that machine platform or solution. The entire system configuration file for a specific development board is located in the configs/ directory.
dl/ Directory contains open-source packages downloaded from the official website. After the first download, it will not download from the official website again but will take the open-source packages from the dl/ directory to save time.
docs/ Stores relevant reference documents.
fs/ Stores automatic build scripts for various file systems.
linux/ Stores automatic build scripts for the Linux kernel.
output/ This is the output folder for compiled files. The build/ directory inside stores the site of various software packages after extraction and compilation. The host/ directory contains the compiled toolchain, while the target/ directory is used to create rootfs, containing the basic directory structure of the Linux system, various compiled application libraries, and executable binaries. The Images/ directory contains various images that can be flashed onto the board.
package/ Directory stores automatic compilation build scripts for various third-party open-source application packages. These build scripts are generally tested and can build the corresponding software packages.
support/ Directory stores some fixed process scripts for building.
system/ Directory stores templates for the filesystem directory and device nodes, which will be copied to the output/ directory for creating the root filesystem rootfs.
toolchain/ Directory contains scripts for creating various toolchains. Buildroot can choose to create its toolchain from scratch using gcc, the Linux kernel, glibc, uclibc libraries, etc., or download third-party open-source tools that have already been created.
—— The End ——
Recommended Reading:
Collection | Linux Driver Development
Collection | Linux System Programming
Collection | A Little C Every Day
Collection | Introduction to Qt
Author: zhou_chenz
Source: https://blog.csdn.net/zhou_chenz/article/details/52295674

Leave a Comment