Skip to content

Commit 73ab7cd

Browse files
committed
Merge README instructions into bootloader README
This commit removes most of the instructions from this repository's README. The removed instructions have been reworded and merged into the corresponding bootloader repository's README. This commit also introduces use of the new `boot_get_current_version` function in mcuboot (not yet merged). This commit temporarily retargets the mcuboot.lib dependency to a test branch since some required changes have not yet been merged into mcuboot master.
1 parent fb82678 commit 73ab7cd

File tree

3 files changed

+14
-111
lines changed

3 files changed

+14
-111
lines changed

README.md

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,7 @@
22

33
This example project shows how to configure an Mbed-OS application to be booted by an mcuboot bootloader.
44

5-
The mcuboot bootloader is a small mbed-os application loaded at the beginning of flash and executed first by the processor. The bootloader looks at available internal/external flash and decides when to carry out updates, handles flashing an update and error recovery, and ultimately jumps to the beginning of the main application.
6-
7-
## Memory Regions Overview
8-
9-
### Bootloader
10-
The bootloader lives in the first region of flash where the processor begins execution. The basic mcuboot bootloader does not implement any interfaces to receive updates. It simply looks at available application "slots". The application (or another bootloader) is responsible for loading application updates into a slot visible to the mcuboot bootloader. Update candidates are typically placed in the "secondary" flash region. See the bootloader readme for more information.
11-
12-
Briefly, the bootloader has a maximum size set by `target.restrict_size` when building the bootloader. In this example the bootloader is restricted to a size of `0x1FC00` bytes. This is way larger than required but allows the bootloader to be built with a debug profile during development. In production the bootloader size should be optimized based on your use case.
13-
14-
### Application Header Info
15-
16-
When deciding what to boot/update, the mcuboot bootloader looks at an installed application's header info, which is a special struct prepended to the application binary. It uses this header info to validate there is a bootable image installed in the "slot". There are also type-length-value (TLV) encoded pieces of information following the application binary called the "application trailer". These TLV encoded values include things like a digital signature and SHA hash, among other things. See mcuboot documentation for more information.
17-
18-
By default, this header is configured to be 4kB in size. ~~This is probably way more than needed in most cases and can be adjusted using the configuration parameter `mcuboot.header_size`. This value should be aligned on 4-byte boundaries.~~ **NOTE:** Due to the way the FlashIAP block device currently works while erasing, the header_size should be configured to be the size of an erase sector (4kB in the case of an nRF52840). Erasing using the FlashIAPBlockDevice only works if the given address is erase-sector aligned!
19-
20-
This header prepended to the application hex during the signing process (explained later). The trailer is also appended to the application hex during signing.
21-
22-
~~Please note: the bootloader size should be restricted to ensure it does not collide with the application header info. For example, if the application start address is set to `0x20000` and the header size is `0x400`, the bootloader size should be restricted to at most `0x20000 - 0x400 = 0x1FC00`.~~ **NOTE:** Currently, the bootloader size should be restricted to match the application start address. This could cause issues if the bootloader fills this space exactly (and overwrites the application header area). Potential solution: Add `MBED_CONF_MCUBOOT_HEADER_SIZE` to `POST_APPLICATION_ADDR` to get the actual start address of the application...
23-
24-
### Primary Application
25-
26-
The primary application is the currently installed, bootable application. In this case it is the typical mbed-os-example-blinky application (plus some mcuboot-specific things). The application start address is configured using `target.mbed_app_start` and the size can be restricted using `target.mbed_app_size`.
27-
28-
### Scratch Space
29-
30-
If mcuboot is configured to perform swap-type updates (ie: the update candidate is written to the main application space while the main application is written to the update candidate space), the end of the flash memory map has several sectors reserved for "scratch space". This is an area of flash where mcuboot can temporarily store pieces of each application as well as update status information in case an unexpected reset/power failure happens during an update. See mcuboot documentation for information on considerations when configuring the size of the scratch space.
31-
32-
Please note: The primary application size should be restricted to ensure it does not collide with the scratch space region. For example, if the application start address is set to `0x20000`, the device flash ends at `0x100000`, and the scratch space size is configured to `0x4000`, the application size should be restricted to `0x100000 - (0x20000 + 0x4000) = 0xDC000`.
33-
34-
The size of the scratch space can be configured using `mcuboot.scratch-size` -- this value **must** be erase-sector aligned (ie: a multiple of the flash's eraseable size).
35-
36-
## Configuration
37-
38-
There are many configuration options available in mcuboot and these are covered in mcuboot's documentation. This section will go over basic configuration that needs to be done to boot an mbed-os application with mcuboot.
39-
40-
The mcuboot repository is included to allow the application to call some application-related mcuboot functions. One use case is having the application flag itself as "okay" after an update has occurred. This prevents mcuboot from reverting the update on the next boot.
41-
42-
By default, the mcuboot repository/library is configured to build a bootloader, **not** an application. So when building an application with mcuboot, it is important to add the following to your `mbed_app.json` configuration file:
43-
44-
```
45-
"mcuboot.bootloader-build": 0
46-
```
47-
48-
Additionally, the application start location and maximum allowed size should be configured as discussed in the above section, "Memory Regions Overview". A bare-minimum mcuboot application configuration file should look like the below `mbed_app.json` excerpt:
49-
50-
```
51-
{
52-
"target_overrides": {
53-
"*": {
54-
"mcuboot.bootloader-build": 0,
55-
"target.mbed_app_start": "0x20000",
56-
"target.mbed_app_size": "0xDC000"
57-
}
58-
}
59-
}
60-
```
61-
62-
The example project contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/).
63-
64-
You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
65-
(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
66-
67-
1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
68-
1. From the command-line, import the example: `mbed import mbed-os-example-blinky`
69-
1. Change the current directory to where the project was imported.
70-
71-
## Application functionality
72-
73-
The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board.
74-
75-
## Building and running
76-
77-
1. Connect a USB cable between the USB port on the board and the host computer.
78-
1. Run the following command to build the example project and program the microcontroller flash memory:
79-
80-
```bash
81-
$ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash
82-
```
83-
84-
Your PC may take a few minutes to compile your code.
85-
86-
The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`.
87-
88-
Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB.
89-
90-
Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:
91-
92-
```bash
93-
$ mbed compile -S
94-
```
95-
96-
## Expected output
97-
The LED on your target turns on and off every 500 milliseconds after being booted by mcuboot.
98-
99-
100-
## Troubleshooting
101-
If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
102-
103-
## Related Links
104-
105-
* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html).
106-
* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html).
107-
* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html).
108-
* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html).
109-
* [Mbed boards](https://os.mbed.com/platforms/).
5+
All information for this example has been moved to the combined README in the bootloader repository, [`mbed-mcuboot-demo`](https://github.com/AGlass0fMilk/mbed-mcuboot-demo).
1106

1117
### License and contributions
1128

main.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "mbed.h"
88

99
#include "bootutil/bootutil.h"
10+
#include "bootutil/image.h"
1011
#include "FlashIAP/FlashIAPBlockDevice.h"
1112
#include "drivers/InterruptIn.h"
1213

@@ -19,8 +20,6 @@ mbed::BlockDevice* get_secondary_bd(void) {
1920
return &sliced_bd;
2021
}
2122

22-
const static char version[] = "1.0";
23-
2423
int main()
2524
{
2625
// Enable traces from relevant trace groups
@@ -43,7 +42,16 @@ int main()
4342

4443
InterruptIn btn(DEMO_BUTTON);
4544

46-
tr_info("Hello version %s", version);
45+
// Get the current version from the mcuboot header information
46+
struct image_version version;
47+
ret = boot_get_current_version(&version);
48+
if(ret == 0) {
49+
tr_info("Hello version %d.%d.%d+%lu", version.iv_major, version.iv_minor,
50+
version.iv_revision, version.iv_build_num);
51+
} else {
52+
tr_error("Failed to load version information: %d", ret);
53+
}
54+
4755

4856
// Erase secondary slot
4957
// On the first boot, the secondary BlockDevice needs to be clean
@@ -86,8 +94,7 @@ int main()
8694
}
8795

8896
// Copy the update image from internal flash to secondary BlockDevice
89-
// This is a "hack" that requires you to preload the update image (i.e. with pyocd flash -a <address> <image>.bin)
90-
// TODO: Use Serial OTA to fetch image
97+
// This is a "hack" that requires you to preload the update image into `mcuboot.primary-slot-address` + 0x40000
9198

9299
FlashIAPBlockDevice fbd(MCUBOOT_PRIMARY_SLOT_START_ADDR + 0x40000, 0x20000);
93100
ret = fbd.init();

mcuboot.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/LDong-Arm/mcuboot.git/#03b472cb1800196a69e4878b5cdd7b529320d7d6
1+
https://github.com/AGlass0fMilk/mcuboot.git#ec30818cff735e5926f8dc30b8e354312f440b2f

0 commit comments

Comments
 (0)