NVS Settings subsys custom partition placement

Hi,

I am working on a project where I use the Settings subsys with the NVS backend.
I am using a "provisioning" firmware that is used to initialize the settings partition with default values and to provision the modem with certificates and keys.

Now I would like to be sure that the settings_storage partition is located at the same address for my provisioning and my main applications (end of flash).
To do so I would like to specify it using a custom partition manager configuration file and not use the default generated one, which raise multiple questions:

1. where can I define a custom partition ? (I tried in a pm.yml file at the root of the project but it seems to be ignored. I am not sure to have fully understood everything about multi image build)
2. will my custom partition be in conflict with the one that is automatically added by the settings subsys ?
3. is there any sample where the partition is used to define a custom partition ?

Regards

Alexandre

Parents
  • Hi,

    1. where can I define a custom partition ? (I tried in a pm.yml file at the root of the project but it seems to be ignored. I am not sure to have fully understood everything about multi image build)

    You can do this by using static configuration and static partitions in a pm_static.yml https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/scripts/partition_manager/partition_manager.html#static-configuration. If you create one in the root folder of your project it should be included by the build system when you build your project. 

    2. will my custom partition be in conflict with the one that is automatically added by the settings subsys ?

    Any partitions you create in a static_partition will be used instead of the dynamic partitioning, and any partitions not included in the static_partition that is still required by the build system will be included by the dynamic partitioning manager. In other words, as long as you name your partitions properly, it will not be in conflict with the dynamic partitioning.

    3. is there any sample where the partition is used to define a custom partition ?

    There isn't any sample that showcases how to create a pm_static.yml, but there are multiple samples that uses a pm_static.yml (most wireless protocol samples has CONFIG_SETTINGS=y and many of them also uses static partitioning.

    The steps to create a static pm yourself can be done as follows:

    1. Create your application using the dynamic partitioning used by the build system
    2. Copy the contents of partitions.yml from build/partitions.yml to a pm_static.yml located in your project directory
    3. Modify the addresses according to your need. 
      1. Do note that if you intend to have DFU support, then mcuboot primary and mcuboot secondary needs to be identically large, and mcuboot primary must fit your entire application (and have room for updates if you plan on adding features to your fw later down the products life span).
      2. The same pm_static.yml is recommended to be used for all updates in the products life span

    Kind regards,
    Andreas

  • Hi and thanks for your answer !

    Ok so I do not any choice other than using a static partition definition.

    The downside I see here is that I cannot use the CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE Kconfig variable anymore in development phase. But do I have to keep synced the size defined in the pm_static.yml file and the size defined in CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE ?

    I indeed plan to use mcuboot and DFU but with the secondary located in an external flash, do you see any potential problem with this configuration ?

    I think an advanced Partition Manager sample would be very useful to help beginner and vanilla Zephyr user to understand how it works :)

    Regards.

  • Zoptune said:
    The downside I see here is that I cannot use the CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE Kconfig variable anymore in development phase. But do I have to keep synced the size defined in the pm_static.yml file and the size defined in CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE ?

    You can still use the partition_size_settings when you define the sizes of the partitions in your yaml. The example here showcases this https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/scripts/partition_manager/partition_manager.html#configuration-file-preprocessing.

    Zoptune said:
    I indeed plan to use mcuboot and DFU but with the secondary located in an external flash, do you see any potential problem with this configuration ?

    No, this is fine :) Just make sure that the primary and secondary slots are equal in size and that you meet any other conditions mentioned here: developer.nordicsemi.com/.../partition_manager.html

    Zoptune said:
    I think an advanced Partition Manager sample would be very useful to help beginner and vanilla Zephyr user to understand how it works :)

    Yes, I agree and I will add a request for that. But luckily the documentation for PM is quite comprehensive so it is relatively straight forward to follow! :) 

    Kind regards,
    Andreas

  • Ok thanks for the MCUboot confirmation and for the sample request follow up Slight smile

    I tried to use CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE in the pm_static.yml file but I got a type error in the partition manager python script execution :

    Partition 'nonsecure_storage' is not included in the dynamic resolving since it is statically defined.
    Partition 'settings_storage' is not included in the dynamic resolving since it is statically defined.
    Dropping partition 'nrf_modem_lib_trace' since its size is 0.
    Traceback (most recent call last):
      File "/home/alexandre/Documents/Dev/Tools/nRF_Connect_SDK_2.3.0/opt/ncs/nrf/scripts/partition_manager.py", line 1978, in <module>
        main()
      File "/home/alexandre/Documents/Dev/Tools/nRF_Connect_SDK_2.3.0/opt/ncs/nrf/scripts/partition_manager.py", line 1028, in main
        solution.update(solve_region(pm_config, region, region_config,
      File "/home/alexandre/Documents/Dev/Tools/nRF_Connect_SDK_2.3.0/opt/ncs/nrf/scripts/partition_manager.py", line 971, in solve_region
        get_region_config(partitions, region_config, static_partitions, system_reqs=pm_config)
      File "/home/alexandre/Documents/Dev/Tools/nRF_Connect_SDK_2.3.0/opt/ncs/nrf/scripts/partition_manager.py", line 760, in get_region_config
        calculate_end_address(pm_config)
      File "/home/alexandre/Documents/Dev/Tools/nRF_Connect_SDK_2.3.0/opt/ncs/nrf/scripts/partition_manager.py", line 726, in calculate_end_address
        pm_config[part]['end_address'] = pm_config[part]['address'] + pm_config[part]['size']
    TypeError: unsupported operand type(s) for +: 'int' and 'str'

    It looks like the CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE is not replaced by the actual value defined in prj.conf.

    Also, I noticed that with the dynamic partitioning and settings subsystem, a nonsecure_storage partition is created, what is the purpose of this partition ? Should I define it in the pm_static.yml ?

    One last question, with static partitioning the CONFIG_PM_PARTITION_ALIGN_SETTINGS_STORAGE parameter is not usable anymore. Is this assumption correct ?

    Regards

  • Zoptune said:
    It looks like the CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE is not replaced by the actual value defined in prj.conf.

    The documentation indicates that it should be possible, but your results shows that it might not be as straight forward. I will try to recreate the same behavior on my end as well. 

    Zoptune said:
    Also, I noticed that with the dynamic partitioning and settings subsystem, a nonsecure_storage partition is created, what is the purpose of this partition ? Should I define it in the pm_static.yml ?

    The nonsecure_storage partition is used for TF-M and TrustZone. To be able to use the modem you must build the application for non-secure domain, so this storage partition is thus nonsecure.

    Zoptune said:
    One last question, with static partitioning the CONFIG_PM_PARTITION_ALIGN_SETTINGS_STORAGE parameter is not usable anymore. Is this assumption correct ?

    As per my first comment in this reply, I will try to recreate it and come back to you.

    Kind regards,
    Andreas

  • Hi,

    It looks like you're correct. 

    In your pm_static you can use overlay/dts APIs such as DT_CHOSEN to for instance fetch the devices, but it looks like you can't use the config-parameters defined such as sizes (for instance CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE ) seems to not be included in pm_static.yml, but are however included in pm.yml, which are different.

    mcuboot_secondary:
      address: 0x0
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0xf4000
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0xf4000

    I will keep looking into this during the next week, but my initial conclusion is atleast what I just said

    Kind regards,
    Andreas

Reply
  • Hi,

    It looks like you're correct. 

    In your pm_static you can use overlay/dts APIs such as DT_CHOSEN to for instance fetch the devices, but it looks like you can't use the config-parameters defined such as sizes (for instance CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE ) seems to not be included in pm_static.yml, but are however included in pm.yml, which are different.

    mcuboot_secondary:
      address: 0x0
      device: DT_CHOSEN(nordic_pm_ext_flash)
      end_address: 0xf4000
      placement:
        align:
          start: 0x4
      region: external_flash
      share_size:
      - mcuboot_primary
      size: 0xf4000

    I will keep looking into this during the next week, but my initial conclusion is atleast what I just said

    Kind regards,
    Andreas

Children
Related