Maximum settings partition size estimation

Hi there,

I need help finalizing the size of my product's settings partition. I only store Bluetooth bonds on the settings partition: 20 bonds to other Nordic devices via the Nordic UART service and 10 bonds to BLE HID devices. These connections must be securely encrypted.

According to what I see, the following settings keys are stored:
- bt/sc/0123456789abc 4 bytes, stored for one device
- bt/cf/0123456789abc - 2 bytes, stored for one device
- bt/keys/0123456789abc - 80 bytes, stored for all devices
- bt/ccc/0123456789abc - 12-32 bytes, stored for all devices

The reason I can't estimate the maximum storage size for my needs is because of the following:
- Some keys are present for all devices I tested, while others are only for one. I don't know which keys are stored in which cases.
- Some keys vary in size, and I don't know their minimum and maximum size.
- There may be additional keys that are used on select occasions, which I don't know.
- I don't know the storage overhead of NVS.
- Can NVS be fragmented? If so, it should be accounted for.

Thanks in advance!
- Laci

Parents
  • Hello,

    How much flash is used by settings is very application depended (number of setting entries and how frequent they are updated). I recommend using the nvs_calc_free_space() to help profile the flash usage for your application. Flash wear should also be considered: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/storage/nvs/nvs.html#flash-wear 

    You can use this function to retreive the NVS instance used by the settings module: https://github.com/nrfconnect/sdk-zephyr/commit/ccf8c547d090ad3f76dbfa64744f32333658dcdb 

    Best regards,

    Vidar

  • Hi Vidar,

    I've included the following in my main():

    	void *storage;
        int rc = settings_storage_get(&storage);
        ssize_t size = nvs_calc_free_space((struct nvs_fs *)storage);
        printk("Free space: %d\n", size);
    

    According to the printed result, the free space doesn't exceed 4K, even though I've allocated 8K for storage.

    my-board.dtsi:

    &flash0 {
        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;
    
            boot_partition: partition@0 {
                label = "mcuboot";
                reg = <0x0 0x10000>;
            };
            slot0_partition: partition@10000 {
                label = "image-0";
                reg = <0x10000 0xdd000>;
            };
            hardware_config_partition: partition@ed000 {
                label = "hardware-config";
                reg = <0xed000 0x1000>;
            };
            user_config_partition: partition@ee000 {
                label = "user-config";
                reg = <0xee000 0x10000>;
            };
            storage_partition: partition@fe000 {
                label = "storage";
                reg = <0xfe000 0x2000>;
            };
        };
    };
    

    pm_static.yml:

    app:
      address: 0x10200
      end_address: 0xfe000
      region: flash_primary
      size: 0xede00
    mcuboot:
      address: 0x0
      end_address: 0x10000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x10000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0xfe000
      orig_span: &id001
      - app
      - mcuboot_pad
      region: flash_primary
      size: 0xee000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xfe000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0xede00
      span: *id002
    hardware_config_partition:
      address: 0xed000
      end_address: 0xee000
      size: 0x1000
    user_config_partition:
      address: 0xee000
      end_address: 0xfe000
      size: 0x10000
    settings_storage:
      address: 0xfe000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    

    Thanks in advance for your help!

Reply
  • Hi Vidar,

    I've included the following in my main():

    	void *storage;
        int rc = settings_storage_get(&storage);
        ssize_t size = nvs_calc_free_space((struct nvs_fs *)storage);
        printk("Free space: %d\n", size);
    

    According to the printed result, the free space doesn't exceed 4K, even though I've allocated 8K for storage.

    my-board.dtsi:

    &flash0 {
        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;
    
            boot_partition: partition@0 {
                label = "mcuboot";
                reg = <0x0 0x10000>;
            };
            slot0_partition: partition@10000 {
                label = "image-0";
                reg = <0x10000 0xdd000>;
            };
            hardware_config_partition: partition@ed000 {
                label = "hardware-config";
                reg = <0xed000 0x1000>;
            };
            user_config_partition: partition@ee000 {
                label = "user-config";
                reg = <0xee000 0x10000>;
            };
            storage_partition: partition@fe000 {
                label = "storage";
                reg = <0xfe000 0x2000>;
            };
        };
    };
    

    pm_static.yml:

    app:
      address: 0x10200
      end_address: 0xfe000
      region: flash_primary
      size: 0xede00
    mcuboot:
      address: 0x0
      end_address: 0x10000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x10000
    mcuboot_pad:
      address: 0x10000
      end_address: 0x10200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x10000
      end_address: 0xfe000
      orig_span: &id001
      - app
      - mcuboot_pad
      region: flash_primary
      size: 0xee000
      span: *id001
    mcuboot_primary_app:
      address: 0x10200
      end_address: 0xfe000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0xede00
      span: *id002
    hardware_config_partition:
      address: 0xed000
      end_address: 0xee000
      size: 0x1000
    user_config_partition:
      address: 0xee000
      end_address: 0xfe000
      size: 0x10000
    settings_storage:
      address: 0xfe000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    

    Thanks in advance for your help!

Children
Related