ROC-RK3568-PC入门篇连载进程:
✅ [ROC-RK3568-PC] 手把手教你把出厂的Android系统烧写为Ubuntu系统
✅ [ROC-RK3568-PC] 手把手教你制作Ubuntu系统TF卡启动盘
在前面主要讲述如何烧写Firefly官方Ubuntu固件到板卡ROC-RK3568-PC,但是身为一名嵌入式开发者,我们需要定制自己Ubuntu固件,那么我们应该如何才能编译并打包出自己的固件呢?别急,这篇给大家揭晓!
众所周知,编译最让人头疼的就是主机环境问题!假设我手上有其他芯片厂商的板卡,每个厂商的SDK都使用不同的编译环境,而我的Ubuntu主机系统只有一个,那怎么办?
使用Docker容器!
按照Firefly官方维基介绍,推荐使用Ubuntu 18.04,那我们在Docker下搭建一个Ubuntu 18.04系统好了!
照搬我之前写的这篇:Linux工具篇 | Ubuntu搭建Docker容器引擎
$ sudo apt update
$ docker pull ubuntu:18.04
切换Shell到Ubuntu 18.04:
$ docker container run -p 8000:3000 -it ubuntu:18.04 /bin/bash
root@32b7b9ddcaab:/# cat /etc/issue
Ubuntu 18.04.6 LTS \n \l
root@32b7b9ddcaab:/# apt update
root@32b7b9ddcaab:/# apt install byobu vim-gtk inetutils-ping net-tools wget cpio unzip rsync xz-utils
过程中需要配置地区,选择亚洲上海:
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities,
representing the time zones in which they are located.
1. Africa 3. Antarctica 5. Arctic 7. Atlantic 9. Indian 11. SystemV 13. Etc
2. America 4. Australia 6. Asia 8. Europe 10. Pacific 12. US
Geographic area: 6
Please select the city or region corresponding to your time zone.
1. Aden 13. Barnaul 25. Dushanbe 37. Jerusalem 49. Macau 61. Pyongyang 73. Taipei 85. Vientiane
2. Almaty 14. Beirut 26. Famagusta 38. Kabul 50. Magadan 62. Qatar 74. Tashkent 86. Vladivostok
3. Amman 15. Bishkek 27. Gaza 39. Kamchatka 51. Makassar 63. Qostanay 75. Tbilisi 87. Yakutsk
4. Anadyr 16. Brunei 28. Harbin 40. Karachi 52. Manila 64. Qyzylorda 76. Tehran 88. Yangon
5. Aqtau 17. Chita 29. Hebron 41. Kashgar 53. Muscat 65. Rangoon 77. Tel_Aviv 89. Yekaterinburg
6. Aqtobe 18. Choibalsan 30. Ho_Chi_Minh 42. Kathmandu 54. Nicosia 66. Riyadh 78. Thimphu 90. Yerevan
7. Ashgabat 19. Chongqing 31. Hong_Kong 43. Khandyga 55. Novokuznetsk 67. Sakhalin 79. Tokyo
8. Atyrau 20. Colombo 32. Hovd 44. Kolkata 56. Novosibirsk 68. Samarkand 80. Tomsk
9. Baghdad 21. Damascus 33. Irkutsk 45. Krasnoyarsk 57. Omsk 69. Seoul 81. Ujung_Pandang
10. Bahrain 22. Dhaka 34. Istanbul 46. Kuala_Lumpur 58. Oral 70. Shanghai 82. Ulaanbaatar
11. Baku 23. Dili 35. Jakarta 47. Kuching 59. Phnom_Penh 71. Singapore 83. Urumqi
12. Bangkok 24. Dubai 36. Jayapura 48. Kuwait 60. Pontianak 72. Srednekolymsk 84. Ust-Nera
Time zone: 70
Current default time zone: 'Asia/Shanghai'
Local time is now: Tue Nov 30 18:05:30 CST 2021.
Universal Time is now: Tue Nov 30 10:05:30 UTC 2021.
Run 'dpkg-reconfigure tzdata' if you wish to change it.
设置超级用户:
root@32b7b9ddcaab:/# apt install sudo
root@32b7b9ddcaab:/# visudo
添加自己的用户名,保存并退出:
neutionwei ALL=(ALL:ALL) ALL
切换到普通用户:
root@32b7b9ddcaab:/# adduser neutionwei
root@32b7b9ddcaab:/# su neutionwei
进入Firefly官方进行下载,链接如下:
https://www.t-firefly.com/doc/download/107.html
大家点击以下图片中指向的地方进行下载:
下载最新版本:
下载完成后首先使用md5sum进行校验:
$ ls
md5sum.txt
README_EN.txt
README.txt
rk356x_linux_release_v1.2.0_20211019_firefly_split.file0
rk356x_linux_release_v1.2.0_20211019_firefly_split.file1
rk356x_linux_release_v1.2.0_20211019_firefly_split.file2
rk356x_linux_release_v1.2.0_20211019_firefly_split.file3
rk356x_linux_release_v1.2.0_20211019_firefly_split.file4
$ md5sum *firefly_split*
b633414d69240faa0c3bd755c255ede8 rk356x_linux_release_v1.2.0_20211019_firefly_split.file0
5cb1e2b63bbb4e3595c731038f6723fd rk356x_linux_release_v1.2.0_20211019_firefly_split.file1
e06c0f29fd5a870e0942139a1877a470 rk356x_linux_release_v1.2.0_20211019_firefly_split.file2
4e14fbf72ccbb9b87f81d83a256205b0 rk356x_linux_release_v1.2.0_20211019_firefly_split.file3
be8b003703b51e7220e52bb36439a357 rk356x_linux_release_v1.2.0_20211019_firefly_split.file4
确认与目录内的md5sum.txt
文件内容无误!
根据Firefly官方维基安装必要工具:
neutionwei@32b7b9ddcaab:/$ 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
在Ubuntu 18.04新建一个目录:
neutionwei@32b7b9ddcaab:/$ cd ~
neutionwei@32b7b9ddcaab:~$ mkdir project
neutionwei@32b7b9ddcaab:~$ cd project/
neutionwei@32b7b9ddcaab:~/project$ pwd
/home/neutionwei/project
主机使用docker
命令把Linux_SDK拷贝到Docker下的Ubuntu 18.04:
$ docker cp rk356x_linux_release_v1.2.0_20211019_split_dir 32b7b9ddcaab:/home/neutionwei/project
解压缩Linux_SDK:
neutionwei@32b7b9ddcaab:~/project$ cat rk356x_linux_release_v1.2.0_20211019_split_dir/*firefly_split* | tar -xzv
同步Linux_SDK:
neutionwei@32b7b9ddcaab:~/project$ cd rk356x_linux_release_20211019
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ .repo/repo/repo sync -l
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ .repo/repo/repo sync -c --no-tags
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ .repo/repo/repo start firefly --all
后续可以使用以下命令更新Linux_SDK:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ .repo/repo/repo sync -c --no-tags
配置板卡型号,选择roc-rk3568-pc-ubuntu.mk
:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ls
Makefile build.sh debian docs external mkfirmware.sh rkbin tools yocto
app buildroot device envsetup.sh kernel prebuilts rkflash.sh u-boot
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ls device/rockchip/rk356x/
BoardConfig-rk3566-evb2-lp4x-v10-32bit.mk aio-3568j-openwrt.mk parameter-buildroot-spi-nor-64M.txt
BoardConfig-rk3566-evb2-lp4x-v10.mk aio-3568j-ubuntu.mk parameter-openwrt.txt
BoardConfig-rk3568-evb1-ddr4-v10-32bit.mk boot.its parameter-ubuntu-fit.txt
BoardConfig-rk3568-evb1-ddr4-v10-spi-nor-64M.mk boot4recovery.its roc-rk3566-pc-buildroot.mk
BoardConfig-rk3568-evb1-ddr4-v10.mk bootramdisk.its roc-rk3566-pc-lede.mk
BoardConfig-rk3568-nvr-spi-nand.mk firefly-rk3566-buildroot.mk roc-rk3566-pc-openwrt.mk
BoardConfig-rk3568-nvr.mk firefly-rk3566-ubuntu.mk roc-rk3566-pc-ubuntu.mk
BoardConfig-rk3568-uvc-evb1-ddr4-v10.mk firefly-rk3568-buildroot.mk roc-rk3568-pc-buildroot.mk
BoardConfig.mk firefly-rk3568-nvr-buildroot.mk roc-rk3568-pc-lede.mk
aio-3566-jd4-buildroot.mk firefly-rk3568-ubuntu.mk roc-rk3568-pc-openwrt.mk
aio-3566-jd4-ubuntu.mk firefly-rk356x-openwrt.mk roc-rk3568-pc-ubuntu.mk
aio-3568j-buildroot.mk parameter-buildroot-NVR-128M.txt station-m2-ubuntu.mk
aio-3568j-lede.mk parameter-buildroot-NVR-spi-nand-128M.txt station-p2-ubuntu.mk
aio-3568j-nvr.mk parameter-buildroot-fit.txt zboot.its
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./build.sh roc-rk3568-pc-ubuntu.mk
processing option: roc-rk3568-pc-ubuntu.mk
switching to board: /home/neutionwei/project/rk356x_linux_release_20211019/device/rockchip/rk356x/roc-rk3568-pc-ubuntu.mk
开始进行全编译:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./build.sh all
编译过程中发生的错误:
/bin/sh: 1: bc: not found
Kbuild:42: recipe for target 'include/generated/timeconst.h' failed
make[1]: *** [include/generated/timeconst.h] Error 127
Makefile:1244: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
make: *** Waiting for unfinished jobs....
HOSTCC scripts/recordmcount
HOSTCC scripts/dtc/checks.o
HOSTCC scripts/dtc/util.o
LEX scripts/dtc/dtc-lexer.lex.c
YACC scripts/dtc/dtc-parser.tab.h
HOSTCC scripts/resource_tool
HOSTCC scripts/mkkrnlimg
HOSTCC scripts/mod/sumversion.o
YACC scripts/dtc/dtc-parser.tab.c
HOSTCC scripts/sortextable
HOSTCC scripts/dtc/dtc-lexer.lex.o
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/asn1_compiler
HOSTCC scripts/dtc/dtc-parser.tab.o
HOSTCC scripts/extract-cert
HOSTLD scripts/mod/modpost
HOSTLD scripts/dtc/dtc
ERROR: Running build_kernel failed!
ERROR: exit code 2 from line 561:
make ARCH=$RK_ARCH $RK_KERNEL_DTS.img -j$RK_JOBS
安装bc
命令:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ sudo apt install bc
继续全编译:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./build.sh all
依然有错误:
./build.sh: line 874: /usr/bin/time: No such file or directory
ERROR: Running build_recovery failed!
ERROR: exit code 127 from line 874:
/usr/bin/time -f "you take %E to build recovery" $COMMON_DIR/mk-ramdisk.sh recovery.img $RK_CFG_RECOVERY
安装time
命令:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ sudo apt install time
继续全编译:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./build.sh all
终于编译通过:
you take 0:01.53 to build recovery
====Build recovery ok!====
Running build_recovery succeeded.
Skipping build_ramboot for missing configs: RK_CFG_RAMBOOT.
Running build_all succeeded.
首先下载Firefly官方的Ubuntu根文件系统:
https://www.t-firefly.com/doc/download/107.html
选择最新版的Ubuntu 20.04:
点击7z文件进行下载(第一项的md5是校验文件):
把文件拷贝到Ubuntu 18.04:
$ docker cp ubuntu_20.04_RK3568_ext4_v2.10-51-g7ecad547_20211201-1551_DESKTOP.7z 32b7b9ddcaab:/home/neutionwei/project/rk356x_linux_release_20211019
安装7z
命令并解压:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ sudo apt-get install p7zip-full
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ 7z x ubuntu_20.04_RK3568_ext4_v2.10-51-g7ecad547_20211201-1551_DESKTOP.7z
新建ubuntu_rootfs
目录:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ mkdir ubuntu_rootfs
移动根文件系统到ubuntu_rootfs
目录:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ mv ubuntu_20.04_RK3568_ext4_v2.10-51-g7ecad547_20211201-1551_DESKTOP.img ubuntu_rootfs
建立软链接:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ cd ubuntu_rootfs
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019/ubuntu_rootfs$ ls
ubuntu_20.04_RK3568_ext4_v2.10-51-g7ecad547_20211201-1551_DESKTOP.img
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019/ubuntu_rootfs$ ln -sf ubuntu_20.04_RK3568_ext4_v2.10-51-g7ecad547_20211201-1551_DESKTOP.img rk356x_ubuntu_rootfs.img
更新打包目录软链接:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019/ubuntu_rootfs$ cd ..
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./mkfirmware.sh
/usr/bin/fakeroot
create rootfs.img...done.
create parameter...done.
/home/neutionwei/project/rk356x_linux_release_20211019/device/rockchip/rk356x/parameter-ubuntu-fit.txt
0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00020000@0x00008000(boot),0x00020000@0x00028000(recovery),0x00010000@0x00048000(backup),0x00c00000@0x00058000(rootfs),-@0x00c58000(userdata:grow)
create misc.img...done.
warning: not found!
create uboot.img...done.
create idblock.bin...done.
uboot fotmat type is fit, so ignore trust.img...
create loader...done.
create boot.img...done.
mkupdate.sh will resize the rootfs partition.
Image: image in rockdev is ready
打包Ubuntu固件:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ ./build.sh updateimg
processing option: updateimg
File name is ROC-RK3568-PC-UBUNTU20.04-GPT
Rename the file? [N|y]n
Make update.img
start to make update.img...
Resize rootfs partition size
dumpe2fs 1.44.1 (24-Mar-2018)
Android Firmware Package Tool v1.66
------ PACKAGE ------
Add file: ./package-file
Add file: ./package-file done,offset=0x800,size=0x11a,userspace=0x1
Add file: ./Image/MiniLoaderAll.bin
Add file: ./Image/MiniLoaderAll.bin done,offset=0x1000,size=0x719c0,userspace=0xe4
Add file: ./Image/parameter.txt
Add file: ./Image/parameter.txt done,offset=0x73000,size=0x1d5,userspace=0x1
Add file: ./Image/uboot.img
Add file: ./Image/uboot.img done,offset=0x73800,size=0x400000,userspace=0x800
Add file: ./Image/misc.img
Add file: ./Image/misc.img done,offset=0x473800,size=0xc000,userspace=0x18
Add file: ./Image/boot.img
Add file: ./Image/boot.img done,offset=0x47f800,size=0x1ff4800,userspace=0x3fe9
Add file: ./Image/recovery.img
Add file: ./Image/recovery.img done,offset=0x2474000,size=0x1e23800,userspace=0x3c47
Add file: ./Image/rootfs.img
Add file: ./Image/rootfs.img done,offset=0x4297800,size=0xa744fc00,userspace=0x14e8a0
Add CRC...
Make firmware OK!
------ OK ------
********RKImageMaker ver 1.66********
Generating new image, please wait...
Writing head info...
Writing boot file...
Writing firmware...
Generating MD5 data...
MD5 data generated successfully!
New image generated successfully!
Making ./Image/update.img OK.
Make update image ok!
/home/neutionwei/project/rk356x_linux_release_20211019/rockdev/pack/ROC-RK3568-PC-UBUNTU20.04-GPT-20211203-2103.img
Running build_updateimg succeeded.
可以看到我们打包的固件在/home/neutionwei/project/rk356x_linux_release_20211019/rockdev/pack/
目录。
在主机使用docker
命令把固件拷贝回主机烧写即可:
$ docker cp 32b7b9ddcaab:/home/neutionwei/project/rk356x_linux_release_20211019/rockdev/pack/ROC-RK3568-PC-UBUNTU20.04-GPT-20211203-2103.img .
大家可能好奇为啥根文件系统要放在ubuntu_rootfs
目录并建立软链接,我们可以看一下roc-rk3568-pc-ubuntu.mk
配置文件:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ cat device/rockchip/rk356x/roc-rk3568-pc-ubuntu.mk
#!/bin/bash
CMD=`realpath $BASH_SOURCE`
CUR_DIR=`dirname $CMD`
source $CUR_DIR/firefly-rk3568-ubuntu.mk
# Kernel dts
export RK_KERNEL_DTS=rk3568-firefly-roc-pc
# PRODUCT MODEL
export RK_PRODUCT_MODEL=ROC_RK3568_PC
从这个配置文件中不难看出,这个文件依赖于firefly-rk3568-ubuntu.mk
,我们再看看这个文件:
neutionwei@32b7b9ddcaab:~/project/rk356x_linux_release_20211019$ cat device/rockchip/rk356x/firefly-rk3568-ubuntu.mk
#!/bin/bash
CMD=`realpath $BASH_SOURCE`
CUR_DIR=`dirname $CMD`
source $CUR_DIR/BoardConfig.mk
# Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3568
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig
# parameter for GPT table
export RK_PARAMETER=parameter-ubuntu-fit.txt
# packagefile for make update image
export RK_PACKAGE_FILE=rk356x-ubuntu-package-file
# build idblock
export RK_IDBLOCK_UPDATE=true
# update spl
export RK_LOADER_UPDATE_SPL=true
# Set rootfs type, including ext2 ext4 squashfs
export RK_ROOTFS_TYPE=ext4
# rootfs image path
export RK_ROOTFS_IMG=ubuntu_rootfs/rk356x_ubuntu_rootfs.img
# recovery ramdisk
export RK_RECOVERY_RAMDISK=rk356x-recovery-arm64.cpio.gz
# recovery ramdisk raw
export RK_RECOVERY_RAMDISK_RAW=rk356x-recovery-arm64-raw.cpio.gz
# Set userdata partition type
export RK_USERDATA_FS_TYPE=ext4
# kernel image format type: fit(flattened image tree)
export RK_KERNEL_FIT_ITS=bootramdisk.its
# Buildroot config
export RK_CFG_BUILDROOT=
# Recovery config
export RK_CFG_RECOVERY=
#OEM config
export RK_OEM_DIR=
#userdata config
export RK_USERDATA_DIR=
# rootfs_system
export RK_ROOTFS_SYSTEM=ubuntu
大家看到这句话了没?哈哈
# rootfs image path
export RK_ROOTFS_IMG=ubuntu_rootfs/rk356x_ubuntu_rootfs.img