This folder contains an example to perform FOTA (application update) using MCUboot and mcumgr to be used with Alif Ensemble DevKit. Included applications are Bootloaders for both cores that are responsible for handling the applying the updates, Example application running in M55_HE that handles transporting the update to the device and Blinky application that represents application running on M55_HP.
Example verification public key has been generated from the MCUboot default RSA2048 private key. NOTE! This key is NOT suitable for production as it's distributed publicly as example key for MCUboot!
This example is built to work on M55 HE and (optionally) M55 HP core(s). M55 HE acts as the update dowloader, storing the updates into MCUboot's secondary slots.
By default, both cores will apply the update via their respective bootloaders. If HE_UPDATES_BOTH is set to true in CMAKE configuration, HE bootloader will instruct the HP to shut down and then applies the update to both cores. In this scenario HP bootloader only validates the image before jumping into it.
Currently, this example supports OVERWRITE, SWAP and RAM_LOAD modes (see Bootloader design). Only supported storage is internal MRAM. Verification is supported with embedded key and enabled by default but encryption is not supported.
The update can be uploaded to the device and scheduled for updating by three different methods. Using mcumgr-cli though uart or usb, direct writing to MRAM by debugger or by writing the update via Alif Security Toolkit.
+-------------------+ 0x8000 0000
| |
| HE Bootloader |
| |
+-------------------+ 0x8001 0000
| |
| HE primary slot |
| |
+-------------------+ 0x8002 0000
| |
| HE secondary slot |
| |
+-------------------+ 0x8003 0000
| |
| HE Scratch area |
| |
+-------------------+ 0x8003 1000
. .
+-------------------+ 0x8003 F000
| |
| HP Scratch area | (HP scratch area is not in use if HE_UPDATES_BOTH=ON)
| |
+-------------------+ 0x8004 0000
| |
| HP Bootloader |
| |
+-------------------+ 0x8005 0000
| |
| HP primary slot |
| |
+-------------------+ 0x8006 0000
| |
| HP secondary slot |
| |
+-------------------+ 0x8007 0000
| |
| SERAM primary | (HE_UPDATES_BOTH=ON and HP_UPDATES_SERAM=ON)
| |
+-------------------+ 0x800C 0000
| |
| SERAM secondary | (HE_UPDATES_BOTH=ON and HP_UPDATES_SERAM=ON)
| |
+-------------------+ 0x8057 FFFF
In RAM_LOAD configuration, the layout of the MRAM remains the same as above but the image from the MRAM is loaded into the core's ITCM.
+-------------------+ 0x0000 0000
| |
| EMPTY (*) |
| |
+-------------------+ 0x0000 0800
| |
| Image header |
| |
+-------------------+ 0x0000 1000
| |
| Application image |
| |
+-------------------+ 0x0001 0000
. .
+-------------------+ <end of ITCM>
* = Due to the way the image signing tool works, RAM_LOAD target cannot start from address 0x0 so empty space is left in the beginning so that Application Image starts from next suitable address given the Vector table alignment requirement of Cortex-M55.
This folder contains CMakeLists.txt for the project.
- Install and add to PATH:
- cmake 3.19 or above
- build tool (make/nmake)
- gcc-arm-none-eabi compiler (version 12.3 or above)
- Python 3
- Install the MCUboot imgtool requirements from libs/mcuboot/scripts/requirements.txt (
pip install -r libs/mcuboot/scripts/requirements.txt). - Create build folder and enter it. (
mkdir build; cd build). - Run cmake [path_to_this_folder]. (
cmake ..). - Run compilation command (depends on the selected generator of cmake; by default make for Linux and nmake for Windows). (
make) - The built elf-file, binary and map file will be generated in the bin directory under the build folder. Example applications are signed automatically.
- OPTIONAL: Install Go, download mcumgr-cli and follow building instruction from associated README.md to issue update commands via mcumgr-cli.
To build RAM_LOAD configuration, add parameter -DMCUBOOT_MODE=RAM_LOAD to cmake command.
The RAM_LOAD configuration does not support / require image test and confirmation, the later image is always loaded. All uploads will be stored to the secondary slot preserving the initial flashed application as 'golden image' in primary slot.
Default board is DevKit-7. To build with another Alif board, for example DevKit-e8, add the following after cmake .. : -DTARGET_BOARD=DevKit-e8. Available board values: AppKit-e7, DevKit-e1c, DevKit-e4, DevKit-e7 and DevKit-e8.
- Build the MCUboot application and example applications, see Building.
- Write MCUboot application and the signed example application to internal MRAM using Alif Security Toolkit. See alif_mcuboot.json in this folder.
- Observe logs from UART2 and UART4, serial settings 115200-8-N-1, to verify the applications are running.
- Build the project with selected transport mechanism. Uart is built by default, usb transport mechanism can be configured with
cmake .. -DTRANSPORT=usb. - Establish connection between your computer and the development board. For uart, UART3 is used by default. This requires attaching an FTDI cable to pins P1_2 and P1_3 (or P2_4 and P2_5 on E1C) on the board. For usb, attach an usb cable to 'SoC USB' port.
- Create connection profile for the mcumgr-cli, for example:
mcumgr conn add uart type=serial connstring="dev=/dev/ttyACM0,baud=115200". Connection type and baud rate are same for uart and usb connections. - Test the connection between mcumgr-cli and the device:
mcumgr -cuart echo "Echo test". The command should print out 'Echo test' to indicate the device returned same string it was sent.
-
Query existing images on the device:
mcumgr -cuart image list. -
Upload the update:
mcumgr -cuart image upload build/bin/alif-example-app-update_signed.bin -w1. -
Query existing images on the device:
mcumgr -cuart image list.$ ./mcumgr -cuart image list Images: image=0 slot=0 version: 1.0.0 bootable: true flags: active confirmed hash: 06147dfeb20df969eeea5b01028ec6635a9a54adea43035997a050618417cb97 image=0 slot=1 version: 2.0.0 bootable: true flags: hash: 5d2f3bf869e7aafd29825a932e285daafc42ac7aaa00958096dfde09dd3c2fb9 Split status: N/A (0)
- Mark the image to be test-booted on next reset:
mcumgr -cuart image test <hash>.- The image hash can be seen in the output of the
mcumgr -cuart image listcommand, under image= 0 slot=1
- The image hash can be seen in the output of the
- Reset the device:
mcumgr -cuart reset. - Validate new image is running:
mcumgr -cuart image list.
- After update, query existing images on the device:
mcumgr -cuart image list. - Reset the device:
mcumgr -cuart reset. - Validate the old firmware is now running:
mcumgr -cuart image list.
- After update, query existing images on the device:
mcumgr -cuart image list. - Confirm the update so it won't be reverted on next reset:
mcumgr -cuart image confirm <hash>.- The hash for this command is the same as given to
mcumgr -cuart image test <hash>-command in Setting the update pending and updating the application-phase. At this point, it can be seen under image=0 slot=0 in themcumgr -cuart image list-command.
- The hash for this command is the same as given to
- Reset the device:
mcumgr -cuart reset. - Validate new image is still running:
mcumgr -cuart image list.
This flow can be used to inspect the application-side logic only. Debugger writing directly to the MRAM is used as transport layer.
- Ensure JLink folder is in the path when running cmake.
- Run
make updatein the build directory. - Observe the logs from UART2, the application should indicate update is available to be set pending.
- Write [build_folder]/bin/alif-example-app-update_signed.bin into address 0x80020000 with any tool.
- Reboot the board/SoC by pressing SW2 (RESET).
- Observe the logs from UART2, the application should indicate update is available to be set pending.
- Press the SW1 button on the development board to set the update pending.
- Reboot the board/SoC by pressing SW2 (RESET).
- Observe logs from UART2, the blinking led also changes to different color blink.
- After update, observe logs from UART2.
- Reboot the board/SoC by pressing SW2 (RESET) without pressing the SW1 button on the development board.
- Observe logs from UART2, the blinking led also changes to different color blink when original image is loaded again.
- The update can be set pending again by pressing the SW1 button on the development board.
- Press the SW1 button on the development board after update has been done.
- Reboot the board/SoC by pressing SW2 (RESET).
- Observe logs from UART2, updated image is loaded consistently through resets.
In this flow, both the 'initial' example application and the update candidate is written using Alif Security Toolkit.
- Use alif_mcuboot_with_update.json as Alif Security Toolkit atoc configuration file.
- Observe the logs from UART2, the application should indicate update is available to be set pending.
- Press the SW1 button on the development board to set the update pending.
- Reboot the board/SoC by pressing SW2 (RESET).
- Observe logs from UART2, the blinking led also changes to different color blink.
INF: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
INF: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
INF: Boot source: primary slot
INF: Image index: 0, Swap type: none << Internal MCUboot logging
Loading image, version 1.0.0 (build: 0) << Bootloader app prints, see bootloader_app/src/main.c
image size: 38112.
Example app running! << Example app print, see example_app/src/main.c
PRIMARY slot:
offset: 0x80010000
size: 0x10000
magic: 3
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 0
version: 1.0.0
SECONDARY slot:
offset: 0x80020000
size: 0x10000
magic: 3
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 0
ERR: Bad image magic 0x0
No update available.
INF: Image index: 0, Swap type: none << Internal MCUboot logging
Loading image, version 1.0.0 (build: 0) << Bootloader app prints, see bootloader_app/src/
image size: 29808.
Example app running! << Example app print, see example_app/src/main.c
PRIMARY slot:
offset: 0x80010000
size: 0x10000
magic: 3
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 3
version: 1.0.0
SECONDARY slot:
offset: 0x80020000
size: 0x10000
magic: 3
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 0
version: 2.0.0
Press button to pend update.
INF: Image index: 0, Swap type: perm << Internal MCUboot logging
INF: Image 0 upgrade secondary slot -> primary slot
INF: Erasing the primary slot
INF: Image 0 copying the secondary slot to the primary slot: 0xzx bytes
DBG: writing magic; fa_id=1 off=0xfff0 (0x8001fff0)
DBG: erasing secondary header
DBG: erasing secondary trailer
Loading image, version 2.0.0 (build: 0) << Bootloader app prints, see bootloader_app/src/
image size: 29808.
Updated app running! << Example app print, see example_app/src/main.c
PRIMARY slot:
offset: 0x80010000
size: 0x10000
magic: 1
swap_type: 2
copy_done: 1
image_ok: 3
image_num: 0
version: 2.0.0
SECONDARY slot:
offset: 0x80020000
size: 0x10000
magic: 3
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 0
ERR: Bad image magic 0x0
No update available.
INF: Image index: 0, Swap type: none << Internal MCUboot logging
Loading image, version 2.0.0 (build: 0) << Bootloader app prints, see bootloader_app/src/
image size: 29808.
Updated app running! << Example app print, see example_app/src/main.c
PRIMARY slot:
offset: 0x80010000
size: 0x10000
magic: 1
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 0
version: 2.0.0
SECONDARY slot:
offset: 0x80020000
size: 0x10000
magic: 3
swap_type: 1
copy_done: 3
image_ok: 3
image_num: 0
ERR: Bad image magic 0x0
No update available.
To use the SERAM update feature, the following criteria must be met:
- Both HE_UPDATES_BOTH and HP_UPDATES_SERAM must be enabled.
- A full SERAM update image, with a version matching the one currently running on the device, must be signed using imgtool.py.
- The signed SERAM update image with the matching version must be placed in image 2, slot 0 (0x80070000).
- A full SoC reset is required to perform a test boot e.g., by pressing the physical reset button.