1. Compile Linux firmware

1.1. Get SDK

First prepare an empty folder to store the SDK. It is recommended to store the SDK in the home directory. This article uses ~/proj as an example.

Notice:

1. The SDK is cross-compiled, so use the SDK on an X86_64 computer and do not download the SDK to the board

2. Please use Ubuntu18.04 (real machine or docker container) for the compilation environment. Using other versions may cause compilation errors

3. Do not store or decompress the SDK in virtual machine shared folders or non-English directories

4. Please use an ordinary user to obtain and compile the SDK. Root privileges are not allowed or required (unless apt installation software is required)

1.1.1. Installation tools

To obtain the SDK, you need to install it first:

sudo apt update
sudo apt install -y repo git python

1.1.2. Initialize warehouse

*Method 1 (recommended for domestic users)

SDK source code is placed in the compressed package

After downloading, verify the MD5 code:

lvsx@tchip16:~ $ md5sum T36X.7z
a0aba53273aedef9ca085266bdad8806  T36X.7z

After confirming that it is correct, you can unzip:

7x x T36X.7z

1.2. Linux IPC SDK configuration introduction

1.2.1. SDK directory structure description

Directory Path Introduction
build.sh SDK compilation script
Soft link to project/build.sh
media Multimedia codec, ISP and other algorithm related
sysdrv U-Boot, kernel, rootfs directory
project Reference application, compilation configuration and script directory
docs SDK Document Directory
tools Burning image packaging tool and burning tool
output SDK compiled image file storage directory
output/image Burning image output directory
output/out File generated by compilation
output/out/app_out Refer to the compiled file of the application
output/out/media_out media related compiled files
output/out/sysdrv_out sysdrv compiled file
output/out/sysdrv_out/kernel_drv_ko ko files for peripherals and multimedia
output/out/rootfs_xxx File system packaging directory
output/out/S20linkmount Partition mount script
output/out/userdata userdata

Note: media and sysdrv can be compiled independently from the SDK.

1.2.2. Sysdrv directory description

Sysdrv can be compiled independently of the SDK and includes U-Boot, kernel, rootfs and some image packaging tools. Compile command:

# Compile all by default
make all

# Compile U-Boot
make uboot_clean
make uboot

# Compile kernel
make kernel_clean
make kernel

# Compile rootfs
make rootfs_clean
make rootfs

# Clear compilation
make clean

# Clear compilation and delete out directory
make distclean

# Check the compilation configuration, such as uboot and kernel detailed compilation commands
make info
sysdrv subdirectory Description
cfg Kernel and U-Boot compilation related configurations
out sysdrv compilation output directory
out/bin/board_glibc_xxx Programs running on the board end
out/bin/pc Programs running on PC
out/bin/image_glibc_xxx Generated burning image output directory
out/bin/rootfs_glibc_xxx Root file system directory
source/busybox busybox compilation directory, the source code is in sysdrv/tools/board/busybox
source/kernel Kernel source code directory
source/uboot U-Boot source code directory and rkbin (ddr initialization precompiled image)
tools/board Board end program source code
tools/pc Tools for PC-side image packaging

1.2.3. Configuration file introduction

In the project/cfg/BoardConfig_IPC/ directory, there are configuration files (xxxx.mk) for different board types, which are used to manage the compilation configuration of each link of the SDK. Related configuration introduction:

