Fix RPi 5 getting stuck in bootloader after some reboots (#3842)

Probably since home-assistant/supervisor#5276 introduced in Supervisor
2024.9.0, RAUC bootloader handler for tryboot can set the tryboot flag also
when the tryboot file is not present, causing the Pi to become stuck in
bootloader, trying to load the tryboot file.

This happens when the device is already in the tryboot state, in that case the
tryboot files and flag are created by set-primary and in turn the files are
removed in set-state, while the flag is persisted, causing the bootloader to
attempt loading non-existing file.

To avoid unnecessary juggling with tryboot/config files, only create them and
set the flag if the boot slot is different than the current one. Also, make
sure that the flag is reboot parameter is cleared when the tryboot files are
removed by the handler.

Fixes #3740
This commit is contained in:
Jan Čermák 2025-01-30 11:35:51 +01:00 committed by GitHub
parent f9776abb6a
commit ffca0b30a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,19 +10,30 @@ boot_dir="/mnt/boot"
root_slot_a="PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd"
root_slot_b="PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20"
get_primary() {
echo "tryboot get-primary" >&2
cmdline=$(head -n1 "${boot_dir}/cmdline.txt")
get_value rauc.slot "${cmdline}"
}
case "$1" in
get-primary)
# Actions to be performed when getting the primary bootloader
# Example: Output the path to the current primary bootloader
echo "tryboot get-primary" >&2
cmdline=$(head -n1 "${boot_dir}/cmdline.txt")
get_value rauc.slot "${cmdline}"
get_primary
;;
set-primary)
# Actions to be performed when setting the primary bootloader
# Example: Set the specified bootloader as the primary one
slot_bootname="$2"
# Do nothing if we're already booted in the requested slot
if [ "$(get_primary)" = "${slot_bootname}" ]; then
echo "tryboot set-primary $slot_bootname: already set" >&2
exit 0
fi
echo "tryboot set-primary $slot_bootname" >&2
cmdline=$(head -n1 "${boot_dir}/cmdline.txt")
if [ "${slot_bootname}" = "A" ]; then
@ -85,6 +96,7 @@ case "$1" in
"${boot_dir}/tryboot.txt" > "${boot_dir}/config.txt"
mv "${boot_dir}/cmdline-tryboot.txt" "${boot_dir}/cmdline.txt"
rm "${boot_dir}/tryboot.txt"
rm /run/systemd/reboot-param
fi
;;