Thingy91 nRF9160 SDK v2.6.1 TF-M Partition Alignment Error For Static Partitions

Relates to: Thingy91 nRF9160 SDK v2.6.1

I am having trouble successfully extending the size of the tfm partition. I took a sample static partition file from nrf\boards\arm\thingy91_nrf9160\thingy91_pm_static.yml. I was successful in building and flashing with this static partition file. 

app: {address: 0x18000, size: 0x5b000}
mcuboot:
  address: 0x0
  placement:
    before: [mcuboot_primary]
  size: 0xc000
mcuboot_pad:
  address: 0xc000
  placement:
    align: {start: 0x1000}
    before: [mcuboot_primary_app]
  size: 0x200
mcuboot_primary:
  address: 0xc000
  size: 0x69000
  span: [tfm, mcuboot_pad, app]
mcuboot_primary_app:
  address: 0xc200
  size: 0x68e00
  span: [app, tfm]
mcuboot_scratch:
  address: 0xde000
  placement:
    after: [app]
    align: {start: 0x1000}
  size: 0x1e000
mcuboot_secondary:
  address: 0x75000
  placement:
    after: [mcuboot_primary]
    align: {start: 0x1000}
  share_size: [mcuboot_primary]
  size: 0x69000
EMPTY_0:
  address: 0xfc000
  size: 0x2000
settings_storage:
  address: 0xfe000
  placement:
    after: [mcuboot_scratch]
  size: 0x2000
nonsecure_storage:
  address: 0xfe000
  size: 0x2000
  span: [settings_storage]
tfm_secure:
  address: 0xc000
  size: 0xc000
  span: [mcuboot_pad, tfm]
tfm_nonsecure:
  address: 0x18000
  size: 0x5b000
  span: [app]
tfm:
  address: 0xc200
  size: 0xbe00


I attempted to expand the size of the tfm partition for debugging the project after configuring the project with the following configurations.

CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_SIZE_OPTIMIZATIONS=n

# modified the addres based on the tfm address plus size
app: {address: 0x24000, size: 0x5b000}
mcuboot:
  address: 0x0
  placement:
    before: [mcuboot_primary]
  size: 0xc000
mcuboot_pad:
  address: 0xc000
  placement:
    align: {start: 0x1000}
    before: [mcuboot_primary_app]
  size: 0x200
mcuboot_primary:
  address: 0xc000
  size: 0x75000
  span: [tfm, mcuboot_pad, app]
mcuboot_primary_app:
  address: 0xc200
  # modified the size based on app and tfm sizes
  size: 0x74e00
  span: [app, tfm]
mcuboot_scratch:
  # modified based on mcuboot_secondary address plus size
  address: 0xe2000
  placement:
    after: [app]
    align: {start: 0x1000}
  size: 0x1e000
mcuboot_secondary:
  # modified based on tfm_nonsecure (includes the previous padding of 0x2000)
  address: 0x81000
  placement:
    after: [mcuboot_primary]
    align: {start: 0x1000}
  share_size: [mcuboot_primary]
  # Reduced in size to fit into 0x100000 of primary flash
  size: 0x61000
EMPTY_0:
  # modified based on mcuboot_scratch address plus size
  address: 0xfe000
  size: 0x0
settings_storage:
  # modified based on EMPTY_0 address plus size
  address: 0xfe000
  placement:
    after: [mcuboot_scratch]
  size: 0x2000
nonsecure_storage:
  # modified based on EMPTY_0 address plus size
  address: 0xfe000
  size: 0x2000
  span: [settings_storage]
tfm_secure:
  address: 0xc000
  # modified to be the sum of the sizes of mcuboot_pad and tfm
  size: 0x17e00
  span: [mcuboot_pad, tfm]
tfm_nonsecure:
  # modified to be the address plus the size of tfm_secure
  address: 0x23e00
  size: 0x5b00
  span: [app]
tfm:
  address: 0xc200
  # modified from size 0xbe00
  size: 0x17c00


My build configuration is as follows.


When building, I get the following error related to the static partition. #error "TF-M non-secure start address is not aligned to SPU HW requirements"



Note that I intended to set the tfm_nonsecure start address to 0x24000. After reading related threads RE: "Partition alignment error" after upgrading the SDK from v2.2.0 to v2.5.0
I attempted different starting addresses: 0x24000, 0x23e00, 0x24200. Changing to these starting addresses did not seem to fix the issue. 

What might be a solution here? 
  • Hello, 

    I have been assigned your ticket and will investigate the issue. I will respond to you within tomorrow or Thursday with a possible solution. 

    Kind regards,
    Øyvind

  • Hello, and my sincere apologies for the late reply. 

    Have you been able to solve the issue? If not, have read through the documentation on TF-M partition alignment requirements?

    Kind regards,
    Øyvind

  • Hello, I got it working now. I had seen this documentation, and I incorrectly assumed that CONFIG_NRF_SPU_FLASH_REGION_SIZE was 0x4000 instead of 0x8000. The following static partition file was able to work. 

    # Obtained from nrf\boards\arm\thingy91_nrf9160\thingy91_pm_static.yml
    
    # author: gguadiana
    # This is a file that sets the partition file. To be used, the build configuration should be set
    # to sysbuild. The mappings can be configured based on your needs. This file is automatically
    # detected when it is present in the root directory of the app.
    
    # modified the addres based on the tfm address plus size
    app: {address: 0x28000, size: 0x5b000}
    mcuboot:
      address: 0x0
      placement:
        before: [mcuboot_primary]
      size: 0xc000
    mcuboot_pad:
      address: 0xc000
      placement:
        align: {start: 0x1000}
        before: [mcuboot_primary_app]
      size: 0x200
    mcuboot_primary:
      address: 0xc000
      # modified based on the start address of mcuboot_secondary
      size: 0x79000
      span: [tfm, mcuboot_pad, app]
    mcuboot_primary_app:
      address: 0xc200
      # modified the size based on app and tfm sizes
      size: 0x78e00
      span: [app, tfm]
    mcuboot_scratch:
      # modified based on mcuboot_secondary address plus size
      address: 0xe2000
      placement:
        after: [app]
        align: {start: 0x1000}
      size: 0x1e000
    mcuboot_secondary:
      # modified based on tfm_nonsecure (includes the previous padding of 0x2000)
      address: 0x85000
      placement:
        after: [mcuboot_primary]
        align: {start: 0x1000}
      share_size: [mcuboot_primary]
      # Reduced in size to fit into 0x100000 of primary flash
      size: 0x77000
    EMPTY_0:
      # modified based on mcuboot_scratch address plus size
      address: 0xfc000
      size: 0x2000
    settings_storage:
      # modified based on EMPTY_0 address plus size
      address: 0xfe000
      placement:
        after: [mcuboot_scratch]
      size: 0x2000
    nonsecure_storage:
      # modified based on EMPTY_0 address plus size
      address: 0xfe000
      size: 0x2000
      span: [settings_storage]
    tfm_secure:
      address: 0xc000
      # modified to be the sum of the sizes of mcuboot_pad and tfm
      size: 0x1c000
      span: [mcuboot_pad, tfm]
    # Due to alignment constraints, this must be a multiple of CONFIG_NRF_SPU_FLASH_REGION_SIZE (0x8000)
    tfm_nonsecure:
      # modified to be the address plus the size of tfm_secure
      address: 0x28000
      size: 0x5b000
      span: [app]
    tfm:
      address: 0xc200
      # @dev: modifications to the static partition file came from wanting to increment the tfm size
      # modified from size 0xbe00
      size: 0x1be00
    
    

Related