Skip to content

Commit 7d68582

Browse files
georgemoussalemrobimarko
authored andcommitted
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: openwrt/openwrt#21038 Signed-off-by: Robert Marko <[email protected]>
1 parent d02de1d commit 7d68582

File tree

1 file changed

+77
-0
lines changed
  • target/linux/qualcommax/ipq50xx/base-files/lib/upgrade

1 file changed

+77
-0
lines changed

target/linux/qualcommax/ipq50xx/base-files/lib/upgrade/platform.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
. /lib/functions/bootconfig.sh
2+
13
PART_NAME=firmware
24
REQUIRE_IMAGE_METADATA=1
35

@@ -50,6 +52,81 @@ remove_oem_ubi_volume() {
5052
fi
5153
}
5254

55+
linksys_bootconfig_set_primaryboot() {
56+
local partname=$1
57+
local tempfile
58+
local mtdidx
59+
60+
mtdidx=$(find_mtd_index "$partname")
61+
[ ! "$mtdidx" ] && {
62+
echo "cannot find mtd index for $partname"
63+
return 1
64+
}
65+
66+
# No need to cleanup as files in /tmp will be removed upon reboot
67+
tempfile=/tmp/mtd"$mtdidx".bin
68+
dd if=/dev/mtd"$mtdidx" of="$tempfile" bs=1 count=336 2>/dev/null
69+
[ $? -ne 0 ] || [ ! -f "$tempfile" ]&& {
70+
echo "failed to create a temp copy of /dev/mtd$mtdidx"
71+
return 1
72+
}
73+
74+
set_bootconfig_primaryboot "$tempfile" "0:HLOS" $2
75+
[ $? -ne 0 ] && {
76+
echo "failed to toggle primaryboot on 0:HLOS part"
77+
return 1
78+
}
79+
80+
set_bootconfig_primaryboot "$tempfile" "rootfs" $2
81+
[ $? -ne 0 ] && {
82+
echo "failed to toggle primaryboot for rootfs part"
83+
return 1
84+
}
85+
86+
mtd write "$tempfile" /dev/mtd"$mtdidx" 2>/dev/null
87+
[ $? -ne 0 ] && {
88+
echo "failed to write temp copy back to /dev/mtd$mtdidx"
89+
return 1
90+
}
91+
}
92+
93+
linksys_bootconfig_pre_upgrade() {
94+
local setenv_script="/tmp/fw_env_upgrade"
95+
96+
CI_UBIPART="rootfs_1"
97+
boot_part="$(fw_printenv -n boot_part)"
98+
if [ -n "$UPGRADE_OPT_USE_CURR_PART" ]; then
99+
CI_UBIPART="rootfs"
100+
else
101+
if [ "$boot_part" -eq "1" ]; then
102+
echo "boot_part 2" >> $setenv_script
103+
linksys_bootconfig_set_primaryboot "0:bootconfig" 1
104+
linksys_bootconfig_set_primaryboot "0:bootconfig1" 1
105+
else
106+
echo "boot_part 1" >> $setenv_script
107+
linksys_bootconfig_set_primaryboot "0:bootconfig" 0
108+
linksys_bootconfig_set_primaryboot "0:bootconfig1" 0
109+
fi
110+
fi
111+
112+
boot_part_ready="$(fw_printenv -n boot_part_ready)"
113+
if [ "$boot_part_ready" -ne "3" ]; then
114+
echo "boot_part_ready 3" >> $setenv_script
115+
fi
116+
117+
auto_recovery="$(fw_printenv -n auto_recovery)"
118+
if [ "$auto_recovery" != "yes" ]; then
119+
echo "auto_recovery yes" >> $setenv_script
120+
fi
121+
122+
if [ -f "$setenv_script" ]; then
123+
fw_setenv -s $setenv_script || {
124+
echo "failed to update U-Boot environment"
125+
return 1
126+
}
127+
fi
128+
}
129+
53130
linksys_mx_pre_upgrade() {
54131
local setenv_script="/tmp/fw_env_upgrade"
55132

0 commit comments

Comments
 (0)