1. Compile Ubuntu firmware(GPT)

In order to facilitate the use and development of users, the official Linux development kit SDK is provided. This chapter explains the specific use of the SDK in detail.

1.1. Preparatory work

1.1.1. Set up compilation environment

Please confirm the installation of the following files!

Here is use Ubuntu 18.04 for testing(It is recommended to use the ubuntu18.04 system for development, or use docker to deploy the Ubuntu18.04 container, otherwise the environment package cannot be installed):

sudo apt-get update

sudo apt-get install 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 gcc-arm-linux-gnueabihf libssl-dev liblz4-tool genext2fs lib32stdc++6 \
gcc-aarch64-linux-gnu g+conf 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 libssl-dev texinfo fakeroot \
libparse-yapp-perl default-jre patchutils swig chrpath diffstat gawk

Note: Ubuntu 17.04 or higher systems also need the following dependency packages:

sudo apt-get install lib32gcc-7-dev g++-7 libstdc++-7-dev

1.1.2. Download Firefly_Linux_SDK sub-volume compressed package

Since the Firefly_Linux_SDK source code package is relatively large, some users’ computers do not support files above 4G or the network transmission of a single file is slow, so we use the method of sub-volume compression to package the SDK. Users can obtain the Firefly_Linux_SDK source code package in the following ways:Firefly_Linux_SDK Source

After the download is complete, verify the MD5 code:

