Chozmao / MyBlog

0 stars 0 forks source link

Buildroot 学习 #7

Open Chozmao opened 3 years ago

Chozmao commented 3 years ago

Buildroot Learning

About Buildroot

Buildroot is a tools for building a complex Linux system for an embedded device, using cross-compilation. For this purpose, Buildroot is able to generete:

Buildroot is designed to run on a Linux machine. Some tools might needed from the host system. Every 3 months

a new release will be published.

Buildroot Quick Start

Note: you can and should build everything as a normal user! No need for root authority.

First of all, using configuration tool to create configuration file before starting Buildroot building process. Configuration tools reads in the Config.in file and generates a .config file, which contains entire configuration and will be read by the top-level Makefile.

Config.in -------> make menuconfig -------> .config -------> top-level Makefile

Second, using make command to start building process.

make -------> output/
                    |__ images (stores kernel, bootloader, and root fs images)
                    |__ build (e.g., compiled packages for the target)
                    |__ host (contains tools built for the host and the sysroot of target                       |         toolchains)
                    |__ staging (symlink points to sysroot inside the host directory)
                    |__ target (contains almost the complete root filesystem for the target                                 except /dev directory, because Buildroot does not run as                                    root)

General produces after calling make:

Cross-compilation toolchain: runs on host sytem but generates code for target system. It consists of 3 components: a compiler (e.g., gcc), a assembler/linker (e.g., binutils), and a standard C library (e.g., GNU Libc (glibc) or uClibc-ng).

Crosstool-NG

Init System: init program is the first userspace program started by the kernel, BusyBox init is sufficient for most embedded systems. systemd can be used for more complex situations.

what is defconfig, kconfig, and .config files in linux system?

when .config file is being generated, kernel build system goes through all Kconfig files (from all subdirs) and checks all the options in those Kconfig files:

Rebuild a package: to rebuild a single package from scrath is to remove its build directory in output/build.

How to use the existing configuration file for module building?

Make tips

make clean: Explicit cleaning is required when any of the architecture or toolchain configuration options are changed. To delete all build products (including build directories, host, staging and target trees, the images and the toolchain).

make distclean: delete all build products as well as the configuration (resetting Buildroot to a new target).

make clean all: achieved a full rebuild.

make <package>-dirclean: removes the package's build directory in output/build. This is necessary, when you just want to rebuild a single package.

make <package>-rebuild: restarts the compilation and installation of the package, but not from scratch: it basically re-executes make and make install inside the package, so it will only rebuild the files that changed.

Building out-of-tree

When using out-of-tree builds, the Buildroot .config and temporary files are also stored in the output directory. This means that you can safely run multiple builds in parallel using the same source tree as long as they use unique output directories.

make O=/tmp/build -C path/to/buildroot

Note: for ease of use, Buildroot generates a Makefile wrapper in the output directory - so after the first run, you no longer need to pass O=<...> and -C <...>, simply run (in the output directory):

make <target>

Details about packages

make show-info: produces a JSON blurb that describes the set of enabled packages in the current configuration, together with their dependencies, licenses and other metadata.

make pkg-stats: produces details about packages as HTML and JSON output. Amongst other things, these details include whether known CVEs affect the packages in your current configuration. It also shows if there is a newer upstream version for those packages.

Graphing the dependencies between packages

To enable this feature, you need to install the graphviz package on your host system.

make graph-depends: generated graph is stored in output/graph/graph-depends.pdf

make <pkg>-graph-depends: generated graph is stored in output/graph/-graph-depends.pdf

Graphing the build duration

To enable this feature, you need to install python-matplotlib and python-numpy on your host system.

make graph-build: generate a set of files in output/graphs.

Graphing the filesystem size contribution of packages

make graph-size

Developer guide

build out-of-tree: make imx6ulevk_defconfig O=/tmp/imx6_build, this command generates a .config file for imx6ulevk board and a wrapper for it in our customized directory /tmp/imx6_build. We can now go to /tmp/imx6_build directory and run make there or make menuconfig to change the configuration file.

Chozmao commented 1 year ago

Make version 4.3 does not allow to use printvar receipt, which causes it fail to call receipt make pkg-stats