!!!Partition alignment error!!!

Dear Nordic Engineers

I used gd25lq32e to replace mx25r6435 and it is a 32Mbit Flash, when I add it to the Devicetree of Lwmwm(NCS 2.6.1), the build will report the following log:

!!!Partition alignment error!!!
The non-secure start address in pm_static.yml or generated partition.yml is: 0x1be00
which is not aligned with the SPU HW requirements.
Refer to the documentation section 'TF-M partition alignment requirements'
for more information.

'
18 | #pragma message \
| ^~~~~~~
E:/NCS/v2.6.1/nrf/modules/trusted-firmware-m/tfm_boards/common/assert.c:27:2: error: #error "TF-M non-secure start address is not aligned to SPU HW requirements"
27 | #error "TF-M non-secure start address is not aligned to SPU HW requirements"
| ^~~~~
ninja: build stopped: subcommand failed.

I tried to set CONFIG_PM_PARTITION_SIZE_TFM=0x8000, but it didn't work.

This is my partitions.yml, please give me some good suggestions.

EMPTY_0:
  address: 0xf2000
  end_address: 0xf8000
  placement:
    after:
    - settings_storage
  region: flash_primary
  size: 0x6000
EMPTY_tfm_ps:
  address: 0xfc000
  end_address: 0x100000
  region: flash_primary
  size: 0x4000
app:
  address: 0x1be00
  end_address: 0xe8000
  region: flash_primary
  size: 0xcc200
external_flash:
  address: 0x4d4200
  end_address: 0x400000
  region: external_flash
  size: -0xd4200
fmfu_storage:
  address: 0xd4200
  align: 0x10000
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0x4d4200
  placement:
    before:
    - end
  region: external_flash
  size: 0x400000
mcuboot:
  address: 0x0
  end_address: 0x13e00
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0x13e00
mcuboot_pad:
  address: 0x13e00
  end_address: 0x14000
  placement:
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0x13e00
  end_address: 0xe8000
  orig_span: &id001
  - app
  - mcuboot_pad
  - tfm
  region: flash_primary
  size: 0xd4200
  span: *id001
mcuboot_primary_app:
  address: 0x14000
  end_address: 0xe8000
  orig_span: &id002
  - app
  - tfm
  region: flash_primary
  size: 0xd4000
  span: *id002
mcuboot_secondary:
  address: 0x0
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0xd4200
  placement:
    align:
      start: 0x4
  region: external_flash
  share_size:
  - mcuboot_primary
  size: 0xd4200
mcuboot_sram:
  address: 0x20000000
  end_address: 0x20016000
  orig_span: &id003
  - tfm_sram
  region: sram_primary
  size: 0x16000
  span: *id003
nonsecure_storage:
  address: 0xe8000
  end_address: 0xf2000
  orig_span: &id004
  - settings_storage
  - nvs_storage
  region: flash_primary
  size: 0xa000
  span: *id004
nrf_modem_lib_ctrl:
  address: 0x20016000
  end_address: 0x200164e8
  inside:
  - sram_nonsecure
  placement:
    after:
    - tfm_sram
    - start
  region: sram_primary
  size: 0x4e8
nrf_modem_lib_rx:
  address: 0x20018568
  end_address: 0x2001a568
  inside:
  - sram_nonsecure
  placement:
    after:
    - nrf_modem_lib_tx
  region: sram_primary
  size: 0x2000
nrf_modem_lib_sram:
  address: 0x20016000
  end_address: 0x2001a568
  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: 0x200164e8
  end_address: 0x20018568
  inside:
  - sram_nonsecure
  placement:
    after:
    - nrf_modem_lib_ctrl
  region: sram_primary
  size: 0x2080
nvs_storage:
  address: 0xe8000
  end_address: 0xf0000
  inside:
  - nonsecure_storage
  placement:
    align:
      start: 0x8000
    before:
    - settings_storage
  region: flash_primary
  size: 0x8000
otp:
  address: 0xff8108
  end_address: 0xff83fc
  region: otp
  size: 0x2f4
settings_storage:
  address: 0xf0000
  end_address: 0xf2000
  inside:
  - nonsecure_storage
  placement:
    align:
      start: 0x8000
    before:
    - end
  region: flash_primary
  size: 0x2000
sram_nonsecure:
  address: 0x20016000
  end_address: 0x20040000
  orig_span: &id006
  - sram_primary
  - nrf_modem_lib_ctrl
  - nrf_modem_lib_tx
  - nrf_modem_lib_rx
  region: sram_primary
  size: 0x2a000
  span: *id006
