Simplify and align sysupgrade structure

This commit is contained in:
jav4 authored and GitHub committed 2026-04-03 17:45:39 +02:00
1 parent e255c1975a
commit 9e10c2e371
1 file changed
+14 -41
+14 -41
View File
@@ -1,43 +1,21 @@
#!/bin/sh
# MSM8916 eMMC sysupgrade - kernel (Android boot image) + rootfs (squashfs)
#
# The sysupgrade bundle is a tar containing:
# boot - Android boot image for the kernel
# rootfs - squashfs root filesystem
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
platform_check_image() {
local tar_file="$1"
local member
local fw_image="$1"
local boardname="$(board_name | tr -d '-' | tr ',' '-')"
# Must be a tar archive
if ! tar -tf "$tar_file" > /tmp/sysupgrade-members 2>/dev/null; then
echo "sysupgrade: not a valid tar archive"
return 1
fi
local control_len=$( (tar xf $fw_image sysupgrade-$boardname/CONTROL -O | wc -c) 2> /dev/null)
# Must contain both 'boot' and 'rootfs' members
if ! grep -q '^boot$' /tmp/sysupgrade-members; then
echo "sysupgrade: missing 'boot' member in image"
# check if valid sysupgrade tar archive
if [ "$control_len" = "0" ]; then
echo "Invalid sysupgrade file: $fw_image"
return 1
fi
if ! grep -q '^rootfs$' /tmp/sysupgrade-members; then
echo "sysupgrade: missing 'rootfs' member in image"
return 1
fi
# Validate squashfs magic in the rootfs member
local magic
magic=$(tar -xOf "$tar_file" rootfs 2>/dev/null | dd bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/4 "%08x"')
case "$magic" in
73717368)
;;
*)
echo "sysupgrade: rootfs member does not look like squashfs (magic: $magic)"
return 1
;;
esac
return 0
}
@@ -45,26 +23,22 @@ platform_check_image() {
platform_do_upgrade() {
local tar_file="$1"
local boot_part rootfs_part
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
# Locate partitions by GPT label
boot_part=$(find_mmc_part "boot")
rootfs_part=$(find_mmc_part "rootfs")
if [ -z "$boot_part" ]; then
echo "sysupgrade: cannot find 'boot' partition"
return 1
fi
if [ -z "$rootfs_part" ]; then
echo "sysupgrade: cannot find 'rootfs' partition"
return 1
fi
[ -z "$boot_part" ] && { echo "sysupgrade: cannot find 'boot' partition"; return 1; }
[ -z "$rootfs_part" ] && { echo "sysupgrade: cannot find 'rootfs' partition"; return 1; }
echo "sysupgrade: writing kernel to $boot_part"
tar -xOf "$tar_file" boot 2>/dev/null | \
tar -xOf "$tar_file" ${board_dir}/kernel 2>/dev/null | \
dd of="$boot_part" bs=4096 conv=fsync
echo "sysupgrade: writing rootfs to $rootfs_part"
tar -xOf "$tar_file" rootfs 2>/dev/null | \
tar -xOf "$tar_file" ${board_dir}/root 2>/dev/null | \
dd of="$rootfs_part" bs=4096 conv=fsync
sync
@@ -82,8 +56,7 @@ platform_copy_config() {
return 0
}
mkdir -p "$mnt/.overlay"
cp -af "$UPGRADE_BACKUP" "$mnt/.overlay/sysupgrade.tgz" 2>/dev/null
cp -f "$UPGRADE_BACKUP" "$mnt/.overlay-sysupgrade.tgz" 2>/dev/null
umount "$mnt"
rmdir "$mnt"