Skip to content

feat: keep A/B firmware in the eMMC boot partitions - #474

Merged
otavio merged 5 commits into
masterfrom
feat/boot-emmc
Nov 21, 2026
Merged

otavio merged 5 commits into
masterfrom
feat/boot-emmc

Conversation

@otavio

@otavio otavio commented Nov 19, 2026

Copy link
Copy Markdown
Member

What

Native A/B firmware in eMMC hardware boot partitions. Boards such as the STM32MP135 boot TF-A and the FIP from mmcblkNboot0/boot1, picked by PARTITION_CONFIG (EXT_CSD[179]). Until now, updating that firmware needed scripts to clear force_ro, write the right partition and switch PARTITION_CONFIG, outside the agent's view of the update.

[firmware.boot-emmc]
device = "/dev/mmcblk1"
{ "mode": "raw", "target-type": "boot-emmc", "target": "/dev/mmcblk1", ... }

Installation set N boots from boot partition N, and the eMMC follows the active set. The target type and the base-device rule match RAUC's boot-emmc, but the partition is coupled to the A/B set instead of being toggled on its own.

How

  • Install: the running firmware is copied to the boot partition of the inactive set (skipped when identical), then the boot-emmc objects are written over it. Only that partition is unlocked, and it is synced through the writer's own file before activation. A package without firmware therefore keeps the running one instead of booting stale content.
  • Activation: after swap_active, PARTITION_CONFIG is switched with MMC_IOC_CMD (CMD6, keeping BOOT_ACK) and read back. If the switch fails, the set is swapped back.
  • Repair: a device booting from the partition about to be written, e.g. one provisioned before this, gets its firmware copied to the other boot partition and boots from there. This is logged as a warning.
  • Startup: the pending-update record notes that the eMMC was written and in which boot (kernel boot ID). On the next boot the eMMC follows the set again. That covers a bootloader rollback, and a power cut between the set swap and the eMMC switch. In the second case the agent reboots once, so the update is validated running its own firmware, and rolls the update back if the eMMC still doesn't follow. An agent restarting before the device rebooted doesn't validate the update. A pending record without the eMMC note, e.g. from an older agent, leaves the eMMC alone.
  • Stale kernel cache: some kernels write a cached PARTITION_CONFIG back on the next boot-partition access. Each partition is read uncached (O_DIRECT) before it is written, and the selector is checked again after the writes. If it moved, the update fails and the eMMC is switched back to the running firmware.
  • Refusals: updates are refused while one waits for a reboot, with storage.read_only (the record is what brings the eMMC back after a rollback), for another eMMC device, and when the inactive set changed since validation.

Also in this PR:

  • firmware::reboot() (refactor). Test builds refuse to run any reboot outside the temporary directory, after a test agent outlived its test and rebooted the development machine.
  • Runtime settings are saved atomically: temp file, fsync, rename, directory fsync. A symlinked path keeps its link.

Compatibility

  • SDK: api::info::settings::Firmware gains boot_emmc, and api::info::runtime_settings::RuntimeUpdate gains boot_emmc. This is a source-level break for code building them with struct literals. Both fields are optional and omitted when unset.
  • Downgrades: devices without boot-emmc write exactly the runtime settings older agents parse.
  • Deployment notes:
    • Firmware and OS are two selectors, so the agent can only converge once a mismatched pair boots far enough to run it. Coupling them before Linux starts needs bootloader support.
    • Runtime settings must be shared by both installation sets, as they already must be for validation.
    • A failed activation clears the applied package UID without forcing a probe, so the package is retried on the normal schedule, like any other failed install.
  • Companion changes: the JSON schema (UpdateHub/package-schema) and uhu need boot-emmc support. Those branches are ready locally and will follow in their own PRs.

Tests

tests/boot_emmc.rs runs the agent binary against a simulated eMMC, enabled through UPDATEHUB_EMMC_SIMULATOR and available in test builds only. The test plays the ROM, U-Boot, power cuts and the server through one device history:

  • updates and a failed validation;
  • a bootloader rollback;
  • a power cut while writing, which checks the exact bytes on the medium and SIGABRT;
  • a power cut between the set swap and the eMMC switch;
  • the one-shot corrective reboot and the rollback after it;
  • an agent restart before the reboot;
  • a package for another eMMC, and an OS-only package;
  • the repair;
  • a kernel with a stale PARTITION_CONFIG;
  • a pending record from an older agent.

