Compile Buildroot firmware

This chapter describes the compilation and use of the Buildroot firmware.

Prerequisite

Download source code

Download repo tools:

mkdir linux
cd linux
git clone https://github.com/FireflyTeam/repo.git

Download Linux-SDK:

mkdir linux-sdk
cd linux-sdk

# Init repo.git
../repo/repo init --repo-url https://github.com/FireflyTeam/repo.git -u https://github.com/FireflyTeam/manifests.git -b linux-sdk -m rk3399/rk3399_linux_release.xml

# Synchronous source code
../repo/repo sync -c

Environment

Install the tools needed to compile and ensure that the tools are properly installed:

sudo apt-get install repo git-core gitk git-gui gcc-arm-linux-gnueabihf u-boot-tools device-tree-compiler \
gcc-aarch64-linux-gnu mtools parted libudev-dev libusb-1.0-0-dev python-linaro-image-tools \
linaro-image-tools autoconf autotools-dev libsigsegv2 m4 intltool libdrm-dev curl sed make \
binutils build-essential gcc g++ bash patch gzip bzip2 perl tar cpio python unzip rsync file bc wget \
libncurses5 libqt4-dev libglib2.0-dev libgtk2.0-dev libglade2-dev cvs git mercurial rsync openssh-client \
subversion asciidoc w3m dblatex graphviz python-matplotlib libc6:i386 libssl-dev texinfo \
liblz4-tool genext2fs lib32stdc++6

Compile SDK

Configuration

Select the configuration file corresponding to the development board. The configuration file will be linked to device/rockchip/.BoardConfig.mk, which will be checked to confirm the currently used configuration file:

./build.sh firefly-rk3399.mk

# file path: `device/rockchip/rk3399/firefly-rk3399.mk`

The .mk file is configured by default to compile the Buildroot firmware. The following describes the Buildroot configuration:

# Buildroot config
export RK_CFG_BUILDROOT=rockchip_rk3399     # Buildroot root filesystem configuration file

# file path: `buildroot/configs/rockchip_rk3399_defconfig`
# Recovery config
export RK_CFG_RECOVERY=rockchip_rk3399_recovery     # Root filesystem configuration file in recovery mode (can be omitted)

# file path: `buildroot/configs/rockchip_rk3399_recovery_defconfig`
# rootfs image path
export RK_ROOTFS_IMG=buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPE   # Buildroot root filesystem mirror path

# In this case, the file path is in `buildroot/output/rockchip_rk3399/images/rootfs.ext4`
# Note: This file path will be generated after the root filesystem is first compiled.

When the compile command is executed, it will be compiled according to the .mk file.

Automatic compilation

The automatic compilation will compile and package the firmware update.img, generate firmware directory rockdev/:

./build.sh

Partial compilation

  • kernel

./build.sh kernel
  • u-boot

./build.sh uboot
  • rootfs

Compile the Buildroot root filesystem and generate the compiled output directory in buildroot/output:

./build.sh buildroot

# Note: Be sure to compile the Buildroot root filesystem as a normal user to avoid unnecessary errors.
# The required packages are automatically downloaded during the compilation process, please stay connected.

Package firmware

Pack

Image the parts of the rockdev directory into firmware update.img:

./build.sh updateimg

Introduce Buildroot

Output

The Buildroot compilation output is saved in the output directory. The specific directory is determined by the configuration file. This example is saved in the buildroot/output/rockchip_rk3399 directory. You can then execute make to compile the root filesystem in this directory.

When fully automated, the buildroot/output/rockchip_rk3399_recovery directory is generated by default, which is the compiled output directory of recovery.

Subdirectory description:

  • build/ contains all source files, including the required host tools and selected packages for Buildroot. This directory contains all Module source code.

  • host/ Tools required for host-side compilation include cross-compilation tools.

  • images/ contains a compressed root filesystem image file.

  • staging/ This directory is similar to the directory structure of the root filesystem. It contains all the header files and libraries generated by the compiler, as well as other development files, but they are not tailored and are too large to be used for the target filesystem.

  • target/ contains the complete root filesystem. Compared to staging/, it has no development files, no header files, and the binary files are strip processed.

Customize Buildroot

Configure module

The default compiled root filesystem does not necessarily meet our needs. We may need to add some third-party packages or modify the configuration options of the package. Buildroot supports graphical configuration to select configurations:

cd buildroot/output/rockchip_rk3399/

# Enter the graphical configuration interface, select the required module, save and exit
make menuconfig

# Save configuration to configuration file 'buildroot/configs/rockchip_rk3399_defconfig'
make savedefconfig

#Compile the Buildroot root filesystem
make

What you need to know is:

  • When compiling, Buildroot will automatically get related packages from the network according to the configuration, including some third-party libraries, plug-ins, utilities, etc., placed in the dl/ directory.

  • The package will be extracted in the output/build/ directory and compiled.

  • If you want to modify the source code of the package, you can modify it by patching it. The patch is placed in the package/ directory, and Buildroot will patch it when unpacking the package.

Modify busybox

The command tool that busybox uses to manage the system can be modified as follows:

cd buildroot/output/rockchip_rk3399/

# Enter the graphical configuration interface, select the required module, save and exit
make busybox-menuconfig

# Save configuration to configuration file `board/rockchip/common/base/busybox.config`
make busybox-update-config

make

Overlay root filesystem

A filesystem overlay is a tree of files that are copied directly over the target filesystem after it has been built. In this way, we can simply add or modify some files:

  • private overlays path buildroot/board/rockchip/rk3399/fs-overlay-64

  • public overlays path buildroot/board/rockchip/common

Example: buildroot/board/rockchip/rk3399/fs-overlay-64/etc/input-event-daemon.conf will overwrite the filesystem’s /etc/input-event-daemon.conf.

Buildroot website

More detailed and specific development techniques can be learned from the Buildroot website.

Buildroot website

Buildroot development manual