Increment ota

This commit is contained in:
zzh 2026-06-03 18:09:21 +08:00
parent 26d1df1466
commit 12888c8abf
7 changed files with 86 additions and 7 deletions

View File

@ -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

Binary file not shown.

View File

@ -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"

View File

@ -1 +1 @@
demo128_nand-ota-marker=2026-04-27_v1001
demo128_nand-ota-marker=2026-06-03_v1003

View File

@ -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";
}
);

View File

@ -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

View File

@ -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