Littlefs file system on external SPI flash memory with non-secure build

In my project, I am planning to use LTE modem and an external flash memory with a file system. I have problems to run code for the non-secure build type. A similar problem occurs when trying to use the shell/fs example (developer.nordicsemi.com/.../README.html) on the nrf9160dk_nrf9160_ns target. Building for the secure nrf9160dk_nrf9160 target works well.

Here is my "prj.conf":

CONFIG_FLASH=y
CONFIG_LOG=y
#CONFIG_FS_LOG_LEVEL_DBG=y
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_SHELL=y
CONFIG_SHELL_LOG_LEVEL_INF=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_SHELL=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

and here is my "app.overlay":

/delete-node/ &storage_partition;

&mx25r64  {
  // spi-max-frequency = <1000000>;
  partitions {
    compatible = "fixed-partitions";
    #address-cells = <1>;
    #size-cells = <1>;

    storage_partition: partition@0 {
      label = "storage";
      reg = <0x00000000 0x00800000>;
    };
  };
};

For nrf9160dk_nrf9160 target there is usual shell:

uart:~$ *** Booting Zephyr OS build v3.0.99-ncs1  ***

uart:~$ fs mount littlefs /lfs
[00:00:24.930,999] <inf> littlefs: LittleFS version 2.4, disk version 2.0
[00:00:24.932,769] <inf> littlefs: FS at MX25R64:0x0 is 2048 0x1000-byte blocks with 512 cycle
[00:00:24.932,800] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[00:00:24.935,363] <inf> littlefs: /lfs mounted
uart:~$ fs cd /lfs
uart:~$ fs ls
file.bin
uart:~$ fs read file.bin
File size: 9
00000000  11 22 33 44 55 BA DC 0F FE                       ."3DU....
uart:~$ fs statvfs /lfs
bsize 16, frsize 4096, blocks 2048, bfree 2046
uart:~$

But for nrf9160dk_nrf9160_ns target nothing happens. I can run with the debugger and see that everything stops somewhere here:

My question is: what additional settings are required for the example to work in non-secure mode?

  • Hi,

    I am able to reproduce this.
    I will investigate it and return with an answer tomorrow.

    Regards,
    Sigurd Hellesvik

  • Hi,

    This seems like an issue related to Trusted Firmware-M (TF-M).

    I have reported this to our developers as a bug, and will keep you updated in this case.

    As a workaround, you can use SPM instead of TF-M by setting "CONFIG_BUILD_WITH_TFM=n" in prj.conf.

    Regards,
    Sigurd Hellesvik

  • Well, actually I can not. It seems that in SPM mode external flash is not visible at all:

    *** Booting Zephyr OS build v3.0.99-ncs1  ***
    Flash regions           Domain          Permissions
    00 01 0x00000 0x10000   Secure          rwxl
    02 31 0x10000 0x100000  Non-Secure      rwxl

    Non-secure callable region 0 placed in flash region 1 with size 32.

    SRAM region             Domain          Permissions
    00 03 0x00000 0x08000   Secure          rwxl
    04 31 0x08000 0x40000   Non-Secure      rwxl

    Peripheral              Domain          Status
    00 NRF_P0               Non-Secure      OK
    01 NRF_CLOCK            Non-Secure      OK
    02 NRF_RTC0             Non-Secure      OK
    03 NRF_RTC1             Non-Secure      OK
    04 NRF_NVMC             Non-Secure      OK
    05 NRF_UARTE1           Non-Secure      OK
    06 NRF_UARTE2           Secure          SKIP
    07 NRF_TWIM2            Non-Secure      OK
    08 NRF_SPIM3            Non-Secure      OK
    09 NRF_TIMER0           Non-Secure      OK
    10 NRF_TIMER1           Non-Secure      OK
    11 NRF_TIMER2           Non-Secure      OK
    12 NRF_SAADC            Non-Secure      OK
    13 NRF_PWM0             Non-Secure      OK
    14 NRF_PWM1             Non-Secure      OK
    15 NRF_PWM2             Non-Secure      OK
    16 NRF_PWM3             Non-Secure      OK
    17 NRF_WDT              Non-Secure      OK
    18 NRF_IPC              Non-Secure      OK
    19 NRF_VMC              Non-Secure      OK
    20 NRF_FPU              Non-Secure      OK
    21 NRF_EGU0             Non-Secure      OK
    22 NRF_EGU1             Non-Secure      OK
    23 NRF_EGU2             Non-Secure      OK
    24 NRF_EGU3             Non-Secure      OK
    25 NRF_EGU4             Non-Secure      OK
    26 NRF_EGU5             Non-Secure      OK
    27 NRF_DPPIC            Non-Secure      OK
    28 NRF_REGULATORS       Non-Secure      OK
    29 NRF_PDM              Non-Secure      OK
    30 NRF_I2S              Non-Secure      OK
    31 NRF_GPIOTE1          Non-Secure      OK

    SPM: NS image at 0x10000
    SPM: NS MSP at 0x200104b8
    SPM: NS reset vector at 0x16585
    SPM: prepare to jump to Non-Secure image.


    uart:~$ *** Booting Zephyr OS build v3.0.99-ncs1  ***

    uart:~$ fs mount littlefs /lfs
    [00:00:15.987,915] <inf> littlefs: LittleFS version 2.4, disk version 2.0
    [00:00:15.988,159] <inf> littlefs: FS at NRF_FLASH_DRV_NAME:0xfa000 is 6 0x1000-byte blocks with 512 cycle
    [00:00:15.988,159] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    [00:00:15.988,311] <err> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1077: Corrupted dir pair at {0x0, 0x1}
    [00:00:15.988,311] <wrn> littlefs: can't mount (LFS -84); formatting
    [00:00:16.164,703] <inf> littlefs: /lfs mounted
    uart:~$

  • Hi,

    I think it is usual for the filesystem samples to have some (timing?) issues when first setting up the partitions.

    Try to reset the Developement Kit.

    Regards,
    Sigurd Hellesvik

Related