How to configure Settings API to work on a specific partition defined in the pm_static.yaml file

I'm trying to get the settings api working with multiple partitions using little FS. Some of the implementation is specific to Nordic and was hoping to get an example of how to do it with the pm_static.yaml. The fs subsystem is working, but I'm not sure how to configure the settings_storage partition to be used for settings.

I have this in my pm_static.yaml:

littlefs_storage:
  address: 0x0
  region: external_flash
  size: 0x200000
lvgl_raw_partition:
  address: 0x200000
  region: external_flash
  size: 0x200000
settings_storage:
  address: 0x400000
  size: 0x100000
  region: external_flash

This is how I am trying to initialize it. I know it's incomplete but am having trouble getting to the next steps.

#define STORAGE_PARTITION	storage_partition
#define STORAGE_PARTITION_ID	FIXED_PARTITION_ID(STORAGE_PARTITION)


/*
struct settings_handler my_conf = {
    .name = "foo",
    .h_set = foo_settings_set
};
*/



static int setting_manager_load_cb(const char *name, size_t len,
                            settings_read_cb read_cb, void *cb_arg)
{
    LOG_DBG("Loading setting %s", name);
}

SETTINGS_STATIC_HANDLER_DEFINE(settings_app_handler, SETTINGS_PATH, NULL,
                               setting_manager_load_cb, NULL, NULL);

void setting_manager_init()
{
    LOG_DBG("Initializing setting manager");
    int rc;
    rc = settings_subsys_init();
	if (rc) {
		LOG_ERR("settings subsys initialization: fail (err %d)", rc);
		return;
	}
    LOG_DBG("Settings subsystem initialized, loading...");


    //settings_register(&my_conf);
    settings_load();
    LOG_DBG("Settings loaded");


    //foo_val++;
    //settings_save_one("foo/bar", &foo_val, sizeof(foo_val));

    //printk("foo: %d\n", foo_val);

}

The log entries when running are:

<dbg> setting_manager: setting_manager_init: Initializing setting manager
<dbg> setting_manager: setting_manager_init: Settings subsystem initialized, loading...
<err> fs: file open error (-2)

I saw these threads on the topic, 

  • Does it basically make mcuboot partitions for primary and secondary and everything else is just mount point we use for settings and mcuboot?

    I guess I need to delete the pm_static.yml file:

    littlefs_storage:
      address: 0x0
      region: external_flash
      size: 0x200000
    lvgl_raw_partition:
      address: 0x200000
      region: external_flash
      size: 0x200000
    settings_storage:
      address: 0x400000
      size: 0x100000
      region: external_flash

    And the code in the overlay:

    /delete-node/ &storage_partition;
    
    &mx25r64 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		littlefs_storage: partition@0 {
    			label = "littlefs_storage";
    			reg = <0x00000000 0x00200000>;
    		};
    		lvgl_raw_partition: partition@200000 {
    			label = "lvgl_raw_partition";
    			reg = <0x00200000 0x00200000>;
    		};
            settings_partition: partition@400000 {
                label = "settings_partition";
                reg = <0x400000 0x100000 >;
            };
    	};
    };

    I made the changes and with this code:

        LOG_DBG("%s: bsize = %lu ; frsize = %lu ;blocks = %lu ; bfree = %lu", 
    		mp->mnt_point,sbuf.f_bsize, 
    		sbuf.f_frsize,sbuf.f_blocks, sbuf.f_bfree);

    The output is:

    filesystem_manager_init: /lfs: bsize = 16 ; frsize = 4096 ;blocks = 6 ; bfree = 0

    Which doesn't seem right. This is a nRF5340 DK with external flash. When I do it with the manual partitions I get:

    filesystem_manager_init: /lfs: bsize = 16 ; frsize = 4096 ;blocks = 512 ; bfree = 492

    I would like some way to use the 1 MB flash on the nRF5340 and the 64 megabit external flash memory for mcu boot primary/secondary, files, and settings. 

    I tried with the littlefs sample and got this:

    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 8 ; bfree = 6

    From the code:

    	LOG_PRINTK("%s: bsize = %lu ; frsize = %lu ;"
    		   " blocks = %lu ; bfree = %lu\n",
    		   mountpoint->mnt_point,
    		   sbuf.f_bsize, sbuf.f_frsize,
    		   sbuf.f_blocks, sbuf.f_bfree);

    Which does not seem to be the external flash drive on the dk which should be 64megabit, right?

    What is the right way to configure external flash for lfs, settings, and MCUboot? Should I use partition manager or have a pm_static.yml?

  • I don't know if I should start a new thread on this given that the request has changed based on the feedback but, if I am going to use dynamic partitioning using partition manger as recommended here and on this Nordic video ("I recommend that, while developing, you use dynamic partitioning"). I want to use partition manager for setting up partitions to support littlefs, settings, and MCU boot using external flash on the nRF5340 DK.

    I started as  did with the littlefs sample. I added CONFIG_PARTITION_MANAGER_ENABLED=y  to the prj.conf.

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # Optionally force the file system to be recreated
    #CONFIG_APP_WIPE_STORAGE=y
    
    # fs_dirent structures are big.
    CONFIG_MAIN_STACK_SIZE=4096
    
    # Let __ASSERT do its job
    CONFIG_DEBUG=y
    
    CONFIG_LOG=y
    CONFIG_LOG_MODE_MINIMAL=y
    
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    
    CONFIG_SPI=y
    CONFIG_PARTITION_MANAGER_ENABLED=y
    #CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
    
    

    and got this error on build:

    fatal error: pm_config.h: No such file or directory
       12 | #include <pm_config.h>

    My intent was to start with littlefs, get partition manger working, get external flash working, get settings working, then get MCU Boot working. I got stuck on the first step.

  • lcj said:
    My intent was to start with littlefs, get partition manger working, get external flash working, get settings working, then get MCU Boot working.

    Are you able to run my uploaded example without issue?

  • Did you have:

    CONFIG_PARTITION_MANAGER_ENABLED=y

    I tried to build and got when building:

    /opt/nordic/ncs/v2.6.1/nrf/subsys/partition_manager/flash_map_partition_manager.c:12:10: fatal error: pm_config.h: No such file or directory
       12 | #include <pm_config.h>
          |          ^~~~~~~~~~~~~
    compilation terminated.
    [59/168] Building C object CMakeFiles/app.dir/src/main.c.obj
    /Users/xxx/Downloads/littlefs/src/main.c: In function 'littlefs_flash_erase':
    /Users/xxx/Downloads/littlefs/src/main.c:259:22: warning: implicit declaration of function 'flash_area_flatten'; did you mean 'flash_area_align'? [-Wimplicit-function-declaration]
      259 |                 rc = flash_area_flatten(pfa, 0, pfa->fa_size);
          |                      ^~~~~~~~~~~~~~~~~~
          |                      flash_area_align
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/580e4ef81c/bin/cmake --build /Users/leojunquera/Downloads/littlefs/build

Related