Utilize device tree partition with MCU boot

I am working on custom hardware with an nRF52840. I have added the MCU boot in my earlier development as well but this issue I have never faced before.

Problem statement

I have defined a partition as mentioned below snippet where I have used the minimal MCU boot size configuration along with the MOVE WITH SCRATCH configuration. Along with 4 defined partitions of MCU boot boot, slot0, slot1, and scratc,h there is another partition named data_logger_storage which I have added to save my application data.

&flash0 {

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

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x00000000 0x00003E00>;
		};
		slot0_partition: partition@3E00 {
			label = "image-0";
			reg = <0x00003E00 0x0007B000>;
		};
		slot1_partition: partition@7EE00 {
			label = "image-1";
			reg = <0x0007EE00 0x0007B000>;
		};
		scratch_partition: partition@F9E00 {
			label = "image-scratch";
			reg = <0xF9E00 0x3F00>;
		};
		/*
		 * The flash starting at 0x000f8000 and ending at
		 * 0x000fffff is reserved for use by the application.
		 */

		/*
		 * Storage partition will be used by FCB/LittleFS/NVS
		 * if enabled.
		 */
		 data_logger_storage_partition: partition@FDD00 {
			label = "storage";
			reg = <0x000FDD00 0x00002000>;
		};		
	};
};

Here when I compile my code, I face an error 

error: 'PM_PM_PM_data_logger_storage_partition_ID_LABEL_OFFSET' was not declared in this scope

I have not added the pm.yml or pm_static.yml file in my application, because I have other running code with MCU boot and device tree partition that does not have the pm.yml.

So here are my query,
1. How can we use the device tree partition only when we enable the MCU boot? Because I do not have a scope to define pm.yml as the same code is designed in such a way that it can be used with any of nrf boards i.e the same code can be built for nrf52840 and nrf5340

I have attached the partitions.yml generated with this build, which certainly has different data from what I have defined in the device tree.

  • EMPTY_0:
      address: 0x7c00
      end_address: 0x8000
      placement:
        before:
        - mcuboot_pad
      region: flash_primary
      size: 0x400
    app:
      address: 0x8200
      end_address: 0x81000
      region: flash_primary
      size: 0x78e00
    mcuboot:
      address: 0x0
      end_address: 0x7c00
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x7c00
    mcuboot_pad:
      address: 0x8000
      end_address: 0x8200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x8000
      end_address: 0x81000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      sharers: 0x1
      size: 0x79000
      span: *id001
    mcuboot_primary_app:
      address: 0x8200
      end_address: 0x81000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0x78e00
      span: *id002
    mcuboot_secondary:
      address: 0x81000
      end_address: 0xfa000
      placement:
        after:
        - mcuboot_primary
        align:
          start: 0x1000
      region: flash_primary
      share_size:
      - mcuboot_primary
      size: 0x79000
    nvs_storage:
      address: 0xfa000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x6000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    

  • Hi Ankit, 
    I will look deeper at the ticket tomorrow. But I just want to point to where the partition manager "overwrite" the configuration of the partition in device tree: \nrf\include\flash_map_pm.h

    /* Aliases for zephyr - mcuboot/ncs style naming */
    #define image_0 mcuboot_primary
    #define slot0_partition mcuboot_primary
    #define image_1 mcuboot_secondary
    #define slot1_partition mcuboot_secondary
    #define image_0_nonsecure mcuboot_primary
    #define slot0_ns_partition mcuboot_primary
    #define image_1_nonsecure mcuboot_secondary
    #define slot1_ns_partition mcuboot_secondary
    #define image_2 mcuboot_primary_1
    #define image_3 mcuboot_secondary_1
    #define slot2_partition mcuboot_primary_1
    #define slot3_partition mcuboot_secondary_1
    #define slot4_partition mcuboot_primary_2
    #define slot5_partition mcuboot_secondary_2
    #define image_scratch mcuboot_scratch
    #define image_scratch mcuboot_scratch

    When multiple image is compiled, partition manager will be used. You can see in the doc here: https://docs.nordicsemi.com/bundle/ncs-2.2.0/page/nrf/scripts/partition_manager/partition_manager.html

    I'm not sure if you can remove partition manager in a multi images build, but have you looked at the option to use pm  ? You just need to configure the partitions correctly. 

  • Hi Hung,

    Thanks for your reply. 

    Your suggestion to enable PM will allow me to configure the partition using the pm.yml file. And as I mentioned my application code is distinct amongst the different boards (like nrf52 and nrf53). I have different sensors one is using nRF52 and the other is using nRF53.

    The partitions for nRF52 and nRF53 will differ, so using pm.yml is not an option for me as it will freeze the partition for all boards.

    Please current my understanding if I am wrong with this terminology.

  • Hi Ankit, 
    It's actually possible to make pm_static file for each board. Just name it pm_static_*boardname*.yml
    You can take a look at our sample for reference: 

  • Hi Hung,

    I see. That should resolve my concern.

    So what I understood is that the pm_statuc.yml file is the only way to define a custom flash partition when the MCUBoot is enabled.

    I am running another project where I found the partition.yml file in the build/ directory which has the generated partition.  Here is the partition.yml

    app:
      address: 0xc200
      end_address: 0x83000
      region: flash_primary
      size: 0x76e00
    mcuboot:
      address: 0x0
      end_address: 0xc000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0xc000
    mcuboot_pad:
      address: 0xc000
      end_address: 0xc200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0xc000
      end_address: 0x83000
      orig_span: &id001
      - app
      - mcuboot_pad
      region: flash_primary
      sharers: 0x1
      size: 0x77000
      span: *id001
    mcuboot_primary_app:
      address: 0xc200
      end_address: 0x83000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0x76e00
      span: *id002
    mcuboot_secondary:
      address: 0x83000
      end_address: 0xfa000
      placement:
        after:
        - mcuboot_primary
        align:
          start: 0x1000
      region: flash_primary
      share_size:
      - mcuboot_primary
      size: 0x77000
    nvs_storage:
      address: 0xfa000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x6000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000

    When I saw the file and compared the partition with the device tree partition, I did not find any scratch partition in the partition.yml file. Below are my device tree partition details.

    &flash0 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x0 0xc000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0xc000 0x72000>;
    		};
    		slot1_partition: partition@7e000 {
    			label = "image-1";
    			reg = <0x7e000 0x72000>;
    		};
    		scratch_partition: partition@f0000 {
    			label = "image-scratch";
    			reg = <0xf0000 0xa000>;
    		};
    		storage_partition: partition@f8000 {
    			label = "storage";
    			reg = <0xf8000 0x6000>;
    		};
    	};
    };

    However, my MCUboot is configured to handle the dual image partition with the Swap With the Scratch option enabled. I am curious to know how the OTA is performing without scratch partition.

    Can you please help me to understand this concept?

Related