Reference Bootloader
Tip: If you cannot access some of the repos referenced in this section, please contact us to request access.
Tip: This section is a short introduction to the bootloader. For more information, see the full README.
When a device downloads new firmware, it stores it locally (in the storage area) and reboots. A bootloader must be present on the device to handle the update after the reboot. The bootloader:
-
Takes over after reboot.
-
Checks the integrity of the active firmware. It does that by calculating the hash of the active image and comparing it to the one in the metadata header.
-
Looks for available firmware on the system. There may be more than one image, depending on image sizes.
-
Chooses the firmware with the latest time stamp.
-
Checks the integrity of the image in the storage area by checking its hash against its internal metadata header - a structure the application uses to communicate with the bootloader.
-
Copies the image in the storage area to the active application region if it is applicable.
-
Forwards control to the start of the active firmware, which contains the Update client. The firmware can now receive updates.
Note: The bootloader must have an interface agreement with Update client to have correct handover. You can learn more in the documentation of this interface.
When an update becomes available, the Update client inside the firmware performs the following actions:
- Receives a notification from one of its update sources.
- Downloads the new manifest and parses it to obtain the firmware URI.
- Fetches the firmware from one of its update sources. Either the manifest or a cost-ranking algorithm specifies the update source to use.
- Writes the firmware into the storage region on the SD card (or external SPI Flash), as a candidate firmware image.
- Reboots, handing control back to the bootloader.
Flash layout for the example bootloader
The bootloader expects to have the following internal flash layout if KVSTORE provides the Root of Trust:
+--------------------------+
| |
| |
| |
|Firmware Candidate Storage|
| |
| |
| |
+--------------------------+ <-+ update-client.storage-address
| |
| KVSTORE |
| |
+--------------------------+ <-+ storage_tdb_internal.internal_base_address
| |
| |
| |
| Active App |
| |
| |
| |
+--------------------------+ <-+ mbed-bootloader.application-start-address
|Active App Metadata Header|
+--------------------------+ <-+ update-client.application-details
| |
| Bootloader |
| |
+--------------------------+ <-+ 0