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.

  • 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

  • I redownloaded the file and ran it successfully. I can also do that with the generic littlefs same. Now I need it to:

    1. Use External Flash on the DK
    2. Use Settings
    3. Use MCUBoot
  • Executing "ninja partition_manager_report" under the build folder would show the memory layout, as my figure in the previous reply. My example is already enabled External Flash/Settings/MCUBoot as the memory layout indicates. 

  • I get:

    (3.8.0) xxx build % ninja partition_manager_report
    zsh: command not found: ninja

    Also prints are:

    I: littlefs partition at /lfs1
    I: LittleFS version 2.5, disk version 2.0
    I: FS at flash-controller@39000:0xf8000 is 8 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    I: Automount /lfs1 succeeded
    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Sample program to r/w files on littlefs
    Area 0 at 0xf8000 on flash-controller@39000 for 32768 bytes
    /lfs1 automounted
    /lfs1: bsize = 16 ; frsize = 4096 ; blocks = 8 ; bfree = 5

    Wouldn't there be more blocks?

    How do you have settings running without something like this in the prj.conf:

    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_RUNTIME=y
    CONFIG_SETTINGS_FS=y
    CONFIG_SETTINGS_FS_DIR="/lfs/settings"
    CONFIG_SETTINGS_FS_FILE="/lfs/settings/run"

    or MCUBoot without:

    # Enable MCUboot and FOTA
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
    CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="mcuboot/root-rsa-2048.pem"

  • lcj said:
    Wouldn't there be more blocks?

    Could you build the code with sysbuild (--sysbuild)?

    west command:
    west build -p -b nrf5340dk_nrf5340_cpuapp -d build_nrf5340dk_nrf5340_cpuapp --sysbuild  && west flash --build-dir build_nrf5340dk_nrf5340_cpuapp --recover

    The output log would look like this:

    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Image index: 0, Swap type: none
    I: Bootloader chainload address offset: 0xc000
    I: littlefs partition at /lfs1slot
    I: LittleFS version 2.5, disk version 2.0
    I: FS at mx25r6435f@0:0x200000 is 512 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    I: Automount /lfs1 succeeded
    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Sample program to r/w files on littlefs
    Area 8 at 0x200000 on mx25r6435f@0 for 2097152 bytes
    /lfs1 automounted
    /lfs1: bsize = 16 ; frsize = 4096 ; blocks = 512 ; bfree = 509
    
    Listing dir /lfs1 ...
    [FILE] boot_count (size = 1)
    [FILE] pattern.bin (size = 547)
    /lfs1/boot_count read count:1 (bytes: 1)
    /lfs1/boot_count write new boot count 2: [wr:1]
    ------ FILE: /lfs1/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: /lfs1 unmounted
    /lfs1 unmount: 0

    Executing "ninja partition_manager_report" under the build folder would get the memory layout like this:

    lcj said:
    How do you have settings running without something like this in the prj.conf:

    I use non-volatile storage (CONFIG_SETTINGS_NVS) by setting in the nrf5340dk_nrf5340_cpuapp.conf:

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    # Copyright (c) 2019 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # Need this when storage is on flash
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    
    # Need this when storage is on MX25R64
    CONFIG_NORDIC_QSPI_NOR=y
    CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    ################################################################################
    # Settings - Used to store real-time device configuration to flash.
    CONFIG_NVS=y 
    CONFIG_SETTINGS=y 
    CONFIG_SETTINGS_NVS=y
    CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x200000 
    CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x200000

    MCUBoot is enabled by SB_CONFIG_BOOTLOADER_MCUBOOT=y in the sysbuild.conf.

Reply
  • lcj said:
    Wouldn't there be more blocks?

    Could you build the code with sysbuild (--sysbuild)?

    west command:
    west build -p -b nrf5340dk_nrf5340_cpuapp -d build_nrf5340dk_nrf5340_cpuapp --sysbuild  && west flash --build-dir build_nrf5340dk_nrf5340_cpuapp --recover

    The output log would look like this:

    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Image index: 0, Swap type: none
    I: Bootloader chainload address offset: 0xc000
    I: littlefs partition at /lfs1slot
    I: LittleFS version 2.5, disk version 2.0
    I: FS at mx25r6435f@0:0x200000 is 512 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    I: Automount /lfs1 succeeded
    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Sample program to r/w files on littlefs
    Area 8 at 0x200000 on mx25r6435f@0 for 2097152 bytes
    /lfs1 automounted
    /lfs1: bsize = 16 ; frsize = 4096 ; blocks = 512 ; bfree = 509
    
    Listing dir /lfs1 ...
    [FILE] boot_count (size = 1)
    [FILE] pattern.bin (size = 547)
    /lfs1/boot_count read count:1 (bytes: 1)
    /lfs1/boot_count write new boot count 2: [wr:1]
    ------ FILE: /lfs1/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: /lfs1 unmounted
    /lfs1 unmount: 0

    Executing "ninja partition_manager_report" under the build folder would get the memory layout like this:

    lcj said:
    How do you have settings running without something like this in the prj.conf:

    I use non-volatile storage (CONFIG_SETTINGS_NVS) by setting in the nrf5340dk_nrf5340_cpuapp.conf:

    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    # Copyright (c) 2019 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # Need this when storage is on flash
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    
    # Need this when storage is on MX25R64
    CONFIG_NORDIC_QSPI_NOR=y
    CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    
    ################################################################################
    # Settings - Used to store real-time device configuration to flash.
    CONFIG_NVS=y 
    CONFIG_SETTINGS=y 
    CONFIG_SETTINGS_NVS=y
    CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x200000 
    CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x200000

    MCUBoot is enabled by SB_CONFIG_BOOTLOADER_MCUBOOT=y in the sysbuild.conf.

Children
Related