RV1126 是 Rockchip 推出的一款编解码芯片,CPU 为 4 核 ARM Cortex-A7 32 位,专用于面向人工智能的机械视觉领域,支持 4K 编解码,支持 8 路 1080P 同时进行编解码,内置 2.0TOPS的 NPU。像这种专用芯片,芯片厂商都会给出芯片的 SDK 包进行二次开发,用它来开发有很多好处,比如:不用安装一下特殊的软件和库,自带交叉工具链、文件系统和第三方库,可以直接编译出系统镜像,开发环境搭建比较容易等等。但是开发自由度不够高,更新软件版本很麻烦,代码里有很多私货(芯片厂商自己定义的代码)等等
? app : 存放上层应用程序的目录。
? buildroot :SDK 包使用的文件系统为 buildroot。
? build.sh :编译用的脚本,使用方法后面会教。
? device/rockchip :存放每个平台的一些编译和打包固件的脚步和预备文件。
? docs :存放 RK 开发指导文件、平台支持列表、工具使用文档、Linux 开发指南等。
? envsetup.sh :要修改文件系统时候要设置的环境脚本。
? external : 存放相关的库,包括音频,视频等。
? kernel :kernel 源码。
? makefile :整个 SDK 包编译的 Makefile。
? mkfirmware.sh :固件打包使用的脚本,默认在当前路径下的 rockdev 目录。
? prebuilts : 存放交叉编译工具链。
? rkbin: 存放固件和工具。
? rkflash.sh : linux 下的系统烧录脚本。
? tools :存放固件和工具的目录。
? u-boot :U-boot 源码目录。
? rockdev:存放编译输出固件的目录(整个 SDK 包编译完成后就会创建
什么叫做模块代码?一个完整的 SDK 包除了 kernel、u-boot、buildroot 之外,还需要提供上层的第三方库和 APP,第三方库和 APP 合起来叫做模块代码。
查看 build.sh 使用帮助
morgan@morgan-machine:~/Work/rv1126$ ./build.sh lunch -h
Usage: build.sh [OPTIONS]
Available options:
BoardConfig*.mk -switch to specified board config
lunch -list current SDK boards and switch to specified board config
uboot -build uboot
spl -build spl
loader -build loader
kernel -build kernel
modules -build kernel modules
toolchain -build toolchain
rootfs -build default rootfs, currently build buildroot as default
buildroot -build buildroot rootfs
ramboot -build ramboot image
multi-npu_boot -build boot image for multi-npu board
yocto -build yocto rootfs
debian -build debian10 buster/x11 rootfs
distro -build debian10 buster/wayland rootfs
pcba -build pcba
recovery -build recovery
all -build uboot, kernel, rootfs, recovery image
cleanall -clean uboot, kernel, rootfs, recovery
firmware -pack all the image we need to boot up system
updateimg -pack update image
otapackage -pack ab update otapackage image (update_ota.img)
sdpackage -pack update sdcard package image (update_sdcard.img)
save -save images, patches, commands used to debug
allsave -build all & firmware & updateimg & save
check -check the environment of building
info -see the current board building information
app/<pkg> -build packages in the dir of app/*
external/<pkg> -build packages in the dir of external/*
实际编译测试使用耗时
morgan@morgan-machine:~/Work/rv1126$ time ./build.sh
processing board option: allsave
processing option: allsave
.....
vccio7-supply
regulator-min-microvolt = 1800mV
regulator-max-microvolt = 1800mV
Running build_allsave succeeded.
real 116m26.217s
user 244m36.079s
sys 41m30.641s
envsetup.sh 脚本主要的作用是,使能 buildroot 的配置文件。在 RV1126 这个芯片里,一共可以选择的配置文件有 3 种分别为:文件系统的配置文件,recovery 分区的配置文件(此分区主要是用作升级和复原的文件系统,它也是一个文件系统)和 libs 的配置文件(生成一些库,方便
我们写应用层代码做测试,导出文件系统的库文件)。
mkfirmware.sh 脚本主要的作用是,把 uboot、kernel、文件系统等等进行打包和生成镜像。
rkflash.sh 脚本主要的作用是,在 linux 系统下进行固件的烧录
RK 官方提供了很方便的编译方法,直接运行以下./build.sh uboot 命令可以编译 uboot。
morgan@morgan-machine:~/Work/rv1126$ ./build.sh uboot
编译完成后,会在 u-boot 目录下生成 uboot.img 文件和 rv1126_spl_loader_v1.08.108.bin 文件,uboot.img 文件就是我们要烧录的 img 镜像,rv1126_spl_loader_v1.08.108.bin 是启动引导uboot 的文件
选择要修改 Uboot 配置文件,从板级文件知道
morgan@morgan-machine:~/Work/rv1126/u-boot$ make alientek_rv1126_defconfig
进入图形界面配置
morgan@morgan-machine:~/Work/rv1126/u-boot$ make menuconfig
把.config 保存为 defconfig
morgan@morgan-machine:~/Work/rv1126/u-boot$ make savedefconfig
scripts/kconfig/conf --savedefconfig=defconfig Kconfig
更新修改好的配 置文件到alientek_rv1126_defconfig
morgan@morgan-machine:~/Work/rv1126/u-boot$ cp defconfig configs/alientek_rv1126_defconfig
重新编译 uboot
morgan@morgan-machine:~/Work/rv1126$ ./build.sh uboot
红色框里打印日期为“2024-01-12 22:34:42
选择要修改的 kernel 配置文件
morgan@morgan-machine:~/Work/rv1126/kernel$ make ARCH=arm alientek_rv1126_defconfig
#
# configuration written to .config
#
进入图形界面配置
morgan@morgan-machine:~/Work/rv1126/kernel$ make ARCH=arm alientek_rv1126_defconfig
把.config 保存为 defconfig
morgan@morgan-machine:~/Work/rv1126/kernel$ make ARCH=arm savedefconfig
scripts/kconfig/conf --savedefconfig=defconfig Kconfig
更 新 修 改 好 的 配 置 文 件 到 alientek_rv1126_defconfig
cp defconfig arch/arm/configs/alientek_rv1126_defconfig
编译内核
morgan@morgan-machine:~/Work/rv1126$ ./build.sh kernel
配置完成后我们可以直接用 build.sh kernel 脚本进行编译了,就会生成我们想要的 zboot.img 文件
烧录成功会自动重启,我们查看打印信息内核有没有替换成功
在 SDK 包源码目录下,运行以下命令进行配置 buildroot:
配置 buildroot 对应 defconfig
morgan@morgan-machine:~/Work/rv1126$ source envsetup.sh alientek_rv1126
Top of tree: /home/morgan/Work/rv1126
===========================================
#TARGET_BOARD=rv1126
#OUTPUT_DIR=output/alientek_rv1126
#CONFIG=alientek_rv1126_defconfig
===========================================
make: 进入目录“/home/morgan/Work/rv1126/buildroot”
GEN /home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/Makefile
/home/morgan/Work/rv1126/buildroot/build/defconfig_hook.py -m /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig /home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig
BR2_DEFCONFIG='' KCONFIG_AUTOCONFIG=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/build/buildroot-config/auto.conf KCONFIG_AUTOHEADER=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/build/buildroot-config/autoconf.h KCONFIG_TRISTATE=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/build/buildroot-config/tristate.config BR2_CONFIG=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.config HOST_GCC_VERSION="9" BUILD_DIR=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/build SKIP_LEGACY= BR2_DEFCONFIG=/home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig /home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/build/buildroot-config/conf --defconfig=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig Config.in
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:142:warning: override: reassigning to symbol BR2_PACKAGE_RKWIFIBT
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:179:warning: override: reassigning to symbol BR2_PACKAGE_UPDATE
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:185:warning: override: reassigning to symbol BR2_PACKAGE_RKSCRIPT
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:208:warning: override: reassigning to symbol BR2_TARGET_GENERIC_HOSTNAME
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:209:warning: override: reassigning to symbol BR2_TARGET_GENERIC_ISSUE
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:210:warning: override: reassigning to symbol BR2_TARGET_GENERIC_ROOT_PASSWD
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:235:warning: override: reassigning to symbol BR2_PACKAGE_ALSA_UTILS
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:236:warning: override: reassigning to symbol BR2_PACKAGE_ALSA_UTILS_ALSACONF
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:237:warning: override: reassigning to symbol BR2_PACKAGE_ALSA_UTILS_AMIXER
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:238:warning: override: reassigning to symbol BR2_PACKAGE_ALSA_UTILS_APLAY
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:239:warning: override: reassigning to symbol BR2_PACKAGE_ALSA_PLUGINS
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:240:warning: override: reassigning to symbol BR2_PACKAGE_LIBMAD
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:243:warning: override: reassigning to symbol BR2_PACKAGE_ALSA_CONFIG
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:251:warning: override: reassigning to symbol BR2_PACKAGE_LIBV4L
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:252:warning: override: reassigning to symbol BR2_PACKAGE_LIBV4L_UTILS
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:253:warning: override: reassigning to symbol BR2_PACKAGE_CAMERA_ENGINE
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:315:warning: override: reassigning to symbol BR2_PACKAGE_MPP
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:316:warning: override: reassigning to symbol BR2_PACKAGE_MPP_ALLOCATOR_DRM
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:318:warning: override: reassigning to symbol BR2_PACKAGE_LINUX_RGA
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:343:warning: override: reassigning to symbol BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTP
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:344:warning: override: reassigning to symbol BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTPMANAGER
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:345:warning: override: reassigning to symbol BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTSP
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:351:warning: override: reassigning to symbol BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEORATE
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:352:warning: override: reassigning to symbol BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VORBIS
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:353:warning: override: reassigning to symbol BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_OGG
/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.rockchipconfig:558:warning: override: reassigning to symbol BR2_PACKAGE_NTP_NTPD
#
# configuration written to /home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/.config
#
make: 离开目录“/home/morgan/Work/rv1126/buildroot”
进入图形化界面
morgan@morgan-machine:~/Work/rv1126$ make menuconfig
配置完成好保存。运行以下命令进行保存和重新编译(注意:buildroot 有时候不能生成一些配置选项,要运行./build.sh cleanall 命令清除,在编译)
保存配置文件到 buildroot/configs/alientek_rv1126_defconfig
morgan@morgan-machine:~/Work/rv1126$ make savedefconfig
umask 0022 && make -C /home/morgan/Work/rv1126/buildroot O=/home/morgan/Work/rv1126/buildroot/output/alientek_rv1126 savedefconfig
GEN /home/morgan/Work/rv1126/buildroot/output/alientek_rv1126/Makefile
grep "#include" /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig > /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig.split || true
cat /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig >> /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig.split
/home/morgan/Work/rv1126/buildroot/build/defconfig_hook.py -s /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig.split /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig
rm /home/morgan/Work/rv1126/buildroot/configs/alientek_rv1126_defconfig.split
编译
morgan@morgan-machine:~/Work/rv1126$ ./build.sh rootfs
在 SDK 包源码目录下,运行以下命令进行配置 busybox
/配置 buildroot 对应 defconfig
morgan@morgan-machine:~/Work/rv1126$ source envsetup.sh alientek_rv1126
进入图形化界面
morgan@morgan-machine:~/Work/rv1126$ make busybox-menuconfig
保存刚刚修改的配置
morgan@morgan-machine:~/Work/rv1126$ make busybox-menuconfig
重新编译文件系统