From 80c16a60a979481a2a1267cfb6eaf9297beb7ca0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20H=C3=B6glund?= <jonas.hoglund@embeddednation.com>
Date: Tue, 23 Mar 2021 11:37:08 +0100
Subject: [PATCH] Save current nvram to migrator volume.

---
 .../image/bundled-migrator-script/script.sh   | 30 ++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/iopsys-brcm63xx-arm/image/bundled-migrator-script/script.sh b/iopsys-brcm63xx-arm/image/bundled-migrator-script/script.sh
index 38d30afbe..069256dae 100755
--- a/iopsys-brcm63xx-arm/image/bundled-migrator-script/script.sh
+++ b/iopsys-brcm63xx-arm/image/bundled-migrator-script/script.sh
@@ -47,7 +47,25 @@ upgrade_ubi_volume() {
 	fsync /dev/ubi0_$id
 }
 
-local img="$1" size
+# Save nvram values in migrator raw ubi partition.
+# These values are picked up by uboot on first boot
+# and stored in uboot environment.
+save_nvram() {
+	names=$(ls /proc/nvram | sort)
+
+	for name in $names; do
+		# Skip the bootline
+		[ $name == bootline ] || [ $name == Bootline ] && continue
+
+		value=$(cat /proc/nvram/$name)
+		echo "$name=$value" >> /tmp/nvram
+	done
+
+	size=$(ls -l /tmp/nvram  | awk '{ print $5 }')
+	echo $size
+}
+
+img="$1"
 
 echo "Running iop5 to iop6 migration script"
 
@@ -58,6 +76,7 @@ size=$(extract_section $img loader)
 if [ $size -gt 0 ]; then
 	mtd -e /dev/mtd1 write /tmp/loader /dev/mtd1
 else
+	echo "Bad boot loader size; exiting."
 	return 1
 fi
 
@@ -83,12 +102,15 @@ echo "Extracting rootfs"
 size=$(extract_section $img rootfs)
 upgrade_ubi_volume rootfs $size rootfs1 4
 
-# Create the overlay. Save id 6 for rootfs2.
+echo "Saving nvram"
+size=$(save_nvram)
+upgrade_ubi_volume nvram $size migrator 10
+
 echo "Creating overlay partition"
-ubimkvol "/dev/ubi0" -n 10 -N overlay1 -t dynamic -s 38092800
+ubimkvol "/dev/ubi0" -n 11 -N overlay1 -t dynamic -s 38092800
 
 echo "Upgrade completed; rebooting."
-#reboot
+reboot
 
 # Halt execution of sysupgrade, both when sourced and execuded as a task.
 return 1 || exit 1
-- 
GitLab