FOTA with mcuboot & external flash slot-2, scratch algorithm

Hi,

This is more of a bug-report than really a help question, as it can be dealt with.

The device I am developing uses an external flash for storing MCUBoot's slot-2, such FOTA update functionality with LwM2M not slashes the internal flash available for user program code in half. This mechanism is verified to work, my signed application image correctly appears in the external flash chip.

If I intentionally corrupt this image before transmission, verification fails and the bootloader attempts no swap. This makes it highly likely that transmission, storage & reading of the external flash as well as image verification does exactly what it needs do: There's only a swap with a correct image, meaning data is read from external flash.

I swap slot-1 (on nRF internal flash) and slot-2 (on SPI external flash) using the scratch algorithm.

Everything works fine with NCS v3.0.2, but breaks when upgrading to v3.1.0 or v3.1.1.

MCUBoot as provided by NCS v3.0.2 is revision: ae1ee57f (works)
MCUBoot as provided by NCS v3.1.1 is revision: 9b4ae4cb (broken)

I have verified the problem really is with MCUBoot, as checking out (and doing west update & all that) NCS v3.1.1 but with MCUBoot at revision ae1ee57f (as was shipped with NCS v3.0.2) yields me a perfectly working FOTA mechanism.

I'm currently in the process of comparing both revisions but haven't found a smoking gun yet. I will reply below if I find something myself.

I also need find a way for pinning a west module (MCUBoot) to a specific version in ncs/manifest/west.yml or something (my own files) even though ncs/nrf/west.yml (which comes out of a git repo, which west update then uses as starting point for checking out other repo's) has another version listed. If I find an elegant solution for this workaround I will reply below as well.

  • I'm glad to hear that it works now, thanks for the update. But it's surprising that you are experiencing these problems with the swap algorithms. Did you try the default one as well (i..e swap without scratch)? 

  • Due to differences in page size between the nRF internal flash and my external SPI flash chip, effectively having a scratch partition was my only option.

    So, it was sysbuild.conf:SB_CONFIG_MCUBOOT_MODE_SWAP_SCRATCH=y & sysbuild/mcuboot/prj.conf:CONFIG_BOOT_SWAP_USING_SCRATCH=y after all.

    I did however move my scratch partition to external flash now, to free up some more space in the program memory.

    For those readers wanting to know how that looks like, here's my pm_static.yml:

    mcuboot:
      address: 0x0
      size: 0x10000
    
    mcuboot_pad:
      address: 0x10000
      placement:
        align: {start: 4096}
      size: 0x200
    
    mcuboot_primary:
      address: 0x10000
      span:
      - mcuboot_pad
      - app
      - tfm
      size: 0xF0000
    
    mcuboot_secondary:
      address: 0x0
      placement:
        align: {start: 256}
      size: 0xF0000
      region: external_flash
    
    mcuboot_scratch:
      address: 0xF0000
      placement:
        after: mcuboot_secondary
        align: {start: 256}
      size: 0x20000
      region: external_flash
    
    external_data:
      address: 0x110000
      placement:
        after: mcuboot_scratch
        before: end
      region: external_flash
      size: 0x6F0000
    

Related