Little FS on external FLASH with nrf9161dk and NCS 2.8.0

Hi,

We are developing application software on the nrf9161dk that uses the little FS file system running on external FLASH.  Most of the application development has been completed using NCS v2.4.0, and we are now porting the application to NCS v2.8.0.

Our application builds successfully, but when we attempt to open the FLASH file system using  flash_area_open(), it returns with -2 (-ENOENT) indicating that it cannot find the partition.  I have checked that the partition is properly defined in the device tree, but for some reason it is not placed in the default_flash_map defined in zephyr/subsys/storage/flash_map/flash_map_default.c.

I have duplicated this failure using spi_flash_test application privided in this ticket:  nRF5340-DK: Partition Manager for external flash 

To make this example work with the nrf9161dk board, I added a nrf9161dk_nrf9161.conf file in the spi_flash_test/boards folder:

#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

# nriedel update for nrf9161
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x10000

CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

I also added a device tree overlay file nrf9161dk_nrf9161.overlay:

/ {
	chosen {
		nordic,pm-ext-flash = &gd25wb256;
	};
	// nriedel add:
	aliases {
		spi-flash0 = &gd25wb256;
	};
};

&gd25wb256 {
    status = "okay";
    partitions {
	    compatible = "fixed-partitions";
	    #address-cells = <1>;
	    #size-cells = <1>;

	    lfs_part1: partition@0 {
		    label = "littlefs_storage";
		    reg = <0x00000000 0x1e84800>;
	    };
    };
};

I build normally:

west build -b nrf9161dk

Running the code on the nrf9161dk I get:

*** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
*** Using Zephyr OS v3.7.99-0bc3393fb112 ***                                                                                                                                                                   
                                                                                                                                                                                                               
gd25wb256e3ir@1 SPI flash testing                                                                                                                                                                              
==========================                                                                                                                                                                                     
                                                                                                                                                                                                               
Perform test on single sector                                                                                                                                                                                  
Test 1: Flash erase                                                                                                                                                                                            
Failed to retreive flash partition information -2                                                                                                                                                              

The full source for this modified version of the spi_flash_test application is attached.

  • Hi,

    With v2.8.0, you get the partition manager enabled by default. See some theory on this under our Sysbuild course.

    With the partition manager, DTS partitioning is mostly ignored.

    If you do not want nor need the partition manager, you can set SB_CONFIG_PARTITION_MANAGER=n in sysbuild.conf.

    Does that work?

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,

    Thank you for your quick response.  I tried disabling the partition manager as you selected.  In addition, I changed main.c to remove the include of pm_config.h and updated the FLASH partition ID definition:

    #define FLASH_PARTITION_ID 		DT_N_S_soc_S_peripheral_50000000_S_spi_b000_S_gd25wb256e3ir_1_S_partitions_S_partition_0_PARTITION_ID

    I got the FLASH_PARTITION_ID value from inspecting the file build/spi_flash_test/zephyr/include/generated/zephyr/devicetree_generated.h

    Unfortunately, the problem still exists.  The call to flash_area_open() returns "-2" indicating it cannot find the partition.  This is the same failure I had with the PM enabled.

    I think the problem is in the file zephyr/subsys/storage/flash_map/flash_map_default.c.  This file defines the default FLASH map that Zephyr uses to look for the partition ID:

    /* We iterate over all compatible 'fixed-partitions' nodes and
     * use DT_FOREACH_CHILD to iterate over all the partitions for that
     * 'fixed-partitions' node.  This way we build a global partition map
     */
    const struct flash_area default_flash_map[] = {
    	DT_INST_FOREACH_STATUS_OKAY(FOREACH_PARTITION)
    };
    
    

    For some reason, it does not add the littlefs partition to this list.

    I also tried enabling the PM and using dynamic partitioning (i.e. I deleted the pm_static.yml file) as described in the sysbuild course.  I used "PM_littlefs_storage_ID" as the partition ID in main.c.  The result was that the littlefs file system is placed in on-chip FLASH.  This configuration works correctly.  

    However, if I try to move it to external FLASH by building with 

        west build -b nrf9161dk -p -- -DCONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y

    The PM places the littlefs in external FLASH (as indicated by the partitions.yml file), but the sample does not work with the same "-2" error.

    Is it possible for you to provide a sample on the nrf9161dk that uses littlefs on the external flash with NCS v2.8.0?

    Thanks,

    Neal

  • Neal Riedel said:
    Is it possible for you to provide a sample on the nrf9161dk that uses littlefs on the external flash with NCS v2.8.0?

    I tried and I also get -2.

    I will have to dig some more into this

  • Thanks, Sigurd.  Any help you can provide is greatly appreciated!

Related