From 80f637c5319d772e5b19be7a39a8b318754cc60b Mon Sep 17 00:00:00 2001 From: Tomaz Zaman Date: Mon, 10 Aug 2026 16:53:27 +0200 Subject: [PATCH 12/72] layerscape: sysupgrade support sysupgrade.bin is a sysupgrade-tar whose kernel member is the complete boot partition image (Image.gz + dtb + extlinux.conf travel together) and whose root member is the resize-prepped ext4. platform_do_upgrade dd's them to p1/p2 - the GPT and the raw boot firmware in the first 32 MiB are never touched - and the config backup is staged as /sysupgrade.tgz on the new rootfs for the standard preinit restore. First boot after upgrade re-expands the filesystem via the shipped uci-defaults script. Requires CONFIG_TARGET_IMAGES_GZIP=n: the global gzip step would wrap the image after append-metadata and break the metadata check. Verified on hardware: config marker survived, rootfs re-expanded, offload stack up after upgrade. Co-Authored-By: Claude Fable 5 --- .../base-files/lib/upgrade/platform.sh | 40 +++++++++++++++++++ target/linux/layerscape/image/armv8_64b.mk | 20 +++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/target/linux/layerscape/base-files/lib/upgrade/platform.sh b/target/linux/layerscape/base-files/lib/upgrade/platform.sh index 8ad9df4a13..4a2b41ac25 100644 --- a/target/linux/layerscape/base-files/lib/upgrade/platform.sh +++ b/target/linux/layerscape/base-files/lib/upgrade/platform.sh @@ -67,10 +67,41 @@ platform_copy_config_sdboot() { umount /mnt fi } +platform_do_upgrade_mono() { + local tar_file="$1" + local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$') + board_dir=${board_dir%/} + + # The "kernel" member is the complete boot partition image + # (Image.gz + dtb + extlinux.conf), so the device tree and boot + # config always match the kernel they were built with. The GPT + # and the raw boot firmware in the first 32 MiB are never touched. + echo "Writing boot partition..." + tar xf $tar_file ${board_dir}/kernel -O | dd of=/dev/mmcblk0p1 bs=1M conv=fsync 2>/dev/null + echo "Writing rootfs..." + tar xf $tar_file ${board_dir}/root -O | dd of=/dev/mmcblk0p2 bs=1M conv=fsync 2>/dev/null + # rootfs ships at 1.5G; the uci-defaults script in it re-expands + # to the full partition on first boot +} + +platform_copy_config_mono() { + mkdir -p /tmp/new_root + if mount -t ext4 -o rw,noatime /dev/mmcblk0p2 /tmp/new_root; then + echo "Saving config backup to new rootfs..." + cp -af "$UPGRADE_BACKUP" /tmp/new_root/sysupgrade.tgz + umount /tmp/new_root + fi +} + platform_copy_config() { local board=$(board_name) case "$board" in + mono,gateway-dk | \ + mono,gateway-dk-sdboot) + platform_copy_config_mono + return 0 + ;; fsl,ls1012a-frwy-sdboot | \ fsl,ls1021a-iot-sdboot | \ fsl,ls1021a-twr-sdboot | \ @@ -92,6 +123,10 @@ platform_check_image() { nand_do_platform_check "ten64-mtd" $1 return $? ;; + mono,gateway-dk | \ + mono,gateway-dk-sdboot) + return 0 + ;; fsl,ls1012a-frdm | \ fsl,ls1012a-frwy-sdboot | \ fsl,ls1012a-rdb | \ @@ -128,6 +163,11 @@ platform_do_upgrade() { touch /var/lock/fw_printenv.lock case "$board" in + mono,gateway-dk | \ + mono,gateway-dk-sdboot) + platform_do_upgrade_mono "$1" + return 0 + ;; traverse,ten64) platform_do_upgrade_traverse_slotubi "${1}" ;; diff --git a/target/linux/layerscape/image/armv8_64b.mk b/target/linux/layerscape/image/armv8_64b.mk index 1e2bdbcb1b..b1e693d81e 100644 --- a/target/linux/layerscape/image/armv8_64b.mk +++ b/target/linux/layerscape/image/armv8_64b.mk @@ -425,6 +425,22 @@ define Build/mono-emmc-img $(MONO_BOOTFS_SIZE) $(MONO_ROOTFS_PART) endef +# Same resize-metadata prep as the eMMC image (make_ext4fs output +# cannot be grown online); the boot partition blob travels as the +# "kernel" member so dtb and extlinux.conf always match the kernel. +define Build/mono-sysupgrade + cp $(IMAGE_ROOTFS) $@.rootfs + e2fsck -fy $@.rootfs || true + truncate -s 1536M $@.rootfs + resize2fs $@.rootfs + sh $(TOPDIR)/scripts/sysupgrade-tar.sh \ + --board $(subst _,$(comma),$(DEVICE_NAME)) \ + --kernel $@.bootfs \ + --rootfs $@.rootfs \ + $@ + rm -f $@.rootfs +endef + define Device/mono_gateway-dk DEVICE_VENDOR := Mono DEVICE_MODEL := Gateway DK @@ -449,8 +465,10 @@ define Device/mono_gateway-dk FILESYSTEMS := ext4 MONO_BOOTFS_SIZE := 64 MONO_ROOTFS_PART := 30208 - IMAGES := emmc.img.gz + SUPPORTED_DEVICES := mono,gateway-dk mono,gateway-dk-sdboot + IMAGES := emmc.img.gz sysupgrade.bin IMAGE/emmc.img.gz := mono-bootfs | mono-emmc-img | gzip | append-metadata + IMAGE/sysupgrade.bin := mono-bootfs | mono-sysupgrade | append-metadata endef TARGET_DEVICES += mono_gateway-dk -- 2.47.3