Problem with data sharing

Hello,

I have a project that contains the b0+mcuboot+app. My project works but now I would like to add "data sharing" in order to retrieve some information in my application about the mcuboot (currently used slot, version number).

I am using the nRF Connext SDK V2.7.0 and I am using the nrf52840DK.

Here is the config I added in my <Project>\Application\boards\<board>.overlay:

/ {
	sram@2003F000 {
		compatible = "zephyr,memory-region", "mmio-sram";
		reg = <0x2003F000 DT_SIZE_K(1)>;
		zephyr,memory-region = "RetainedMem";
		status = "okay";

		retainedmem {
			compatible = "zephyr,retained-ram";
			status = "okay";
			#address-cells = <1>;
			#size-cells = <1>;

			boot_info0: boot_info@0 {
				compatible = "zephyr,retention";
				status = "okay";
				reg = <0x0 0x100>;
			};

			retention1: retention@100 {
				compatible = "zephyr,retention";
				status = "okay";
				reg = <0x100 0x101>;
			};
		};
	};

	/*
	* In some default configurations within the nRF Connect SDK,
	* e.g. on nRF52840, the chosen zephyr,entropy node is &cryptocell.
	* This devicetree overlay ensures that default is overridden wherever it
	* is set, as this application uses the RNG node for entropy exclusively.
	*/
	chosen {
		//zephyr,entropy = &rng;
		zephyr,bootloader-info = &boot_info0;
		//zephyr,boot-mode = &retention1;
	};
};

&sram0 {
	reg = <0x20000000 DT_SIZE_K(255)>;
};

Here is what I put in my <Project>\Application\sysbuild\mcuboot\boards\<board>.overlay:

/* SPDX-License-Identifier: Apache-2.0 */
#include "../../../boards/<board>.overlay"

/ {
	chosen {
		zephyr,code-partition = &boot_partition;
	};
};

Here is what I put in my <Project>\Application\sysbuild\mcuboot\prj.conf:

#Adds a bootloader information sharing system which allows for retreiving data from the bootloader when data sharing is enabled:
CONFIG_RETAINED_MEM=y
CONFIG_RETENTION=y
CONFIG_BOOT_SHARE_DATA=y
CONFIG_BOOT_SHARE_DATA_BOOTINFO=y
CONFIG_BOOT_SHARE_BACKEND_RETENTION=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y

Here is what I put in my <Project>\Application\prj.conf:

#Adds a bootloader information sharing system which allows for retreiving data from the bootloader when data sharing is enabled:
CONFIG_RETAINED_MEM=y
CONFIG_RETENTION=y
CONFIG_RETENTION_BOOTLOADER_INFO=y
CONFIG_RETENTION_BOOTLOADER_INFO_TYPE_MCUBOOT=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_RETENTION_BOOTLOADER_INFO_OUTPUT_SETTINGS=y

I use a pm_static.yml file to define my partitions:

EMPTY_0:
  address: 0x19200
  end_address: 0x1a000
  placement:
    before:
    - s1_pad
  region: flash_primary
  size: 0xe00
EMPTY_1:
  address: 0x2a200
  end_address: 0x2b000
  placement:
    before:
    - mcuboot_pad
  region: flash_primary
  size: 0xe00
app:
  address: 0x2b200
  end_address: 0xEC000
  region: flash_primary
  size: 0xc0e00
app_image:
  address: 0x2b200
  end_address: 0xEC000
  orig_span: &id001
  - app
  region: flash_primary
  size: 0xC0E00
  span: *id001
b0:
  address: 0x0
  end_address: 0x8000
  placement:
    after:
    - start
  region: flash_primary
  size: 0x8000
b0_container:
  address: 0x0
  end_address: 0x9000
  orig_span: &id002
  - b0
  - provision
  region: flash_primary
  size: 0x9000
  span: *id002
mcuboot:
  address: 0x9200
  end_address: 0x19200
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  sharers: 0x1
  size: 0x10000
mcuboot_pad:
  address: 0x2b000
  end_address: 0x2b200
  placement:
    align:
      start: 0x1000
    before:
    - mcuboot_primary_app
  region: flash_primary
  sharers: 0x2
  size: 0x200
mcuboot_primary:
  address: 0x2b000
  end_address: 0xEC000
  orig_span: &id003
  - mcuboot_pad
  - app
  region: flash_primary
  sharers: 0x1
  size: 0xC1000
  span: *id003
mcuboot_primary_app:
  address: 0x2b200
  end_address: 0xEC000
  orig_span: &id004
  - app
  region: flash_primary
  size: 0xC0E00
  span: *id004
mcuboot_secondary:
  address: 0xEC000
  end_address: 0xfc000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x1000
    align_next: 0x1000                  
  region: flash_primary
  share_size:
  - mcuboot_primary
  size: 0x10000
provision:
  address: 0x8000
  end_address: 0x9000
  placement:
    after:
    - b0
    align:
      start: 0x1000
  region: flash_primary
  size: 0x1000