sram_primary:
  address: 0x2001a568
  end_address: 0x20040000
  region: sram_primary
  size: 0x25a98
sram_secure:
  address: 0x20000000
  end_address: 0x20016000
  orig_span: &id007
  - tfm_sram
  region: sram_primary
  size: 0x16000
  span: *id007
tfm:
  address: 0x14000
  end_address: 0x1be00
  inside:
  - mcuboot_primary_app
  placement:
    before:
    - app
  region: flash_primary
  size: 0x7e00
tfm_its:
  address: 0xf8000
  end_address: 0xfa000
  region: flash_primary
  size: 0x2000
tfm_nonsecure:
  address: 0x1be00
  end_address: 0xe8000
  orig_span: &id008
  - app
  region: flash_primary
  size: 0xcc200
  span: *id008
tfm_otp_nv_counters:
  address: 0xfa000
  end_address: 0xfc000
  region: flash_primary
  size: 0x2000
tfm_secure:
  address: 0x13e00
  end_address: 0x1be00
  orig_span: &id009
  - mcuboot_pad
  - tfm
  region: flash_primary
  size: 0x8000
  span: *id009
tfm_sram:
  address: 0x20000000
  end_address: 0x20016000
  inside:
  - sram_secure
  placement:
    after:
    - start
  region: sram_primary
  size: 0x16000
tfm_storage:
  address: 0xf8000
  end_address: 0x100000
  region: flash_primary
  size: 0x8000
  span:
  - EMPTY_tfm_ps
  - tfm_its
  - tfm_otp_nv_counters

Best regards,

