Compile Ubuntu firmware

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

Preparatory work

Set up 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 https://gitlab.com/firefly-linux/git-repo.git -u https://gitlab.com/firefly-linux/manifests.git -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

$ tree -L 1
.
├── app
├── buildroot # Buildroot root filesystem build directory
├── build.sh -> device/rockchip/common/build.sh # Compile script
├── debian # Debian root filesystem 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 toolchain
├── rkbin
├── rkflash.sh -> device/rockchip/common/rkflash.sh # Flash script
├── tools # Tools directory
├── u-boot
└── yocto

Build Linux-SDK

Precompile Configuration

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

./build.sh roc-rk3566-pc-ubuntu.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=arm64 # 64-bit ARM
# Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3566 # u-boot configuration
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig # kernel configuration
# Kernel dts
export RK_KERNEL_DTS=rk3566-firefly-roc-pc # dts file
# parameter for GPT table
export RK_PARAMETER=parameter-ubuntu-fit.txt # partition table
# rootfs image path
export RK_ROOTFS_IMG=ubuntu_rootfs/rk356x_ubuntu_rootfs.img # filesystem path

Select Accessories to Compile

Select Screen

Choose different DTS in roc-rk3566-pc-ubuntu.mk :

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

Build

Partial compilation

  • u-boot

./build.sh uboot
  • kernel

./build.sh kernel
  • recovery

./build.sh recovery

Download Ubuntu filesystem

7z x ubuntu-aarch64-rootfs.7z
  • Move filesystem to ubuntu_rootfs/

mkdir ubuntu_rootfs
mv ubuntu-aarch64-rootfs.img ubuntu_rootfs/rk356x_ubuntu_rootfs.img

Pack the firmware

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

RK firmware

RK firmware is the firmware packaged in Rockchip’s proprietary format, and can be flashed to eMMC or SD card with the tools provided by Rockchip (Note: If there is no special instruction, the firmware mentioned on WIKI defaults to RK firmware) .

# Pack RK firmware
./build.sh updateimg

RAW firmware

RAW firmware is a kind of firmware that can be flashed to the storage device in a bit-by-bit copy mode, and is the original image of the storage device. Different from the RK firmware, currently it only supports flashing to SD card to boot with Etcher tool.

Etcher official download link

# Package RAW firmware
./build.sh rawimg

Automatic compilation

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

./build.sh

Partition table

parameter

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

path: device/rockchip/rk356x/parameter-ubuntu-fit.txt

FIRMWARE_VER: 1.0
MACHINE_MODEL: RK3568
MACHINE_ID: 007
MANUFACTURER: RK3568
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 0xffffffff
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT
CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00010000@0x00008000(boot),0x00010000@0x00018000(recovery),0x00010000@0x00028000(backup),0x00c00000@0x00038000(rootfs),-@0x00c38000(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/rk356x-ubuntu-package-file

# NAME          Relative path
#
#HWDEF          HWDEF
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
userdata        RESERVED
backup          RESERVED