openwrt RK3568_EVB移植


openwrt SDK下载

根据 firefly 官方提供的教程下载编译 ROC-RK3568-PC 版本的 openwrt firefly SDK,具体可以参考以下连接。

​https://wiki.t-firefly.com/zh_CN/ROC-RK3568-PC/openwrt_compile.html​

openwrt 编译

在确保编译环境完善之后先不要着急编译 openwrt ,因为 openwrt 需要下载并且编译一部分自己的依赖库(类似 buildroot 的操作)

编译环境依赖库安装可以参考:(推荐使用 Ubuntu 18.04 系统)

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 \
unzip

安装完成依赖后,先不要着急根据 firefly 文档进行编译(主流程是文档上写的)。先将 SDK 文档中的代码进行清理以防在自己的编译环境下编译出错:

./build.sh cleanall

并且进入 openwrt 代码目录,在 SDK 包中的 firefly_openwrt/openwrt_sdk/openwrt/ 路径下,在这个路径下也进行代码清理操作:

make

编译 操作:

对于 uboot 、kernel 先不着急编译(这部分一般不会有问题),因为 openwrt 第一次编译需要更新和拉取大量的第三方库,所以首次编译最好先单独编译 openwrt,操作如下:

cd firefly_openwrt/openwrt_sdk/openwrt/

./scripts/feeds update -a
./scripts/feeds install -a
cp configs/rk356x_config .config
make defconfig
make download -j8
make

这个过程大概需要 2个多小时,并且需要确保网络通畅,其中主要耗时操作在 feeed install 和 make download 这两步,需要耐心等待。

整体编译操作:

顺利完成 openwrt 首次编译后,就可以回到 SDK top 路径下进行完整编译了,需要根据自己的板子配置选择对应的编译配置,这里参考 firefly ROC-RK3568-PC 需求,具体操作如下:

./build.sh roc-rk3568-pc-openwrt.mk
./build.sh uboot
./build.sh kernel
./build.sh openwrt
./build.sh all

安装顺序顺利完成以上操作后,基本上编译就算完成了。方便烧写可以进行固件打包,通常采用线刷固件,如下操作:

./build.sh firmware
./build.sh updateimg

完成后会产生 ROC-RK3568-PC-OPENWRT-GPT-{日期}-{时间}.img 在 rockdev/pack 路径下。这里就可以参考 RK3568 的烧写方式烧写固件了。

RK3568_EVB1_DDR4_V10 板子移植

基于 firefly 的 ROC-RK3568-PC 上的 openwrt 进行移植到 RK3568_EVB1_DDR4_V10 板子上,通过观察发现,ROC-RK3568-PC 这个板子本身是基于 RK3568_EVB1_DDR4_V10 进行开发的(通过比较两者的 dts 可以看到)。

kernel 部分的修改:

kernel/drivers/mmc 替换成RK原厂代码包里的 kernel/drivers/mmc
rk3568-evb.dtsi 中修改 &pmu_io_domains,将其中的 vccio4 和 vccio6 修改成 vcc_1v8 电压,eth1 网口需要 1.8V 供电才能启用,3.3V 会有问题

config 部分的修改:

参考 ROC-RK3568-PC 的配置文件进行修改,在 device/rockchip/rk356x 下创建自定义使用的配置文件 zmj-roc-rk3568-pc-openwrt.mk 内容如下:

#!/bin/bash

CMD=`realpath $BASH_SOURCE`
CUR_DIR=`dirname $CMD`

source $CUR_DIR/firefly-rk356x-openwrt.mk

# Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3568
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=station_linux_defconfig
# Kernel dts
export RK_KERNEL_DTS=rk3568-evb1-ddr4-v10-linux
# PRODUCT MODEL
export RK_PRODUCT_MODEL=ROC_RK3568_PC

# Openwrt version select
export RK_OPENWRT_VERSION_SELECT=openwrt
# Openwrt defconfig
export RK_OPENWRT_DEFCONFIG=rk356x_config

修改完成后,再次重新编译:

