ok1028移植openwrt系统
背景
前段时间接到一个工作,是要在OK1028A-C的开发板上移植一下OpenWRT系统,在之前的OpenWRT版本是,原本是不支持LS1028的SOC的,不过在最新的版本上增加了支持。
其实LSxx系列的开发板,像是LS1012,1043,1046很早之前就支持了OpenWRT系统,不过的处理方式也简单很多,使用OpenWRT源码编译完成之后,只要它编译出来的内核设备树以及文件系统,像是U-boot以及引导方面的固件还是使用发布资料中的LSDK的镜像来实现。关于这部分的内容,博客中之前的博文也有很多提到了,可以参考了解一下:https://resona.top/tags/OpenWRT/
原本这次的工作也是按照这个方法来做的,这样的实现起来简单很多。但是资料交付给客户之后,客户说他必须需要OpenWRT系统中的使用网页界面升级的功能,这一下就难搞很多了呀。
这样就必须要按照OpenWRT的原生镜像的格式来制作,烧写到板子上的系统的结构也需要和OpenWRT的原生的结构保持一致才行。
前期的探索尝试
刚开始的时候,先是在GitHub上拉取了最新的OpenWRT源码,并切换到了最新的tag
git clone https://github.com/openwrt/openwrt.git
cd openwrt
git tag
git checkout v23.05.0-rc3
然后就是使用make menuconfig看了一下OpenWRT系统原生支持的LS1028的板卡类型
make menuconfig
可以看到以下内容
可以看到,官方原生支持了两种配置,一种是NXP LS1028A-RDB Default
,这种是用于qspi启动的。一种是NXP LS1028A-RDB SD Card Boot
,这种是基于SD卡启动的。既然我们要试配的OK1028A-C开发板是emmc启动的,那么我们就基于NXP LS1028A-RDB SD Card Boot
来做就可以。
首先是使用openwrt的预编译镜像做了一张TF系统卡,先试试起官方的系统是什么效果,预编译镜像的链接为https://downloads.openwrt.org/snapshots/targets/layerscape/armv8_64b/
结果遗憾的是使用balenaEtcher将TF系统卡做好之后,插到板子上根本起不来,心跳灯一直在一秒隔间的闪烁,串口打印信息一点也没有。这种情况一般就是bl2的镜像都有问题,不适用于OK1028A-C的配置,因为灯都有反应了,说明TF卡里面是有东西的,只是核心板一直在不断的复位。
不过幸运的的是我们这里有一个LS1028 的evk板,也就是OpenWRT menuconfig配置中所写的NXP LS1028A-RDB
,然后我重新制作了一张SD卡,插到evk板上试了一下,这个时候需要注意要拆开evk的大铁盒,按照LSDKUG中的说明将拨码开关拨到SD Card启动的位置
实际中拨码如下:
之后上电之后,板子可以正常启动了,成功的进入到了OpenWRT的系统中,串口打印也是正常的信息,然后我也尝试了一下客户需要的网页界面升级的功能也可以的,这个说明本身的镜像是没有问题的。
所以接下来的工作还是要想办法去让OpenWRT源码去适配OK1028A-C的板子。
解决U-boot启动的问题
如果去修改OpenWRT源码的话,那就需要找到bl2固件相关的源码位置,包括RCW,以及ATF部分的东西,还有U-boot源码也需要修改适配。为了快速的解决问题,我还是想先尝试一下使用现有的LSDK中的镜像来拼凑出一个可用的镜像。包括烧写时使用的fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img
,以及网页界面升级时使用的fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin
。
首先是先看一下fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img
的结构吧,毕竟整个镜像是使用dd的方法写入到SD卡中去的,那么我们可以直接使用fdisk来看一下它:
我们可以再看一下在evk板子上使用的SD卡的信息
甚至可以看一下windows里面的磁盘管理的信息
其实这样一看就比较明了了
存放U-boot | 存放fitImage | 未分配 | 存放文件系统 | 未分配 |
---|---|---|---|---|
ext4 | ext4 | |||
16M | 40M | 8M | 104M | 14.32GB |
mmc0blkp1 | mmc0blkp2 |
然后通过在U-boot命令行我们可以看到,mmc的第一个分区中存放了一个fitImage,然后结合printenv的信息
我们可以知道这个fitImage应该就是内核和设备树的文件,而文件系统放在了mmc的第二个分区中
但是我们却无法看到mmc的第二个分区中的内容
那这个先放一边,反正我们可以先基于它现有的这个fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img
镜像直接dd出一个我们可以使用的镜像
根据之前的工作经验以及LSDKUG文档,我们知道emmc的前面16M的空间内存放着的内容如下:
所以我们就将LSDK中的固件直接覆盖进去,首先是做一个TF启动卡
烧写整个的镜像
sudo dd if=openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img of=/dev/sdb bs=512
烧写bl2
sudo dd if=bl2_sd.pbl of=/dev/sdb bs=1K seek=4
烧写U-boot
sudo dd if=fip_uboot.bin of=/dev/sdb bs=1K seek=1024
烧写dp固件(可不需要)
sudo dd if=ls1028a-dp-fw.bin of=/dev/sdb bs=1K seek=9472
用上面方法做出来的TF卡插到OK1028A-C的底板上,拨码开关拨到TF卡启动,上电之后就可以正常启动了(目前也就是可以启动到加载内核就卡死了,不过现阶段就够了)。
验证了方法可行之后,我们可以进一步,使用ramdisk将镜像烧写到OK1028-C的emmc之中
我们可以在U-boot命令行中先修改启动的环境变量以适配从emmc启动,保存后进入ramdisk系统,并将U-boot环境变量提取到文件中
提取1028 emmc中的U-boot环境变量
setenv loadaddr '0x84000000'
setenv sd_boot 'ext4load mmc 1:1 $loadaddr fitImage;bootm $loadaddr'
dd if=/dev/mmcblk1 of=boot_env bs=1K skip=5120 count=1024
在ramdisk中烧写openwrt镜像到emmc(位置偏移可以参考LSDKUG_Rev21.08.pdf P181 《LSDK memory layout and Userland》)
dd if=openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img of=/dev/mmcblk1
dd if=bl2_emmc.pbl of=/dev/mmcblk1 bs=1K seek=4
dd if=fip_uboot.bin of=/dev/mmcblk1 bs=1K seek=1024
dd if=boot_env of=/dev/mmcblk1 bs=1K seek=5120 count=1024
操作完成之后,将OK1028A-C的拨码开关拨到emmc启动,重启开发板,即可发现可以正常启动了(也是启动到加载内核就卡住了)。
解决内核启动的问题
在解决了第一阶段的启动之后,我们尝试着去解决启动到加载内核就卡住的问题,首先是找到fitImage的制作方法,位置在以下地方
openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/fsl_ls1028a-rdb-sdboot-kernel.bin.its
通过查看文件可以看到
images {
kernel-1 {
...
load = <0x80000000>;
entry = <0x80000000>;
...
}
}
默认的内核加载位置为0x80000000
使用的内核文件以及设备树文件我们也可以找到:
内核:
openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/linux-5.15.127/arch/arm64/boot/Image
设备树:
openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/linux-5.15.127/arch/arm64/boot/dts/freescale/fsl-ls1028a-rdb.dtb
然后我们尝试按照LSDK启动方式单独使用内核设备树镜像启动,在U-boot命令行输入以下内容
usb start
load usb 0:1 0x81000000 /test/Image
load usb 0:1 0x90000000 /test/fsl-ls1028a-rdb.dtb
booti 0x81000000 - 0x90000000
发现无问题,可以加载内核启动
可以看到LSDK的启动地址是内核在0x81000000位置上,所以我们将内核的加载和启动地址改为0x81000000
images {
kernel-1 {
...
load = <0x81000000>;
entry = <0x81000000>;
...
}
}
然后使用以下命令生成fitImage镜像
mkimage -f fsl_ls1028a-rdb-sdboot-kernel.bin.its ./fitImage
实测使用此fitImage可以解决问题,但是原因未知,等后续有机会再排查这个问题吧。
解决了以上两个问题之后,我们就可以顺利的进入到OpenWRT的文件系统中了,同时也可以验证一下网页页面升级的功能,这个时候还是使用的OpenWRT官方预编译好的sysupgrade.bin镜像,升级完之后就发现无法启动了(因为fitImage被修改成官方的镜像了),说明功能是可用的,但是文件系统却没有变化,原因是因为网页页面升级是调用的/sbin/sysupgrade命令来实现的,我们可以vim打开看一下,发现最终在/lib/upgrade/platform.sh文件里面,会有以下内容:
platform_do_upgrade_sdboot() {
local diskdev partdev parttype=ext4
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
if export_partdevice partdev 1; then
mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 2>&1
echo "Writing kernel..."
tar xf $tar_file ${board_dir}/kernel -O > /mnt/fitImage
umount /mnt
fi
echo "Erasing rootfs..."
dd if=/dev/zero of=/dev/mmcblk1p2 bs=1M > /dev/null 2>&1
echo "Writing rootfs..."
tar xf $tar_file ${board_dir}/root -O | dd of=/dev/mmcblk1p2 bs=512k > /dev/null 2>&1
}
注意这里是烧写镜像的操作,默认是烧写到/dev/mmcblk0p2中,也就是TF卡的位置,这里我们需要改成/dev/mmcblk1p2,以将系统烧写到mmc中。
改完之后再次测试,发现网页页面升级的功能就可以了。
编写自动构建镜像脚本
当上面的操作完成之后,我们现在可以手动去将OpenWRT的镜像烧写到OK1028A-C中了,也可以实现我们想要的功能,但是我们不能每次都去手动dd这样去烧写板子,而且sysupgrade.bin镜像也没用构建成我们想要的样子。所以接下来,我们就需要写一个脚本,来从OpenWRT工程中提取我们需要的镜像,并自动做成烧写镜像以及升级镜像。
在编译OpenWRT源码时,我们可以使用make V=s -j1来查看详细的编译过程,下面是我们可以看到的烧写镜像的合成时的关键信息:
[ -f /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/fsl_ls1028a-rdb-sdboot-kernel.bin -a -f /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/root.squashfs ]
rm -f /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
./gen_sdcard_head_img.sh /home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-sdcard-head.img 16 40 64 512
+ [ 5 -eq 5 ]
+ OUTPUT=/home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-sdcard-head.img
+ KERNELOFFSET=16384
+ KERNELSIZE=40
+ ROOTFSOFFSET=65536
+ ROOTFSSIZE=512
+ head=4
+ sect=63
+ ptgen -o /home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-sdcard-head.img -h 4 -s 63 -t 83 -p 40M@16384 -p 512M@65536
part 16384 40960
part 65536 524288
+ set 16777216 42057728 67108864 536981504
dd if=/home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-sdcard-head.img >> /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
1+0 records in
1+0 records out
512 bytes copied, 0.000363927 s, 1.4 MB/s
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz of=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new bs=4K conv=sync
0+1 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 9.7499e-05 s, 42.0 MB/s
mv /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
dd if=/home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-bl2.pbl >> /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
154+1 records in
154+1 records out
78921 bytes (79 kB, 77 KiB) copied, 0.000494415 s, 160 MB/s
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz of=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new bs=1M conv=sync
0+1 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0013785 s, 761 MB/s
mv /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
dd if=/home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-fip.bin >> /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
1663+1 records in
1663+1 records out
851773 bytes (852 kB, 832 KiB) copied, 0.00290891 s, 293 MB/s
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz of=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new bs=5M conv=sync
0+1 records in
1+0 records out
5242880 bytes (5.2 MB, 5.0 MiB) copied, 0.0101531 s, 516 MB/s
mv /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
dd if=/home/zyh/workspace/OpenWRT/openwrt/staging_dir/target-aarch64_generic_musl/image/fsl_ls1028a-rdb-sdboot-uboot-env.bin >> /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
16+0 records in
16+0 records out
8192 bytes (8.2 kB, 8.0 KiB) copied, 0.000215152 s, 38.1 MB/s
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz of=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new bs=16M conv=sync
0+1 records in
1+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0.0226388 s, 741 MB/s
mv /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
mkdir -p /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.tmp && cp /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/fsl_ls1028a-rdb-sdboot-kernel.bin /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.tmp/fitImage && make_ext4fs -J -L kernel -l "40M" -T 1692453666 "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.kernel.part" "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.tmp" && dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.kernel.part >> /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz && rm -rf /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.tmp && rm -f /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.kernel.part
Creating filesystem with parameters:
Size: 41943040
Block size: 4096
Blocks per group: 32768
Inodes per group: 2560
Inode size: 256
Journal blocks: 0
Label: kernel
Blocks: 10240
Block groups: 1
Reserved blocks: 0
Reserved block group size: 7
Created filesystem with 12/2560 inodes and 2018/10240 blocks
81920+0 records in
81920+0 records out
41943040 bytes (42 MB, 40 MiB) copied, 0.160418 s, 261 MB/s
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz of=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new bs=64M conv=sync
0+1 records in
1+0 records out
67108864 bytes (67 MB, 64 MiB) copied, 0.0967873 s, 693 MB/s
mv /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/root.squashfs >> /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
205232+1 records in
205232+1 records out
105079295 bytes (105 MB, 100 MiB) copied, 0.370964 s, 283 MB/s
dd if=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz of=/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new bs=576M conv=sync
0+1 records in
1+0 records out
603979776 bytes (604 MB, 576 MiB) copied, 0.838288 s, 720 MB/s
mv /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
/home/zyh/workspace/OpenWRT/openwrt/staging_dir/host/bin/gzip -f -9n -c /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz > /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz.new
cp /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz /home/zyh/workspace/OpenWRT/openwrt/bin/targets/layerscape/armv8_64b/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sdcard.img.gz
以及sysupgrade.bin系统升级镜像的关键信息:
squashfs格式文件系统生成命令
/home/zyh/workspace/OpenWRT/openwrt/staging_dir/host/bin/mksquashfs4 /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/root-layerscape /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/root.squashfs -nopad -noappend -root-owned -comp gzip -b 256k -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1' -no-xattrs
sysupgrade.bin镜像文件生成命令
sh /home/zyh/workspace/OpenWRT/openwrt/scripts/sysupgrade-tar.sh --board fsl_ls1028a-rdb-sdboot --kernel /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/fsl_ls1028a-rdb-sdboot-kernel.bin --rootfs /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/root.squashfs /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin
echo '{ "metadata_version": "1.1", "compat_version": "1.0", "supported_devices":["fsl,ls1028a-rdb-sdboot"], "version": { "dist": "OpenWrt", "version": "23.05.0-rc3", "revision": "r23389-5deed175a5", "target": "layerscape/armv8_64b", "board": "fsl_ls1028a-rdb-sdboot" } }' | fwtool -I - /home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin
sha256sum "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin" | cut -d" " -f1 > "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin.sha256sum"
[ ! -s "/home/zyh/workspace/OpenWRT/openwrt/key-build" -o ! -s "/home/zyh/workspace/OpenWRT/openwrt/key-build.ucert" -o ! -s "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin" ] || { cp "/home/zyh/workspace/OpenWRT/openwrt/key-build.ucert" "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin.ucert" ; usign -S -m "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin" -s "/home/zyh/workspace/OpenWRT/openwrt/key-build" -x "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin.sig" ; ucert -A -c "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin.ucert" -x "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin.sig" ; fwtool -S "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin.ucert" "/home/zyh/workspace/OpenWRT/openwrt/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/tmp/openwrt-layerscape-armv8_64b-fsl_ls1028a-rdb-sdboot-squashfs-sysupgrade.bin" ; }
由此我们可以总结出squashfs镜像的生成方法,脚本squashfs_build.sh为:
#!/bin/bash
mk_squashfs() {
tar xvf $FORLINX_PREBUILD/etc_1028.tar.bz2 -C $OPWNERT_ORI/build_dir/target-aarch64_generic_musl/root-layerscape/
cp $FORLINX_PREBUILD/platform.sh $OPWNERT_ORI/build_dir/target-aarch64_generic_musl/root-layerscape/lib/upgrade/platform.sh
cd $OPWNERT_ORI/build_dir/target-aarch64_generic_musl/root-layerscape/root/
cp $FORLINX_APP/spidev_test/fltest_spidev_test ./
cp $FORLINX_APP/uarttest/fltest_uarttest ./
cp $FORLINX_APP/watchdog/fltest_watchdog ./
cp $FORLINX_APP/watchdogrestart/fltest_watchdogrestart ./
cd -
$FORLINX_DIR/tools/mksquashfs4 $OPWNERT_ORI/build_dir/target-aarch64_generic_musl/root-layerscape/ root.squashfs -nopad -noappend -root-owned -comp gzip -b 256k -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1' -no-xattrs
}
clean_squashfs() {
rm -rf root.squashfs
}
case "$1" in
build)
mk_squashfs;
;;
clean)
clean_squashfs;
;;
esac
fitImage镜像的生成方法,脚本forlinx_fitImage_build.sh为:
#!/bin/bash
mk_fitImage() {
cp $OPWNERT_ORI/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/linux-5.15.127/arch/arm64/boot/Image ./ && gzip Image
cp $OPWNERT_ORI/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/linux-5.15.127/arch/arm64/boot/dts/freescale/OK1028A-C.dtb ./
mkimage -f forlinx_fitImage.its ./fitImage
mkdir -p fitImage-sdcard.tmp && cp fitImage fitImage-sdcard.tmp
make_ext4fs -J -L kernel -l "40M" -T 1692453666 fitImage-sdcard.part fitImage-sdcard.tmp
}
clean_fitImage() {
rm -rf Image fitImage Image.gz OK1028A-C.dtb fitImage-sdcard.tmp fitImage-sdcard.part
}
case "$1" in
build)
mk_fitImage;
;;
clean)
clean_fitImage;
;;
esac
U盘烧写镜像,以及网页页面升级镜像sysupgrade.bin的生成以及认证方法为:
#!/bin/bash
case "$1" in
clean)
rm -rf OK1028A-C-emmcboots-quashfs-sysupgrade.bin OK1028A-C-emmcboot.img OK1028A-C-emmcboot-quashfs-sysupgrade.bin
cd fitImage_build_dir && ./forlinx_fitImage_build.sh clean && cd -
cd squashfs_build_dir && ./squashfs_build.sh clean && cd -
exit 0
esac
source env.sh
cd $FORLINX_DIR
cd fitImage_build_dir && ./forlinx_fitImage_build.sh build && cd -
cd squashfs_build_dir && ./squashfs_build.sh build && cd -
./tools/gen_sdcard_head_img.sh OK1028A-C-emmcboot.head.img 16 40 64 512
dd if=OK1028A-C-emmcboot.head.img >> OK1028A-C-emmcboot.img
dd if=OK1028A-C-emmcboot.img of=OK1028A-C-emmcboot.img.new bs=4K conv=sync
mv OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot.img
dd if=$FORLINX_PREBUILD/bl2_emmc.pbl >> OK1028A-C-emmcboot.img
dd if=OK1028A-C-emmcboot.img of=OK1028A-C-emmcboot.img.new bs=1M conv=sync
mv OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot.img
dd if=$FORLINX_PREBUILD/fip_uboot.bin >> OK1028A-C-emmcboot.img
dd if=OK1028A-C-emmcboot.img of=OK1028A-C-emmcboot.img.new bs=5M conv=sync
mv OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot.img
dd if=$FORLINX_PREBUILD/boot_env >> OK1028A-C-emmcboot.img
dd if=OK1028A-C-emmcboot.img of=OK1028A-C-emmcboot.img.new bs=16M conv=sync
mv OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot.img
dd if=./fitImage_build_dir/fitImage-sdcard.part >> OK1028A-C-emmcboot.img
dd if=OK1028A-C-emmcboot.img of=OK1028A-C-emmcboot.img.new bs=64M conv=sync
mv OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot.img
dd if=./squashfs_build_dir/root.squashfs >> OK1028A-C-emmcboot.img
dd if=OK1028A-C-emmcboot.img of=OK1028A-C-emmcboot.img.new bs=576M conv=sync
mv OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot.img
./tools/sysupgrade-tar.sh --board fsl_ls1028a-rdb-sdboot --kernel ./fitImage_build_dir/fitImage --rootfs ./squashfs_build_dir/root.squashfs OK1028A-C-emmcboot-quashfs-sysupgrade.bin
echo '{ "metadata_version": "1.1", "compat_version": "1.0", "supported_devices":["fsl,ls1028a-rdb-sdboot"], "version": { "dist": "OpenWrt", "version": "23.05.0-rc3", "revision": "r23389-5deed175a5", "target": "layerscape/armv8_64b", "board": "fsl_ls1028a-rdb-sdboot" } }' | ./tools/fwtool -I - OK1028A-C-emmcboot-quashfs-sysupgrade.bin
cp $OPWNERT_ORI/key-build.ucert OK1028A-C-emmcboot-quashfs-sysupgrade.bin.ucert
./tools/usign -S -m "OK1028A-C-emmcboot-quashfs-sysupgrade.bin" -s "$OPWNERT_ORI/key-build" -x "OK1028A-C-emmcboot-quashfs-sysupgrade.bin.sig"
./tools/ucert -A -c "OK1028A-C-emmcboot-quashfs-sysupgrade.bin.ucert" -x "OK1028A-C-emmcboot-quashfs-sysupgrade.bin.sig"
./tools/fwtool -S "OK1028A-C-emmcboot-quashfs-sysupgrade.bin.ucert" "OK1028A-C-emmcboot-quashfs-sysupgrade.bin"
rm -rf OK1028A-C-emmcboot.head.img OK1028A-C-emmcboot.img.new OK1028A-C-emmcboot-quashfs-sysupgrade.bin.ucert OK1028A-C-emmcboot-quashfs-sysupgrade.bin.sig