diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2022-12-25 21:10:39 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2022-12-26 08:53:58 +0100 |
commit | 192281ae3038a57d98c8e0a06bcab0bd8efa2fc7 (patch) | |
tree | 6e722088ac5182b9c1952fb3886a5402e478250c /package/fwupdate/src | |
parent | 6605e98ef31bab3d073cc2e2b95ccb8eb41e33d1 (diff) |
implement dual-boot for rockpi4-plus device
Diffstat (limited to 'package/fwupdate/src')
-rwxr-xr-x | package/fwupdate/src/fwupdate | 45 | ||||
-rwxr-xr-x | package/fwupdate/src/fwvalidate | 50 |
2 files changed, 79 insertions, 16 deletions
diff --git a/package/fwupdate/src/fwupdate b/package/fwupdate/src/fwupdate index 1efe08339..68796d7bd 100755 --- a/package/fwupdate/src/fwupdate +++ b/package/fwupdate/src/fwupdate @@ -2,8 +2,22 @@ # This file is part of the OpenADK project. # Do update. -PART0="/dev/sda2" -PART1="/dev/sda3" +GRUB=$(which grub-reboot) +if [ "${GRUB}" = "/usr/sbin/grub-reboot" ]; then + REVERSE=0 +else + REVERSE=1 +fi + +DISK=@@DISK@@ + +if [ $REVERSE -eq 1 ]; then + PART0="/dev/${DISK}p1" + PART1="/dev/${DISK}p2" +else + PART0="/dev/${DISK}2" + PART1="/dev/${DISK}3" +fi # Name of the archive, which is the firmware. For this file is the checksum calculated and # checked against the one from the tar archive. @@ -59,10 +73,12 @@ CURRENT_SYS="$(rdev /|awk '{ print $1 }')" case "$CURRENT_SYS" in "$PART0") MOUNTPART="$PART1" + PARTNUM=2 OS=OpenADK2 ;; "$PART1") MOUNTPART="$PART0" + PARTNUM=1 OS=OpenADK1 ;; *) @@ -130,18 +146,23 @@ fi cd / umount $MOUNTPART -grep /boot /proc/mounts 2>/dev/null -if [ $? -eq 0 ]; then - mount -o remount,rw /boot +if [ $REVERSE -eq 1 ]; then + echo "Switch bootable partition to new system" + sfdisk -A /dev/$DISK $PARTNUM >/dev/null 2>&1 else - mount /dev/sda1 /boot -fi -grub-reboot $OS grep /boot /proc/mounts 2>/dev/null -if [ $? -eq 0 ]; then - mount -o remount,ro /boot -else - umount /boot + if [ $? -eq 0 ]; then + mount -o remount,rw /boot + else + mount /dev/sda1 /boot + fi + grub-reboot $OS + grep /boot /proc/mounts 2>/dev/null + if [ $? -eq 0 ]; then + mount -o remount,ro /boot + else + umount /boot + fi fi sync echo "Reboot now to the updated system $OS" diff --git a/package/fwupdate/src/fwvalidate b/package/fwupdate/src/fwvalidate index e87c5beed..f388da784 100755 --- a/package/fwupdate/src/fwvalidate +++ b/package/fwupdate/src/fwvalidate @@ -2,8 +2,22 @@ # This file is part of the OpenADK project. # Validate update. -PART0="/dev/sda2" -PART1="/dev/sda3" +GRUB=$(which grub-reboot) +if [ "${GRUB}" = "/usr/sbin/grub-reboot" ]; then + REVERSE=0 +else + REVERSE=1 +fi + +DISK=@@DISK@@ + +if [ $REVERSE -eq 1 ]; then + PART0="/dev/${DISK}p1" + PART1="/dev/${DISK}p2" +else + PART0="/dev/${DISK}2" + PART1="/dev/${DISK}3" +fi APPLIANCE_NAME=OpenADK @@ -43,6 +57,24 @@ chk_initial_save(){ echo "please save configuration" fi } + +updatebootflag(){ + + case "$CURRENT_SYS" in + "$PART1") + sfdisk -A /dev/$DISK 1 + ;; + "$PART0") + sfdisk -A /dev/$DISK 2 + ;; + *) + echo "Current partition $CURRENT_SYS not recognized" + exit 1 + ;; + esac + +} + updategrub(){ mount -o remount,rw /boot @@ -120,12 +152,22 @@ if [ $TESTS -eq $TESTSUM ]; then logger -t update "All Tests passed." if [ "x$1" = "x" ]; then logger -t update "Set default boot partition for bootloader." + mount -o remount,rw / rm /firmware_check + mount -o remount,ro / echo "System check was successful" >> $STAT_FILE - updategrub + if [ $REVERSE -eq 1 ]; then + echo "Nothing todo. All fine." + logger -t update "Nothing todo. All fine." + else + updategrub + fi fi else - logger -t update "Not all tests passed. The the default system remains on the current partition." + if [ $REVERSE -eq 1 ]; then + updatebootflag + fi + logger -t update "Not all tests passed. The default system remains on the current partition." logger -t update "Please try to reboot the system and repeat the update." echo "ERROR last system update failed, please reboot and try again." >> $STAT_FILE exit 1 |