[PATCH] bcm4908: fix sysupgrade with backup

Rafał Miłecki zajec5 at gmail.com
Fri Feb 11 10:21:06 PST 2022


From: Rafał Miłecki <rafal at milecki.pl>

1. Clean "rootfs_data" manually as bcm4908 doesn't use nand.sh helpers
2. Update image sequence in rootfs_data to make overlay_verify accept it
3. Set CI_UBIPART to make nand_do_upgrade_success() (re)store backup

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 .../base-files/lib/upgrade/platform.sh        | 33 ++++++++++++++++---
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/target/linux/bcm4908/base-files/lib/upgrade/platform.sh b/target/linux/bcm4908/base-files/lib/upgrade/platform.sh
index 5fb8f14af4..f7ab703cb8 100644
--- a/target/linux/bcm4908/base-files/lib/upgrade/platform.sh
+++ b/target/linux/bcm4908/base-files/lib/upgrade/platform.sh
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
 
-RAMFS_COPY_BIN="bcm4908img expr egrep fdtget fw_printenv fw_setenv tr"
+RAMFS_COPY_BIN="bcm4908img expr egrep fdtget fw_printenv fw_setenv tr ln"
 
 PART_NAME=firmware
 
@@ -190,8 +190,6 @@ platform_pkgtb_setup_env_config() {
 }
 
 platform_pkgtb_get_upgrade_index() {
-	platform_pkgtb_setup_env_config
-
 	case "$(fw_printenv -l /tmp -n -c /tmp/env.config COMMITTED)" in
 		1) echo 2;;
 		2) echo 1;;
@@ -207,8 +205,6 @@ platform_pkgtb_commit() {
 	local seq2
 	local tmp
 
-	platform_pkgtb_setup_env_config
-
 	# Read current values
 	for valid in $(fw_printenv -l /tmp -n -c /tmp/env.config VALID | tr ',' ' '); do
 		case "$valid" in
@@ -322,11 +318,36 @@ platform_check_image() {
 # upgrade
 #
 
+platform_pkgtb_clean_rootfs_data() {
+	local ubidev=$(nand_find_ubi $CI_UBIPART)
+	local ubivol="$(nand_find_volume $ubidev rootfs_data)"
+	local dir=/tmp/new_root
+	local seq
+
+	sync
+	mkdir $dir
+	if ! mount -t ubifs /dev/$ubivol $dir; then
+		echo "mounting ubifs $ubivol failed"
+		rmdir $dir
+		return 1
+	fi
+
+	rm -rf $dir/..?* $dir/.[!.]* $dir/*
+	seq=$(fw_printenv -l /tmp -n -c /tmp/env.config SEQ | cut -d ',' -f $idx)
+	ln -f -s $seq $dir/.openwrt-image-seq
+
+	umount $dir
+	sync
+	rmdir $dir
+}
+
 platform_do_upgrade_pkgtb() {
 	local cmd="${2:-cat}"
 	local size
 	local idx bootfs_id rootfs_id
 
+	platform_pkgtb_setup_env_config
+
 	idx=$(platform_pkgtb_get_upgrade_index)
 	case "$idx" in
 		1) bootfs_id=3; rootfs_id=4;;
@@ -345,6 +366,8 @@ platform_do_upgrade_pkgtb() {
 
 	platform_pkgtb_commit $idx
 
+	CI_UBIPART="image"
+	platform_pkgtb_clean_rootfs_data
 	nand_do_upgrade_success
 }
 
-- 
2.34.1




More information about the openwrt-devel mailing list