partition manager doesn't place the modem shared memory correctly, pm_static.yml required?

I am currently trying to port an application derived from multiple samples to nrf9160dk_nrf9160_ns.  I'm running into an issue with the modem shlib:

error: static assertion failed: "The libmodem shmem configuration exceeds the range of memory readable by the Modem core"
81 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)

From another thread it appears this happens when the partition manager places the modem shared memory beyond the first 128-k of sram.

In my application, I am trying to delay switching to static partition management until the expected sizes of the tfm and application are better understood, since each time a region changes there tends to be multiple cascading changes in hardcoded addresses.

I have found that the partition manager places the shared modem region into non-secure sram region (sram_nonsecure) which is placed after the tfm_sram region which happens to be larger than 128k.  

If possible I would like to find a way to get the modem shared space placed in the first 128k WITHOUT locking the rest of the SRAM into rigid/fixed sizes and definitely without locking the flash partitioning. 

 Is there any way to tell partition manager the modem shared memory needs to be placed  in the first 128KB of SRAM?

I'm guessing that the minimal configuration for tfm reduces the  sram partition.  How can I determine the actual memory needed by my non-minimal TFM configuration.. perhaps TFM can get by with less than the 0x46000

Parents
  • Hi,

     

    Could you share your build-folder/partitions.yml file?

     

     Is there any way to tell partition manager the modem shared memory needs to be placed  in the first 128KB of SRAM?

    Here's an example of "ninja partition_manager_report" from the stock "udp" sample:

      sram_primary (0x40000 - 256kB): 
    +--------------------------------------------------+
    +---0x20000000: sram_secure (0x8000 - 32kB)--------+
    | 0x20000000: tfm_sram (0x8000 - 32kB)             |
    +---0x20008000: sram_nonsecure (0x38000 - 224kB)---+
    +---0x20008000: nrf_modem_lib_sram (0x4568 - 17kB)-+
    | 0x20008000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
    | 0x200084e8: nrf_modem_lib_tx (0x2080 - 8kB)      |
    | 0x2000a568: nrf_modem_lib_rx (0x2000 - 8kB)      |
    +--------------------------------------------------+
    | 0x2000c568: sram_primary (0x33a98 - 206kB)       |
    +--------------------------------------------------+
    

    I suspect there's another reason why the static assertion is being triggered here, probably related to one or more of the nrf_modem_lib* region sizes or the tfm_sram region.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Could you share your build-folder/partitions.yml file?

     

     Is there any way to tell partition manager the modem shared memory needs to be placed  in the first 128KB of SRAM?

    Here's an example of "ninja partition_manager_report" from the stock "udp" sample:

      sram_primary (0x40000 - 256kB): 
    +--------------------------------------------------+
    +---0x20000000: sram_secure (0x8000 - 32kB)--------+
    | 0x20000000: tfm_sram (0x8000 - 32kB)             |
    +---0x20008000: sram_nonsecure (0x38000 - 224kB)---+
    +---0x20008000: nrf_modem_lib_sram (0x4568 - 17kB)-+
    | 0x20008000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
    | 0x200084e8: nrf_modem_lib_tx (0x2080 - 8kB)      |
    | 0x2000a568: nrf_modem_lib_rx (0x2000 - 8kB)      |
    +--------------------------------------------------+
    | 0x2000c568: sram_primary (0x33a98 - 206kB)       |
    +--------------------------------------------------+
    

    I suspect there's another reason why the static assertion is being triggered here, probably related to one or more of the nrf_modem_lib* region sizes or the tfm_sram region.

     

    Kind regards,

    Håkon

