This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF9160 Defining extra flash partition

Hi,

The actual problem: I want to store some stuff to flash at factory, that is never erased. And I also need another persistent memory that can be written in runtime. I figured that the best ways to achieve this is to make two partitions and define the other one as read only(in application level)

And the 8 hours of head banging problem:

What are the steps to define a second partition for NVS use? I've tried to read the docs and concluded that it should work by just adding e.g. this to my custom overlay file

&flash0 {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
...
// Clip the others away, same as DK board definitions
...
		storage_partition: partition@fa000 {
			label = "storage";
			reg = <0x000fa000 0x00005000>;
		};
        permanent_storage_partition: partition@ff000 {
			label = "storage-1";
			reg = <0x000ff000 0x00001000>;
		};
	};
};

However this causes FLASH_AREA_OFFSET(storage_1) macro to give strange errors:

nordic/ncs/nrf/include/flash_map_pm.h:34:11: error: 'PM_PM_PM_storage_1_ID_LABEL_ADDRESS' undeclared (first use in this function)
  UTIL_CAT(PM_, UTIL_CAT(UTIL_CAT(PM_, UTIL_CAT(PM_ID(label), _LABEL)), _ADDRESS))

I also tried to modify the /ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts file directly, but after rm -rf:ing the build folder and rebuild I get the same error. When I grep my build folder I see these:

