Compile Buildroot firmware

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

Preparatory work

Build a compilation environment

sudo apt-get install repo git ssh make gcc libssl-dev liblz4-tool \
expect g++ patchelf chrpath gawk texinfo chrpath diffstat binfmt-support \
qemu-user-static live-build bison flex fakeroot cmake gcc-multilib g++-multilib \
unzip device-tree-compiler python-pip ncurses-dev python-pyelftools

Download Firefly_Linux_SDK

  • Method One

Download via repo:

mkdir ~/proj/rk356x_linux_release_20211019/
cd ~/proj/rk356x_linux_release_20211019/
repo init --no-clone-bundle --repo-url -u -b master -m rk356x_linux_release.xml
  • Method Two

Download Firefly_Linux_SDK sub-volume compressed package: Firefly_Linux_SDK Source

After downloading, verify the MD5 code:

$ md5sum rk356x_linux_release_v1.2.0_20211019_split_dir/*firefly_split*
b633414d69240faa0c3bd755c255ede8  rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file0
5cb1e2b63bbb4e3595c731038f6723fd  rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file1
e06c0f29fd5a870e0942139a1877a470  rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file2
4e14fbf72ccbb9b87f81d83a256205b0  rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file3
be8b003703b51e7220e52bb36439a357  rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file4

After confirming that it is correct, you can unzip:

Attention: To avoid unnecessary errors, please do not unzip the SDK in shared folders, mounted folders or non-english directories.

mkdir ~/proj/
cd ~/proj/
cat path/to/rk356x_linux_release_v1.2.0_20211019_split_dir/*firefly_split* | tar -xzv

Sync Code

Execute the following command to synchronize the code:

# Enter the SDK root directory
cd ~/proj/rk356x_linux_release_20211019/

# Sync
.repo/repo/repo sync -l
.repo/repo/repo sync -c --no-tags
.repo/repo/repo start firefly --all

You can use the following command to update the SDK later:

.repo/repo/repo sync -c --no-tags

Directory Structure

$ tree -L 1
├── app
├── buildroot # Buildroot root filesystem build directory
├── -> device/rockchip/common/ # Compile script
├── debian # Debian root filesystem compilation directory
├── device # Compile related configuration files
├── distro
├── docs # Documentation
├── -> buildroot/build/
├── external
├── kernel
├── Makefile -> buildroot/build/Makefile
├── -> device/rockchip/common/ # Link script
├── prebuilts # Cross compilation toolchain
├── rkbin
├── -> device/rockchip/common/ # Flash script
├── tools # Tools directory
├── u-boot
└── yocto

Compile SDK

Configuration before compilation

In the device/rockchip/rk356x/ directory, there are configuration files of different board types, select the configuration file:


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

Related configuration introduction:

# Target arch
export RK_ARCH=arm64 # 64-bit ARM architecture
# Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3566 # u-boot configuration file
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig # kernel configuration file
# Kernel dts
export RK_KERNEL_DTS=rk3566-firefly-roc-pc # dts file
# Buildroot config
export RK_CFG_BUILDROOT=rockchip_rk3566 # Buildroot configuration
# Recovery config
export RK_CFG_RECOVERY=rockchip_rk356x_recovery # recovery configuration
# parameter for GPT table
export RK_PARAMETER=parameter-buildroot-fit.txt # Partition table
# rootfs image path
export RK_ROOTFS_IMG=rockdev/rootfs.${RK_ROOTFS_TYPE} # root filesystem path

Select Accessories to Compile

Select Screen

Choose different DTS in :

# Kernel dts
export RK_KERNEL_DTS=rk3566-firefly-roc-pc # HDMI (Default)
# Or
export RK_KERNEL_DTS=rk3566-firefly-roc-pc-mipi101_HSTM101014_BE45_B1 # DM-M10R800 V2 MIPI

Select Camera

In the DTS that selected in previous step, include different dtsi to select camera:

*                               select camera
* using single camera xc7160        --->  rk3566-firefly-roc-pc-cam-8ms1m.dtsi
* using dual camera gc2053/gc2093   --->  rk3566-firefly-roc-pc-cam-2ms2m.dtsi
// Using single-camera module CAM-8MS1M
#include "rk3566-firefly-roc-pc-cam-8ms1m.dtsi"
// Or using dual-camera module CAM-2MS2MF
#include "rk3566-firefly-roc-pc-cam-2ms2m.dtsi"

Partial compilation

  • Compile u-boot

./ uboot
  • Compile kernel

./ kernel
  • Compile recovery

./ recovery
  • Compile Buildroot root filesystem

Compiling the Buildroot root filesystem will generate a compilation output directory in buildroot/output:

./ buildroot

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

Package the firmware

Update each part of the mirror link to the rockdev/ directory:


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

./ updateimg

Automatic compilation

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


Partition description

parameter partition table

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

Path: device/rockchip/rk356x/parameter-buildroot-fit.txt

MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 0xffffffff
PWR_HLD: 0,0,A,0,1
CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00010000@0x00008000(boot),0x00010000@0x00018000(recovery),0x00010000@0x00028000(backup),0x00040000@0x00038000(oem),0x00c00000@0x00078000(rootfs),-@0x00c78000(userdata:grow)

The CMDLINE attribute is our focus. Taking uboot as an example, 0x00004000 in 0x00002000@0x00004000(uboot) is the starting position of the uboot partition, 0x00002000 is the size of the partition, and so on.


The package-file 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 file.

Path: tools/linux/Linux_Pack_Firmware/rockdev/rk356x-package-file

package-file    package-file
bootloader      Image/MiniLoaderAll.bin
parameter       Image/parameter.txt
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        Image/userdata.img
backup          RESERVED