Memory optimization in TF-M enabled applications

Hi, 

We have a project where we are using TF-M application along with DFU and we observe a memory overflow in the TF-M partition when we try to reduce the TF-M partition size.

Attached the memory report.

What is b0 partition and EMPTY_X partitions are used?  How to reduce these partitions size?

We see TF-M is consuming around 270KB and how to reduce this partition at least to its half. 

We basically need the TF-M partition to be minimal to make room for application in non-secure partition.

memory-map.xlsx

Parents Reply Children
  • Saving 30KB should be OK for us, we may use the additional space for storing user information and stuff.

    We now configuring TFM MINIMAL with ITS enabled, this give us a room for both non-secure application and ITS expansion also.

    Thank you for the support.

  • Hi Sigurd,

    We are trying to understand the partition manager configuration and we see _pad on s0, s1, mcuboot.
    Can you please explain what is the use of _pad partition?

    Is it mandatory to have these partitions? if not we can save further memory space for our application.

    We also see 2 EMPTY_x partition which each of size around 15KB. Can't we remove this partition and replace it with the successive partitions? This save us huge memory if we can completely remove EMPTY_x partitions.

    We also noticed, the TFM secure and non-secure partition should be aligned to the NRF_SPU flash region size(0x4000), so removing EMPTY partitions should help us to save around 30KB or more.

    Please help us on defining a partition table without any EMPTY partitions or unused or optional partitions.

  • Jithin A said:

    Can you please explain what is the use of _pad partition?

    Is it mandatory to have these partitions? if not we can save further memory space for our application.

    From mcuboots pm.yml, the pad partition is for header information. I think some of them may be for mcuboot trailer information as well, but I am not 100% sure.

    Either way, these are mandatory and used for MCUboots metadata.

    Jithin A said:

    We also see 2 EMPTY_x partition which each of size around 15KB. Can't we remove this partition and replace it with the successive partitions? This save us huge memory if we can completely remove EMPTY_x partitions.

    We also noticed, the TFM secure and non-secure partition should be aligned to the NRF_SPU flash region size(0x4000), so removing EMPTY partitions should help us to save around 30KB or more.

    Please help us on defining a partition table without any EMPTY partitions or unused or optional partitions.

    It is sometimes possible to partition so that you can get rid of the EMPTY partitons.
    However as you say SPU is important here. For example, the tfm_its partition is probably together with EMPTY, as you can not put any NSPE partition in the same SPU region as it.

    If you can give your partitioning report "west build -t partition_manager_report", I can maybe give you some more substantial advice?

    Here are some devzone tickets on EMPTY partitions:

     west build generates large EMPTY partitions

     [nRF5340 DK] What is empty_0 and empty_1 in flash partition? Why use static partition for firmware update? 

     RE: Partition Manager not using flash efficiently 

  • Hi Sigurd,

    We are trying to configure to each partition by defining in pm_static.yml. So far, we are good, and we are able to reduce some and keep it for application.

    One thing I want to know is can we allot/resize B0 and MCUBoot such that the size is aligned to 0x4000 and less than what is set by default.

    I understand that any partition size should be aligned to 0x4000. So that it does not create any empty slots for further alignment.

    After looking into memory report, we get to know that these partitions are not taking the complete allocated memory so thought of using the unused memory for our application instead.

    The thing is we have a lot of packages like crypto operations and TLS functionalities in our application and to which these libraries are taking a lot of memory, and we cannot have external flash due to hardware restrictions with all of this we are seeing to get space from wherever possible.

    Please let me your thoughts on this.

  • I will see if I can make up some thoughts soon, but in the meantime I thought that maybe this draft PR could be useful for you to look at:

    github.com/.../13812

Related