Children
  • I believe the issue is that my TF-M is not using the minimal configuration since I want to add a custom service in a ARoT partition and also I am using ITS with encryption as well as PSA Crypto.

    I suspect the minimal TF-M shrinks the sram and flash size. 

    Where can I find the modifications for TF-M minimal mode?

    I was able to workaround this issue after adding this config for nrf9160 builds:

    #reduce TFM sram partition so the modem shared memory can be placed with the first 128-KB
    CONFIG_PM_PARTITION_SIZE_TFM_SRAM=18000

    However I'm still wondering..

    What if I needed that more SRAM in TF-M?  Is it possible with the SPU to create the share modem shared memory as a separate region that comes before the secure sram?  Perhaps this would be an improvement opportunity..

    Until then perhaps the default TF-M SRAM region for nrf9160 should be reduced for non-minimal TF-M.

    Here is my partions.yml after modifying the TF-M SRAM,  I am still having problems with the overall project fitting into flash space.

    EMPTY_0:
      address: 0x14200
      end_address: 0x18000
      placement:
        before:
        - s1_pad
      region: flash_primary
      size: 0x3e00
    EMPTY_1:
      address: 0x24200
      end_address: 0x28000
      placement:
        before:
        - mcuboot_pad
      region: flash_primary
      size: 0x3e00
    EMPTY_2:
      address: 0xfc000
      end_address: 0x100000
      placement:
        after:
        - tfm_ps
      region: flash_primary
      size: 0x4000
    EMPTY_3:
      address: 0xf2000
      end_address: 0xf4000
      placement:
        after:
        - settings_storage
      region: flash_primary
      size: 0x2000
    EMPTY_4:
      address: 0xee000
      end_address: 0xf0000
      placement:
        after:
        - littlefs_storage
      region: flash_primary
      size: 0x2000
    app:
      address: 0x48000
      end_address: 0x88000
      region: flash_primary
      size: 0x40000
    app_image:
      address: 0x28200
      end_address: 0x88000
      orig_span: &id001
      - tfm
      - app
      region: flash_primary
      size: 0x5fe00
      span: *id001
    b0:
      address: 0x0
      end_address: 0x8000
      placement:
        after:
        - start
      region: flash_primary
      size: 0x8000
    b0_container:
      address: 0x0
      end_address: 0x8000
      orig_span: &id002
      - b0
      region: flash_primary
      size: 0x8000
      span: *id002
    littlefs_storage:
      address: 0xe8000
      end_address: 0xee000
      inside:
      - nonsecure_storage
      placement:
        align:
          start: 0x8000
        before:
        - settings_storage
      region: flash_primary
      size: 0x6000
    mcuboot:
      address: 0x8200
      end_address: 0x14200
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      sharers: 0x1
      size: 0xc000
    mcuboot_pad:
      address: 0x28000
      end_address: 0x28200
      placement:
        align:
          start: 0x8000
        before:
        - mcuboot_primary_app
      region: flash_primary
      sharers: 0x2
      size: 0x200
    mcuboot_primary:
      address: 0x28000
      end_address: 0x88000
      orig_span: &id003
      - tfm
      - app
      - mcuboot_pad
      region: flash_primary
      sharers: 0x1
      size: 0x60000
      span: *id003
    mcuboot_primary_app:
      address: 0x28200
      end_address: 0x88000
      orig_span: &id004
      - app
      - tfm
      region: flash_primary
      size: 0x5fe00
      span: *id004
    mcuboot_secondary:
      address: 0x88000
      end_address: 0xe8000
      placement:
        after:
        - mcuboot_primary
        align:
          start: 0x8000
      region: flash_primary
      share_size:
      - mcuboot_primary
      size: 0x60000
    mcuboot_sram:
      address: 0x20000000
      end_address: 0x20018000
      orig_span: &id005
      - tfm_sram
      region: sram_primary
      size: 0x18000
      span: *id005
    nonsecure_storage:
      address: 0xe8000
      end_address: 0xf0000
      orig_span: &id006
      - settings_storage
      - littlefs_storage
      region: flash_primary
      size: 0x8000
      span: *id006
    nrf_modem_lib_ctrl:
      address: 0x20018000
      end_address: 0x200184e8
      inside:
      - sram_nonsecure
      placement:
        after:
        - tfm_sram
        - start
      region: sram_primary
      size: 0x4e8
    nrf_modem_lib_rx:
      address: 0x2001a568
      end_address: 0x2001c568
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_tx
      region: sram_primary
      size: 0x2000
    nrf_modem_lib_sram:
      address: 0x20018000
      end_address: 0x2001c568
      orig_span: &id007
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x4568
      span: *id007
    nrf_modem_lib_tx:
      address: 0x200184e8
      end_address: 0x2001a568
      inside:
      - sram_nonsecure
      placement:
        after:
        - nrf_modem_lib_ctrl
      region: sram_primary
      size: 0x2080
    otp:
      address: 0xff8388
      end_address: 0xff83fc
      region: otp
      size: 0x74
    provision:
      address: 0xff8108
      end_address: 0xff8388
      region: otp
      size: 0x280
    s0:
      address: 0x8000
      end_address: 0x14200
      orig_span: &id008
      - mcuboot
      - s0_pad
      region: flash_primary
      size: 0xc200
      span: *id008
    s0_image:
      address: 0x8200
      end_address: 0x14200
      orig_span: &id009
      - mcuboot
      region: flash_primary
      size: 0xc000
      span: *id009
    s0_pad:
      address: 0x8000
      end_address: 0x8200
      placement:
        after:
        - b0_container
        align:
          start: 0x8000
      region: flash_primary
      share_size:
      - mcuboot_pad
      size: 0x200
    s1:
      address: 0x18000
      end_address: 0x24200
      orig_span: &id010
      - s1_pad
      - s1_image
      region: flash_primary
      size: 0xc200
      span: *id010
    s1_image:
      address: 0x18200
      end_address: 0x24200
      placement:
        after:
        - s1_pad
        - s0
      region: flash_primary
      share_size:
      - mcuboot
      size: 0xc000
    s1_pad:
      address: 0x18000
      end_address: 0x18200
      placement:
        after:
        - s0
        align:
          start: 0x8000
      region: flash_primary
      share_size:
      - mcuboot_pad
      size: 0x200
    settings_storage:
      address: 0xf0000
      end_address: 0xf2000
      inside:
      - nonsecure_storage
      placement:
        align:
          start: 0x8000
        before:
        - tfm_storage
        - end
      region: flash_primary
      size: 0x2000
    sram_nonsecure:
      address: 0x20018000
      end_address: 0x20040000
      orig_span: &id011
      - sram_primary
      - nrf_modem_lib_ctrl
      - nrf_modem_lib_tx
      - nrf_modem_lib_rx
      region: sram_primary
      size: 0x28000
      span: *id011
    sram_primary:
      address: 0x2001c568
      end_address: 0x20040000
      region: sram_primary
      size: 0x23a98
    sram_secure:
      address: 0x20000000
      end_address: 0x20018000
      orig_span: &id012
      - tfm_sram
      region: sram_primary
      size: 0x18000
      span: *id012
    tfm:
      address: 0x28200
      end_address: 0x48000
      inside:
      - mcuboot_primary_app
      placement:
        before:
        - app
      region: flash_primary
      size: 0x1fe00
    tfm_its:
      address: 0xf4000
      end_address: 0xf6000
      inside:
      - tfm_storage
      placement:
        before:
        - tfm_otp_nv_counters
      region: flash_primary
      size: 0x2000
    tfm_nonsecure:
      address: 0x48000
      end_address: 0x88000
      orig_span: &id013
      - app
      region: flash_primary
      size: 0x40000
      span: *id013
    tfm_otp_nv_counters:
      address: 0xf6000
      end_address: 0xf8000
      inside:
      - tfm_storage
      placement:
        before:
        - tfm_ps
      region: flash_primary
      size: 0x2000
    tfm_ps:
      address: 0xf8000
      end_address: 0xfc000
      inside:
      - tfm_storage
      placement:
        align:
          start: 0x8000
        before:
        - end
      region: flash_primary
      size: 0x4000
    tfm_secure:
      address: 0x28000
      end_address: 0x48000
      orig_span: &id014
      - mcuboot_pad
      - tfm
      region: flash_primary
      size: 0x20000
      span: *id014
    tfm_sram:
      address: 0x20000000
      end_address: 0x20018000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x18000
    tfm_storage:
      address: 0xf4000
      end_address: 0xfc000
      orig_span: &id015
      - tfm_ps
      - tfm_its
      - tfm_otp_nv_counters
      region: flash_primary
      size: 0x8000
      span: *id015
    

  • Hi,

     

    I am glad to hear that you solved the RAM issue.

    Anthony Ambuehl said:

    Where can I find the modifications for TF-M minimal mode?

    I was able to workaround this issue after adding this config for nrf9160 builds:

    #reduce TFM sram partition so the modem shared memory can be placed with the first 128-KB
    CONFIG_PM_PARTITION_SIZE_TFM_SRAM=18000

    However I'm still wondering..

    You can see the ROM/RAM use of tfm by issuing tfm_rom_report / tfm_ram_report:

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/tfm/build.html#footprint-and-memory-usage

    For the RAM, this includes the static RAM (ie. BSS + DATA section)

    To reduce the flash usage, you can select the TFM_PROFILE_TYPE_MEDIUM. I've recently posted a sample on this here: 

     How to reduce the code size of TF-M 

     

    And if you do not want to use a pm_static.yml file at this point, reduce the flash usage by setting CONFIG_PM_PARTITION_SIZE_TFM=0x2FE00. Please let me know if you run into any issues, and be sure to share the relevant prj.conf settings and the generated build/partitions.yml file.

    Anthony Ambuehl said:
    What if I needed that more SRAM in TF-M?  Is it possible with the SPU to create the share modem shared memory as a separate region that comes before the secure sram? 

    Technically, it does seem possible: https://infocenter.nordicsemi.com/topic/ps_nrf9160/spu.html?cp=2_0_0_5_14_2#ram_access_control

    But, I believe it is easier to slim down the tfm image in your case. I am not sure how the build-system handles uneven distribution of S/NS regions.

     

    Kind regards,

    Håkon

  • west built -t tfm_ram_report really helps here.

    The modem share memory is ram and must be placed in the non-secure region therefore adjusting CONFIG_PM_PARTITION_SIZE_TFM_SRAM or creating a static partition config are necessary to fix the share memory issue.

Related