From: George Moussalem Date: Thu, 4 Dec 2025 05:20:00 +0000 (+0400) Subject: qualcommax: ipq50xx: upgrade SMEM dualboot Linksys devices X-Git-Tag: v25.12.0-rc2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c936a98ed3bab4a174aca40645fb4f08d72152ab;p=thirdparty%2Fopenwrt.git qualcommax: ipq50xx: upgrade SMEM dualboot Linksys devices Add support for upgrades on dual firmware Linksys devices with the partition table stored in SMEM and that store both the kernel and rootfs in a single partition. Switching the active boot partition requires updating the partition info table in SMEM in addition to setting the active boot partition in a U-boot variable as U-boot will keep them in sync upon reboot if they're not. U-boot always sets the name of the active partition to rootfs and that of the inactive partition to rootfs_1 in SMEM. when Linux loads the partition table from SMEM it will load the right partition based on the offset set in the SMEM partition table. For upgrades, flashing to the alternate partition will always be to rootfs_1, while flashing the current partition will be on rootfs. Signed-off-by: George Moussalem Link: https://github.com/openwrt/openwrt/pull/21038 Link: https://github.com/openwrt/openwrt/pull/21273 Signed-off-by: Robert Marko --- diff --git a/target/linux/qualcommax/ipq50xx/base-files/lib/upgrade/platform.sh b/target/linux/qualcommax/ipq50xx/base-files/lib/upgrade/platform.sh index 9d921f73b6a..bbc6d8eb7f3 100644 --- a/target/linux/qualcommax/ipq50xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/qualcommax/ipq50xx/base-files/lib/upgrade/platform.sh @@ -1,3 +1,5 @@ +. /lib/functions/bootconfig.sh + PART_NAME=firmware REQUIRE_IMAGE_METADATA=1 @@ -50,6 +52,81 @@ remove_oem_ubi_volume() { fi } +linksys_bootconfig_set_primaryboot() { + local partname=$1 + local tempfile + local mtdidx + + mtdidx=$(find_mtd_index "$partname") + [ ! "$mtdidx" ] && { + echo "cannot find mtd index for $partname" + return 1 + } + + # No need to cleanup as files in /tmp will be removed upon reboot + tempfile=/tmp/mtd"$mtdidx".bin + dd if=/dev/mtd"$mtdidx" of="$tempfile" bs=1 count=336 2>/dev/null + [ $? -ne 0 ] || [ ! -f "$tempfile" ]&& { + echo "failed to create a temp copy of /dev/mtd$mtdidx" + return 1 + } + + set_bootconfig_primaryboot "$tempfile" "0:HLOS" $2 + [ $? -ne 0 ] && { + echo "failed to toggle primaryboot on 0:HLOS part" + return 1 + } + + set_bootconfig_primaryboot "$tempfile" "rootfs" $2 + [ $? -ne 0 ] && { + echo "failed to toggle primaryboot for rootfs part" + return 1 + } + + mtd write "$tempfile" /dev/mtd"$mtdidx" 2>/dev/null + [ $? -ne 0 ] && { + echo "failed to write temp copy back to /dev/mtd$mtdidx" + return 1 + } +} + +linksys_bootconfig_pre_upgrade() { + local setenv_script="/tmp/fw_env_upgrade" + + CI_UBIPART="rootfs_1" + boot_part="$(fw_printenv -n boot_part)" + if [ -n "$UPGRADE_OPT_USE_CURR_PART" ]; then + CI_UBIPART="rootfs" + else + if [ "$boot_part" -eq "1" ]; then + echo "boot_part 2" >> $setenv_script + linksys_bootconfig_set_primaryboot "0:bootconfig" 1 + linksys_bootconfig_set_primaryboot "0:bootconfig1" 1 + else + echo "boot_part 1" >> $setenv_script + linksys_bootconfig_set_primaryboot "0:bootconfig" 0 + linksys_bootconfig_set_primaryboot "0:bootconfig1" 0 + fi + fi + + boot_part_ready="$(fw_printenv -n boot_part_ready)" + if [ "$boot_part_ready" -ne "3" ]; then + echo "boot_part_ready 3" >> $setenv_script + fi + + auto_recovery="$(fw_printenv -n auto_recovery)" + if [ "$auto_recovery" != "yes" ]; then + echo "auto_recovery yes" >> $setenv_script + fi + + if [ -f "$setenv_script" ]; then + fw_setenv -s $setenv_script || { + echo "failed to update U-Boot environment" + return 1 + } + fi +} + linksys_mx_pre_upgrade() { local setenv_script="/tmp/fw_env_upgrade"