Skip to content

Refill boot tries before slot selection in U-Boot scripts - #5054

Merged
sairon merged 2 commits into
devfrom
refill-uboot-slots-before-slot-selection
Oct 1, 2026
Merged

sairon merged 2 commits into
devfrom
refill-uboot-slots-before-slot-selection

Conversation

@sairon

@sairon sairon commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

When no slot had tries left, the boot scripts reset both counters to 3, stored the env and rebooted right away. On USB disks the write can sit in the drive's cache. U-Boot never flushes it and the RPi bootloader cuts USB power on reboot. The write is lost and the board loops forever.

Refill the counters before the slot loop instead, so the board boots in the same pass. The branch after the loop now only stores the decremented counters and resets. This replaces the ODROID-N2 approach from #4832, which kept the store and reset.

Fixes #4886

Summary by CodeRabbit

  • Bug Fixes
    • Improved A/B boot recovery across supported devices. When no slot listed in the boot order has attempts remaining, both slot counters are restored to three before boot selection, and any missing A or B slots are added to the order.
    • When kernel loading fails, the device records the boot state and restarts without resetting counters in the failure branch.

When no slot had tries left, the boot scripts reset both counters to 3,
stored the env and rebooted right away. On USB disks the write can sit
in the drive's cache. U-Boot never flushes it and the RPi bootloader
cuts USB power on reboot. The write is lost and the board loops
forever.

Refill the counters before the slot loop instead, so the board boots in
the same pass. The branch after the loop now only stores the
decremented counters and resets. This replaces the ODROID-N2 approach
from #4832, which kept the store and reset.

Fixes #4886
@sairon
sairon requested a review from agners October 1, 2026 11:58
@sairon sairon added board/raspberrypi Raspberry Pi Boards board/odroid Hardkernel's ODROID Boards u-boot U-Boot related issue board/khadas Khadas VIM Boards board/yellow Home Assistant Yellow board/green Home Assistant Green labels Oct 1, 2026
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. ๐ŸŽ‰

โ„น๏ธ Recent review info
โš™๏ธ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2d9da47a-c2c7-4ecf-9d81-3e7dcd74fec7

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 7cf130e and 88e0a79.

๐Ÿ“’ Files selected for processing (10)
  • buildroot-external/board/hardkernel/odroid-c2/uboot-boot.ush
  • buildroot-external/board/hardkernel/odroid-c4/uboot-boot.ush
  • buildroot-external/board/hardkernel/odroid-m1/uboot-boot.ush
  • buildroot-external/board/hardkernel/odroid-m1s/uboot-boot.ush
  • buildroot-external/board/hardkernel/odroid-n2/uboot-boot.ush
  • buildroot-external/board/khadas/vim3/uboot-boot.ush
  • buildroot-external/board/nabucasa/green/uboot-boot.ush
  • buildroot-external/board/raspberrypi/uboot-boot.ush
  • buildroot-external/board/raspberrypi/uboot-boot64.ush
  • buildroot-external/board/raspberrypi/yellow/uboot-boot64.ush

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


๐Ÿ“ Walkthrough

Walkthrough

Ten U-Boot scripts now check slot counters before slot selection. If no listed slot has tries remaining, each script resets both counters to 3 and adds missing A or B slots to BOOT_ORDER. Kernel-load failure branches no longer reset the counters.

Changes

Boot slot try recovery

Layer / File(s) Summary
Restore counters before slot selection
buildroot-external/board/hardkernel/*/uboot-boot.ush, buildroot-external/board/khadas/vim3/uboot-boot.ush, buildroot-external/board/nabucasa/green/uboot-boot.ush, buildroot-external/board/raspberrypi/uboot-boot.ush, buildroot-external/board/raspberrypi/uboot-boot64.ush, buildroot-external/board/raspberrypi/yellow/uboot-boot64.ush
Each script checks BOOT_ORDER for a slot with tries remaining. If none has tries remaining, the script sets both counters to 3 and appends any missing A or B slots to BOOT_ORDER.
Change kernel-load failure handling
buildroot-external/board/hardkernel/*/uboot-boot.ush, buildroot-external/board/khadas/vim3/uboot-boot.ush, buildroot-external/board/nabucasa/green/uboot-boot.ush, buildroot-external/board/raspberrypi/uboot-boot.ush, buildroot-external/board/raspberrypi/uboot-boot64.ush, buildroot-external/board/raspberrypi/yellow/uboot-boot64.ush
Failure messages change. The failure branches no longer reset both counters. Existing state storage and device reset behavior remains.

Priority: โž– Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix ยท Severity of issue fixed: Medium

Merge Risk: โšช Minimal ยท up to 88e0a

The change allows exhausted boot slots to be retried without a recovery-only reboot. No actionable merge-blocking risk is established; normal checks and board validation remain appropriate.

๐Ÿšฅ Pre-merge checks | โœ… 5
โœ… Passed checks (5 passed)
Check name Status Explanation
Description Check โœ… Passed Check skipped - CodeRabbitโ€™s high-level summary is enabled.
Title check โœ… Passed The title clearly and concisely describes the main change: refilling boot-attempt counters before U-Boot slot selection across the modified scripts.
Linked Issues check โœ… Passed The Raspberry Pi boot scripts now refill both counters before slot selection when no listed slot has tries remaining. They also restore missing slots in BOOT_ORDER, decrement the selected counter, aโ€ฆ
Out of Scope Changes check โœ… Passed The changes are limited to U-Boot A/B boot scripts. The same counter-refill and boot-state persistence logic is applied across supported boards, including Raspberry Pi. These changes support the boot โ€ฆ
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0โ€ฆ
โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

A rabbit checks the boot order with care,
And counts the tries for slots A and B there.
When both run out, three tries return,
Missing slots join the order in turn.
If kernels fail, the counters stay,
The boot state stores before reset away.

Comment @coderabbitai help to get the list of available commands.

if test -z "${BOOT_TRIES_LEFT}"; then
echo "No slot has tries left, resetting tries to 3"
setenv BOOT_A_LEFT 3
setenv BOOT_B_LEFT 3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also reset BOOT_ORDER? ๐Ÿค”

If we can't boot, maybe try the previously marked bad again isn't the worst idea.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's actually good idea, since the bad slots get removed by RAUC. Pushed in another commit.

RAUC removes a slot from BOOT_ORDER when it marks it bad. If the
remaining slot then used up all its tries, the refill only retried that
slot and never the other one. Append any missing slot to BOOT_ORDER when
refilling, keeping the current order so the preferred slot is still
tried first.
@sairon
sairon requested a review from agners October 1, 2026 15:26
@sairon
sairon merged commit 0771032 into dev Oct 1, 2026
3 checks passed
@sairon
sairon deleted the refill-uboot-slots-before-slot-selection branch October 1, 2026 20:35
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

board/green Home Assistant Green board/khadas Khadas VIM Boards board/odroid Hardkernel's ODROID Boards board/raspberrypi Raspberry Pi Boards board/yellow Home Assistant Yellow cla-signed hacktoberfest u-boot U-Boot related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RPi4/NVMe-UAS-over-USB: Endless reboot after unexpected power loss with BOOT_A_LEFT=0 and BOOT_B_LEFT=0 (recovered by manual edit with fw_setenv)

2 participants