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

Related