Repository navigation
feat: keep A/B firmware in the eMMC boot partitions - #474
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 clearforce_ro, write the right partition and switch PARTITION_CONFIG, outside the agent's view of the update.{ "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
boot-emmcobjects 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.swap_active, PARTITION_CONFIG is switched withMMC_IOC_CMD(CMD6, keeping BOOT_ACK) and read back. If the switch fails, the set is swapped back.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.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 anyrebootoutside the temporary directory, after a test agent outlived its test and rebooted the development machine.Compatibility
api::info::settings::Firmwaregainsboot_emmc, andapi::info::runtime_settings::RuntimeUpdategainsboot_emmc. This is a source-level break for code building them with struct literals. Both fields are optional and omitted when unset.UpdateHub/package-schema) anduhuneedboot-emmcsupport. Those branches are ready locally and will follow in their own PRs.Tests
tests/boot_emmc.rsruns the agent binary against a simulated eMMC, enabled throughUPDATEHUB_EMMC_SIMULATORand available in test builds only. The test plays the ROM, U-Boot, power cuts and the server through one device history:The ioctl path was checked separately on QEMU's
emmcdevice (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-envpasses.cargo clippy --workspace --all-targetsis clean with and without--features test-env.