1. Linux SDK introduction

Linux SDK is a Linux software development kit officially provided by Firefly, which is designed to facilitate user’s module development and system customization based on it.

1.1. Obtain the SDK

Note: The following steps are applicable to the Ubuntu 18.04 system environment. If you use other system versions, you may need to adjust the compilation environment accordingly.

For details, please go to Wiki, after selecting the board, click on the Compile Ubuntu Firmware page under Linux .

For example ROC-RK3568-PC:

_images/wiki_select_roc-rk3568-pc_en.png _images/wiki_select_roc-rk3568-pc_build_ubuntu_en.png

1.2. SDK directory tree

The Linux SDK directory tree of each chip platform may be slightly different, but generally as follows:

.
├── app # store application APPs like qcamera/qfm/qplayer/qseting and other applications.
├── buildroot # root file system based on Buildroot (2018.02-rc3).
├── build.sh -> device/rockchip/common/build.sh # Linux SDK compile script.
├── debian # root file system based on Debian.
├── device # store board-level configuration for each chip and some scripts and prepared files for
building and packaging firmware.
├── docs # stores development guides, platform support lists, tool usage, Linux development guides,
and so on.
├── envsetup.sh -> buildroot/build/envsetup.sh # configure the Buildroot build environment script
├── external # stores some third-party libraries, including audio, video, network, recovery and so on.
├── kernel # stores kernel development code.
├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh # rockdev directory link update script
├── prebuilts # stores cross-building toolchain.
├── rkbin # stores Rockchip Binary and tools.
├── rkflash.sh -> device/rockchip/common/rkflash.sh # Flash script
├── tools # stores some commonly used tools under Linux and Windows system.
├── u-boot # store U-Boot code developed based on v2017.09 version.
└── yocto # stores the root file system developed based on Yocto.

1.3. Precompile configuration

Before compiling the SDK, the user needs to select the board configuration files, which are located in the <SDK>/device/rockchip directory, such as rk356x:

.
├── aio-3566-jd4-2cam-buildroot.mk
├── aio-3566-jd4-2cam-ubuntu.mk
├── aio-3566-jd4-buildroot.mk
├── aio-3566-jd4-mipi-2cam-buildroot.mk
├── aio-3566-jd4-mipi-2cam-ubuntu.mk
├── aio-3566-jd4-mipi-buildroot.mk
├── aio-3566-jd4-mipi-ubuntu.mk
├── aio-3566-jd4-ubuntu.mk
├── aio-3568j-2cam-buildroot.mk
├── aio-3568j-2cam-ubuntu.mk
├── aio-3568j-buildroot.mk
├── aio-3568j-lede.mk
├── aio-3568j-mipi-2cam-buildroot.mk
├── aio-3568j-mipi-2cam-ubuntu.mk
├── aio-3568j-mipi-buildroot.mk
├── aio-3568j-mipi-ubuntu.mk
├── aio-3568j-nvr.mk
├── aio-3568j-openwrt.mk
├── aio-3568j-ubuntu.mk
├── ipc-m10r800-a3568j-ubuntu.mk
├── itx-3568jq-2cam-ubuntu.mk
├── itx-3568jq-lvds-2cam-ubuntu.mk
├── itx-3568jq-lvds-ubuntu.mk
├── itx-3568jq-mipi-ubuntu.mk
├── itx-3568jq-ubuntu.mk
├── roc-rk3566-pc-2cam-buildroot.mk
├── roc-rk3566-pc-2cam-ubuntu.mk
├── roc-rk3566-pc-buildroot.mk
├── roc-rk3566-pc-lede.mk
├── roc-rk3566-pc-mipi-2cam-buildroot.mk
├── roc-rk3566-pc-mipi-2cam-ubuntu.mk
├── roc-rk3566-pc-mipi-buildroot.mk
├── roc-rk3566-pc-mipi-ubuntu.mk
├── roc-rk3566-pc-openwrt.mk
├── roc-rk3566-pc-ubuntu.mk
├── roc-rk3568-pc-2cam-buildroot.mk
├── roc-rk3568-pc-2cam-ubuntu.mk
├── roc-rk3568-pc-buildroot.mk
├── roc-rk3568-pc-lede.mk
├── roc-rk3568-pc-mipi-2cam-buildroot.mk
├── roc-rk3568-pc-mipi-2cam-ubuntu.mk
├── roc-rk3568-pc-mipi-buildroot.mk
├── roc-rk3568-pc-mipi-ubuntu.mk
├── roc-rk3568-pc-openwrt.mk
├── roc-rk3568-pc-ubuntu.mk
├── station-m2-ubuntu.mk
└── station-p2-ubuntu.mk

Note: Due to different SDK versions, these files are slightly different, please refer to the SDK!

Taking roc-rk3568-pc-mipi-2cam-buildroot.mk as an example, the naming combination of the board configuration file is as follows:

  • Board: roc-rk3568-pc

  • Accessories: mipi-2cam

  • Rootfs: buildroot

The meaning of each accessory name is as follows:

xxxx-buildroot.mk # Use HDMI + single-camera
xxxx-2cam-buildroot.mk # # Use HDMI + dual-camera
xxxx-mipi-buildroot.mk # Use mipi + single-camera
xxxx-mipi-2cam-buildroot.mk # Use mipi + dual-camera

After confirming the board configuration file, use the build.sh script in the SDK root directory to specify:

./build.sh roc-rk3568-pc-mipi-2cam-buildroot.mk

After specifying the file, it will be updated to the <SDK>/device/rockchip/.BoardConfig.mk file, and checking this file can 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_rk3568 # u-boot configuration file
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig # kernel configuration file
# Kernel dts
export RK_KERNEL_DTS=rk3568-firefly-roc-pc # dts file
# parameter for GPT table
export RK_PARAMETER=parameter-ubuntu-fit.txt # partition table file
# rootfs image path
export RK_ROOTFS_IMG=ubuntu_rootfs/rk356x_ubuntu_rootfs.img # rootfs path

1.4. Firmwate partition table

1.4.1. parameter

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

Path: <SDK>/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),0x00020000@0x00008000(boot:bootable),0x00020000@0x00028000(recovery),0x00010000@0x00048000(backup),0x00c00000@0x00058000(rootfs),-@0x00c58000(userdata:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9

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

1.4.2. 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.

Partition mirroring is the mirrored data of the partition, which is used to program the corresponding partition of the storage device. For example, compiling the SDK will build partition image files such as u-boot.img, boot.img, and recovery.img. The boot.img will be written to the “boot” partition of the eMMC or SD card. Note that boot.img is actually kernel image file.

Path: <SDK>/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

1.5. Firmware packaging format

The SDK can package firmware in two formats:

  • RK format firmware: ./build.sh updateimg (default)

  • RAW format firmware: ./build.sh rawimg

RAW format firmware is a kind of firmware that can be burned to the storage device in a bit-by-bit copy mode, and is the original image of the storage device. RAW format firmware is generally burned to SD card. The tools for burning RAW format firmware can be selected:

RK format firmware is a firmware packaged in Rockchip’s proprietary format. It can be burned to eMMC or SD card using tools provided by Rockchip. The tools for flashing RK format firmware can be selected:

Flash eMMC:

  • AndroidTool(RKDevTool) (Windows)

  • Linux_Upgrade_Tool(upgrade_tool) (Linux)

Flash SD card:

  • SD_Firmware_Tool (Windows)

If you want to burn the firmware to the SD card, should pay attention to the purchase of the SD card. Please read this good article about how to prepare a SD card first, to make sure that you have a good, reliable and fast SD card, which is of essential importance for system stability.