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, 

Parents
  • Hi, 

    but I'm not sure how to configure the settings_storage partition to be used for settings.

    You can enable CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL to let the partition manager decide automatically. 

    However, the error looks like it concerns the file system. The error "fs: file open error (-2)" corresponds to ENOENT (No such file or directory) and typically indicates that the file you're trying to open does not exist or cannot be found. You can take a look at the littlefs sample. 

    Regards,
    Amanda H.

  • I have littlefs working for one of the partitions. I would like to keep that working. I would like to get multiple partitions to work. One specifically for settings and another for MCU Boot. This is a step in that direction. I want to get the 2nd partition running for settings and have the settings subsystem us it.

  • Hi, 

    What NCS version are you using? Are you using QSPI or SPI external flash?

    The Partition Manager will handle the partition automatically. See the External flash memory partitions and Using external flash memory partitions for more details on using external flash memory with MCUboot.

    -Amanda H.

  • If I want to manage the partition size, so I can accurately relay how much space can support a device (like sensor log file size along with settings along with mcuboot) I would think the best approach would be to specify the partition. As nice has handling the partition automatically would be, it might not be right for every circumstance. I am using the nRF5340 DK currently and have a setting: 

    CONFIG_NORDIC_QSPI_NOR=y
    in the prj.conf.
    The link you provided is helpful, and I will re-read it, but I have found it complex to implement what I am looking to do with it and some of the other materials on the same topic. I have communicated with some people who have more experience than I and they found it challenging as well. I thought this forum might be better if I asked a specific enough question.
    I want to have multiple partitions and use them for:
    1. Files
    2. Settings
    3. MCUBoot

    and be able to configure it so the setting subsystem will work. I will need to move from the DK to custom hardware so I think it's important to understand how this works and configure it cleanly.

  • lcj said:
    If I want to manage the partition size, so I can accurately relay how much space can support a device (like sensor log file size along with settings along with mcuboot)

    I can understand your situation. There are common variants of the Kconfig option to adjust the partition size. See Configuring dynamic partitions

    I would still suggest letting the Partition Manager generate the partition file (under the build folder), and then duplicate and rename it to pm_static.yaml. 

    lcj said:
    I want to have multiple partitions and use them for:
    1. Files
    2. Settings
    3. MCUBoot

    and be able to configure it so the setting subsystem will work.

    Here is my example project littlefs.7z based on the littlefs sample to enable mcuboot/Setting/LittleFileSystem and set the littlefs_storage and settings_storage on the nRF5340DK external flash. The memory layout generated by Partition Manager looks like this:

    Regards,
    Amanda H.

  • 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.

Reply
  • 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.

Children
No Data
Related