Browse Source

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 <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/21038
Link: https://github.com/openwrt/openwrt/pull/21273
Signed-off-by: Robert Marko <[email protected]>
George Moussalem 2 months ago
parent
commit
c936a98ed3
1 changed files with 77 additions and 0 deletions
  1. 77 0
      target/linux/qualcommax/ipq50xx/base-files/lib/upgrade/platform.sh

+ 77 - 0
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"