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?

Parents Reply Children
  • 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

  • Hi,

    In case it helps, here is a report of what I do to make this work.

    Hardware: nRF9160DK 1.0.0
    nRF Connect SDK: v2.0.2
    Sample: zephyr/samples/subsys/fs/littlefs
    Build target: nrf9160dk_nrf9160_ns

    I used the sample as is, except that I added "CONFIG_BUILD_WITH_TFM=n" to prj.conf.

    Flash with erase, and log right after flash:

    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    Sample program to r/w files on littlefs
    Area 2 at 0xfa000 on NRF_FLASH_DRV_NAME for 24576 bytes
    I: LittleFS version 2.4, disk version 2.0
    I: FS at NRF_FLASH_DRV_NAME:0xfa000 is 6 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1077: Corrupted dir pair at {0x0, 0x1}
    W: can't mount (LFS -84); formatting
    I: /lfs mounted
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 4
    
    Listing dir /lfs ...
    /lfs/boot_count read count:0 (bytes: 0)
    /lfs/boot_count write new boot count 1: [wr:1]
    I: Test file: /lfs/pattern.bin not found, create one!
    ------ FILE: /lfs/pattern.bin ------
    01 55 55 55 55 55 55 55 02 55 55 55 55 55 55 55
    03 55 55 55 55 55 55 55 04 55 55 55 55 55 55 55
    05 55 55 55 55 55 55 55 06 55 55 55 55 55 55 55
    07 55 55 55 55 55 55 55 08 55 55 55 55 55 55 55
    09 55 55 55 55 55 55 55 0a 55 55 55 55 55 55 55
    0b 55 55 55 55 55 55 55 0c 55 55 55 55 55 55 55
    0d 55 55 55 55 55 55 55 0e 55 55 55 55 55 55 55
    0f 55 55 55 55 55 55 55 10 55 55 55 55 55 55 55
    11 55 55 55 55 55 55 55 12 55 55 55 55 55 55 55
    13 55 55 55 55 55 55 55 14 55 55 55 55 55 55 55
    15 55 55 55 55 55 55 55 16 55 55 55 55 55 55 55
    17 55 55 55 55 55 55 55 18 55 55 55 55 55 55 55
    19 55 55 55 55 55 55 55 1a 55 55 55 55 55 55 55
    1b 55 55 55 55 55 55 55 1c 55 55 55 55 55 55 55
    1d 55 55 55 55 55 55 55 1e 55 55 55 55 55 55 55
    1f 55 55 55 55 55 55 55 20 55 55 55 55 55 55 55
    21 55 55 55 55 55 55 55 22 55 55 55 55 55 55 55
    23 55 55 55 55 55 55 55 24 55 55 55 55 55 55 55
    25 55 55 55 55 55 55 55 26 55 55 55 55 55 55 55
    27 55 55 55 55 55 55 55 28 55 55 55 55 55 55 55
    29 55 55 55 55 55 55 55 2a 55 55 55 55 55 55 55
    2b 55 55 55 55 55 55 55 2c 55 55 55 55 55 55 55
    2d 55 55 55 55 55 55 55 2e 55 55 55 55 55 55 55
    2f 55 55 55 55 55 55 55 30 55 55 55 55 55 55 55
    31 55 55 55 55 55 55 55 32 55 55 55 55 55 55 55
    33 55 55 55 55 55 55 55 34 55 55 55 55 55 55 55
    35 55 55 55 55 55 55 55 36 55 55 55 55 55 55 55
    37 55 55 55 55 55 55 55 38 55 55 55 55 55 55 55
    39 55 55 55 55 55 55 55 3a 55 55 55 55 55 55 55
    3b 55 55 55 55 55 55 55 3c 55 55 55 55 55 55 55
    3d 55 55 55 55 55 55 55 3e 55 55 55 55 55 55 55
    3f 55 55 55 55 55 55 55 40 55 55 55 55 55 55 55
    
    41 55 55 55 55 55 55 55 42 55 55 55 55 55 55 55
    43 55 55 55 55 55 55 55 44 55 55 55 55 55 55 55
    45 55 aa 
    I: /lfs unmounted
    /lfs unmount: 0
    

    Then I press the reset button on the nRF9160DK:

    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    Sample program to r/w files on littlefs
    Area 2 at 0xfa000 on NRF_FLASH_DRV_NAME for 24576 bytes
    I: LittleFS version 2.4, disk version 2.0
    I: FS at NRF_FLASH_DRV_NAME:0xfa000 is 6 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    I: /lfs mounted
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 3
    
    Listing dir /lfs ...
    [FILE] boot_count (size = 1)
    [FILE] pattern.bin (size = 547)
    /lfs/boot_count read count:1 (bytes: 1)
    /lfs/boot_count write new boot count 2: [wr:1]
    ------ FILE: /lfs/pattern.bin ------
    02 55 55 55 55 55 55 55 03 55 55 55 55 55 55 55
    04 55 55 55 55 55 55 55 05 55 55 55 55 55 55 55
    06 55 55 55 55 55 55 55 07 55 55 55 55 55 55 55
    08 55 55 55 55 55 55 55 09 55 55 55 55 55 55 55
    0a 55 55 55 55 55 55 55 0b 55 55 55 55 55 55 55
    0c 55 55 55 55 55 55 55 0d 55 55 55 55 55 55 55
    0e 55 55 55 55 55 55 55 0f 55 55 55 55 55 55 55
    10 55 55 55 55 55 55 55 11 55 55 55 55 55 55 55
    12 55 55 55 55 55 55 55 13 55 55 55 55 55 55 55
    14 55 55 55 55 55 55 55 15 55 55 55 55 55 55 55
    16 55 55 55 55 55 55 55 17 55 55 55 55 55 55 55
    18 55 55 55 55 55 55 55 19 55 55 55 55 55 55 55
    1a 55 55 55 55 55 55 55 1b 55 55 55 55 55 55 55
    1c 55 55 55 55 55 55 55 1d 55 55 55 55 55 55 55
    1e 55 55 55 55 55 55 55 1f 55 55 55 55 55 55 55
    20 55 55 55 55 55 55 55 21 55 55 55 55 55 55 55
    22 55 55 55 55 55 55 55 23 55 55 55 55 55 55 55
    24 55 55 55 55 55 55 55 25 55 55 55 55 55 55 55
    26 55 55 55 55 55 55 55 27 55 55 55 55 55 55 55
    28 55 55 55 55 55 55 55 29 55 55 55 55 55 55 55
    2a 55 55 55 55 55 55 55 2b 55 55 55 55 55 55 55
    2c 55 55 55 55 55 55 55 2d 55 55 55 55 55 55 55
    2e 55 55 55 55 55 55 55 2f 55 55 55 55 55 55 55
    30 55 55 55 55 55 55 55 31 55 55 55 55 55 55 55
    32 55 55 55 55 55 55 55 33 55 55 55 55 55 55 55
    34 55 55 55 55 55 55 55 35 55 55 55 55 55 55 55
    36 55 55 55 55 55 55 55 37 55 55 55 55 55 55 55
    38 55 55 55 55 55 55 55 39 55 55 55 55 55 55 55
    3a 55 55 55 55 55 55 55 3b 55 55 55 55 55 55 55
    3c 55 55 55 55 55 55 55 3d 55 55 55 55 55 55 55
    3e 55 55 55 55 55 55 55 3f 55 55 55 55 55 55 55
    40 55 55 55 55 55 55 55 41 55 55 55 55 55 55 55
    
    42 55 55 55 55 55 55 55 43 55 55 55 55 55 55 55
    44 55 55 55 55 55 55 55 45 55 55 55 55 55 55 55
    46 55 ab 
    I: /lfs unmounted
    /lfs unmount: 0
    

    Is this what you are trying to do?

    Regards,
    Sigurd Hellesvik

Related