Buildroot: Simplifying Embedded Linux System Builds

    Follow and star our official account for exciting content.

Author: zhou_chenz
Source: https://blog.csdn.net/zhou_chenz/article/details/52295674

Using Buildroot makes building embedded Linux systems more convenient.

1. What is Buildroot? Buildroot is an open-source automatic build framework for embedded Linux systems on the Linux platform. The entire Buildroot consists of Makefile scripts and Kconfig configuration files. Similar to compiling the Linux kernel, you can modify the configuration through buildroot's menuconfig to compile a complete Linux system software that can be directly flashed to the machine (including boot, kernel, rootfs, and various libraries and applications in rootfs).

2. Demonstration of Buildroot usage using the classic mini2440 development board project maintained by the official Buildroot open-source community as an example.
1) First, download the latest stable version zip package from the Buildroot official website and extract it on the Ubuntu system.
2) Enter the extracted Buildroot main directory, the directory structure is as follows.

3) make mini2440_defconfig
4) make all
5) After compilation, the generated flashable image file is located in the output/images/ folder in the main directory, as shown below:

It seems that by just executing the commands make *config and make all, u-boot/linuxkernel/rootfs can all be compiled at once, and the resulting image can be directly flashed to the mini2440 development board. In the future, the tedious work of making uboot, compiling the kernel, compiling various apps, and creating rootfs can all be automated in one go; my mother no longer needs to worry about errors in my build process. Buildroot truly lives up to its reputation as an automatic build tool.

3. Advantages of Buildroot
Buildroot has the following advantages:
a). After make *config, you can configure the software packages to compile using make menuconfig. The menuconfig directory is as follows:

In fact, the uboot, linux kernel, and ffmpeg application packages do not all need to be compiled; they can all be selected for compilation and construction through make menuconfig. Buildroot essentially provides an automatic build framework, and the specific packages to compile are up to the user to choose.
b). Support for a rich set 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 applications familiar? That's right, these open-source application packages can all be automatically completed under Buildroot through your configuration scripts, including downloading from the official website, extraction, system environment configuration, compilation, and installation into the root filesystem, among other tedious tasks.
You no longer need 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 your own new software package in the future, all the tedious porting work can be written into an automatic build script using Makefile; once the porting work is done, you won't have to do it again. Just let Buildroot handle it automatically.

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 other interesting applications. That's right, as long as you add the corresponding configuration files to the configs/ directory, the next time you compile, select that configuration and run make all. You can immediately build the corresponding flashable image, allowing your development board to instantly transform from a phone into a router without the need for time-consuming porting and modifications each time.

d). A tool for team collaboration. You don't need to manually instruct your colleagues or partners on how to build the entire software package of a certain system from scratch. Just hand them your configured Buildroot, and everything will be done automatically. If there are any unclear steps, they can refer to the build scripts of each software package, making everything instantly clear.

4. How Buildroot Works
Buildroot is essentially an automatic build framework. Although the official community has implemented build scripts for classic open-source software packages like u-boot and linux kernel, sometimes you still need to add your own unique app_pkg software package for building your applications.
Buildroot provides a function framework and variable command framework (details will be introduced in the next article). The app_pkg.mk format of the 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, running make all executes the Makefile in the Buildroot main directory to generate the image you want.
The package/pkg-generic.mk already helps you automatically implement a series of mechanized processes such as downloading, extracting, and compiling dependency packages by calling the pkg-download.mk and pkg-utils.mk files in the same directory. You only need to follow the format to write the Makefile app_pkg.mk, filling in the download address, linking the names of the dependent libraries, and other specific build details.
In summary, Buildroot itself provides the framework for the build process, and developers write scripts according to the format, provide the necessary build details, configure the entire system, and finally automatically build your system.

5. Overview of the Buildroot Directory Structure
Below is a screenshot of the Buildroot main directory, with a brief introduction to the scripts stored in each directory.

The arch/ directory stores CPU architecture-related configuration scripts, such as arm/mips/x86. These CPU-related configurations are crucial when creating toolchains and compiling boot and kernels.
The board/ directory stores various board-specific configuration scripts. During system construction, the default boot and Linux kernel configuration files, as well as some board-related special build process scripts, are all stored in this directory, waiting to be called during automatic construction.
The boot/ directory contains automatic build scripts for various boot software, not just u-boot, but also grub, etc., which can also be built using Buildroot.
The configs/ directory stores the 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 compilation choices for that machine platform or solution. The configuration file for the entire system of a specific development board is located in the configs/ directory.
The dl/ directory stores open-source packages downloaded from the official website. After the first download, it won't download from the official website again but will take the open-source package from the dl/ directory to save time.
The docs/ directory stores relevant reference documents.
The fs/ directory contains automatic build scripts for various filesystems.
The linux/ directory stores automatic build scripts for the Linux kernel.
The output/ directory is the output folder where compiled files are stored. Inside the build/ directory, the site of various software packages after extraction and compilation is stored. The host/ directory contains the compiled toolchain, while the target/ directory is used to create the rootfs, containing the basic directory structure of the Linux system and various compiled application libraries and executable files. The Images/ directory contains all the various images generated that can be flashed onto the board.
The package/ directory stores automatic compilation build scripts for various third-party open-source application packages, which have generally been tested to successfully build the corresponding software packages.
The support/ directory stores some fixed process scripts for building.
The system/ directory stores templates for filesystem directories and device nodes, which are copied to the output/ directory for creating the root filesystem (rootfs).
The toolchain/ directory contains scripts for making various toolchains. Buildroot can choose to create a toolchain from scratch using gcc and the Linux kernel, glibc, uclibc libraries, etc., or it can download third-party open-source tools.
Copyright Statement: This article is sourced from the internet and is freely disseminated knowledge. The copyright belongs to the original author. If there are any copyright issues, please contact me for deletion.

‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧  END  ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧

Follow my WeChat public account and reply 'Join group' to join the technical exchange group according to the rules.

Click 'Read the original' for more sharing. Feel free to share, save, like, or view.

Leave a Comment