Build Buildroot firmware

This chapter introduces the compilation process of Buildroot firmware. It is recommended to develop under Ubuntu 16.04 system environment. If you use other system versions, you may need to adjust the compilation environment accordingly.

Prerequisite

Download Firefly_Linux_SDK

Download: Linux_SDK.7z

After downloading, verify the MD5 code:

$ md5sum firefly-sdk-20200629.7z

d8c52272725ff8a2216fc2be7a92ffc4  firefly-sdk-20200629.7z

After confirming that it is correct, you can unzip:

mkdir -p ~/proj/AIO-3288C
cd ~/proj/AIO-3288C
7z x /path/to/firefly-sdk-20200629.7z -r -o ./
git reset --hard
  • Update

Note: Be sure to update the remote warehouse after decompression. The following is how to update from github:

#1. Enter the SDK root directory
cd ~/proj/AIO-3288C

#2. Download remote bundle repository
git clone https://github.com/FireflyTeam/bundle.git -b rk3288-linux-bundle

#3. If clone fails, you can go to github to download bundle.zip:

#4. Update the SDK, and subsequent updates do not need to pull the remote warehouse again, just execute the following command
./bundle/update rk3288-linux-bundle

#5. Follow the prompts to update the content to FETCH_HEAD, synchronize FETCH_HEAD to the firefly branch
git rebase FETCH_HEAD

#6. Update sharing code
./bundle/update common-linux-bundle
git rebase FETCH_HEAD

Directory

$ tree -L 1
.
├── app
├── buildroot                                               # Buildroot filesystem
├── build.sh -> device/rockchip/common/build.sh             # compile script
├── debian                                                  # Debian filesystem
├── device                                                  # config files
├── distro
├── docs                                                    # document
├── envsetup.sh -> buildroot/build/envsetup.sh
├── external
├── kernel
├── makefile -> buildroot/build/makefile
├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh   # link script
├── prebuilts                                               # cross-compile toolchain
├── rkbin
├── rkflash.sh -> device/rockchip/common/rkflash.sh         # flashing script
├── tools
├── u-boot
└── yocto

Set up compilation environment

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 lzop libncurses5-dev libssl1.0.0 libssl1.0.0 expect

Build Linux-SDK

Precompile Configuration

There are configuration files for different board in device/rockchip/rk3288/, select the configuration file:

./build.sh aio-3288c-buildroot.mk

The configuration file will be connected to device/rockchip/.BoardConfig.mk, check the file to verify whether the configuration is successful.

Configruation content:

# Target arch
export RK_ARCH=arm                                              # 32-bit ARM
# Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3288                        # u-boot configuration
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig              # kernel configuration
# Kernel dts
export RK_KERNEL_DTS=rk3288-firefly-aioc                        # dts file
# Buildroot config
export RK_CFG_BUILDROOT=rockchip_rk3288                         # Buildroot configuration
# Recovery config
export RK_CFG_RECOVERY=rockchip_rk3288_recovery                 # recovery configuration
# parameter for GPT table
export RK_PARAMETER=parameter-buildroot.txt                     # partition table
# rootfs image path
export RK_ROOTFS_IMG=buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPE   # filesystem path

Partial compilation

  • u-boot

./build.sh uboot
  • kernel

./build.sh kernel
  • recovery

./build.sh recovery
  • Buildroot filesystem

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

./build.sh buildroot

# Note: Be sure to compile the Buildroot filesystem as a normal user to avoid unnecessary errors.

Pack the firmware

Update each part of the .img link to the directory rockdev/:

./mkfirmware.sh

Pack the firmware, the firmware will be saved to the directory rockdev/pack/.

./build.sh updateimg

Automatic compilation

The automatic compilation will perform the above compilation and packaging operations to generate complete firmware.

./build.sh

Partition table

parameter

The parameter.txt file contains the partition information of the firmware. Take parameter-buildroot.txt as an example:

path: device/rockchip/rk3288/parameter-buildroot.txt

FIRMWARE_VER: 8.1
MACHINE_MODEL:RK3288
MACHINE_ID:007
MANUFACTURER:RK3288
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 3288
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT
CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(trust),0x00002000@0x00008000(misc),0x00010000@0x0000a000(boot),0x00010000@0x0001a000(recovery),0x00010000@0x0002a000(backup),0x00020000@0x0003a000(oem),0x00100000@0x0005a000(rootfs),-@0x0015a000(userdata:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9

The CMDLINE attribute is where we are concerned. Take uboot as an example. In 0x00002000@0x00004000(uboot), 0x00004000 is the starting position of the uboot partition, 0x00002000 is the size of the partition, and so on.

package-file

The package-file is used to determine the required partition image and image path when packaging the firmware, and it needs to be consistent with the parameter.txt.

path: tools/linux/Linux_Pack_Firmware/rockdev/rk3288-package-file

# name          relative path
#
#hwdef          hwdef
package-file    package-file
bootloader      image/miniloaderall.bin
parameter       image/parameter.txt
trust           image/trust.img
uboot           image/uboot.img
misc            image/misc.img
boot            image/boot.img
recovery        image/recovery.img
rootfs          image/rootfs.img
oem             image/oem.img
userdata:grow   image/userdata.img
backup          reserved

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_rk3288 directory. You can then execute make to compile the filesystem in this directory.

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 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_rk3288/

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

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

#Compile the Buildroot 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_rk3288/

# 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:

For example, we add the file overlay-test to the directory buildroot/board/rockchip/rk3288/fs-overlay/etc/overlay-test, and then recompile the filesystem. After the compilation is complete, by looking at the target/ directory, you can find that the file /etc/overlay-test was generated in the corresponding directory of the filesystem.

Buildroot website

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

Buildroot website

Buildroot development manual