跳到主要内容

Ubuntu系统编译

电脑硬件配置

编译 Ubuntu 开发环境电脑硬件配置建议:

  • 64 位 CPU
  • Ubuntu20.04系统,不要使用 Windows 子系统 (WSL)
  • 16GB 内存
  • 250GB 空闲空间用来编译
  • 普通用户编译,不要使用 root 用户编译

电脑软件配置

安装环境包

sudo apt update
sudo apt-get install 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 libncurses-dev

sudo apt install python3-pip
sudo pip install python-pip pyelftools
sudo apt install python2
sudo apt install python

SDK获取

发送邮件至 support@neardi.com 获取相关开发资料

下载完成后,在解压前先查看 MD5 码和Neardi-3576-SDK-Linux-Version.tar.gz.md5sum中是否一致:

$ md5sum Neardi-3576-SDK-Linux-${Version}.tar.gz
******************************** Neardi-3576-SDK-Linux-${Version}tar.gz

解压:

请使用当前Ubuntu系统用户直接解压文件,避免在Windows系统中解压后再复制到Ubuntu系统中。这样做可以确保文件属性和权限的正确性,避免潜在的兼容性问题

tar zxvf Neardi-3576-SDK-Linux-${Version}.tar.gz

提取:

cd Neardi-3576-SDK-Linux-${Version}

# 务必执行,否则只有.git目录,没有源码
git reset --hard

编译 SDK

选择配置

./build.sh lunch
默认选择 rockchip_rk3576_neardi_lb200_defconfig

全自动编译

第一次编译SDK,务必全编一次,否则打包会出错

全自动编译会执行所有编译, 编译生成u-boot、kernel和buildroot。

./build.sh

编译Ubuntu 22.04

./build.sh jammy

打包固件

RK 固件,是以 Rockchip 专有格式打包的固件,使用 Rockchip 提供的工具可以烧写到 eMMC 或者 SD 卡中(注:若无特殊说明,WIKI 上提及的固件默认为 RK 固件)。

# 打包 RK 固件
./build.sh updateimg

生成的完整固件会保存到 rockdev/update.img

分区说明

parameter 分区表

parameter.txt 文件中包含了固件的分区信息:

路径:device/rockchip/rk3576/parameter.txt

FIRMWARE_VER: 1.0
MACHINE_MODEL: RK3576
MACHINE_ID: 007
MANUFACTURER: RK3576
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 0xffffffff
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT
GROW_ALIGN: 0
CMDLINE: mtdparts=:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00020000@0x00008000(boot),0x00040000@0x00028000(recovery),0x00010000@0x00068000(backup),0x00040000@0x00078000(oem),0x00040000@0x000b8000(userdata),-@0x000f8000(rootfs:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9
uuid:boot=7A3F0000-0000-446A-8000-702F00006273

CMDLINE 属性是我们关注的地方,以 uboot 为例, 0x00002000@0x00004000(uboot) 中 0x00004000 为uboot 分区的起始位置,0x00002000 为分区的大小,以此类推。

package-file

package-file 文件用于打包固件时确定需要的分区镜像和镜像路径,同时它需要与 parameter.txt 文件保持一致。

路径:tools/linux/Linux_Pack_Firmware/rockdev/rk3576-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
backup RESERVED

FAQ

如何单独编译

  • 编译 u-boot
./build.sh uboot
  • 编译 kernel
./build.sh kernel
  • 编译 recovery
./build.sh recovery

编译错误

lz4错误

Incorrect parameters
Usage :
lz4 [arg] [input] [output]

input : a filename
with no FILE, or when FILE is - or stdin, read standard input
Arguments :
-1 : Fast compression (default)
-9 : High compression
-d : decompression (default for .lz4 extension)
-z : force compression
-f : overwrite output without prompting
-h/-H : display help/long help and exit
arch/arm64/boot/Makefile:31: recipe for target 'arch/arm64/boot/Image.lz4' failed
make[2]: *** [arch/arm64/boot/Image.lz4] Error 1
make[2]: *** Deleting file 'arch/arm64/boot/Image.lz4'
arch/arm64/Makefile:170: recipe for target 'Image.lz4' failed
make[1]: *** [Image.lz4] Error 2
make[1]: *** Waiting for unfinished jobs....

解决方法,重新手动安装lz4:

git clone https://github.com/lz4/lz4.git
cd lz4
make
sudo make install