commit | a1c1204f65f4c6d55602a1da87dccffec7c57c92 | [log] [tgz] |
---|---|---|
author | Christopher Collins <ccollins@apache.org> | Thu May 23 14:00:28 2019 -0700 |
committer | ccollins476ad <ccollins476ad@gmail.com> | Fri May 31 10:15:08 2019 -0700 |
tree | cb404a2ba437a4c987a32ef4903f6b7831e71dee | |
parent | 2c88e69be7fc995e7b806f3637ad246e55636e1b [diff] |
Fix double swap on interrupted revert This fixes #480. When mcuboot rewrites image trailers during a swap, some information is lost. If a reset occurs before the swap completes, mcuboot may not be able to determine what which swap type to resume upon startup. Specifically, if a "revert" swap gets interupted, mcuboot will perform an extraneous swap on the subsequent boot. See https://github.com/JuulLabs-OSS/mcuboot/issues/480 for details. This commit adds an additional field to the image trailer: `swap-type`. The new trailer structure is illustrated below: ``` 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ~ ~ ~ Swap status (BOOT_MAX_IMG_SECTORS * min-write-size * 3) ~ ~ ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ~ Encryption key 0 (16 octets) [*] ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ~ Encryption key 1 (16 octets) [*] ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Swap size | 0xff padding (4 octets) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Swap type | 0xff padding (7 octets) ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Copy done | 0xff padding (7 octets) ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Image OK | 0xff padding (7 octets) ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ~ MAGIC (16 octets) ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ``` The `swap-type` field contains one of the `BOOT_SWAP_TYPE_[...]` constants. Every time a trailer is written, this field is written along with it. When resuming an interrupted swap, mcuboot uses this field alone to determine the type of swap being resumed. For new swap operations (non-resume case), this field is not read at all; instead, mcuboot consults the `boot_swap_tables` array to determine the swap operation to perform (as it did prior to this commit). Some additional changes were necessary to make all the simulated unit tests pass: * Before initiating a new swap operation, always write the image trailer to the scratch area. This step allows mcuboot to persist the `swap-type` field somewhere before erasing the trailer in the primary slot. If a reset occurs immediately after the erase, mcuboot recovers by using the trailer in the scratch area. * Related to the above: if the scratch area is being used to hold status bytes (because there are no spare sectors in the primary slot), erase the scratch area immediately after the trailer gets written to the primary slot. This eliminates ambiguity regarding the location of the current trailer in case a reset occurs shortly afterwards. Signed-off-by: Christopher Collins <ccollins@apache.org>
This is mcuboot, version 1.3.0
MCUboot is a secure bootloader for 32-bit MCUs. The goal of MCUboot is to define a common infrastructure for the bootloader, system flash layout on microcontroller systems, and to provide a secure bootloader that enables easy software upgrade.
MCUboot is operating system and hardware independent and relies on hardware porting layers from the operating system it works with. Currently, mcuboot works with both the Apache Mynewt, and Zephyr operating systems, but more ports are planned in the future. RIOT is currently supported as a boot target with a complete port planned.
Instructions for different operating systems can be found here:
The issues being planned and worked on are tracked using GitHub issues. To participate please visit:
Issues were previously tracked on MCUboot JIRA , but it is now deprecated.
Information and documentation on the bootloader are stored within the source.
It was previously also documented on confluence: MCUBoot Confluence however, it is now deprecated and not currently maintained
For more information in the source, here are some pointers:
Developers welcome!