From 56e3a377db68451968b086249e1fe3c295d562e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Mon, 24 Feb 2025 15:17:43 +0100 Subject: [PATCH] Fix RAUC tryboot handler set-state idempotency, add more checks (#3891) When RPi is booted in the tryboot state and the set-state operation is called for the second time, the tryboot files don't exists anymore and the handler exits with an error code, printing an error in the Supervisor logs. Fix handling of this case and add few more checks to make the handler a bit more robust/traceable. --- .../usr/lib/rauc/rpi-tryboot.sh | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/buildroot-external/board/raspberrypi/rpi5-64/rootfs-overlay/usr/lib/rauc/rpi-tryboot.sh b/buildroot-external/board/raspberrypi/rpi5-64/rootfs-overlay/usr/lib/rauc/rpi-tryboot.sh index d78129da8..96af5f91c 100755 --- a/buildroot-external/board/raspberrypi/rpi5-64/rootfs-overlay/usr/lib/rauc/rpi-tryboot.sh +++ b/buildroot-external/board/raspberrypi/rpi5-64/rootfs-overlay/usr/lib/rauc/rpi-tryboot.sh @@ -73,9 +73,8 @@ case "$1" in slot_bootname="$2" new_state="$3" echo "tryboot set-state $slot_bootname $new_state" >&2 - if [ "${new_state}" = "good" ]; then - touch "${boot_dir}/slot-${slot_bootname}/.good" - else + + if [ "${new_state}" != "good" ]; then rm -f "${boot_dir}/slot-${slot_bootname}/.good" exit 0 fi @@ -85,6 +84,20 @@ case "$1" in # Check if tryboot is active if ! cmp -s -n 4 /proc/device-tree/chosen/bootloader/tryboot /dev/zero; then + if [ ! -f "${boot_dir}/cmdline-tryboot.txt" ]; then + if [ -f "${boot_dir}/slot-${slot_bootname}/.good" ]; then + # Most probably already handled on this boot before, do nothing + exit 0 + else + echo "cmdline-tryboot.txt not found, can't commit current state." >&2 + exit 1 + fi + fi + # tryboot.txt MUST exist at this point + if [ ! -f "${boot_dir}/tryboot.txt" ]; then + echo "tryboot.txt not found, can't commit current state." >&2 + exit 1 + fi cmdline_tryboot=$(head -n1 "${boot_dir}/cmdline-tryboot.txt") tryboot_slot=$(get_value rauc.slot "${cmdline_tryboot}") if [ "${tryboot_slot}" != "${slot_bootname}" ]; then @@ -98,6 +111,10 @@ case "$1" in rm "${boot_dir}/tryboot.txt" rm /run/systemd/reboot-param fi + + if [ "${new_state}" = "good" ]; then + touch "${boot_dir}/slot-${slot_bootname}/.good" + fi ;; get-current)