Embedded Linux System Automatic Build Framework

Scan to FollowLearn Embedded Together, let’s learn and grow together

Embedded Linux System Automatic Build Framework

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.
You can configure Buildroot and modify it through menuconfig, just like compiling the Linux kernel, 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).

2. Buildroot Usage Demonstration

Taking the classic mini2440 development board project maintained by the official Buildroot open-source community as an example to demonstrate how to use it.
1) First, download the latest stable version zip package from the Buildroot official website and extract it under the Ubuntu system.
2) Enter the extracted Buildroot main directory; its directory structure is as follows.
Embedded Linux System Automatic Build Framework
3) make mini2440_defconfig
4) make all
5) After compilation, the generated flashable file image is located in the output/images/ folder in the main directory, as shown in the screenshot below:
Embedded Linux System Automatic Build Framework
It seems that as long as you execute the commands make *config and make all, u-boot/linuxkernel/rootfs can all be compiled at once, and the generated image can be directly flashed into the mini2440 development board to run. 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 is truly an automatic build artifact.
3. Advantages of Buildroot
Buildroot has the following advantages:
a). After running make *config, you can configure the software packages to compile using make menuconfig; the menuconfig directory is as follows:
Embedded Linux System Automatic Build Framework
Embedded Linux System Automatic Build Framework
In fact, applications such as uboot, linux kernel, and ffmpeg are not mandatory to compile; they can all be selected for compilation and building through make menuconfig. Buildroot essentially provides an automatic build framework, and users can choose what packages to compile.
b). Support for a rich set of open-source application packages. Who says embedded software engineers only deal with kernel drivers? With Buildroot, so many open-source applications can be ported and built onto your development board. Below is a screenshot of the open-source projects supported for automatic build in the Buildroot/package/ directory:
boost, python, ffmpeg, redis, opencv, opengl, webkit… Are these open-source applications familiar to you? That’s right; all these open-source application packages can be automatically completed in Buildroot through your configuration script, including downloading from the official website, extracting, configuring the system environment, compiling, and installing into the root file system, etc.
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 new software packages in the future, all the tedious porting work can be written into an automatic build script using Makefile. Once you have done the porting work once, you won’t have to do it again; just let Buildroot handle it automatically.
Embedded Linux System Automatic Build Framework
Embedded Linux System Automatic Build Framework
Embedded Linux System Automatic Build Framework
c). A single development board can be reused multiple times. A board can be configured as a phone, set-top box, monitor, router, or various interesting applications you can think of. That’s right; just add the corresponding configuration file to the configs/ directory, and the next time you compile, select that configuration and run make all. Then you can immediately build the corresponding flashable image, allowing your development board to transform from a phone to a router without having to go through the tedious porting and modification process each time.
Embedded Linux System Automatic Build Framework
d). A tool for team collaboration. You don’t have to handhold your colleagues or partners on how to rebuild an entire software package for a certain system; just give them your configured Buildroot, and everything will be done automatically. If any steps are unclear, they can look at the build scripts of each software package for instant clarity.

4. Buildroot Working Principle

Buildroot is essentially an automatic build framework. Although the official community has implemented the build scripts for classic open-source software packages like u-boot and linux kernel, sometimes you still need to add your unique app_pkg software package to build your applications.
Buildroot provides a function framework and 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, running make all executes the Makefile in the Buildroot main directory to generate the desired image.
The package/pkg-generic.mk script has already automatically implemented 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 just need to write the Makefile script app_pkg.mk according to the format, filling in the download address, the names of the linked dependencies, and other specific build details.
In summary, Buildroot 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.
Embedded Linux System Automatic Build Framework

5. Introduction to Buildroot Directory Structure

The screenshot of the Buildroot main directory is as follows, with a brief introduction to the scripts stored in each directory.
Embedded Linux System Automatic Build Framework
arch/ directory stores configuration scripts related to CPU architecture, such as arm/mips/x86. These CPU-related configurations are crucial when creating toolchains and compiling boot and kernel.
board/ directory stores various board-specific configuration scripts. The default boot and Linux kernel configuration files for the board and some special build process scripts related to the board are stored in this directory, waiting to be called during the automatic build.
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.
configs/ directory stores global configuration files for each scheme. The previous make mini2440_defconfig actually called the configuration for the mini2440 scheme in this directory. The configuration files in this directory record the toolchain, boot, kernel, and various application package configurations and whether they are selected for compilation. The configuration file for a specific development board’s entire system is also found in the configs/ directory.
dl/ directory contains open-source software packages downloaded from the official website. After the first download, subsequent downloads will be taken 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/ is the output folder for compiled files, where the build/ directory contains the site after various software packages have been extracted and compiled. The host/ directory contains the compiled toolchain, and the target/ directory is used to create rootfs, which contains the basic directory structure of the Linux system and various compiled application libraries and executable files. 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 have generally been tested and can successfully build the corresponding software packages.
support/ directory stores some fixed process scripts for building.
system/ directory stores templates for file system directories and device nodes. These templates will be copied to the output/ directory for creating the root file system rootfs.
toolchain/ directory contains scripts for creating various toolchains. Buildroot can either start from scratch using gcc and the Linux kernel, glibc, uclibc libraries as raw materials to create its own toolchain or download third-party pre-made open-source tools.

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

Content sourced from the internet, copyright belongs to the original author. If there is any infringement, please contact for removal.

Embedded Linux System Automatic Build Framework

Scan to join the high-quality embedded group chat

Embedded Linux System Automatic Build Framework

Follow me【Learn Embedded Together】, let’s learn and grow together.

If you find the article good, click “Share“, “Like“, or “View“!

Leave a Comment