Hannibal

  • Hi Hannibal,

    There are quite a few items here you will need to fix in your .dts and overlay.

    The first item is your external flash, which has a negative size in the generated partition layout. How did you set it up in your board files?

    Kind regards,
    Andreas

  • Hi Andreas

    1. I changed 2 overlay files of lwm2m/boards path and added the configure of gd25lq32e to them, as the following files.

    7607.nrf9160dk_nrf9160_ns_0_14_0.overlay1830.nrf9160dk_nrf9160_ns.overlay

    2. I changed an overlay file of lwm2m\child_image\mcuboot\boards path as same as the last step, this is the file. 

    nrf9160dk_nrf9160_0_14_0.overlay

    And then this is the zephyr.dts file from the build/zephyr path.  

    0488.zephyr.dts

    Is there any problem with this configuration?

    Best regards,

    Hannibal

  • At first lookthrough the files look ok.

    Them moving on to the second item, the CONFIG_PM_PARTITION_SIZE_TFM:

    You need to change the size of the TF-M partition so that it follows the requirement that the secure and non-secure partition addresses are aligned with the TrustZone flash region size This can be done by changing CONFIG_PM_PARTITION_SIZE_TFM.

    From a discussion with my colleague, the following example should explain how you can achieve this: For example if the default value in the sample you've based your application on is set to 0x20000 in the sample, such that the TF-M partition is from 0x0 to 0x20000, with tfm_secure starting at 0x0 and tfm_nonsecure starting at 0x20000 so that they are both aligned to 0x4000:

    However, when you add MCUboot to your project, partition manager will add an MCUboot partition from 0x0 to 0xc000, causing TF-M to start at 0xc000 instead. This will shift tfm_secure in such a way that the start of tfm_nonsecure will no longer be aligned with 0x4000, so you need to change the size of TF-M to ensure that both tfm_secure and tfm_nonsecure are still aligned.

    Kind regards,
    Andreas

  • Hi Andreas

    I tried to set CONFIG_PM_PARTITION_SIZE_TFM=0x8000 and 0x10000, but it didn't improve.

    This is the build log while I set CONFIG_PM_PARTITION_SIZE_TFM=0x10000

    !!!Partition alignment error!!!
    The non-secure start address in pm_static.yml or generated partition.yml is: 0x24000
    which is not aligned with the SPU HW requirements.
    Refer to the documentation section 'TF-M partition alignment requirements'
    for more information.
    
    '
    18 | #pragma message \
    | ^~~~~~~
    E:/NCS/v2.6.1/nrf/modules/trusted-firmware-m/tfm_boards/common/assert.c:27:2: error: #error "TF-M non-secure start address is not aligned to SPU HW requirements"
    27 | #error "TF-M non-secure start address is not aligned to SPU HW requirements"
    | ^~~~~
    ninja: build stopped: subcommand failed.

    This is the partitions.yml file.

    EMPTY_0:
      address: 0xf2000
      end_address: 0xf8000
      placement:
        after:
        - settings_storage
      region: flash_primary
      size: 0x6000
    EMPTY_tfm_ps:
      address: 0xfc000
      end_address: 0x100000
      region: flash_primary
      size: 0x4000
    app:
      address: 0x24000
      end_address: 0xe8000
      region: flash_primary
      size: 0xc4000
    external_flash:
      address: 0x4d4200
      end_address: 0x400000
      region: external_flash
      size: -0xd4200
    fmfu_storage:
      address: 0xd4200
      align: 0x10000
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0x4d4200
      placement:
        before:
        - end
      region: external_flash
      size: 0x400000
    mcuboot:
      address: 0x0
      end_address: 0x13e00
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x13e00
    mcuboot_pad:
      address: 0x13e00
      end_address: 0x14000
      placement:
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x13e00
      end_address: 0xe8000
      orig_span: &id001
      - tfm
      - mcuboot_pad
      - app
      region: flash_primary
      size: 0xd4200
      span: *id001
    mcuboot_primary_app:
      address: 0x14000
      end_address: 0xe8000
      orig_span: &id002
      - app
      - tfm
      region: flash_primary
      size: 0xd4000
      span: *id002
    mcuboot_secondary:
      address: 0x0
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0xd4200
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0xd4200
    mcuboot_sram:
      address: 0x20000000
      end_address: 0x20016000
      orig_span: &id003
      - tfm_sram
      region: sram_primary
      size: 0x16000
      span: *id003
    nonsecure_storage:
      address: 0xe8000
      end_address: 0xf2000
      orig_span: &id004
      - settings_storage
      - nvs_storage
      region: flash_primary
      size: 0xa000
      span: *id004
    nrf_modem_lib_ctrl:
      address: 0x20016000
      end_address: 0x200164e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - tfm_sram
        - start
      region: sram_primary
      size: 0x4e8
    nrf_modem_lib_rx:
      address: 0x20018568
      end_address: 0x2001a568
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_tx
      region: sram_primary
      size: 0x2000
    nrf_modem_lib_sram:
      address: 0x20016000
      end_address: 0x2001a568
      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: 0x200164e8
      end_address: 0x20018568
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_ctrl
      region: sram_primary
      size: 0x2080
    nvs_storage:
      address: 0xe8000
      end_address: 0xf0000
      inside:
      - nonsecure_storage
      placement:
        align:
          start: 0x8000
        before:
        - settings_storage
      region: flash_primary
      size: 0x8000
    otp:
      address: 0xff8108
      end_address: 0xff83fc
      region: otp
      size: 0x2f4
    settings_storage:
      address: 0xf0000
      end_address: 0xf2000
      inside:
      - nonsecure_storage
      placement:
        align:
          start: 0x8000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_nonsecure:
      address: 0x20016000
      end_address: 0x20040000
      orig_span: &id006
      - sram_primary
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x2a000
      span: *id006
    sram_primary:
      address: 0x2001a568
      end_address: 0x20040000
      region: sram_primary
      size: 0x25a98
    sram_secure:
      address: 0x20000000
      end_address: 0x20016000
      orig_span: &id007
      - tfm_sram
      region: sram_primary
      size: 0x16000
      span: *id007
    tfm:
      address: 0x14000
      end_address: 0x24000
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0x10000
    tfm_its:
      address: 0xf8000
      end_address: 0xfa000
      region: flash_primary
      size: 0x2000
    tfm_nonsecure:
      address: 0x24000
      end_address: 0xe8000
      orig_span: &id008
      - app
      region: flash_primary
      size: 0xc4000
      span: *id008
    tfm_otp_nv_counters:
      address: 0xfa000
      end_address: 0xfc000
      region: flash_primary
      size: 0x2000
    tfm_secure:
      address: 0x13e00
      end_address: 0x24000
      orig_span: &id009
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0x10200
      span: *id009
    tfm_sram:
      address: 0x20000000
      end_address: 0x20016000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x16000
    tfm_storage:
      address: 0xf8000
      end_address: 0x100000
      region: flash_primary
      size: 0x8000
      span:
      - EMPTY_tfm_ps
      - tfm_its
      - tfm_otp_nv_counters
    

    So, do you have other good suggestions?

    Best regards,

    Hannibal

  • Hi,

    In your build log it is clearly written where you need to look next:

    "The non-secure start address in pm_static.yml or generated partition.yml is: 0x24000
    which is not aligned with the SPU HW requirements.
    Refer to the documentation section 'TF-M partition alignment requirements'
    for more information."

    Please have a look at the TF-M documentation it refers to: https://docs.nordicsemi.com/bundle/ncs-2.6.1/page/nrf/security/tfm.html 

    Kind regards,
    Andreas

Related