rk3568 openwrt镜像打包过程

一、创建文件夹

# 创建必要文件夹
mkdir -p /home/openwrt/bin/targets/rockchip/armv8 
mkdir -p /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp

二、拷贝kernel

拷贝vmlinux

rm -f /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/firefly_station-p2-kernel.bin
cp /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/vmlinux \ /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/firefly_station-p2-kernel.bin

三、压缩文件系统

3.1 tar.gz

压缩文件系到 ~/bin/targets/rockchip/armv8/openwrt-rockchip-armv8-firefly_station-p2-rootfs.tar.gz

tar -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name --mtime="@1686251287" -C \ /home/openwrt/build_dir/target-aarch64_generic_musl/root-rockchip/ . | \
    gzip -9n > /home/openwrt/bin/targets/rockchip/armv8/openwrt-rockchip-armv8-firefly_station-p2-rootfs.tar.gz

3.2 cpio.gz

压缩文件系统 ~/bin/targets/rockchip/armv8/openwrt-rockchip-armv8-rootfs.cpio.gz

cd /home/openwrt/build_dir/target-aarch64_generic_musl/root-rockchip; 
find . | /home/openwrt/staging_dir/host/bin/cpio -o -H newc -R 0:0 | \
    gzip -9n >/home/openwrt/bin/targets/rockchip/armv8/openwrt-rockchip-armv8-rootfs.cpio.gz 

3.3 root.squashfs

压缩文件系 ~/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.squashfs

/home/openwrt/staging_dir/host/bin/mksquashfs4 \
    /home/openwrt/build_dir/target-aarch64_generic_musl/root-rockchip \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.squashfs  \
    -nopad -noappend -root-owned -comp xz  \
    -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2  \
    -b 1024k -p '/dev d 755 0 0' -p '/dev/console  c 600 0 0 5 1' -no-xattrs

3.4 root.ext4

压缩文件系统 ~/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.ext4

/home/openwrt/staging_dir/host/bin/make_ext4fs \
    -L rootfs -l 167772160 -b 4096 -m 0 -J -T 1686251287 \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.ext4 \
    /home/openwrt/build_dir/target-aarch64_generic_musl/root-rockchip/

四、打包镜像

openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot.img

4.1 判断kernel和fs在不在

-f /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/firefly_station-p2-kernel.bin \
-a -f /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.ext4

4.2 创建镜像相关文件夹

创建文件夹 openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot

m -fR /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot
mkdir -p /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot

4.3 拷贝dtb

rockchip.dtb

cp -fpR \ 
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/linux-5.15.112/arch/arm64/boot/dts/rockchip/rk3568-roc-pc.dtb \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot/rockchip.dtb

4.4 拷贝kerenl

kernel.img

cp -fpR \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/firefly_station-p2-kernel.bin \
        /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot/kernel.img

4.5 创建uboot引导kernel文件

boot.scr

命令将 nanopi-r5s.bootscript 文件转换成一个适合 U-Boot 使用的引导脚本镜像,并将生成的镜像保存为 boot.scr。这个引导脚本镜像可以被 U-Boot 引导加载程序加载和执行

mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
    -d nanopi-r5s.bootscript 
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot/boot.scr

4.6 生成镜像

生成一个包含内核和根文件系统的磁盘镜像 openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz

PADDING=1 /home/openwrt/scripts/gen_image_generic.sh  \
        /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz \
        32 \
        /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot \
        160 \
        /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.ext4 \
        32768

4.6.1 删除历史镜像

rm -f /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz

4.6.2 生成一个空镜像 带有一个32M和160M的分区

ptgen -o /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz \
    -h 16 -s 63 -p 32m -p 160m -l 32768

ptgen返回值:33554432 33554432 100663296 167772160

KERNELOFFSET=65536
KERNELSIZE=33554432
ROOTFSOFFSET=196608
ROOTFSSIZE=327680

4.6.3 清除rootfs位置空间

dd if=/dev/zero \
    of=/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz \
    bs=512 seek=196608 conv=notrunc count=327680

4.6.4 写入rootfs

dd if=/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/root.ext4 \
        of=/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz \
        bs=512 seek=196608 conv=notrunc

4.6.5 创建kernnel镜像

fs type: ext4
in: openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot
out: openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.kernel

make_ext4fs \
    -J -L kernel -l 33554432 -T 1686251287 \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.kernel \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.boot

4.6.6 写入kernel

