How to select page size when using MCUboot with external flash memory?

Hi!

I'm using an external flash (SPI NOR) to store the secondary partition slot of MCUboot. According to datasheet, the SPI NOR chip in use supports 4KB, 32KB and 64KB paging. Despite this, if I set any other value than 4096 for CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE, MCUboot fails to load. Everywhere I look, I see people using or suggesting to use pages with 4096, but cannot understand the underlying reason. One guess I can take is that paging needs to match between the internal (nrf9151) and external flash, but I can't find any info to sustain this hypothesis.

[00:00:00.782,562] <inf> lwm2m_firmware: Image is confirmed OK                                                                              
[00:00:00.782,562] <inf> lwm2m_firmware: Firmware failed to be updated 

  • Hello,

    do you have a pm_static.yml file? Can you show what it looks like?

  • Be aware, my pm_static.yml is a copy from the auto-generated one.

    EMPTY_0:
      address: 0xc000
      end_address: 0x10000
      placement:
        before:
        - mcuboot_pad
      region: flash_primary
      size: 0x4000
    EMPTY_1:
      address: 0xfa000
      end_address: 0x100000
      placement:
        after:
        - settings_storage
      region: flash_primary
      size: 0x6000
    app:
      address: 0x18000
      end_address: 0xf8000
      region: flash_primary
      size: 0xe0000
    external_flash:
      address: 0xe8000
      end_address: 0x400000
      region: external_flash
      size: 0x318000
    mcuboot:
      address: 0x0
      end_address: 0xc000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0xc000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x8000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0xf8000
      orig_span: &id001
      - app
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0xe8000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xf8000
      orig_span: &id002
      - app
      - tfm
      region: flash_primary
      size: 0xe7e00
      span: *id002
    mcuboot_secondary:
      address: 0x0
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0xe8000
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0xe8000
    mcuboot_sram:
      address: 0x20000000
      end_address: 0x20008000
      orig_span: &id003
      - tfm_sram
      region: sram_primary
      size: 0x8000
      span: *id003
    nonsecure_storage:
      address: 0xf8000
      end_address: 0xfa000
      orig_span: &id004
      - settings_storage
      region: flash_primary
      size: 0x2000
      span: *id004
    nrf_modem_lib_ctrl:
      address: 0x20008000
      end_address: 0x200084e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - tfm_sram
        - start
      region: sram_primary
      size: 0x4e8
    nrf_modem_lib_rx:
      address: 0x2000a568
      end_address: 0x2000c568
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_tx
      region: sram_primary
      size: 0x2000
    nrf_modem_lib_sram:
      address: 0x20008000
      end_address: 0x2000c568
      orig_span: &id005
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x4568
      span: *id005
    nrf_modem_lib_tx:
      address: 0x200084e8
      end_address: 0x2000a568
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_ctrl
      region: sram_primary
      size: 0x2080
    otp:
      address: 0xff8108
      end_address: 0xff83fc
      region: otp
      size: 0x2f4
    settings_storage:
      address: 0xf8000
      end_address: 0xfa000
      inside:
      - nonsecure_storage
      placement:
        align:
          start: 0x8000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_nonsecure:
      address: 0x20008000
      end_address: 0x20040000
      orig_span: &id006
      - sram_primary
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x38000
      span: *id006
    sram_primary:
      address: 0x2000c568
      end_address: 0x20040000
      region: sram_primary
      size: 0x33a98
    sram_secure:
      address: 0x20000000
      end_address: 0x20008000
      orig_span: &id007
      - tfm_sram
      region: sram_primary
      size: 0x8000
      span: *id007
    tfm:
      address: 0x10200
      end_address: 0x18000
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0x7e00
    tfm_nonsecure:
      address: 0x18000
      end_address: 0xf8000
      orig_span: &id008
      - app
      region: flash_primary
      size: 0xe0000
      span: *id008
    tfm_secure:
      address: 0x10000
      end_address: 0x18000
      orig_span: &id009
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0x8000
      span: *id009
    tfm_sram:
      address: 0x20000000
      end_address: 0x20008000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x8000

  • I think I finally found out the reason behind it. But maybe some confirmation from your side would also be good :D

    I think it has to do with the boot swap method I'm using (BOOT_PREFER_SWAP_MOVE) which requires "all sectors in both slots being of the same size". And since pages on internal flash have 4096KiB, that's why I only can use such value on the external flash with secondary slot.

  • That seems like a very plausible reason indeed.

Related