Configuration items Description
RK_ARCH arm or arm64
Define compiling 32-bit or 64-bit programs
RK_CHIP Unmodifiable
Different chips correspond to different SDKs
RK_TOOLCHAIN_CROSS Unmodifiable
Define cross tool chain
RK_BOOT_MEDIUM emmc or spi_nor or spi_nand
Define board storage type
RK_UBOOT_DEFCONFIG U-Boot defconfig file name
File directory sysdrv/source/uboot/u-boot/configs
RK_UBOOT_DEFCONFIG_FRAGMENT U-Boot config file name (optional)
File directory sysdrv/source/uboot/u-boot/configs
Override the defconfig defined by RK_UBOOT_DEFCONFIG
RK_KERNEL_DEFCONFIG Kernel defconfig file name
File directory sysdrv/source/kernel/arch/$RK_ARCH/configs
RK_KERNEL_DEFCONFIG_FRAGMENT Kernel defconfig file name (optional)
File directory sysdrv/source/kernel/arch/$RK_ARCH/configs
Override the defconfig defined by RK_KERNEL_DEFCONFIG
RK_KERNEL_DTS Kernel dts file name
RK_ARCH=arm Directory:
sysdrv/source/kernel/arch/arm/boot/dts
RK_ARCH=arm64 Directory:
sysdrv/source/ kernel/arch/arm64/boot/dts/rockchip
RK_MISC If the recovery function is turned on, read the flag when the system starts to select the recovery system or application system (can be removed when there is no recovery)
RK_CAMERA_SENSOR_IQFILES IQ configuration file of Camera Sensor
File directory media/isp/camera_engine_rkaiq/iqfiles or
media/isp/camera_engine_rkaiq/rkaiq/iqfiles
Multiple IQ files are separated by spaces, for example
RK_CAMERA_SENSOR_IQFILES="iqfile_1 iqfile_2"
RK_PARTITION_CMD_IN_ENV Configure partition table (important)
Partition table format:
<partdef>[,<partdef>]
Format: <size >[@<offset>](part-name)
For detailed configuration, refer to [Partition Table Description Chapter]
RK_PARTITION_FS_TYPE_CFG Configure the partition file system type and mount point (important)
Format description:
Partition name@partition mount point@partition file system type
Note: The partition of the root file system is mounted The default value of the load point is IGNORE (cannot be modified)
RK_SQUASHFS_COMP Configure squashfs image compression algorithm (optional)
Support: lz4/lzo/lzma/xz/gzip (default xz)
RK_UBIFS_COMP Configure ubifs image compression algorithm (optional)
Support: lzo/zlib (default lzo)
RK_APP_TYPE Configure compiled reference applications (optional)
Run ./build.sh info to view supported reference applications
RK_APP_IPCWEB_BACKEND Configure whether to compile web applications (optional)
y: enable
RK_BUILD_APP_TO_OEM_PARTITION Configure whether to install the application to the OEM partition (optional)
y: enable
RK_ENABLE_RECOVERY Configure whether to enable the recovery function (optional)
y: enable
RK_ENABLE_FASTBOOT Configure whether the fast boot function (optional)
y: enable
Needs to cooperate with U-Boot and kernel modifications, you can refer to the
BoardConfig-*-TB.mk provided by the SDK
RK_ENABLE_GDB Configure whether to compile gdb (optional)
y: enable
RK_ENABLE_ADBD Configure whether to support adb function (optional)
y: enable
Note: The kernel needs to open the corresponding USB configuration
RK_BOOTARGS_CMA_SIZE Configure kernel CMA size (optional)
RK_POST_BUILD_SCRIPT The configured script will be executed before packaging rootfs.img (the script is placed in the directory corresponding to
BoardConfig) (optional)
RK_PRE_BUILD_OEM_SCRIPT The configured script will be executed before packaging oem.img (the script is placed in the directory corresponding to
BoardConfig) (optional)

1.2.4. Partition table description

The SDK uses the env partition to set up the partition table, and the partition table information is configured in the RK_PARTITION_CMD_IN_ENV parameter in <SDK>/project/cfg/BoardConfig_IPC/BoardConfig-SPI_NOR-NONE-T36_V10-IPC.mk.

export RK_PARTITION_CMD_IN_ENV="64K(env),128K@64K(idblock),128K(uboot),3M(boot),3M(rootfs),7M(oem),2M(userdata),-(media)"

The partition table is saved in the configuration in the form of a string. The following are examples of partition tables for each storage medium.

Storage media Partition table
eMMC RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),4M(uboot),32M(boot),2G(rootfs),-
(userdata)"
spi nand 或slc
nand
RK_PARTITION_CMD_IN_ENV="256K(env),256K@256K(idblock),1M(uboot),8M(boot),32M(rootfs),-
(userdata)"
spi nor RK_PARTITION_CMD_IN_ENV="64K(env),128K@64K(idblock),128K(uboot),3M(boot),6M(rootfs),-
(userdata)"

The format of each partition is: <size>[@<offset>](part-name), where the partition size and partition name are required, and the offset depends on the situation (see below Note the third point). There are a few things to note when configuring the partition table:

  1. Separate partitions with commas “,”.

  2. The units of partition size are: K/M/G/T/P/E, which are not case-sensitive. If there is no unit, the default is byte; “-“ means that the partition size is the remaining capacity.

  3. If the first partition starts from the 0x0 address, no offset is added. Otherwise, the offset must be added. Subsequent partitions optionally add offsets.

  4. The offset and size of the idblock partition are fixed, please do not modify them.

  5. It is not recommended to modify the env partition name. (If you want to modify the env address and size, you need to modify the corresponding defconfig configuration CONFIG_ENV_OFFSET and CONFIG_ENV_SIZE of U-Boot, regenerate the firmware, erase the env data at the 0 address of the board, and then burn the new firmware)

