Skip to content

u-boot-updatehub-script: Roll back when the loader falls back to the other eMMC boot partition - #143

Merged
otavio merged 2 commits into
masterfrom
feat/emmc-boot-fallback
Nov 24, 2026
Merged

otavio merged 2 commits into
masterfrom
feat/emmc-boot-fallback

Conversation

@otavio

@otavio otavio commented Nov 23, 2026

Copy link
Copy Markdown
Member

Summary

Devices that keep A/B firmware in the eMMC hardware boot partitions can have a first-stage loader
(for example TF-A BL2 with an eMMC boot fallback) that counts boot attempts in a register kept
across resets. After too many failed boots, it loads the firmware of the other boot partition. The
old firmware then boots the rootfs of the update, and the update would pass validation.

This lets the boot script handle that case, with no board-specific code in Linux:

  • UPDATEHUB_BOOTSCRIPT_BEFORE_SELECT: a general hook that runs before the boot count check
    and the selection of the installation set. UPDATEHUB_BOOTSCRIPT_BEFORE_BOOTCMD runs after the
    kernel is loaded, too late to change the set.
  • UPDATEHUB_BOOTSCRIPT_FIRMWARE_FALLBACK_REG: the address of the loader's register. When set,
    the script clears it on every boot it reaches. If the loader fell back while an update is being
    validated (upgrade_available=1), the script reverts to the other installation set. On its next
    start, the agent (with [firmware.boot-emmc], UpdateHub/updatehub master) switches the eMMC boot
    partition back to the active set and confirms the rollback.

The register layout (magic 0xeb57 in bits 31..16, fallback bit 8, count in bits 3..0) is
documented in the recipe header.

Testing

  • BitBake's parser expands do_generate_bootscript correctly with and without the register set.
    An invalid address stops the build.
  • The generated boot.scr ran in U-Boot v2025.01 sandbox (old hush) in 7 scenarios:
    • a fallback while an update is validated reverts the set, with either set active;
    • no pending update, unset upgrade_available, count only, register 0 and wrong magic keep the
      active set;
    • the register ends at 0 in every scenario.
  • Not yet run on hardware.

… set

UPDATEHUB_BOOTSCRIPT_BEFORE_BOOTCMD runs after the kernel of the selected
installation set is loaded, too late for a fragment to change the set.
UPDATEHUB_BOOTSCRIPT_BEFORE_SELECT runs before the boot count check, so a
board-specific fragment that finds the update does not boot can set
'bootcount' to make the script revert to the other installation set.
…other eMMC boot partition

A first-stage loader that keeps A/B firmware in the eMMC boot partitions,
such as TF-A BL2 with STM32MP_EMMC_BOOT_FALLBACK, counts boot attempts in
a register kept across resets and loads the firmware of the other boot
partition after too many. The old firmware would then boot the rootfs of
the update, and the boot would pass validation.

UPDATEHUB_BOOTSCRIPT_FIRMWARE_FALLBACK_REG sets the register address. The
script then clears it on every boot it reaches, and when the loader fell
back while an update is being validated it reverts to the other
installation set. On its next start, the agent switches the eMMC boot
partition back to the active set and confirms the rollback. This leaves
no board-specific code in Linux.
@otavio
otavio merged commit f937e7d into master Nov 24, 2026
@otavio
otavio deleted the feat/emmc-boot-fallback branch November 24, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant