Buildroot Compilation Practice on RK3568 Platform: Customizing Kernel & Root Filesystem

@TOC

  • • Buildroot is a tool for automating the build of embedded Linux systems. It can cross-compile a complete Linux system that runs on embedded devices, including the kernel, root filesystem, bootloader, and other components, starting from source code using simple configuration files and Makefiles.
  • • The official SDK for the RK3568 platform is based on Buildroot. This article will introduce some tips during the Buildroot compilation process based on the RK3568 platform and perform basic validation of the network functionality of the Buildroot system. These network features are fundamental to the characteristics of 5G CPE devices.

Preparation Before Compilation

The compilation environment is Linux. After obtaining the rk356x_linuxv5.10_release_v1.3.2_20230424.tgz package from FAE, extract it.

# Set environment variables
cd buildroot
source envsetup.sh 
./build.sh lunch:rockchip_rk3568_evb1_ddr4_v10_defconfig

General Compilation Process

# One-click compilation
./build.sh

# Compile the system files
./build.sh rootfs

# Compile the kernel:
./build.sh kernel

# Compile uboot
./build.sh  uboot

Customizing the Kernel

You can modify kernel parameters using make menuconfig, but the configuration cannot be permanently saved and may be lost after a clean operation. Therefore, it is necessary to save incremental configurations for long-term maintenance of kernel parameters, facilitating iteration.

Modify Kernel Parameters and Save Incrementally

Enter the kernel directory root@test:/home/test/test/rk356x/kernel.

  1. 1. Load the configuration into .config (output), execute the following command, which will generate the .config file.
    # configuration written to .config
    make ARCH=arm64 rockchip_linux_defconfig
  2. 2. Execute make menuconfig to modify the configuration and save it to .config
  3. 3. make savedefconfig generates the ./defconfig file, which minimizes the saved configuration
  4. 4. Write the defconfig back to the default platform-related defconfig (e.g., rockchip_linux_defconfig), but this operation is not always reliable because many configurations in rockchip_linux_defconfig are not reflected in the ./defconfig generated in the previous step. Therefore, it is recommended to use a manual merge method to incorporate only the modifications made in step 2 into rockchip_linux_defconfig
    cp defconfig arch/arm64/configs/rockchip_linux_defconfig

Modify Root Filesystem and Save Incrementally

  1. 1. Enter the Buildroot directory root@test:/home/ney/test/rk356x/buildroot, load the default configuration
    root@test:/home/ney/test/rk356x/buildroot$
    make rockchip_rk3568_defconfig
    # This operation will apply the default configuration to the compilation process, configuration written to /home/ney/test/rk356x/buildroot/output/rockchip_rk3568/.config
  2. 2. Execute the following operation to perform special customization of Buildroot, the modifications will only be written to /home/ney/test/rk356x/buildroot/output/rockchip_rk3568/.config. At this point, if you execute make rockchip_rk3568_defconfig again, the config will be overwritten, and the parameters from the previous step will be lost.
    make menuconfig
  3. 3. To save the default configuration to defconfig, execute the following operation to save the streamlined configuration to /home/ney/test/rk356x/buildroot/configs/rockchip_rk3568_defconfig
    make savedefconfig

Modify Root Filesystem Package Download Source

  1. 1. If the rootfs download is slow or the downloaded package format is incorrect and cannot be extracted, you can modify the MIRROR address.
    # Modify rockchip_rk3568_defconfig
    BACKUP_SITE="http://sources.buildroot.net"
    KERNEL_MIRROR="https://mirror.bjtu.edu.cn/kernel/"
    GNU_MIRROR="http://mirrors.nju.edu.cn/gnu/"
    LUAROCKS_MIRROR="https://luarocks.cn"
    CPAN_MIRROR="http://mirrors.nju.edu.cn/CPAN/"
    # Execute make rockchip_rk3568_defconfig
    # Execute ./build.sh rootfs

Incremental Addition and Deletion of Root Filesystem Software Packages

The default rootfs of Buildroot compiles many software packages, which can be customized or added/removed according to needs.

  1. 1. For example, to remove BR2_PACKAGE_VALGRIND, modify rockchip_rk3568_defconfig and comment out BR2_PACKAGE_VALGRIND.

Then directly execute ./build.sh rootfs, at this point, it will prompt whether to overwrite the old configuration, select yes, to remove the compilation of valgrind

< BR2_PACKAGE_VALGRIND=y
< BR2_PACKAGE_VALGRIND_MEMCHECK=y
< BR2_PACKAGE_VALGRIND_CACHEGRIND=y
< BR2_PACKAGE_VALGRIND_CALLGRIND=y
< BR2_PACKAGE_VALGRIND_HELGRIND=y
< BR2_PACKAGE_VALGRIND_DRD=y
< BR2_PACKAGE_VALGRIND_MASSIF=y
< BR2_PACKAGE_VALGRIND_DHAT=y
< # BR2_PACKAGE_VALGRIND_SGCHECK is not set
< # BR2_PACKAGE_VALGRIND_BBV is not set
< # BR2_PACKAGE_VALGRIND_LACKEY is not set
< # BR2_PACKAGE_VALGRIND_NULGRIND is not set
---
> # BR2_PACKAGE_VALGRIND is not set
Found old config, override it? (y/n):y
  1. 2. To remove htop compilation, modify rockchip_rk3568_defconfig, remove htop and execute ./build.sh allsave, it will prompt, Found old config, override it? (y/n):, select yes to apply the modifications to rockchip_rk3568_defconfig, yes means to use the configuration after >.
  2. 3. If an error occurs during the compilation process, and the configuration is modified through make menuconfig, the configuration will be directly overwritten to /home/test/test/rk356x/buildroot/output/rockchip_rk3568/.config. When executing ./build.sh rootfs, there will be a prompt, at this point, first n, use the new configuration.
    make: Leaving directory '/home/ney/test/rk356x/buildroot'
    319,320c319,320
    < BR2_GCC_VERSION_9_X=y
    < # BR2_GCC_VERSION_10_X is not set
    ---
    > # BR2_GCC_VERSION_9_X is not set
    > BR2_GCC_VERSION_10_X=y
    323c323
    < BR2_GCC_VERSION="9.4.0"
    ---
    > BR2_GCC_VERSION="10.3.0"
    400c400,401
    < # BR2_PACKAGE_LINUX_TOOLS_PERF is not set
    Found old config, override it? (y/n):n
    ## No  < 后面的配置
  3. 4. The incremental addition and deletion of software package configurations are saved in rockchip_rk3568_defconfig
    # rk356x\buildroot\configs\rockchip_rk3568_defconfig
    BR2_PACKAGE_GIT=y
    BR2_PACKAGE_BRIDGE_UTILS=y
    #BR2_PACKAGE_IFTOP=y
    BR2_PACKAGE_IPROUTE2=y
    BR2_PACKAGE_IPTABLES=y
    BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y
    BR2_PACKAGE_IPTABLES_NFTABLES=y
    #BR2_PACKAGE_IPTRAF_NG=y
    BR2_PACKAGE_IPUTILS_RARPD=y
    BR2_PACKAGE_IPUTILS_TFTPD=y
    BR2_PACKAGE_WIRESHARK=y
    #BR2_PACKAGE_HTOP=y
    BR2_PACKAGE_TAR=y
    BR2_PACKAGE_VIM=y

References

Buildroot – Making Embedded Linux Easy

Rockchip_RK356X_Linux_SDK_Release_V1.1.0_20210520_CN.pdf

Leave a Comment