This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using external flash to store updates for MCUboot & App on nRF5340 which the existing MCUBoot will apply

How do I store updated images for both MCUboot and the main App in external flash on the nRF5340 such that the existing MCUboot will apply the updates to the internal flash and execute them? Does the existing MCUboot codebase support this?


I have a nRF5340 with a MX25R6435F flash chip connected via QSPI. It is also connected to an LTE modem (nRF9160) via another SPI bus. The app on the 5340 will download any needed update data from the internet with custom code interfacing to the modem and write the needed update data to the external flash (this functionality is not part of my question here, assume the download and write to external flash of arbitrary data is working).


My main questions are:

  1. In what format do the updated MCUboot and App images need to be stored in external flash? (address offsets, etc.)
  2. Are any changes required to be made to the MCUboot codebase to support this?
  3. Are any additional configuration changes needed other than I what I have listed below?

I have configured my build system to use the B0 Immutable bootloader as the first-stage bootloader and MCUboot as an upgradeable second-stage bootloader. For the flash layout, I believe I have correctly configured the build for a single app image in internal flash, dual MCUboot image slots in internal flash, and the "mcuboot_secondary" slot in external flash. That all appears to be configured, build, and run correctly.

My goal for functionality is:

  1. The old App runs, downloads the updated image(s) to external flash, and triggers a reboot.
  2. The old MCUboot checks the external flash, detects that an update is available, and begins to copy them to internal flash...
  3. The updated MCUboot code is overwritten to the "other" MCUboot slot (the one not currently running).
  4. The updated App code is overwritten to the single App slot which had the old App code.
  5. The old MCUboot triggers a reboot.
  6. B0 detects the updated MCUboot in the "other" slot and executes it.
  7. The updated MCUboot runs and executes the updated App code.

I have read over some of the guides for DFU and bootloaders, but they seem to only apply to BLE updates not using external flash, or to LTE modem updates, or update MCUboot only but not the app; and aren't clear to me for how to achieve my goals. For example:

Device Firmware Upgrade module

Device Firmware Upgrade

Serial Recovery 

Adding an upgradable bootloader

I have tried to debug/follow the code of context_boot_go() in workspace/bootloader/mcuboot/boot/bootutil/src/loader.c:1780 to better understand how MCUboot works and its upgrade process, but it's not clear to me how it needs to read from the external flash.

My configuration is as follows

Using NCS 1.6.0

Flash layout from west tool:

prj.conf (relevant sections)

mcuboot.conf (applied to the MCUboot image in CMake system)

pm_static.yml

normal boot log

With some debug prints in MCUboot, I was able to see that MCUboot does at least open the external flash partition for access