jussi@jussi-VirtualBox:~/devel/loopshore/loneplus-embedded/nrf91$ grep -r -E "STORAGE_" build/*
build/mcuboot/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_ADDRESS 0xfa000
build/mcuboot/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_SIZE 0x6000
build/mcuboot/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_NAME nvs_storage
build/mcuboot/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_ID 7
build/mcuboot/zephyr/include/generated/pm_config.h:#define PM_nvs_storage_ID PM_NVS_STORAGE_ID
build/mcuboot/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_DEV_NAME "NRF_FLASH_DRV_NAME"
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_ID                    6
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_READ_ONLY             0
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_OFFSET_0              1024000
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_OFFSET                DT_FLASH_AREA_STORAGE_OFFSET_0
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_SIZE_0                20480
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_SIZE                  DT_FLASH_AREA_STORAGE_SIZE_0
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_DEV                   "NRF_FLASH_DRV_NAME"
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_ID                  7
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_READ_ONLY           0
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_OFFSET_0            1044480
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_OFFSET              DT_FLASH_AREA_STORAGE_1_OFFSET_0
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_SIZE_0              4096
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_SIZE                DT_FLASH_AREA_STORAGE_1_SIZE_0
build/mcuboot/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_DEV                 "NRF_FLASH_DRV_NAME"
build/pm_nrf9160dk_nrf9160.config:PM_NVS_STORAGE_ADDRESS=0xfa000
build/pm_nrf9160dk_nrf9160.config:PM_NVS_STORAGE_SIZE=0x6000
build/pm_nrf9160dk_nrf9160.config:PM_NVS_STORAGE_NAME=nvs_storage
build/pm_nrf9160dk_nrf9160.config:PM_NVS_STORAGE_ID=7
build/pm_nrf9160dk_nrf9160.config:PM_nvs_storage_ID=PM_NVS_STORAGE_ID
build/spm/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_ADDRESS 0xfa000
build/spm/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_SIZE 0x6000
build/spm/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_NAME nvs_storage
build/spm/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_ID 7
build/spm/zephyr/include/generated/pm_config.h:#define PM_nvs_storage_ID PM_NVS_STORAGE_ID
build/spm/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_DEV_NAME "NRF_FLASH_DRV_NAME"
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_ID                    6
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_READ_ONLY             0
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_OFFSET_0              1024000
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_OFFSET                DT_FLASH_AREA_STORAGE_OFFSET_0
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_SIZE_0                20480
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_SIZE                  DT_FLASH_AREA_STORAGE_SIZE_0
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_DEV                   "NRF_FLASH_DRV_NAME"
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_ID                  7
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_READ_ONLY           0
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_OFFSET_0            1044480
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_OFFSET              DT_FLASH_AREA_STORAGE_1_OFFSET_0
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_SIZE_0              4096
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_SIZE                DT_FLASH_AREA_STORAGE_1_SIZE_0
build/spm/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_DEV                 "NRF_FLASH_DRV_NAME"
build/zephyr/include/generated/autoconf.h:#define CONFIG_STORAGE_LOOPONE_LOG_LEVEL 4
build/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_ADDRESS 0xfa000
build/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_SIZE 0x6000
build/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_NAME nvs_storage
build/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_ID 7
build/zephyr/include/generated/pm_config.h:#define PM_nvs_storage_ID PM_NVS_STORAGE_ID
build/zephyr/include/generated/pm_config.h:#define PM_NVS_STORAGE_DEV_NAME "NRF_FLASH_DRV_NAME"
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_ID                    6
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_READ_ONLY             0
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_OFFSET_0              1024000
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_OFFSET                DT_FLASH_AREA_STORAGE_OFFSET_0
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_SIZE_0                20480
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_SIZE                  DT_FLASH_AREA_STORAGE_SIZE_0
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_DEV                   "NRF_FLASH_DRV_NAME"
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_ID                  7
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_READ_ONLY           0
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_OFFSET_0            1044480
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_OFFSET              DT_FLASH_AREA_STORAGE_1_OFFSET_0
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_SIZE_0              4096
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_SIZE                DT_FLASH_AREA_STORAGE_1_SIZE_0
build/zephyr/include/generated/devicetree_legacy_unfixed.h:#define DT_FLASH_AREA_STORAGE_1_DEV                 "NRF_FLASH_DRV_NAME"

So it looks like partition sizes have changed, but some PM_NVS constants still hold the original value. Also some offsets show over 1M values, which does not sound too good->Edit: ok those are decimal values so nothing wrong with those(1024000->0xFA000). Anyway, any hints about the steps that I am missing or doing wrong are appreciated.

Edit: I have a custom board, but still compiling with DK device tree definitions + some overlays. NRF sdk 1.3

  • Hi.

    NCS uses the Partition Manager to partition the flash, and not the device tree.

    That is why you are missing your 'storage-1' partition.

    You can read more about the Partition Manager here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.3.0/nrf/scripts/partition_manager/partition_manager.html

    However, I am not sure what is the best way for the application to declare a second NVS partition. I will check with our developers tomorrow and get back to you.

    Best regards,

    Didrik

  • Hi again, and soryy for this taking some time.

    At the moment, there are two ways of defining an extra flash partition. Unfortunatly, both of them has some drawbacks:

    1. You can edit the pm.yml file used by the NVS subsystem (<your NCS folder>/nrf/subsys/partition_manager/pm.yml.nvs). This will let the partition manager place the partition in a suitable location at compile time. The drawback here is that you have to edit a part of the SDK, which will make it (a bit) harder to reproduce on other computers, and it makes it (a bit) more complicated to update NCS version in the future.

    2. You can create a static configuration for the partition manager, with the new partition hard coded in. This will keep all the configuration local to your project, thus avoiding the drawbacks of option 1. The drawback here is that you will have to create the static configuration yourself, which increases the time to "get started". Once you are done developing, or are starting to test DFU, you will need a static configuration anyway, as that is the only way to keep the partition map accross application versions. The difference here is that if the partition map is generated automatically, you can just use that (extract it from the build folder, and rename the file), versus having to construct it yourself. But, you can do something similar, where you use the partition manager to create a partition map with only one NVS partition, then edit it to add the second partition.

    I will also add the ability for the application to define new partitions as a feture request, so that there will be a solution without any of the above drawbacks.

    Edit: This PR will let you add extra partion manager configuration files to the build: https://github.com/nrfconnect/sdk-nrf/pull/2880

    Best regards,

    Didrik

  • Thanks, I'll try these. I have my own fork from pretty much everything already anyway, so changing the pm.yml does not sound too bad.

Related