From 40b5a83fdb9934e92ee875668c828112cce61881 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Thu, 29 Jan 2026 23:40:50 +0100 Subject: [PATCH] gemini: use tar stream to write firmware The firmware update file can get big, so instead of extracting the whole file into the tmp folder potentially running out of space and make the upgrade fail, stream from tar xvf -O directly to the mtd write command. Refactor the checking of partitions and the actual upgrade into two steps when we are at it. Link: https://github.com/openwrt/openwrt/pull/21782 (cherry picked from commit 1977301b5f8f76b4d04b5950b09b2fd7cf607bc4) Link: https://github.com/openwrt/openwrt/pull/21973 Signed-off-by: Linus Walleij --- .../gemini/base-files/lib/upgrade/platform.sh | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/target/linux/gemini/base-files/lib/upgrade/platform.sh b/target/linux/gemini/base-files/lib/upgrade/platform.sh index f7620fd244..0547be8fb0 100644 --- a/target/linux/gemini/base-files/lib/upgrade/platform.sh +++ b/target/linux/gemini/base-files/lib/upgrade/platform.sh @@ -1,7 +1,7 @@ REQUIRE_IMAGE_METADATA=1 MTDSYSFS=/sys/class/mtd -gemini_do_platform_upgrade() { +gemini_check_redboot_parts() { MTD1OF=`cat ${MTDSYSFS}/mtd1/offset` MTD2OF=`cat ${MTDSYSFS}/mtd2/offset` MTD3OF=`cat ${MTDSYSFS}/mtd3/offset` @@ -54,19 +54,23 @@ gemini_do_platform_upgrade() { echo "MTD3 has wrong name, aborting" >&2 exit 1 fi +} + +gemini_do_platform_upgrade() { echo "Extract the three firmware parts" - tar xvfz "$1"; rm "$1" - sync echo 3 > /proc/sys/vm/drop_caches echo "COMMENCING UPGRADE. BE PATIENT, THIS IS NOT FAST!" - echo "Upgrade Kern partition (kernel part 1, $2 erase blocks)" - mtd write zImage Kern + KFSZ=$(tar xfz "$1" zImage -O | wc -c) + echo "Upgrade Kern partition (kernel part 1, size ${KFSZ})" + tar xfz "$1" zImage -O | mtd write - Kern [ $? -ne 0 ] && exit 1 - echo "Upgrade Ramdisk partition (kernel part 2, $3 erase blocks)" - mtd write rd.gz Ramdisk + RFSZ=$(tar xfz "$1" rd.gz -O | wc -c) + echo "Upgrade Ramdisk partition (kernel part 2, size ${RFSZ})" + tar xfz "$1" rd.gz -O | mtd write - Ramdisk [ $? -ne 0 ] && exit 1 - echo "Upgrade Application partition (rootfs, $4 erase blocks)" - mtd write hddapp.tgz Application + AFSZ=$(tar xfz "$1" hddapp.tgz -O | wc -c) + echo "Upgrade Application partition (rootfs, size ${AFSZ})" + tar xfz "$1" hddapp.tgz -O | mtd write - Application [ $? -ne 0 ] && exit 1 } @@ -98,10 +102,12 @@ platform_do_upgrade() { ;; itian,sq201|\ storlink,gemini324) - gemini_do_platform_upgrade "$1" 16 48 48 + gemini_check_redboot_parts "$1" 16 48 48 + gemini_do_platform_upgrade "$1" ;; raidsonic,ib-4220-b) - gemini_do_platform_upgrade "$1" 24 48 48 + gemini_check_redboot_parts "$1" 24 48 48 + gemini_do_platform_upgrade "$1" ;; esac }