summaryrefslogtreecommitdiff
path: root/package/fwupdate
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2022-12-25 21:10:39 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2022-12-26 08:53:58 +0100
commit192281ae3038a57d98c8e0a06bcab0bd8efa2fc7 (patch)
tree6e722088ac5182b9c1952fb3886a5402e478250c /package/fwupdate
parent6605e98ef31bab3d073cc2e2b95ccb8eb41e33d1 (diff)
implement dual-boot for rockpi4-plus device
Diffstat (limited to 'package/fwupdate')
-rw-r--r--package/fwupdate/Makefile6
-rw-r--r--package/fwupdate/files/fwupdate.postinst3
-rwxr-xr-xpackage/fwupdate/src/fwupdate45
-rwxr-xr-xpackage/fwupdate/src/fwvalidate50
4 files changed, 87 insertions, 17 deletions
diff --git a/package/fwupdate/Makefile b/package/fwupdate/Makefile
index 8cf897ed4..738185fd9 100644
--- a/package/fwupdate/Makefile
+++ b/package/fwupdate/Makefile
@@ -5,7 +5,7 @@ include $(ADK_TOPDIR)/rules.mk
PKG_NAME:= fwupdate
PKG_VERSION:= 1.0
-PKG_RELEASE:= 1
+PKG_RELEASE:= 2
PKG_DESCR:= update firmware
PKG_SECTION:= base/adk
PKG_DEPENDS:= mke2fs
@@ -27,5 +27,9 @@ fwupdate-install:
$(INSTALL_DIR) $(IDIR_FWUPDATE)/usr/sbin
$(INSTALL_BIN) $(WRKBUILD)/fwupdate $(IDIR_FWUPDATE)/usr/sbin
$(INSTALL_BIN) $(WRKBUILD)/fwvalidate $(IDIR_FWUPDATE)/usr/sbin
+ $(SED) "s/@@DISK@@/$(ADK_TARGET_ROOTDEV)/g" \
+ $(IDIR_FWUPDATE)/usr/sbin/fwupdate
+ $(SED) "s/@@DISK@@/$(ADK_TARGET_ROOTDEV)/g" \
+ $(IDIR_FWUPDATE)/usr/sbin/fwvalidate
include ${ADK_TOPDIR}/mk/pkg-bottom.mk
diff --git a/package/fwupdate/files/fwupdate.postinst b/package/fwupdate/files/fwupdate.postinst
new file mode 100644
index 000000000..17871ff30
--- /dev/null
+++ b/package/fwupdate/files/fwupdate.postinst
@@ -0,0 +1,3 @@
+#!/bin/sh
+. $IPKG_INSTROOT/etc/functions.sh
+add_rcconf fwupdate NO
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