[openwrt/openwrt] base-files: fix issues in nand sysupgrade

LEDE Commits lede-commits at lists.infradead.org
Tue Apr 19 09:08:28 PDT 2022


dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/bfd9afc38dc8a5e158aea11f89c43980396cceff

commit bfd9afc38dc8a5e158aea11f89c43980396cceff
Author: Rodrigo Balerdi <lanchon at gmail.com>
AuthorDate: Fri Apr 15 10:11:52 2022 -0300

    base-files: fix issues in nand sysupgrade
    
    Fix issues while retaining configuration during nand sysupgrade:
    - abort configuration saving if data partition is not found
    - generate diagnostics if saving fails (eg, because of lack of space)
    - do not output "sysupgrade successful" in case of errors
    
    Signed-off-by: Rodrigo Balerdi <lanchon at gmail.com>
---
 package/base-files/files/lib/upgrade/nand.sh | 31 +++++++++++++++++++---------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
index f941718446..d85b2aa241 100644
--- a/package/base-files/files/lib/upgrade/nand.sh
+++ b/package/base-files/files/lib/upgrade/nand.sh
@@ -97,21 +97,33 @@ identify_tar() {
 }
 
 nand_restore_config() {
-	sync
 	local ubidev=$( nand_find_ubi "$CI_UBIPART" )
 	local ubivol="$( nand_find_volume $ubidev rootfs_data )"
-	[ ! "$ubivol" ] &&
+	if [ ! "$ubivol" ]; then
 		ubivol="$( nand_find_volume $ubidev "$CI_ROOTPART" )"
+		if [ ! "$ubivol" ]; then
+			echo "cannot find ubifs data volume"
+			return 1
+		fi
+	fi
 	mkdir /tmp/new_root
 	if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
-		echo "mounting ubifs $ubivol failed"
+		echo "cannot mount ubifs volume $ubivol"
 		rmdir /tmp/new_root
 		return 1
 	fi
-	mv "$1" "/tmp/new_root/$BACKUP_FILE"
-	umount /tmp/new_root
-	sync
+	if mv "$1" "/tmp/new_root/$BACKUP_FILE"; then
+		if umount /tmp/new_root; then
+			echo "configuration saved"
+			rmdir /tmp/new_root
+			return 0
+		fi
+	else
+		umount /tmp/new_root
+	fi
+	echo "could not save configuration to ubifs volume $ubivol"
 	rmdir /tmp/new_root
+	return 1
 }
 
 nand_remove_ubiblock() {
@@ -223,10 +235,9 @@ nand_upgrade_prepare_ubi() {
 
 nand_do_upgrade_success() {
 	local conf_tar="/tmp/sysupgrade.tgz"
-
-	sync
-	[ -f "$conf_tar" ] && nand_restore_config "$conf_tar"
-	echo "sysupgrade successful"
+	if { [ ! -f "$conf_tar" ] || nand_restore_config "$conf_tar"; } && sync; then
+		echo "sysupgrade successful"
+	fi
 	umount -a
 	reboot -f
 }




More information about the lede-commits mailing list