From aaa55848de556d63b8efa6e6ca940ecac827a07f Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 23 Mar 2022 16:00:49 +0100 Subject: [PATCH] Implement A/B switch when moving back to Barebox (#1794) * Implement manual boot switch when downgrading to Barebox When installing OS 7 or older from a OS 8 installation, the bootloader is changed back to Barebox. However, in this case Barebox does not know which boot slot is correct (and rauc won't update Barebox' state as it is configured to work with GRUB in OS 8+). This implements a poor mans version to switch the boot partition. It clears Barebox state and deploys one of the two pre-configured default states, booting either boot slot A or B. --- .../board/pc/generic-x86-64/hassos-hook.sh | 2 + .../board/pc/ova/hassos-hook.sh | 2 + .../bootloader/barebox-state-efi-A.dtb | Bin 0 -> 1147 bytes .../bootloader/barebox-state-efi-A.dts | 76 ++++++++++++++++++ .../bootloader/barebox-state-efi-B.dtb | Bin 0 -> 1147 bytes .../bootloader/barebox-state-efi-B.dts | 76 ++++++++++++++++++ buildroot-external/ota/rauc-hook | 19 +++++ buildroot-external/scripts/ota.sh | 3 + 8 files changed, 178 insertions(+) create mode 100644 buildroot-external/bootloader/barebox-state-efi-A.dtb create mode 100644 buildroot-external/bootloader/barebox-state-efi-A.dts create mode 100644 buildroot-external/bootloader/barebox-state-efi-B.dtb create mode 100644 buildroot-external/bootloader/barebox-state-efi-B.dts diff --git a/buildroot-external/board/pc/generic-x86-64/hassos-hook.sh b/buildroot-external/board/pc/generic-x86-64/hassos-hook.sh index f64466167..dfac639ae 100755 --- a/buildroot-external/board/pc/generic-x86-64/hassos-hook.sh +++ b/buildroot-external/board/pc/generic-x86-64/hassos-hook.sh @@ -9,6 +9,8 @@ function hassos_pre_image() { cp "${BINARIES_DIR}/barebox.bin" "${BOOT_DATA}/EFI/BOOT/BOOTx64.EFI" cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi.dtb" "${BOOT_DATA}/EFI/barebox/state.dtb" + cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi-A.dtb" "${BOOT_DATA}/EFI/barebox/state-A.dtb" + cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi-B.dtb" "${BOOT_DATA}/EFI/barebox/state-B.dtb" cp "${BOARD_DIR}/cmdline.txt" "${BOOT_DATA}/cmdline.txt" } diff --git a/buildroot-external/board/pc/ova/hassos-hook.sh b/buildroot-external/board/pc/ova/hassos-hook.sh index 4f2278a9c..afc9d4cfb 100755 --- a/buildroot-external/board/pc/ova/hassos-hook.sh +++ b/buildroot-external/board/pc/ova/hassos-hook.sh @@ -9,6 +9,8 @@ function hassos_pre_image() { cp "${BINARIES_DIR}/barebox.bin" "${BOOT_DATA}/EFI/BOOT/BOOTx64.EFI" cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi.dtb" "${BOOT_DATA}/EFI/barebox/state.dtb" + cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi-A.dtb" "${BOOT_DATA}/EFI/barebox/state-A.dtb" + cp "${BR2_EXTERNAL_HASSOS_PATH}/bootloader/barebox-state-efi-B.dtb" "${BOOT_DATA}/EFI/barebox/state-B.dtb" cp "${BOARD_DIR}/cmdline.txt" "${BOOT_DATA}/cmdline.txt" } diff --git a/buildroot-external/bootloader/barebox-state-efi-A.dtb b/buildroot-external/bootloader/barebox-state-efi-A.dtb new file mode 100644 index 0000000000000000000000000000000000000000..e26c070714a446904e51d9cf72f056b5e7ffd62e GIT binary patch literal 1147 zcmb7D+invv5S`EpD1u%j_<*XQ^1!N_-Ly2kG|dbDzypzY?M*E9CfiXj{0JY#Lw}^| zA0X!JEhID|Send?GjsOLv3>XI*FDkpcOp7xzs>$V+X34?8`c%k*3UXz`t3DYPo!E{ zWsz>NJwtF}op1^fJz?uD(y9jEd5V2D^dNt;k{>?&7+*C1@3KFRgi%p({oxU;V5Rqy z5lnl5{h4U*4mD9xxJUZeap_$GWr4G{&Ztc2T<6n?a86~Vvm?K5t>$~q@s}pYtgTMt zxz1e(_KRHhouyyMy=41@6Ov_JGd zCSl+WWRiI2z8`pDIP{~lAP)VZgsvtrx2_wRB|lt!m;- yOm$3gk(I*fC{+}R_?yaQ>pgc; + #size-cells = <1>; + + magic = <0xef98423f>; + compatible = "barebox,state"; + backend = <&backend_state>; + backend-type = "raw"; + backend-stridesize = <4048>; + + bootstate { + #address-cells = <1>; + #size-cells = <1>; + + A { + #address-cells = <1>; + #size-cells = <1>; + remaining_attempts@0 { + reg = <0x0 0x4>; + type = "uint32"; + default = <3>; + }; + priority@4 { + reg = <0x4 0x4>; + type = "uint32"; + default = <20>; + }; + }; + + B { + #address-cells = <1>; + #size-cells = <1>; + remaining_attempts@8 { + reg = <0x8 0x4>; + type = "uint32"; + default = <0>; + }; + priority@c { + reg = <0xc 0x4>; + type = "uint32"; + default = <10>; + }; + }; + + last_chosen@10 { + reg = <0x10 0x4>; + type = "uint32"; + }; + }; + + machine_id@14 { + reg = <0x14 0x24>; + type = "string"; + default = ""; + }; + }; + + partitions { + #address-cells = <1>; + #size-cells = <1>; + compatible = "fixed-partitions"; + + backend_state: state { + partuuid = "33236519-7f32-4dff-8002-3390b62c309d"; + }; + }; + +}; + diff --git a/buildroot-external/bootloader/barebox-state-efi-B.dtb b/buildroot-external/bootloader/barebox-state-efi-B.dtb new file mode 100644 index 0000000000000000000000000000000000000000..8b96079bdb01be3a8fbdfaccdae36220a0010155 GIT binary patch literal 1147 zcmb7@S#H}f5QfK1&<))Jv*_Qarh9QK$#EFqqYo7e>h0=;e%8E)T_L4W)&{A{b4$BcpR3j` z#6+i*Rz)qGPI5(wNPnwRb~; + #size-cells = <1>; + + magic = <0xef98423f>; + compatible = "barebox,state"; + backend = <&backend_state>; + backend-type = "raw"; + backend-stridesize = <4048>; + + bootstate { + #address-cells = <1>; + #size-cells = <1>; + + A { + #address-cells = <1>; + #size-cells = <1>; + remaining_attempts@0 { + reg = <0x0 0x4>; + type = "uint32"; + default = <3>; + }; + priority@4 { + reg = <0x4 0x4>; + type = "uint32"; + default = <10>; + }; + }; + + B { + #address-cells = <1>; + #size-cells = <1>; + remaining_attempts@8 { + reg = <0x8 0x4>; + type = "uint32"; + default = <3>; + }; + priority@c { + reg = <0xc 0x4>; + type = "uint32"; + default = <20>; + }; + }; + + last_chosen@10 { + reg = <0x10 0x4>; + type = "uint32"; + }; + }; + + machine_id@14 { + reg = <0x14 0x24>; + type = "string"; + default = ""; + }; + }; + + partitions { + #address-cells = <1>; + #size-cells = <1>; + compatible = "fixed-partitions"; + + backend_state: state { + partuuid = "33236519-7f32-4dff-8002-3390b62c309d"; + }; + }; + +}; + diff --git a/buildroot-external/ota/rauc-hook b/buildroot-external/ota/rauc-hook index 9c2ef3c56..d3133cf7c 100755 --- a/buildroot-external/ota/rauc-hook +++ b/buildroot-external/ota/rauc-hook @@ -28,6 +28,25 @@ case "$1" in slot-install) # Use install handlers below ;; + slot-post-install) + # Handle main slot only + test "${RAUC_SLOT_CLASS}" = "kernel" || exit 0 + + BOOT_MNT=/mnt/boot + + if ! systemctl -q is-active mnt-boot.mount; then + systemctl start mnt-boot.mount + fi + + # OS 8+ to 7 and lower downgrade path + if ! command -v barebox-state > /dev/null; then + cp -f "${BOOT_MNT}/EFI/barebox/state-${RAUC_SLOT_BOOTNAME}.dtb" "${BOOT_MNT}"/EFI/barebox/state.dtb + blkdiscard /dev/disk/by-partuuid/33236519-7f32-4dff-8002-3390b62c309d + echo "Cleared state and copied default state-${RAUC_SLOT_BOOTNAME}.dtb to state.dtb." + fi + + exit 0 + ;; *) exit 1 ;; diff --git a/buildroot-external/scripts/ota.sh b/buildroot-external/scripts/ota.sh index 918a5f8ee..87ed5f2a5 100755 --- a/buildroot-external/scripts/ota.sh +++ b/buildroot-external/scripts/ota.sh @@ -38,6 +38,9 @@ function create_ota_update() { echo "hooks=install" echo "[image.kernel]" echo "filename=kernel.img" + if [ "${BOOTLOADER}" == "barebox" ]; then + echo "hooks=post-install" + fi echo "[image.rootfs]" echo "filename=rootfs.img" ) > "${rauc_folder}/manifest.raucm"