s0:
  address: 0x9000
  end_address: 0x19200
  orig_span: &id005
  - s0_pad
  - mcuboot
  region: flash_primary
  size: 0x10200
  span: *id005
s0_image:
  address: 0x9200
  end_address: 0x19200
  orig_span: &id006
  - mcuboot
  region: flash_primary
  size: 0x10000
  span: *id006
s0_pad:
  address: 0x9000
  end_address: 0x9200
  placement:
    after:
    - b0_container
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_pad
  size: 0x200
s1:
  address: 0x1a000
  end_address: 0x2a200
  orig_span: &id007
  - s1_pad
  - s1_image
  region: flash_primary
  size: 0x10200
  span: *id007
s1_image:
  address: 0x1a200
  end_address: 0x2a200
  placement:
    after:
    - s1_pad
    - s0
  region: flash_primary
  share_size:
  - mcuboot
  size: 0x10000
s1_pad:
  address: 0x1a000
  end_address: 0x1a200
  placement:
    after:
    - s0
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_pad
  size: 0x200
settings_storage:
  address: 0xfc000
  end_address: 0x100000
  placement:
    align:
      start: 0x1000
    before:
    - end
  region: flash_primary
  size: 0x4000
sram_primary:
  address: 0x20000000
  end_address: 0x20040000
  region: sram_primary
  size: 0x40000

Is there anything else I need to indicate in this file to take into account "data sharing"?

The compilation of this project works but here are the logs I get when I run the code:

00> *** Booting MCUboot v2.1.0-dev-daf2946a0f07 ***
00> *** Using nRF Connect SDK v2.7.0-5cb85570ca43 ***
00> *** Using Zephyr OS v3.6.99-100befc70c74 ***
00> I: Starting bootloader
00> I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
00> I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
00> I: Boot source: none
00> I: Image index: 0, Swap type: none
00> I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
00> I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
00> I: Boot source: none
00> I: Image index: 1, Swap type: none
00> E: Failed to add data to shared memory area.
00> E: Unable to find bootable image

boot_add_data_to_shared_area(…) return rc=2 (SHARED_MEMORY_OVERFLOW)

Could you tell me what I forgot?

Thanks

Parents Reply Children
  • I would suggest to not use the pm_static.yml while developing and use it for updating via DFU stage.

    Did you add boards/nrf52840dk_nrf52840.conf? If this still cannot help, please use this mcuboot_data_sharing sample as a base. 

  • I copied the configs of this example but I still have the same error (there is just the config "CONFIG_BOOT_VALIDATE_SLOT0=n" that I did not use).

    No I have to use the pm_static.yml file to be sure to be able to update the devices in the field.

    But I found where the problem is exactly but I do not know how to solve it...

    I have the error "SHARED_MEMORY_OVERWRITE" because the boot_add_shared_data() function is called twice. So it writes the data on the first call but, on the 2nd call, since the TLVs have already been written, it returns this error...

    It executes this function twice because in "context_boot_go()" it goes through all the images and calls the "boot_add_shared_data()" function for each image.

    But is it normal that I have 2 images?

    So I see this when I retrieve the images in my project (that the sent image is transferts in "image 0 slot 1" and "image 1 slot 1"):

    PS C:\DocTA\Soft\TA-Smart-BT840P> mcumgr -c my_config image list

    Images:

     image=0 slot=0

        version: 2.0.0

        bootable: true

        flags: active confirmed

        hash: 2e7bda6855341724a47a3a31fc9781f0b2c14286dacee41ea540e86e1fdd3cdf

    Split status: N/A (0)

    PS C:\DocTA\Soft\TA-Smart-BT840P> mcumgr -c my_config image upload Application\TA_Smart\signed_by_mcuboot_and_b0_s1_image.bin -e -n2

     45.84 KiB / 45.84 KiB [==============================================================================] 100.00% 2.15 KiB/s 21s

    Done

    PS C:\DocTA\Soft\TA-Smart-BT840P> mcumgr -c my_config image list

    Images:

     image=0 slot=0

        version: 2.0.0

        bootable: true

        flags: active confirmed

        hash: 2e7bda6855341724a47a3a31fc9781f0b2c14286dacee41ea540e86e1fdd3cdf

     image=0 slot=1

        version: 0.1.0

        bootable: true

        flags:

        hash: 8b4aa96742d98e55f36a080328a6d260923566033484e514839d84e4fa3f76fc

     image=1 slot=1

        version: 0.1.0

        bootable: true

        flags:

        hash: 8b4aa96742d98e55f36a080328a6d260923566033484e514839d84e4fa3f76fc

    Split status: N/A (0)

  • Hi,

    QuentinD said:
    But is it normal that I have 2 images?

    image 0 is for the app and image 1 is for the b1 (mcuboot) because you have b0.

  • Hi,

    OK so it's normal Slight smile

    But then how to avoid this error? (the loader writes in the shared memory for the 2 images but fails on the second write because these TLVs are already present and therefore it stops loading)

  • Hi, 

    That needs fixing upstream, the fix will be in NCS for the v3.0 release next year. 

    -Amanda H.

Related