./build.sh zmj-roc-rk3568-pc-openwrt
./build.sh uboot
./build.sh kernel
./build.sh openwrt
./build.sh all
./build.sh firmware
./build.sh updateimg

完成后产生的新的固件 ZMJ-ROC-RK3568-PC-OPENWRT-GPT-20220727-1059.img 就可以正常烧写到 RK3568_EVB1_DDR4_V10 板子上并启用了。

eth0 作为 WAN 口

eth1 作为 LAN 口

路由器web界面默认IP 192.168.2.1,管理员账号 root 密码:firefly

网口打流结果

eth1 打流结果:

- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth
[ 4] 0.00-30.01 sec 336 MBytes 93.9 Mbits/sec sender
[ 4] 0.00-30.01 sec 336 MBytes 93.9 Mbits/sec receiver
[ 6] 0.00-30.01 sec 337 MBytes 94.2 Mbits/sec sender
[ 6] 0.00-30.01 sec 337 MBytes 94.2 Mbits/sec receiver
[ 8] 0.00-30.01 sec 336 MBytes 94.0 Mbits/sec sender
[ 8] 0.00-30.01 sec 336 MBytes 94.0 Mbits/sec receiver
[ 10] 0.00-30.01 sec 334 MBytes 93.5 Mbits/sec sender
[ 10] 0.00-30.01 sec 334 MBytes 93.5 Mbits/sec receiver
[ 12] 0.00-30.01 sec 334 MBytes 93.3 Mbits/sec sender
[ 12] 0.00-30.01 sec 334 MBytes 93.3 Mbits/sec receiver
[ 14] 0.00-30.01 sec 333 MBytes 93.1 Mbits/sec sender
[ 14] 0.00-30.01 sec 333 MBytes 93.1 Mbits/sec receiver
[ 16] 0.00-30.01 sec 332 MBytes 92.9 Mbits/sec sender
[ 16] 0.00-30.01 sec 332 MBytes 92.9 Mbits/sec receiver
[ 18] 0.00-30.01 sec 332 MBytes 92.7 Mbits/sec sender
[ 18] 0.00-30.01 sec 332 MBytes 92.7 Mbits/sec receiver
[ 20] 0.00-30.01 sec 330 MBytes 92.4 Mbits/sec sender
[ 20] 0.00-30.01 sec 330 MBytes 92.4 Mbits/sec receiver
[ 22] 0.00-30.01 sec 329 MBytes 92.0 Mbits/sec sender
[ 22] 0.00-30.01 sec 329 MBytes 92.0 Mbits/sec receiver
[SUM] 0.00-30.01 sec 3.26 GBytes 932 Mbits/sec sender
[SUM] 0.00-30.01 sec 3.26 GBytes 932

eth0 打流结果:

- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-30.00 sec 215 MBytes 60.1 Mbits/sec 738 sender
[ 5] 0.00-30.00 sec 214 MBytes 59.9 Mbits/sec receiver
[ 7] 0.00-30.00 sec 172 MBytes 48.0 Mbits/sec 665 sender
[ 7] 0.00-30.00 sec 171 MBytes 47.8 Mbits/sec receiver
[ 9] 0.00-30.00 sec 193 MBytes 54.1 Mbits/sec 658 sender
[ 9] 0.00-30.00 sec 193 MBytes 53.9 Mbits/sec receiver
[ 11] 0.00-30.00 sec 168 MBytes 46.9 Mbits/sec 702 sender
[ 11] 0.00-30.00 sec 167 MBytes 46.7 Mbits/sec receiver
[ 13] 0.00-30.00 sec 183 MBytes 51.2 Mbits/sec 673 sender
[ 13] 0.00-30.00 sec 182 MBytes 51.0 Mbits/sec receiver
[ 15] 0.00-30.00 sec 209 MBytes 58.6 Mbits/sec 624 sender
[ 15] 0.00-30.00 sec 208 MBytes 58.3 Mbits/sec receiver
[ 17] 0.00-30.00 sec 167 MBytes 46.8 Mbits/sec 705 sender
[ 17] 0.00-30.00 sec 167 MBytes 46.6 Mbits/sec receiver
[ 19] 0.00-30.00 sec 161 MBytes 45.1 Mbits/sec 752 sender
[ 19] 0.00-30.00 sec 161 MBytes 44.9 Mbits/sec receiver
[ 21] 0.00-30.00 sec 195 MBytes 54.4 Mbits/sec 696 sender
[ 21] 0.00-30.00 sec 194 MBytes 54.2 Mbits/sec receiver
[ 23] 0.00-30.00 sec 187 MBytes 52.4 Mbits/sec 692 sender
[ 23] 0.00-30.00 sec 187 MBytes 52.2 Mbits/sec receiver
[SUM] 0.00-30.00 sec 1.81 GBytes 517 Mbits/sec 6905 sender
[SUM] 0.00-30.00 sec 1.80 GBytes 515