1.3. Compile RKIPC firmware

This chapter introduces the compilation process of Buildroot firmware. It is recommended to develop under the Ubuntu 18.04 system environment. If you use other system versions, you may need to make corresponding adjustments to the compilation environment.

1.3.1. Preparation

1.3.1.1. Build the 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 ncurses-dev \

1.3.2. Compile SDK

1.3.2.1. CT36L configuration before compilation

In the project/cfg/BoardConfig_IPC/ directory, there are configuration files for different board types. Select configuration file 14:

./build.sh lunch
...
# Configuration files for other versions are omitted here
...
----------------------------------------------------------------
14. BoardConfig_IPC/BoardConfig-SPI_NOR-NONE-RV1106_T36_V10-IPC.mk
                             boot medium(启动介质): SPI_NOR
                          power solution(电源方案): NONE
                        hardware version(硬件版本): RV1106_T36_V10
                             application(应用场景): IPC
----------------------------------------------------------------

Which would you like? [0]: 14
[build.sh:info] switching to board: /home/lvsx/project/rv1106/test/T36X/project/cfg/BoardConfig_IPC/BoardConfig-SPI_NOR-NONE-RV1106_T36_V10-IPC.mk
[build.sh:info] Running build_select_board succeeded.

1.3.2.2. CT36B configuration before compilation

In the project/cfg/BoardConfig_IPC/ directory, there are configuration files for different board types. Select configuration file 4:

./build.sh lunch
...
# 此处省略其他版型的配置文件
...
----------------------------------------------------------------
4. BoardConfig_IPC/BoardConfig-EMMC-NONE-RV1106_T36B_V10-IPC.mk
                             boot medium(启动介质): EMMC
                          power solution(电源方案): NONE
                        hardware version(硬件版本): RV1106_T36B_V10
                             application(应用场景): IPC
----------------------------------------------------------------

Which would you like? [0]: 4
[build.sh:info] switching to board: /home/lvsx/project/rv1106/test/T36X/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-NONE-RV1106_T36B_V10-IPC.mk
[build.sh:info] Running build_select_board succeeded.

1.3.2.3. Compile

1.3.2.3.1. Fully automatic compilation

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

./build.sh

Package the firmware and the generated complete firmware will be saved to the output/image/ directory.

1.3.2.3.2. Partial compilation
  • Compile u-boot

./build.sh clean uboot
./build.sh uboot

# ./build.sh info You can view the detailed compilation command format of uboot

Generate image files: output/image/download.bin, output/image/idblock.img and output/image/uboot.img

  • Compile kernel

./build.sh clean kernel
./build.sh kernel

# ./build.sh info You can view the detailed compilation command

Generate image file: output/image/boot.img

  • Compile rootfs

./build.sh clean rootfs
./build.sh rootfs

After compilation, use the ./build.sh firmware command to package it into rootfs.img Generate image file: output/image/rootfs.img

  • Compile media

./build.sh clean media
./build.sh media

The storage directory of the generated files: output/out/media_out

  • Compile reference application

./build.sh clean app
./build.sh app

The directory where the generated files are stored: output/out/app_out Note: app depends on media

  • Compile kernel driver

./build.sh clean driver
./build.sh driver

The directory where the generated files are stored: output/out/sysdrv_out/kernel_drv_ko/

  • Package env.img

./build.sh env

env.img is packaged using uboot’s mkenvimage tool. env.img packaging command format:

mkenvimage -s $env_partition_size -p 0x0 -o env.img env.txt

Note: $env_partition_size is different for different storage media. Please check the partition table description for details. View env.img content: strings env.img

# For example, the env.txt content of eMMC
blkdevparts=mmcblk0:32K(env),512K@32K(idblock),256K(uboot),32M(boot),2G(rootfs),1
G(oem),2G(userdata),-(media)
sys_bootargs=root=/dev/mmcblk0p5 rk_dma_heap_cma=64M rootfstype=ext4

Note: The content of env.img will be different for different storage media. You can use strings env.img to view it. blkdevparts and sys_bootargs will be passed to the kernel by uboot, and overwrite the kernel’s corresponding bootargs parameters.

  • Packaged firmware

./build.sh firmware

The directory where the generated files are stored: output/image