From 30a0bb6d8524c5205c01f5ee8aa373151f023234 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 6 Sep 2022 20:28:14 +0200 Subject: [PATCH] Try booting up to 3 times on GRUB2 based systems (#2112) * Retry up to 3 times By default, HAOS used to retry 3 times. That is still true for U-Boot based boards. Apply the same logic for GRUB2 based systems for consistency. This can help to remedy intermittent internet/connectivity issuese. Altough hacky, in practise it makes sense to give the newly installed OS another go. * Also apply to generic-aarch64 --- .../board/arm-uefi/generic-aarch64/grub.cfg | 40 ++++++++++++++----- buildroot-external/board/pc/grub.cfg | 32 ++++++++++----- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/buildroot-external/board/arm-uefi/generic-aarch64/grub.cfg b/buildroot-external/board/arm-uefi/generic-aarch64/grub.cfg index 7ac9c0a4d..27e0d1997 100644 --- a/buildroot-external/board/arm-uefi/generic-aarch64/grub.cfg +++ b/buildroot-external/board/arm-uefi/generic-aarch64/grub.cfg @@ -15,29 +15,43 @@ for SLOT in $ORDER; do INDEX=0 OK=$A_OK TRY=$A_TRY - A_TRY=1 fi if [ "$SLOT" == "B" ]; then INDEX=1 OK=$B_OK TRY=$B_TRY - B_TRY=1 fi - if [ "$OK" -eq 1 -a "$TRY" -eq 0 ]; then + if [ "$OK" -eq 1 -a "$TRY" -lt 3 ]; then default=$INDEX + + # increment attempts and save back to slot + if [ "$TRY" -eq 1 ]; then + TRY=2 + elif [ "$TRY" -eq 2 ]; then + TRY=3 + else + TRY=1 + fi + + if [ "$SLOT" == "A" ]; then + A_TRY=$TRY + fi + if [ "$SLOT" == "B" ]; then + B_TRY=$TRY + fi + break fi done -# reset booted flags +# No bootable slot found, choose rescue... if [ "$default" -eq 99 ]; then - if [ "$A_OK" -eq 1 -a "$A_TRY" -eq 1 ]; then - A_TRY=0 + if [ "$A_OK" -eq 1 ]; then + default=2 fi - if [ "$B_OK" -eq 1 -a "$B_TRY" -eq 1 ]; then - B_TRY=0 + if [ "$B_OK" -eq 1 ]; then + default=3 fi - default=0 fi save_env A_TRY A_OK B_TRY B_OK ORDER MACHINE_ID @@ -57,3 +71,11 @@ menuentry "Slot A (OK=$A_OK TRY=$A_TRY)" { menuentry "Slot B (OK=$B_OK TRY=$B_TRY)" { linux (${boothd},gpt4)/Image root=PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20 $default_cmdline $cmdline rauc.slot=B } + +menuentry "Slot A (rescue shell)" { + linux (${boothd},gpt2)/Image root=PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd $default_cmdline $cmdline rauc.slot=A systemd.unit=recovery.target +} + +menuentry "Slot B (rescue shell)" { + linux (${boothd},gpt4)/Image root=PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20 $default_cmdline $cmdline rauc.slot=B systemd.unit=recovery.target +} diff --git a/buildroot-external/board/pc/grub.cfg b/buildroot-external/board/pc/grub.cfg index 42a11e993..743a2f430 100644 --- a/buildroot-external/board/pc/grub.cfg +++ b/buildroot-external/board/pc/grub.cfg @@ -15,29 +15,43 @@ for SLOT in $ORDER; do INDEX=0 OK=$A_OK TRY=$A_TRY - A_TRY=1 fi if [ "$SLOT" == "B" ]; then INDEX=1 OK=$B_OK TRY=$B_TRY - B_TRY=1 fi - if [ "$OK" -eq 1 -a "$TRY" -eq 0 ]; then + if [ "$OK" -eq 1 -a "$TRY" -lt 3 ]; then default=$INDEX + + # increment attempts and save back to slot + if [ "$TRY" -eq 1 ]; then + TRY=2 + elif [ "$TRY" -eq 2 ]; then + TRY=3 + else + TRY=1 + fi + + if [ "$SLOT" == "A" ]; then + A_TRY=$TRY + fi + if [ "$SLOT" == "B" ]; then + B_TRY=$TRY + fi + break fi done -# reset booted flags +# No bootable slot found, choose rescue... if [ "$default" -eq 99 ]; then - if [ "$A_OK" -eq 1 -a "$A_TRY" -eq 1 ]; then - A_TRY=0 + if [ "$A_OK" -eq 1 ]; then + default=2 fi - if [ "$B_OK" -eq 1 -a "$B_TRY" -eq 1 ]; then - B_TRY=0 + if [ "$B_OK" -eq 1 ]; then + default=3 fi - default=0 fi save_env A_TRY A_OK B_TRY B_OK ORDER MACHINE_ID