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.
Preparatory work¶
Download Firefly_Linux_SDK¶
The Firefly_Linux_SDK source package is relatively large, and the Firefly_Linux_SDK source package can be obtained as follows:Firefly_Linux_SDK Source
After downloading, verify the MD5 code:
$ md5sum firefly-sdk-20200629.7z
d8c52272725ff8a2216fc2be7a92ffc4 firefly-sdk-20200629.7z
After confirming that it is correct, you can unzip:
mkdir -p ~/proj/
cd ~/proj/
7z x /path/to/firefly-sdk-20200629.7z -r -o./
cd firefly-sdk
git reset --hard
Note: Be sure to update the SDK after decompression.
Update code synchronously¶
The SDK update includes the following two parts:
update rk3399-linux-bundle
#1. Enter the SDK root directory
cd ~/proj/firefly-sdk
#2. Download remote bundle repository
git clone https://github.com/FireflyTeam/bundle.git -b rk3399-linux-bundle
#3. Update, and subsequent updates do not need to pull the remote warehouse again, just execute the following command
./bundle/update rk3399-linux-bundle
#4. Follow the prompts to update the content to FETCH_HEAD, synchronize FETCH_HEAD to the firefly branch
git rebase FETCH_HEAD
update common-linux-bundle
Download: common-linux-bundle
#1. Download and put common-linux-bundle in the root directory of SDK
cd ~/proj/firefly-sdk
mv common-linux-bundle/ .common-linux-bundle/
#2. Update, and you can check `Change_log.txt` for subsequent updates
chmod 755 .common-linux-bundle/update && .common-linux-bundle/update
git rebase FETCH_HEAD
Update SDK¶
In the future, it is relatively simple to update the SDK, and does not need to be as complicated as before
Update ~/proj/firefly-sdk/bundle/
cd ~/proj/firefly-sdk/bundle/
git remote update
git pull
git rebase FETCH_HEAD
Update
.common-linux-bundle
Go to the download page ofcommon-linux-bundle
and compare the contents in remotecommon-linux-bundle
and~/proj/firefly-sdk/.common-linux-bundle/
. Check if there is a new bundle file, if there is, copy it to the.common-linux-bundle
folder directory:
cd ~/proj/firefly-sdk/
cp ~/Downloads/13.bundle ../.common-linux-bundle/
Update firefly-sdk
cd ~/proj/firefly-sdk/
git rebase FETCH_HEAD
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
Set up compilation environment¶
Compile debian:
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-4.8-multilib-arm-linux-gnueabihf gcc-arm-linux-gnueabihf libssl-dev
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 libc6:i386 libssl-dev texinfo
liblz4-tool genext2fs lib32stdc++6
Ubuntu firmware: (please use the official root file system image)
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-4.8-multilib-arm-linux-gnueabihf gcc-arm-linux-gnueabihf libssl-dev
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 libc6:i386 libssl-dev texinfo
liblz4-tool genext2fs lib32stdc++6
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
Compile SDK¶
Configuration before compilation¶
The configuration file rk3399-firefly-face-X2-mipi8.mk
:
./build.sh rk3399-firefly-face-X2-mipi8.mk
#The file path: `device/rockchip/rk3399/rk3399-firefly-face-X2-mipi8.mk`
Effective configuration file will be connected to the device/rockchip/.BoardConfig.mk
, check the file to verify that the configuration was successful.
Note : rk3399-firefly-face-X2-mipi8.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_face_x2_linux_defconfig #Compile the kernel configuration file
#Kernel dts
export RK_KERNEL_DTS=rk3399-firefly-face-X2-mipi8 #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:
Put the resulting image in the specified directory in SDK:
#Unpack
tar -xvf rk3399_ubuntu18.04_LXDE.img.tgz
#The root directory of sdk
mkdir ubunturootfs
mv rk3399_ubuntu18.04_LXDE.img ubunturootfs/
#Modify rk3399-firefly-face-X2-mipi8.mk :
vim device/rockchip/rk3399/rk3399-firefly-face-X2-mipi8.mk
#Change the RK_ROOTFS_IMG property to the ubuntu file system image path(such as rk3399_ubuntu18.04_LXDE.img)
RK_ROOTFS_IMG=ubunturootfs/rk3399_ubuntu18.04_LXDE.img
NOTE: Ubuntu root file system image storage path can not be wrong !!
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.
Partial compilation¶
kernel¶
./build.sh kernel
u-boot¶
./build.sh uboot
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 rk3399-firefly-face-X2-mipi8.mk
vim device/rockchip/rk3399/rk3399-firefly-face-X2-mipi8.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
Place the resulting image at the root of the SDK
#Unpack
tar -xvf rk3399_ubuntu18.04_LXDE.img.tgz
#The root directory of sdk
mkdir ubunturootfs
mv rk3399_ubuntu18.04_LXDE.img ubunturootfs/
#Modify rk3399-firefly-face-X2-mipi8.mk :
vim device/rockchip/rk3399/rk3399-firefly-face-X2-mipi8.mk
#Change the RK_ROOTFS_IMG property to the ubuntu file system image path(such asrk3399_ubuntu18.04_LXDE.img)
RK_ROOTFS_IMG=ubunturootfs/rk3399_ubuntu18.04_LXDE.img
NOTE:buntu root file system image storage path can not be wrong!!
Run ./mkfirmware.sh
will automatically update rockdev/rootfs.img
links.
Pack the firmware¶
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_LXDE.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.
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
Partition introduction¶
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)
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
.
FAQs¶
How to enter upgrade mode ?¶
See operation method in Upgrade firmware