Mass USB Storage on External QSPI Flash in Non-secure build with TFM

Hi,
I have been experimenting with an NRF5340dk for the past few days around the application of emulating a Mass USB storage device when connected to a PC.

I came across the Mass Storage Sample outlined here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/zephyr/samples/subsys/usb/mass/README.html
Building and running the application works without issue and I am able to see the dev kit as a USB drive on the PC where I can add and remove files etc.

To take this sample a step further I wanted to achieve the same application but to build with the non-secure board: nrf5340dk_nrf5340_cpuapp_ns to take advantage of TFM.

I have read through the documentation available for the NRF Connect SDK and have yet to have some success with getting the application to build and run correctly. I initially tried modifying the application by doing the following:
- Adding an nrf5340dk_nrf5340_cpuapp_ns.overlay containing the same contents as the included nrf5340dk_nrf5340_cpuapp.overlay.
- Adding the following KConfig arguments:
CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
CONFIG_BUILD_WITH_TFM=y
CONFIG_TFM_PROFILE_TYPE_MINIMAL=y
CONFIG_TFM_BL2=n

However this had no success as I was receiving the following error in the build process:


error: 'PM_storage_partition_ID' undeclared (first use in this function)
41 | #define PM_ID(label) PM_##label##_ID


I believe this is due to the fact that the partition manager is not adding the "storage_partition" in external flash to the "nonsecure_storage" region required when building with TFM. This is observed in this line in the build output:
Dropping partition 'nonsecure_storage' since it is empty.
I then found out that the ncs v2.2.0 has a known issue regarding multiple partitions in "nonsecure_storage" on external flash when building with TFM as per this page:
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/known_issues.html

A workaround is suggested by setting partition size to a multiple of CONFIG_NRF_SPU_FLASH_REGION_SIZE (which I am already doing) or
using a static flash layout. I opted to attempt the static flash layout where I updated the project to include a pm_static.yaml file based off the partitions.yaml produced with dynamic partitioning and following the instruction defined in these locations for using external flash and the "nonsecure_storage" partition. However I am now getting the error shown in the image regarding packing of partitions.

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/scripts/partition_manager/partition_manager.html 

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/ug_tfm.html 

I have attached the project as a zip file, showing this result.5025.mass.zip

 

In further testing I noticed that If I create an EMPTY_0 region that fills up the remainder of the external flash region, it will now build, but the partitions.yaml in the build folder is incorrect with partitions having negative starting addresses or sizes.mass(builds).zip

These are the versions of hardware and sdk I am using:

NRF Connect SDK Version: v2.2.0
Nrf5340dk Version: 0.11.0

If someone could please assist me in determining what might be causing this issue and how to correctly set up the example project in the desired way that would be much appreciated.

Thanks in advance for the assistance.



  • Hi Liam

    Regarding your first error, the storage partition should be defined here in flash_map_pm.h.

    Using the pm_static.yml seems like the right thing to do, however the errors you're seeing here points to various issues in the pm_static.yml file:

    I've never heard of the partitions having negative starting addresses/sizes, have you perhaps by mistake added a "-" or something in either partition.yml or pm_static.yml. Does your project build with just and not the pm_static.yml for example?

    Best regards,

    Simon

  • Hi Simon,

    Thanks for your quick response to my question.

    I understand that the initial error was appearing in the flash_map_pm.h file but this was not the root cause of the issue as I understand it. 

    As you say I think the way forward is to use a pm_static.yml file to layout the flash partitions including the external flash.

    I am aware that the issue most likely lies in my pm_static.yml file (which is contained in the zip files attached) but I am not sure what is causing the issue. I have not put any "-" signs in pm_static.yml and partition.yml is left unchanged after it is generated by the build process.

    I have looked at this page to try and figure out how to correctly map out the flash but there is very little information. The example on the page does not provide any details on how to properly set start address, size etc https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/scripts/partition_manager/partition_manager.html 

    If there is an example or tutorial explaining how to set up the following in a pm_static.yml that would be fantastic:

    1. Set up the start address of the external flash region. There is mention of the CONFIG_PM_EXTERNAL_FLASH_BASE which defaults to 0x0. I would have thought that this would conflict with the internal flash starting at 0x0. Not sure if this is required or how to assign addresses relative to internal flash correctly

    2. Set up the addresses and sizes of partitions on external flash and how they are positioned relative to the internal flash or external flash start address specifically using the _ns board

    Thanks for your assistance with this.

    Best regards,

    Liam

  • Hi again Liam

    I'm sorry, but I have not had time to review your project's partitioning files yet. I will do so by Monday if you don't figure it out. pm_static.yml seems more complicated than it actually is, and you basically only need to fill in the right partitions at the right addresses so the partitions align correctly with one another and don't overlap or go outside the Flash range of the SoC.

    We don't have a dedicated tutorial for this, but the basics are covered in the DevAcademy and I find the "Configuring static partitions" and "Adding a static partition" sections in the documentation helpful.

    Best regards,

    Simon

  • Hi

    So I opened, reviewed and tried building and flashing the mass(builds) folder you uploaded. On my end the partitions.yml file didn't build with negative values as you're describing here. can you upload the partitions.yml file you have in your build folder?

    Best regards,

    Simon

    partitions.7z

  • Hi, thanks for your reply, and for looking into it. 

    I looked at the partitions.yaml file you attached and it doesn't contain the external flash region (which had the negative size) and nonsecure_storage region. Here is the partitions.yaml file that was generated when I build the project.

    I haven't had the chance yet to look into the links you have provided for setting up static partitions. I hope to get onto it in the coming couple of days. partitions.zip

    Best Regards,

    Liam

Related