Compile the Buildroot firmware

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

Preparatory work

Download Firefly_Linux_SDK

The Firefly_Linux_SDK source package is relatively large, and the Firefly_Linux_SDK source package can be obtained as follows:Firefly_Linux_SDK Source

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:

7z x firefly-sdk-20200629.7z
cd firefly-sdk
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 firefly-sdk

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

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

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

#5. Update common bundle
./bundle/update common-linux-bundle
git rebase FETCH_HEAD

Directory Structure

$ tree -L 1
.
├── app
├── buildroot # Buildroot root file system build directory
├── build.sh -> device/rockchip/common/build.sh # compile script
├── debian # Debian root file system compilation directory
├── device # Compile related configuration files
├── distro
├── docs # Documentation
├── envsetup.sh -> buildroot/build/envsetup.sh
├── external
├── kernel
├── Makefile -> buildroot/build/Makefile
├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh # link script
├── prebuilts # Cross compilation tool chain
├── rkbin
├── rkflash.sh -> device/rockchip/common/rkflash.sh # Flash script
├── tools # Tools directory
├── u-boot
└── yocto

Build a compilation environment

sudo apt-get install expect-dev 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 expect

Compile SDK

Configuration before compilation

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

./build.sh firefly-rk3399-buildroot

The configuration file will be linked to device/rockchip/.BoardConfig.mk, 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-rk3399 # u-boot configuration file
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig # kernel configuration file
# Kernel dts
export RK_KERNEL_DTS=rk3399-firefly # dts file
# Buildroot config
export RK_CFG_BUILDROOT=rockchip_rk3399 # Buildroot configuration
# Recovery config
export RK_CFG_RECOVERY=rockchip_rk3399_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 # root file system path

Partial compilation

  • Compile u-boot

./build.sh uboot
  • Compile kernel

./build.sh kernel
  • Compile recovery

./build.sh recovery
  • Compile Buildroot root file system

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

./build.sh buildroot

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

Package the firmware

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

./mkfirmware.sh

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

./build.sh updateimg

Automatic compilation

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

./build.sh

Partition description

parameter partition table

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

Path: device/rockchip/rk3288/parameter.txt

FIRMWARE_VER: 8.1
MACHINE_MODEL: RK3399
MACHINE_ID: 007
MANUFACTURER: RK3399
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 3399
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),0x00010000x@0x0000@2a000) 0x0003a000(oem),0x00c00000@0x0005a000(rootfs),-@0x00c5a000(userdata:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9

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.

package-file

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/rk3399-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
#resource Image/resource.img
#kernel Image/kernel.img
boot Image/boot.img
recovery Image/recovery.img
rootfs Image/rootfs.img
oem Image/oem.img
userdata:grow Image/userdata.img
backup RESERVED
#update-script update-script
#recover-script recover-script