Problem importing a library into TF-M: Not enough space to import i

Hi,

I am developing a project that uses TF-M to run some functions from a secure partition. The structure of the project is shown below:

├── lib
│   ├── ...
│   ├── blst.h
│   ├── libblst.a
├── mycli
│   ├── CMakeLists.txt
│   ├── README.rst
│   ├── prj.conf
│   ├── sample.yaml
│   └── src
│   ├── main.c
│   ├── secure_partition_interface.c
│   └── secure_partition_interface.h
└── secure_partition
    ├── CMakeLists.txt
    ├── README.md
    ├── secure_partition.c
    ├── tfm_manifest_list.yaml.in
    └── tfm_secure_partition.yaml

I need to import a static library whose functions I am going to use only from the secure partition. Therefore, I intend to import them into the safe partition.

To use its functions, I include the library in the file I use it:

#include "blst.h"

If I use its functions, it tells me that they are not defined. I understand that it is because I have not included them in secure_partition/CMakeLists.txt. To include them, I write the following configuration in that file:

target_include_directories(tfm_app_rot_partition_sp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib)

target_link_libraries(tfm_app_rot_partition_sp
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../lib/libblst.a
)


I don't know if I am doing something wrong when I include the library or if I just need more space. If I am doing the import wrong, I would like to know how to fix it. If I need more space, I would like to know how to get it, either by decreasing the size of my secure partition, or by increasing the size of the flash memory dedicated to it (the libblst.a file size is about 110 kB).

Regards,

Pablo

Useful information about the project:
- I'm using the nRF5340DK development kit.
- nRF SDK v2.0.0
- The project is based on the example: TF-M Secure Partition Sample. When doing the build for this example, the available and used space shown is as follows:

Memory region           Used Size     Region Size    %age Used
           FLASH:            21648 B           736 KB            2.87%
           SRAM:            4816 B              256 KB            1.84%
           IDT_LIST:         0 GB                  2 KB             0.00%

Error trace:

e:/programs/nordic/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: bin\tfm_s.axf section `.tfm_rodata' will not fit in region `FLASH'
e:/programs/nordic/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x4bee0 of bin\tfm_s.axf section `.gnu.sgstubs' is not within region `FLASH'
e:/programs/nordic/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: address 0x4bee0 of bin\tfm_s.axf section `.gnu.sgstubs' is not within region `FLASH'
e:/programs/nordic/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `FLASH' overflowed by 49152 bytes
Memory region        Used Size      Region Size    %age Used
           FLASH:         304 KB            256 KB            118.75%
           RAM:            45180 B           256 KB            17.23%
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FAILED: modules/trusted-firmware-m/tfm-prefix/src/tfm-stamp/tfm-build tfm/secure_fw/s_veneers.o tfm/app/libtfm_api_ns.a tfm/generated/interface/include/psa_manifest/sid.h tfm/platform/libplatform_ns.a tfm/bin/tfm_s.elf tfm/bin/tfm_s.bin tfm/bin/tfm_s.hex tfm/bin/tfm_ns.bin tfm/bin/tfm_ns.hex tfm/bin/tfm_s_signed.bin tfm/bin/tfm_ns_signed.bin tfm/bin/tfm_s_ns_signed.bin
cmd.exe /C "cd /D C:\Nordic\tfm\mycli\build\tfm && E:\Programs\Nordic\toolchains\v2.0.0\opt\bin\cmake.exe --build . -j 1"
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'e:\Programs\Nordic\toolchains\v2.0.0\opt\bin\cmake.EXE' --build 'c:\Nordic\tfm\mycli\build'

Parents
  • I would like to add that this is what is shown when I build my application without importing the library into my project.

    Memory region          Used Size     Region Size     %age Used
               FLASH:            92136 B          736 KB            12.23%
               SRAM:            113920 B          256 KB            43.46%
               IDT_LIST:           0 GB               2 KB                0.00%

    It is strange that the total available flash memory space (region size) is larger than when importing the static library.

    On the other hand, if I import the static library in the main part of the project (non-secure partition) it shows the same occupied space as if I don't import it anywhere.

    mycli/CMakeLists.txt:

    target_link_libraries(app PUBLIC ${APPLICATION_SOURCE_DIR}/../lib/libblst.a)

    Memory region          Used Size     Region Size     %age Used
               FLASH:            92136 B          736 KB            12.23%
               SRAM:            113920 B          256 KB            43.46%
               IDT_LIST:           0 GB               2 KB                0.00%

    The problem is that I want to use this library in the secure partition.

  • Hi Pablo,

    I will look into this.

    As this sample and TF-M is quite new, I will have to try to replicate this myself.
    This might take some time, but I hope to be able to return with some information on the issue on Monday.

    Regards,
    Sigurd Hellesvik

  • Ok, thank you for taking the time, Sigurd.

    Regards,

    Pablo

Reply Children
No Data
Related