移植过程问题及解决方式

kernel 启动到最后卡死并且不是崩溃,出错 log 如下:

[    2.049360] dhd_module_init: Exit err=0
[ 2.049694] ==gsl_ts_init==
[ 2.049752] ret=0
[ 2.050476] iommu: Adding device fde40000.npu to group 0
[ 2.050505] RKNPU fde40000.npu: Linked as a consumer to fde4b000.iommu
[ 2.050904] RKNPU fde40000.npu: RKNPU: rknpu iommu is enabled, using iommu mode
[ 2.051016] RKNPU fde40000.npu: Linked as a consumer to regulator.20
[ 2.051038] RKNPU fde40000.npu: can't request region for resource [mem 0xfde40000-0xfde4ffff]
[ 2.051420] [drm] Initialized rknpu 0.4.2 20210701 for fde40000.npu on minor 1
[ 2.051653] RKNPU fde40000.npu: leakage=4
[ 2.051693] RKNPU fde40000.npu: pvtm = 87940, from nvmem
[ 2.052097] RKNPU fde40000.npu: avs=0
[ 2.052641] RKNPU fde40000.npu: l=0 h=2147483647 hyst=5000 l_limit=0 h_limit=0 h_table=0
[ 2.052666] RKNPU fde40000.npu: failed to find power_model node
[ 2.052677] RKNPU fde40000.npu: RKNPU: failed to initialize power model
[ 2.052686] RKNPU fde40000.npu: RKNPU: failed to get dynamic-coefficient
[ 2.053641] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[ 2.056819] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[ 2.057368] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[ 2.057384] cfg80211: failed to load regulatory.db
[ 2.058083] rockchip-pm rockchip-suspend: not set pwm-regulator-config
[ 2.058659] I : [File] : drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c; [Line] : 417; [Func] : mali_module_init(); svn_rev_string_from_arm of this mali_ko is '', rk_ko_ver is '5', built at '07:15:52', on 'Jul 22 2022'.
[ 2.059010] Mali:
[ 2.059012] Mali device driver loaded
[ 2.059033] rkisp rkisp-vir0: clear unready subdev num: 4
[ 2.059045] rockchip-csi2-dphy0: No link between dphy and sensor
[ 2.059405] rockchip-csi2-dphy0: No link between dphy and sensor
[ 2.059418] rkisp-vir0: update sensor failed
v? 2.065622]

解决方式:

1、查找 kernel 卡死的位置,通过查看 log 打印的位置大致判断最后已经 init 的模块有 Mali 、 rkisp rkisp-vir0

2、查看当前编译的 kernel 的 System.map,这个文件中会存放编译的 kernel 的 init 模块顺序,通这个顺序能查看到当前卡死的 kernel 进程的大概位置

3、通过 grep 搜索对应的 init 函数,并在函数中添加 printk 打印,然后观察具体卡死的位置,一步步缩小范围即可。

通过上述方式,最终查找到卡死位置位于 __initcall_mdev_misc_init7s 这个初始化模块中,然后 grep 查找 mdev_misc 这个函数发现其位于一个二进制文件 mmc_blk_data 中,这里包含 firefly 关于 mmc 分区及初始化的相关操作,这里我们直接替换成原厂 RK3568 的代码即可。