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

NRF9160 Using customized flash partition

Dear all,

For our project we want to store information on the device in an additional flash partition.
We have created a new flash partition, called factory_settings_partition, by defining it in our custom board files as follows:

&flash0 {
	/*
	 * For more information, see:
	 * https://docs.zephyrproject.org/latest/guides/dts/legacy-macros.html#legacy-flash-partitions
	 */
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x10000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
		};
		slot0_ns_partition: partition@50000 {
			label = "image-0-nonsecure";
		};
		slot1_partition: partition@80000 {
			label = "image-1";
		};
		slot1_ns_partition: partition@c0000 {
			label = "image-1-nonsecure";
		};
		scratch_partition: partition@f0000 {
			label = "image-scratch";
			reg = <0x000f0000 0xa000>;
		};
		storage_partition: partition@fa000 {
			label = "storage";
			reg = <0x000fa000 0x00006000>;
		};
		factory_settings_partition: partition@100000 {
			label = "factory_settings";
			reg = <0x00100000 0x000007d0>;
		};
	};
};


Now when trying to read and write to the flash we get an error from the FLASH_AREA_OFFSET(factory_settings):
 error: 'PM_PM_PM_factory_settings_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 getting my code to work with an already existing flash partition, namely storage_partition, and that worked fine, I got no errors.
My issue is the same as the issue in this post; for us the first solution offered is not an option and the second solution is a bit unclear to me.

Can you give me guidance to how I can implement and use my own flash partition?

Kind regards,
Maaike

Parents
  • Hi, Maaike!

    As Didrik mentioned in the thread you've linked to any device tree configuration of flash partitions are ignored by the Partition Manager script. This script is used by the build system to properly allocate space for multi-image builds, and is thus used for most nRF9160 applications.

    I agree that his second option in general is more suitable. The partition manager documentation should cover how to configure your own static partitions and I suggest looking into that. For examples the asset_tracker example defines a static partition configuration for the Thingy:91.

    Best regards,
    Carl Richard

  • Hi Carl,

    Thank you for your reply.

    I have added the partition the the pm_static.yml file and it seems that the flash configuration now works well, as I see the partition in the partitions.yml file in the build folder. 

    However, I now get the following error

    fs_nvs: Unable to get page info

    It seems that the page of the offset does not exist.

    This is my pm_static.yml file:
    factory_settings_partition:
       address: 0x00100000
       size: 0x000007d0
       #span: [example]  # Only if this partition had the span property set originally.


    And this is what I see in partitions.yml after building
    app:
      address: 0xc000
      region: flash_primary
      size: 0xee000
    bsdlib_sram:
      address: 0x20010000
      placement:
        after:
        - spm_sram
        - start
      region: sram_primary
      size: 0x10000
    factory_settings_partition:
      address: 0x100000
      region: flash_primary
      size: 0x7d0
    nvs_storage:
      address: 0xfa000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
    otp:
      address: 0xff8108
      region: otp
      size: 0x2f4
    spm:
      address: 0x0
      placement:
        before:
        - app
      region: flash_primary
      size: 0xc000
    spm_sram:
      address: 0x20000000
      inside:
      - sram_secure
      placement:
        after:
        - start
      region: sram_primary
      size: 0x10000
    sram_primary:
      address: 0x20020000
      region: sram_primary
      size: 0x20000
    sram_secure:
      address: 0x20000000
      orig_span: &id001
      - spm_sram
      region: sram_primary
      size: 0x10000
      span: *id001



    Here is how I initialize flash
    static struct nvs_fs fs;
       
    static bool set_config_hwver(const char* majorString, const char* minorString)
    {   
       
        fs.offset = FLASH_AREA_OFFSET(factory_settings_partition);
    
        int rc = 0;
        char buf[32];
        
        struct flash_pages_info info;
        rc = flash_get_page_info_by_offs(
            device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL), fs.offset, &info);
        if (rc) {
            printk("rc: %d\n", rc);
            LOG_DBG("Unable to get page info");
        }
    
        fs.sector_size = info.size;
        fs.sector_count = 3U;
        rc = nvs_init(&fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
        if (rc) {
            LOG_DBG("Flash Init failed\n");
        }


    I am not sure what I am missing, is the offset of my partition defined badly? 

    Kind regards,
    Maaike

  • Hi again!

    This is failing as the address 0x100000 is outside the flash_primary region. To stay within the region I suggest lowering the NVS partition size using CONFIG_PM_PARTITION_SIZE_NVS_STORAGE and then changing the start address and size of your static partition accordingly. 

    For example by setting the NVS storage partition size to 0x0 the following pm_static.yml should work:

    factory_settings_partition:
       address: 0x1f7d0
       size: 0xE0830
       #span: [example]  # Only if this partition had the span property set originally.


    Best regards,
    Carl Richard

Reply
  • Hi again!

    This is failing as the address 0x100000 is outside the flash_primary region. To stay within the region I suggest lowering the NVS partition size using CONFIG_PM_PARTITION_SIZE_NVS_STORAGE and then changing the start address and size of your static partition accordingly. 

    For example by setting the NVS storage partition size to 0x0 the following pm_static.yml should work:

    factory_settings_partition:
       address: 0x1f7d0
       size: 0xE0830
       #span: [example]  # Only if this partition had the span property set originally.


    Best regards,
    Carl Richard

Children
Related