The ioctl path was checked separately on QEMU's emmc device (QEMU 11.1, kernel 6.18), which is not part of this PR. It still needs a run on STM32MP135 hardware.

cargo test --workspace --features test-env passes. cargo clippy --workspace --all-targets is clean with and without --features test-env.

The Reboot state and the rollback on a failed validation each ran the
`reboot` command themselves. With a single `firmware::reboot` there is one
place that decides how the device reboots, which the next commit needs to
keep test builds from ever rebooting the machine running them.
Tests run the real agent on the developer's machine with a fake `reboot`
first in `PATH`. An agent that outlived its test, whose temporary directory
and fake were gone, ran the system's `reboot` and rebooted the machine
running the tests.

Test builds (unit tests and the `test-env` feature) now only run an
executable `reboot` found under the temporary directory, by its absolute
path, and refuse anything else with an error. Release builds still run
`reboot` as before.
The runtime settings were rewritten in place and never synced. A power
cut while saving could leave the file empty or torn, and the record of a
pending update, which the next boot validates or rolls back, was lost with
it: the agent starts over from the defaults and the update is never
validated.

Write a temporary file next to it, sync it, rename it over the old one and
sync the directory. When the configured path is a symlink, e.g. to storage
shared by both installation sets, the file it points to is replaced and the
link kept, even before that file exists.
A raw object can now name an eMMC by its base device (e.g. `/dev/mmcblk1`)
with the `boot-emmc` target type, meaning the hardware boot partition of
the installation set being installed rather than a fixed device. This is
the type RAUC uses for the same purpose, and the one the JSON schema and
uhu accept.

Handlers other than raw cannot write a boot partition and reject it, and
resolving it to a device without knowing the installation set fails.
Boards such as the STM32MP135 boot TF-A and the FIP from an eMMC hardware
boot partition, picked by PARTITION_CONFIG. Updating that firmware took
scripts to unlock the partitions (force_ro), write the right one and
switch PARTITION_CONFIG, all of it outside the agent's view of the update.

With `[firmware.boot-emmc] device = "/dev/mmcblkN"`, installation set N
boots from boot partition N, and the agent keeps the eMMC in step:

- An update first copies the running firmware to the boot partition of
  the set it installs, then writes its `boot-emmc` raw objects over it, so
  a package without firmware, or with part of it, still yields complete
  firmware. Only that partition is unlocked, and it is synced before the
  update is activated.
- When the set is swapped, PARTITION_CONFIG follows it through the
  MMC_IOC_CMD ioctl, keeping the boot acknowledge, and is read back. If it
  cannot, the set is swapped back.
- A device booting from the partition an update is about to write, e.g.
  one provisioned before this, is repaired first with a warning: its
  firmware is copied to the other boot partition, which it then boots.
- A pending update records that it wrote the eMMC, and in which boot. On
  start, the eMMC follows the set again, which covers a bootloader rolling
  the update back and a power cut between the set and the eMMC switching.
  In that case the agent reboots once, so the update is validated running
  its own firmware, and rolls it back if the eMMC still does not follow.
  An agent restarting before the device rebooted does not validate it.
- Kernels that keep a cached PARTITION_CONFIG write it back on the next
  boot partition access. Each partition is read uncached before it is
  written and checked again afterwards; if the eMMC moved, the update
  fails and the eMMC goes back to the running firmware.

boot-emmc needs persistent runtime settings, since they are what brings
the eMMC back after a rollback, and it refuses updates while one waits
for a reboot.

The integration test runs the agent binary against a simulated eMMC (test
builds only) and plays the ROM, U-Boot, power cuts and the server through
an update history: updates, failed validation, bootloader rollback, power
cuts while writing and between the switches, packages for another eMMC or
without firmware, the repair, and a kernel with a stale PARTITION_CONFIG.
@otavio
otavio merged commit b69e080 into master Nov 21, 2026
4 checks passed
@otavio
otavio deleted the feat/boot-emmc branch November 21, 2026 13:29
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