$ md5sum rk3399_linux_release_v2.5.1_20210301_split_dir/*firefly_split*
2cf71e64d35eb8083a4a0fc30c256484  rk3399_linux_release_v2.5.1_20210301_split_dir/rk3399_linux_release_v2.5.1_20210301_firefly_split.file0
f0e9292b3816a8f1ce0eb1eeb483ad56  rk3399_linux_release_v2.5.1_20210301_split_dir/rk3399_linux_release_v2.5.1_20210301_firefly_split.file1
c6aaa5d761d0e7917bea1cb78a0e7229  rk3399_linux_release_v2.5.1_20210301_split_dir/rk3399_linux_release_v2.5.1_20210301_firefly_split.file2
16022cc729d06a28fec30ac52885d91c  rk3399_linux_release_v2.5.1_20210301_split_dir/rk3399_linux_release_v2.5.1_20210301_firefly_split.file3
565426354c01d56c7d48479dd7f3c35b  rk3399_linux_release_v2.5.1_20210301_split_dir/rk3399_linux_release_v2.5.1_20210301_firefly_split.file4
313d311f1705fbfb7bfc45b7937ecf24  rk3399_linux_release_v2.5.1_20210301_split_dir/rk3399_linux_release_v2.5.1_20210301_firefly_split.file5

1.1.3. Unpack Firefly_Linux_SDK sub-volume compressed package

After confirming that it is correct, you can unpack:

cat rk3399_linux_release_v2.5.1_20210301_split_dir/*firefly_split* | tar -xzv

#This SDK folder contains a .repo directory, after decompression, perform the following operations in the current directory
cd rk3399_linux_release_v2.5.1_20210301
ls -al

.repo/repo/repo sync -l
.repo/repo/repo sync -c --no-tags
.repo/repo/repo start firefly --all

1.1.4. Update Firefly_Linux_SDK

You can use the following command to update the SDK later

.repo/repo/repo sync -c --no-tags

1.1.5. Linux_SDK catalog

catalog:

├── linux_sdk
│   ├── app
│   ├── buildroot                                               compile buildroot rootfs directory
│   ├── build.sh -> device/rockchip/common/build.sh             automatic compile script
│   ├── device                                                  config file
│   ├── distro                                                  debian_root.img directory
│   ├── docs                                                    document
│   ├── envsetup.sh -> buildroot/build/envsetup.sh
│   ├── external
│   ├── kernel                                                  kernel directory
│   ├── Makefile -> buildroot/build/Makefile
│   ├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh   update rockdev script
│   ├── prebuilts
│   ├── rkbin
│   ├── rkflash.sh -> device/rockchip/common/rkflash.sh         flashing firmware script
│   ├── rootfs                                                  compile debian rootfs directory
│   ├── tools                                                   flashing and package tools
│   └── u-boot                                                  uboot directory

1.2. Compile SDK

1.2.1. Configuration before compilation

The configuration file firefly-rk3399-ubuntu.mk:

./build.sh firefly-rk3399-ubuntu.mk

#The file path: `device/rockchip/rk3399/firefly-rk3399-ubuntu.mk`

Effective configuration file will be connected to the device/rockchip/.BoardConfig.mk, check the file to verify that the configuration was successful.

Note : firefly-rk3399-ubuntu.mk is configuration file after compiled buildroot firmware. At the same time, users can also generate new configuration files by referring to this configuration to adapt the firmware they need.

Important configuration information :(if you need diy firmware, you may need to modify the following configuration information)

#Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3399              #Compile the uboot configuration file

#Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig            #Compile the kernel configuration file

#Kernel dts
export RK_KERNEL_DTS=rk3399-firefly                                  #Compile the DTS used by kernel

#parameter for GPT table
export RK_PARAMETER=parameter-ubuntu.txt                      #Partitioning information (very important)

#packagefile for make update image
export RK_PACKAGE_FILE=rk3399-ubuntu-package-file             #Packaging configuration file

#rootfs image path
export RK_ROOTFS_IMG=xxxx/xxxx.img                            #The root file system image path

Attention, very important ! !

Buildroot firmware is compiled by default. If you want to compile other firmware (such as ubuntu firmware), please do the following:

  • Download the Ubuntu root filesystem image

  • Because RK3399 belongs to a 64-bit processor, so select the required file system under the corresponding Linux Rootfs/arm64 folder. This article uses rk3399_ubuntu18.04.img.7z as an example. Place the resulting image at the root of the SDK:

  • Put the resulting image in the specified directory in SDK:

#Unpack
7z x rk3399_ubuntu18.04.img.7z

#The root directory of sdk
mkdir ubunturootfs
mv rk3399_ubuntu18.04.img ubunturootfs/

#Modify firefly-rk3399-ubuntu.mk :

vim device/rockchip/rk3399/firefly-rk3399-ubuntu.mk

#Change the RK_ROOTFS_IMG property to the ubuntu file system image path(such as rk3399_ubuntu18.04.img)
RK_ROOTFS_IMG=ubunturootfs/rk3399_ubuntu18.04.img

NOTE: Ubuntu root file system image storage path can not be wrong !!

1.2.2. Automatic compilation

Under the premise that the configuration and setting up of the environment are completed:

./build.sh

Automatic compilation of firmware default compiler buildroot firmware. Generate the firmware directory rockdev/, at the same time will backup in the IMAGE.

1.2.3. Partial compilation

1.2.3.1. kernel

./build.sh kernel

1.2.3.2. u-boot

./build.sh uboot

1.2.3.3. recovery

recovery partition can be omitted, if necessary, compile it:

./build.sh recovery

1.2.3.4. rootfs

  • buildroot

./build.sh rootfs
  • debian:

cd rootfs/

1:
#Building base debian system by ubuntu-build-service from linaro
sudo apt-get install binfmt-support qemu-user-static live-build
sudo dpkg -i ubuntu-build-service/packages/*
sudo apt-get install -f

2:
#Compile 32-bit debian:
RELEASE=stretch TARGET=desktop ARCH=armhf ./mk-base-debian.sh
#Or compile 64-bit debian:
RELEASE=stretch TARGET=desktop ARCH=arm64 ./mk-base-debian.sh

#If the above compilation encounters the following problems:
noexec or nodev issue /usr/share/debootstrap/functions: line 1450: ..../rootfs/ubuntu-build-
service/stretch-desktop-armhf/chroot/test-dev-null: Permission denied E: Cannot install into target
'/home/foxluo/work3/rockchip/rk_linux/rk3399_linux/rootfs/ubuntu-build-service/stretch-
desktop-armhf/chroot' mounted with noexec or nodev

# Solutions:
mount -o remount,exec,dev xxx (xxx is the mount place), then rebuild it.

3:
#Compile 32-bit stretch:
VERSION=debug ARCH=armhf ./mk-rootfs-stretch.sh

#It is recommend to use that rear band debug in the development phase
#Compile 64-bit stretch:
VERSION=debug ARCH=arm64 ./mk-rootfs-stretch-arm64.sh

4:
./mk-image.sh
mv linaro-rootfs.img ../distro/

5:
Modify firefly-rk3399-ubuntu.mk
vim device/rockchip/RK3399/firefly-rk3399-ubuntu.mk

#Change the RK_ROOTFS_IMG property to the ubuntu file system image path(such as linaro-rootfs.img)
RK_ROOTFS_IMG=distro/linaro-rootfs.img
  • ubuntu18.04 can be downloaded via cloud disk:18.04 FS

  • Because RK3399 belongs to a 64-bit processor, so select the required file system under the corresponding Linux Rootfs/arm64 folder. This article uses rk3399_ubuntu18.04.img.7z as an example. Place the resulting image at the root of the SDK:

#Unpack
7z x rk3399_ubuntu18.04.img.7z

#The root directory of sdk
mkdir ubunturootfs
mv rk3399_ubuntu18.04.img ubunturootfs/

#Modify firefly-rk3399-ubuntu.mk :

vim device/rockchip/rk3399/firefly-rk3399-ubuntu.mk

#Change the RK_ROOTFS_IMG property to the ubuntu file system image path(such asrk3399_ubuntu18.04.img)
RK_ROOTFS_IMG=ubunturootfs/rk3399_ubuntu18.04.img

NOTE:buntu root file system image storage path can not be wrong!!

Run ./mkfirmware.sh will automatically update rockdev/rootfs.img links.

1.3. Pack the firmware

1.3.1. Update the part images synchronously

Before each package firmware, ensure rockdev/ directory file link is correct:

ls -l

├── boot.img -> ~/project/linux_sdk/kernel/boot.img
├── idbloader.img -> ~/project/linux_sdk/u-boot/idbloader.img
├── linaro-rootfs.img
├── MiniLoaderAll.bin -> ~/project/linux_sdk/u-boot/rk3399_loader_v1.14.115.bin
├── misc.img -> ~/project/linux_sdk/device/rockchip/rockimg/wipe_all-misc.img
├── oem.img
├── parameter.txt -> ~/project/linux_sdk/device/rockchip/RK3399/parameter-ubuntu.txt
├── recovery.img -> ~/project/linux_sdk/buildroot/output/rockchip_rk3399_recovery/images/recovery.img
├── rootfs.img -> ~/project/linux_sdk/ubunturootfs/rk3399_ubuntu18.04.img
├── trust.img -> ~/project/linux_sdk/u-boot/trust.img
├── uboot.img -> ~/project/linux_sdk/u-boot:/uboot.img
└── userdata.img

Runing ./mkfirmware.sh to update links

./mkfirmware.sh

Tip: If you do not compile all the partition images, you will encounter the following situation when running ./mkfirmware:

error: /home/ljh/proj/linux-sdk/buildroot/output/rockchip_rk3399_recovery/images/recovery.img not found!
#Represents that the recovery partition has not compiled an image, and other situations are similar, such as oem.img, userdata.img. As mentioned above, these are elliptical partition images and can be ignored.

1.3.2. Packaged into a unified firmware

Note: Please make sure tools/linux/Linux_Pack_Firmware/rockdev/package-file is correct before packing. The packaging is partitioned based on this file. This file link is updated when the ./build.sh aio-rk3399c.mk command is executed. If the configuration is not correct, go back to the Configuration before compilation section and configure it again.

Integrated into unified firmware:

./build.sh updateimg

1.4. Partition introduction

1.4.1. parameter

parameter.txt contains firmware partition information is very important. You can find some parameter.txt files in device/rockchip/RK3399 directory. The following is introduced with parameter-debian.txt as an example:

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),0x00010000@0x0002a000(backup),0x00020000@0x0003a000(oem),0x00700000@0x0005a000(rootfs),-@0x0075a000(userdata:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9

CMDLINE property is what we care about. Take uboot as an example, 0x00004000 in 0x00002000@0x00004000(uboot) is the starting position of the uboot partition, and 0x00002000 is the size of the partition. The following partition rules are the same. Users can add or subtract or modify partition information according to their needs, but please keep at least the uboot, trust, boot, rootfs partition, which is a prerequisite for the machine to start normally. The simplest partition scheme is used in parameter-ubuntu.txt.

Partition introduction:

uboot: Upgrade the uboot.img compiled by uboot.

trust: Upgrade the trust.img compiled by uboot.

misc: Upgrade the misc.img. Turn on and Enter recovery mode.(omitted)

boot: Upgrade the boot.img compiled by kernel. Contains kernel and device tree information.

recovery: Upgrade the recovery.img.(omitted)

backup: Reserved. Not for the time being. In the future, it will be used as backup of recovery just like Android.(omitted)

oem: For manufacturers to use, used to store the manufacturer’s app or data. Read-only. Replace the data partition of the original speaker. Mount in /oem.(omitted)

rootfs: Store the rootfs.img compiled by buildroot or debian, Read-only.

userdata: Save the files generated by the app or is for the end user. Read and Write, Mount in /userdata.(omitted)

1.4.2. package-file

This file should be consistent with the parameter and used for firmware packaging. Relevant documents can be found under tools/linux/Linux_Pack_Firmware/rockdev.

# 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
boot            Image/boot.img
rootfs:grow     Image/rootfs.img
backup          RESERVED

The above is the mirror file generated after SDK compilation. Package only the img files you use according to parameter.txt.

1.5. FAQs

1.5.1. How to enter upgrade mode ?

See operation method in Upgrade firmware