Question about partiton alignment

Hi,

I try to build up a project with Settings, LittleFS, and TFM PSA enabled, the partions looks like below.

  flash_primary (0x100000 - 1024kB): 
+--------------------------------------------------+
+---0x0: b0_container (0x8000 - 32kB)--------------+
| 0x0: b0 (0x8000 - 32kB)                          |
+---0x8000: s0 (0xc200 - 48kB)---------------------+
| 0x8000: s0_pad (0x200 - 512B)                    |
+---0x8200: s0_image (0xc000 - 48kB)---------------+
| 0x8200: mcuboot (0xc000 - 48kB)                  |
+--------------------------------------------------+
| 0x14200: EMPTY_0 (0x3e00 - 15kB)                 |
+---0x18000: s1 (0xc200 - 48kB)--------------------+
| 0x18000: s1_pad (0x200 - 512B)                   |
| 0x18200: s1_image (0xc000 - 48kB)                |
+--------------------------------------------------+
| 0x24200: EMPTY_1 (0x3e00 - 15kB)                 |
+---0x28000: mcuboot_primary (0xb0000 - 704kB)-----+
+---0x28000: tfm_secure (0x40000 - 256kB)----------+
| 0x28000: mcuboot_pad (0x200 - 512B)              |
+---0x28200: app_image (0xafe00 - 703kB)-----------+
+---0x28200: mcuboot_primary_app (0xafe00 - 703kB)-+
| 0x28200: tfm (0x3fe00 - 255kB)                   |
+---0x68000: tfm_nonsecure (0x70000 - 448kB)-------+
| 0x68000: app (0x70000 - 448kB)                   |
+---0xd8000: nonsecure_storage (0xa000 - 40kB)-----+
| 0xd8000: littlefs_storage (0x6000 - 24kB)        |
| 0xde000: EMPTY_6 (0x2000 - 8kB)                  |
| 0xe0000: settings_storage (0x2000 - 8kB)         |
+--------------------------------------------------+
| 0xe2000: EMPTY_5 (0x6000 - 24kB)                 |
+---0xe8000: tfm_storage (0x14000 - 80kB)----------+
| 0xe8000: tfm_its (0x2000 - 8kB)                  |
| 0xea000: EMPTY_4 (0x6000 - 24kB)                 |
| 0xf0000: tfm_otp_nv_counters (0x2000 - 8kB)      |
| 0xf2000: EMPTY_3 (0x6000 - 24kB)                 |
| 0xf8000: tfm_ps (0x4000 - 16kB)                  |
+--------------------------------------------------+
| 0xfc000: EMPTY_2 (0x4000 - 16kB)                 |
+--------------------------------------------------+

There are a lot of EMPTY_ partitions inside the table.

And I realize that cause by almost all partions must align to SPU_FLASH_REGION_SIZE in partition management, and that is 32K for 9160.

That basic means every partion take 32KB flash size in the end (design size + EMPTY). 

My question is if the alignment is necessary? What is the impact?

And any suggestion how can I remove those EMPTY partitons to enlarge the app partition size?

PS.
I know I can use pm_static.yml to adjust the partition table.
But when I adjust the partiton table to remove the EMPTY partions, some partitons will lost the 32K alignment.
I'm not sure if it's safe to do this.
  • Hi,

    As you say, the SPU_FLASH_REGION_SIZE is 32kB on the nRF9160, which means that all boundries between secure and non-secure regions must be on a 32k boundary. Otherwise, when one domain tries to access something in the other domain, you get a fault, or you have to waste space (unless you increase the sizes of the partitions to fill the SPU region).

    However, you can have multiple partitions within the same SPU region as long as they belong to the same domain. That means that e.g. the tfm_storage partitions can be placed in the same SPU region, thus only taking 32kB of space, not 80. Below is a pm_static.yml I created for a different project where the tfm_storage partitions have been placed in the same SPU region. You might have to change some of the addresses for it to work in your project, but it should be a good starting point.

    tfm_its:
      address: 0xf8000
      size: 0x2000
    tfm_otp_nv_counters:
      address: 0xfa000
      size: 0x2000
    tfm_ps:
      address: 0xfc000
      size: 0x4000
    tfm_storage:
      address: 0xf8000
      span:
      - tfm_ps
      - tfm_its
      - tfm_otp_nv_counters
      size: 0x8000

    This also moves the tfm_storage partitions to the end of the flash, which should let you move the non-secure storage partitions after, which in turn will let you increase the mcuboot slots.

    Best regards,

    Didrik

Related