This folder contains an example of MCUboot to be used on DevKits containing Alif Ensemble E1-E7 along with example applications that can be loaded to demonstrate update functionality.
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 and manage the application of M55 HE core.
Currently, this example supports only OVERWRITE and SWAP 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.
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.
- 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.
- 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, UART4 is used by default. 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 list
command, 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 update
in 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: 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: 29808.
Example app running! << Example app print, see example_app/src/main.c
PRIMARY slot:
offset: 0x80010000
size: 0x10000
magic: 1
swap_type: 1
copy_done: 2
image_ok: 1
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: 1
swap_type: 1
copy_done: 2
image_ok: 1
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
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: 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.
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.