LittleFS and settings subsystem

Hello,


I am building an application that need to have BLE with bonding enabled.
It also need to save a moderate amount of data to a file system connected to a external flash (mx25r6435f).
The application also need to save some small amount of data to internal flash (e.g. numbers, small strings the BLE bonding information and also some secrets).

I'm currently developing on nRF54L15-DK development board, using VSCode and ncs 3.1.1.
For file system, I'm using LittleFS, and for save and load data to/from internal flash, I'm using the Zephyr Settings subsystem.
I use partition manager to set up the partitions, and a overlay file for LittleFS setup.

The problem is that I'm unable to run LittleFS on external flash and Settings subsystem at the same time. If I use only one at the time, the system works flawlessly.

The whole problem starts when I enable settings (CONFIG_SETTINGS=y), and / or define a "settings_storage" partition in the pm file. Then LittleFS starts to use the internal flash instead of the external, and of course runs out of space almost immediately.
What happens seems to be that if CONFIG_SETTINGS=y is enabled, or settings_storage partition defined, littleFS starts to use the partition defined for "settings_storage" instead of "littlefs_storage".

settings_storage partition is defined this way in pm file (need to comment it out for LittleFS to use external flash):

settings_storage:
  address: 0x163000
  end_address: 0x165000
  region: flash_primary
  size: 0x2000

And littlefs_storage partition this way:

littlefs_storage:
    address: 0x00000000
    end_address: 0x00400000
    region: external_flash
    device: mx25r6435f
    size: 0x400000
    affiliation: disk
    extra_params: {
    disk_name: "littlefs",
    disk_cache_size: 4096,
    disk_sector_size: 512,
    disk_read_only: 0
}

Debug out when neither CONFIG_SETTINGS=y nor "settings_storage" partition defined:

[00:47:15.624,963] <inf> littlefs: LittleFS version 2.11, disk version 2.1
[00:47:15.624,977] <dbg> littlefs: littlefs_flash_init: FS area 1 at 0x0 for 4194304 bytes
[00:47:15.625,352] <inf> littlefs: FS at mx25r6435f@0:0x0 is 1024 0x1000-byte blocks with 512 cycle
[00:47:15.625,362] <inf> littlefs: partition sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[00:47:15.634,785] <dbg> fs: fs_mount: fs mounted at /lfs
[00:47:15.653,005] <inf> FILE: /lfs: bsize = 16 ; frsize = 4096 ; blocks = 1024 ; bfree = 1009

[00:47:15.653,012] <inf> FILE: Littlefs mounted

Debug out when eighter CONFIG_SETTINGS=y or settings_storage partition (or both) defined:

[00:55:06.192,095] <inf> littlefs: LittleFS version 2.11, disk version 2.1
[00:55:06.192,109] <dbg> littlefs: littlefs_flash_init: FS area 3 at 0x163000 for 8192 bytes
[00:55:06.192,131] <inf> littlefs: FS at rram-controller@5004b000:0x163000 is 2 0x1000-byte blocks with 512 cycle
[00:55:06.192,141] <inf> littlefs: partition sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[00:55:06.193,002] <dbg> fs: fs_mount: fs mounted at /lfs
[00:55:06.193,809] <inf> FILE: /lfs: bsize = 16 ; frsize = 4096 ; blocks = 2 ; bfree = 0

[00:55:06.193,816] <inf> FILE: Littlefs mounted

I want that the "settings_storage" partition should be used for Settings subsys, and the "littlefs_storage" partition for LittleFS.
Is that possible?

Regards, Jan

Parents Reply Children
  • Hello Elfving,

    No worries regarding to time to answer. I have been on vacation since before Christmas.

    I managed to find the cause myself. In case someone have similar problem, here are the changes I had to do:

    In the pm_static file:

    settings_storage:
      address: 0x003fe000
      end_address: 0x00400000
      size: 0x00002000
      region: external_flash
      device: mx25r6435f
    littlefs_storage:
      address: 0x00000000
      end_address: 0x003fe000
      region: external_flash
      device: mx25r6435f
      size: 0x003fe000
      affiliation: disk
      extra_params: {
          disk_name: "littlefs",
          disk_cache_size: 4096,
          disk_sector_size: 512,
          disk_read_only: 0
        }

    In the Littlefs setup (.h file):

    fs_mount_t m_littlefs_mnt = {
            .type = FS_LITTLEFS,
            .mnt_point = "/lfs",
            .fs_data = &m_littlefs_data,
            .storage_dev = (void*)FIXED_PARTITION_ID(littlefs_storage),
        };

    In the cpp file:

    int res = fs_mount(&m_littlefs_mnt);

    .storage_dev was set wrong (to this)

    .storage_dev = (void*)FIXED_PARTITION_ID(storage_partition)

    In addition I have this in an overlay file:

    / {
        chosen {
            nordic,pm-ext-flash = &mx25r64;
        };
    };

    With these changes Settings and Littlefs uses the mx25 with its own partitions.
    And everything works.

  • Great! Glad to hear it Jan, and thanks for sharing the solution Slight smile

    Let us know if there is anything else!

    Regards,

    Elfving

Related