diff --git a/package/third-party/swupdate/swupdate.config b/package/third-party/swupdate/swupdate.config index a6b7a7494..e7d633ad7 100644 --- a/package/third-party/swupdate/swupdate.config +++ b/package/third-party/swupdate/swupdate.config @@ -107,7 +107,7 @@ CONFIG_PARSERROOT="" # CONFIG_DISKPART is not set CONFIG_RAW=y # CONFIG_RDIFFHANDLER is not set -# CONFIG_SHELLSCRIPTHANDLER is not set +CONFIG_SHELLSCRIPTHANDLER=y # # archive support needs libarchive diff --git a/target/d211/common/Recovery.gz b/target/d211/common/Recovery.gz index f863ee863..51277ff7a 100644 Binary files a/target/d211/common/Recovery.gz and b/target/d211/common/Recovery.gz differ diff --git a/target/d211/common/post-image.sh b/target/d211/common/post-image.sh index 89e55beac..be5e5e880 100755 --- a/target/d211/common/post-image.sh +++ b/target/d211/common/post-image.sh @@ -266,6 +266,13 @@ function swupdate_pack_swu() mk_info "Pack swu ..." + # 生成 data 增量更新包(tar.gz),替代全量 ubifs 写入 + local DATA_DIR="${TARGET_BOARD_DIR}/data" + if [ -d "$DATA_DIR" ]; then + mk_info "Generating data_update.tar.gz ..." + tar -czf "${BINARIES_DIR}/data_update.tar.gz" -C "$DATA_DIR" . + fi + . $SWU_IMAGES cp "$SWU_IMAGES" "$SWU_DIR" diff --git a/target/d211/demo128_nand/rootfs_overlay/etc/ota_build_id b/target/d211/demo128_nand/rootfs_overlay/etc/ota_build_id index 0e8962666..fb8c9c238 100644 --- a/target/d211/demo128_nand/rootfs_overlay/etc/ota_build_id +++ b/target/d211/demo128_nand/rootfs_overlay/etc/ota_build_id @@ -1 +1 @@ -demo128_nand-ota-marker=2026-04-27_v1001 +demo128_nand-ota-marker=2026-06-03_v1003 diff --git a/target/d211/demo128_nand/swupdate/sw-description b/target/d211/demo128_nand/swupdate/sw-description index 2fdff2ba9..e6516c40d 100644 --- a/target/d211/demo128_nand/swupdate/sw-description +++ b/target/d211/demo128_nand/swupdate/sw-description @@ -104,10 +104,18 @@ software = sha256 = "@system"; }, { - filename = "data"; - volume = "data"; - installed-directly = true; - sha256 = "@data"; + filename = "data_update.tar.gz"; + type = "rawfile"; + path = "/tmp/data_update.tar.gz"; + sha256 = "@data_update.tar.gz"; + } + ); + + scripts: ( + { + filename = "update_data.sh"; + type = "shellscript"; + sha256 = "@update_data.sh"; } ); diff --git a/target/d211/demo128_nand/swupdate/sw-images.cfg b/target/d211/demo128_nand/swupdate/sw-images.cfg index b727e0752..98fd6faa8 100644 --- a/target/d211/demo128_nand/swupdate/sw-images.cfg +++ b/target/d211/demo128_nand/swupdate/sw-images.cfg @@ -5,7 +5,8 @@ ${BINARIES_DIR}/kernel.itb:kernel ${BINARIES_DIR}/logo.itb:logo ${BINARIES_DIR}/rootfs_page_2k_block_128k.ubifs:rootfs ${BINARIES_DIR}/system_page_2k_block_128k.ubifs:system -${BINARIES_DIR}/data_page_2k_block_128k.ubifs:data +${BINARIES_DIR}/data_update.tar.gz:data_update.tar.gz +${TARGET_BOARD_DIR}/swupdate/update_data.sh:update_data.sh #${BINARIES_DIR}/rootfs_page_4k_block_256k.ubifs:rootfs #${BINARIES_DIR}/system_page_4k_block_256k.ubifs:system #${BINARIES_DIR}/data_page_4k_block_256k.ubifs:data diff --git a/target/d211/demo128_nand/swupdate/update_data.sh b/target/d211/demo128_nand/swupdate/update_data.sh new file mode 100644 index 000000000..a2d087f76 --- /dev/null +++ b/target/d211/demo128_nand/swupdate/update_data.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# 增量更新 /data 分区 +# swupdate 已将 data_update.tar.gz 写到 /tmp/data_update.tar.gz + +# 只在 postinst 阶段执行(此时 rawfile 已经复制完成) +if [ "$1" = "preinst" ]; then + echo "[update_data] preinst: skip" + exit 0 +fi + +TAR="/tmp/data_update.tar.gz" +SRC="/tmp/data_update_src" +DST="/mnt/data_update" + +if [ ! -f "$TAR" ]; then + echo "[update_data] ERROR: $TAR not found" + exit 1 +fi + +# 挂载 data 分区到临时挂载点 +mkdir -p "$DST" +if ! mount -t ubifs ubi2:data "$DST"; then + echo "[update_data] ERROR: failed to mount ubi2:data" + exit 1 +fi +echo "[update_data] mounted ubi2:data on $DST" + +# 解压到临时目录 +mkdir -p "$SRC" +tar -xzf "$TAR" -C "$SRC" + +# 遍历升级包中的所有文件,只覆盖不一样的 +find "$SRC" -type f | while read src_file; do + rel_path="${src_file#$SRC/}" + dst_file="$DST/$rel_path" + + # 目标目录不存在则创建 + dst_dir=$(dirname "$dst_file") + [ -d "$dst_dir" ] || mkdir -p "$dst_dir" + + if [ -f "$dst_file" ]; then + src_md5=$(md5sum "$src_file" | cut -d' ' -f1) + dst_md5=$(md5sum "$dst_file" | cut -d' ' -f1) + if [ "$src_md5" = "$dst_md5" ]; then + echo "[update_data] unchanged: $rel_path" + continue + fi + fi + + cp "$src_file" "$dst_file" + echo "[update_data] updated: $rel_path" +done + +# 清理临时文件 +rm -rf "$SRC" "$TAR" + +# 卸载 data 分区 +sync +umount "$DST" +echo "[update_data] unmounted $DST" + +echo "[update_data] done" +exit 0