dd \
    if=/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.kernel \
    of=/home/openwrt/build_dir/target-aarch 64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz \
    bs=512 seek=65536 conv=notrunc

4.6.7 删除kernel 镜像

rm -f /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.kernel

4.6.8 添加idbloader.img

dd \
    if="/home/openwrt/staging_dir/target-aarch64_generic_musl/image"/station-p2-rk3568-idbloader.img \
    of="/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz" \
    seek=64 conv=notrunc

4.6.9 添加uboot.itb

dd \
    if="/home/openwrt/staging_dir/target-aarch64_generic_musl/image"/station-p2-rk3568-u-boot.itb \
    of="/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz" \
    seek=16384 conv=notrunc

4.6.10 压缩gz包

in: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz
out: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.new

/home/openwrt/staging_dir/host/bin/gzip \
    -f -9n \
    -c /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz  > \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.new

五、打包squash.fs文件系统类型

步骤同上

out: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-squashfs-sysupgrade.img.gz.new

六、收尾

6.1 添加镜像信息

附加到镜像末尾

echo '{  "metadata_version": "1.1", "compat_version": "1.0",   "supported_devices":["firefly,station-p2"], "version": { "dist": "OpenWrt", "version": "SNAPSHOT", "revision": "r0+6025-b65b15a30", "target": "rockchip/armv8", "board": "firefly_station-p2" } }' | fwtool -I - /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz

6.2 生成sha256文件

sha256sum "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz" | cut -d" " -f1 > "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.sha256sum

6.3 添加签名证书

6.3.1 判断相关文件是否存在

! -s "/home/openwrt/key-build" -o  \
! -s "/home/openwrt/key-build.ucert" -o \
! -s "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz"

三个条件同时不能为空

6.3.2 拷贝签名证书处理工具

out: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.ucert

cp "/home/openwrt/key-build.ucert" \
    "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.ucert"

6.3.3 签名

out: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.sig

usign -S \
    -m "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz" \
    -s "/home/openwrt/key-build" \
    -x "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.sig" 

6.3.4 追加ucert工具签名

out: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.sig

ucert -A \
    -c "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.ucert" \
    -x "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.sig"

6.3.5 追加签名证书到镜像

out: build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz

fwtool \
    -S "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.ucert" \
    "/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz"

6.4 拷贝生成的镜到bin/targets/rockchip/armv8

cp \
    /home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz \
    /home/openwrt/bin/targets/rockchip/armv8/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz

6.5 生成信息json

DEVICE_ID="firefly_station-p2" SOURCE_DATE_EPOCH=1686251287 FILE_NAME="openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz" FILE_DIR="/home/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/tmp" FILE_TYPE=sysupgrade FILE_FILESYSTEM="ext4" DEVICE_IMG_PREFIX="openwrt-rockchip-armv8-firefly_station-p2" DEVICE_VENDOR="Firefly" DEVICE_MODEL="Station P2" DEVICE_VARIANT="" DEVICE_ALT0_VENDOR="" DEVICE_ALT0_MODEL="" DEVICE_ALT0_VARIANT="" DEVICE_ALT1_VENDOR="" DEVICE_ALT1_MODEL="" DEVICE_ALT1_VARIANT="" DEVICE_ALT2_VENDOR="" DEVICE_ALT2_MODEL="" DEVICE_ALT2_VARIANT="" DEVICE_ALT3_VENDOR="" DEVICE_ALT3_MODEL="" DEVICE_ALT3_VARIANT="" DEVICE_ALT4_VENDOR="" DEVICE_ALT4_MODEL="" DEVICE_ALT4_VARIANT="" DEVICE_TITLE="Firefly Station P2" DEVICE_PACKAGES="kmod-brcmfmac kmod-ikconfig kmod-ata-ahci-platform station-p2-firmware wpad-openssl iwinfo" TARGET="rockchip" SUBTARGET="armv8" VERSION_NUMBER="SNAPSHOT" VERSION_CODE="r0+6025-b65b15a30" SUPPORTED_DEVICES="firefly,station-p2" \
/home/openwrt/scripts/json_add_image_info.py \
    /home/openwrt/build_dir/target-aarch64_generic_musl/json_info_files/openwrt-rockchip-armv8-firefly_station-p2-ext4-sysupgrade.img.gz.json

6.6 squashfs同理

步骤同上

七、以上步骤执行脚本

镜像生成:
target/linux/rockchip/image/Makefile

  • 16
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值