hellesvik-nordic / samples_for_nrf_connect_sdk

Other
36 stars 16 forks source link

[mcuboot_smp_ble_simultaneous] Cannot upgrade: slots are not compatible #3

Closed lexologe closed 1 year ago

lexologe commented 1 year ago

Hello, I try to use the mcuboot_smp_ble_simultaneous sample. It compiles fine and the updates completes successfully in the nRF Connect App on Android. But the image is not booted on the application core after nrfjprog --reset.

I am also facing some warnings on the application core.

I: Starting bootloader
W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small?
W: Cannot upgrade: slots are not compatible
W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small?
W: Cannot upgrade: slots are not compatible
I: Bootloader chainload address offset: 0xc000
*** Booting Zephyr OS build v3.2.99-ncs1 ***
AAA this to see it change.

I don't know why the both slots should be incompatible. Thanks, Alex

hellesvik-nordic commented 1 year ago

Hi Alex, The error Failed reading sectors; BOOT_MAX_IMG_SECTORS=256 - too small? is often due to the external flash not being configured correctly in the mcuboot child image. See the nRF Connect SDK test for MCUboot with external flash to see how you correctly configure external flash. If it works, let me know, and I will update my sample here.

lexologe commented 1 year ago

Hi @hellesvik-nordic, I see a DTS overlay that seems to be used there.

/ {
    chosen {
        nordic,pm-ext-flash = &mx25r64;
    };
};

But if I add it in a file called mcuboot.overlay next to mcuboot.conf it is not merged into DTS.

Then I stumble upon these flash simulator configs in mcuboot.conf.

CONFIG_FLASH_SIMULATOR=y
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
CONFIG_FLASH_SIMULATOR_STATS=n

Do I need flash simulator? If I disable then, I get the following error:

/opt/nordic/ncs/v2.2.0/zephyr/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt_priv.c:29:1: error: static assertion failed: "Missing partitions?"
   29 | BUILD_ASSERT(CONFIG_IMG_MGMT_UPDATABLE_IMAGE_NUMBER == 1 ||
      | ^~~~~~~~~~~~
lexologe commented 1 year ago

I tried to use the pm_static_thingy53_nrf5340_cpuapp.yml and placed them in the root of the sample as pm_static_nrf5340dk_nrf5340_cpuapp.yml - but that didn't remove the "Missing partitions?" error.

hellesvik-nordic commented 1 year ago

The relevant configurations are inside the child_image folder This includes .conf and .overlay files, with he folder structure being important.

hellesvik-nordic commented 1 year ago

Do I need flash simulator?

Yes, this is used for temporary storage of the network core update before it gets swapped to the network core.

But if I add it in a file called mcuboot.overlay next to mcuboot.conf it is not merged into DTS.

child_image/mcuboot/boards/nrf5340dk_nrf5340_cpuapp.overlay

lexologe commented 1 year ago

Thanks to your hints, I think I got it working. But I do not really know why it is related to the folder structure. But now the upgrade works. 🎉 I need to move child_image/mcuboot.conf to a sub-folder child_image/mcuboot/prj.conf and add the .overlay file from the boards folder nrf5340dk_nrf5340_cpuapp.overlay

The commit is in my forked repo https://github.com/lexologe/samples_for_nrf_connect_sdk/commit/763a4f9075715d92a81bf462e32987f7aa97e9eb

hellesvik-nordic commented 1 year ago

Thanks for testing!

But I do not really know why it is related to the folder structure.

The multi-image build system will detect configuration and overlays differently depending on the folder structure: image

I need to move child_image/mcuboot.conf to a sub-folder child_image/mcuboot/prj.conf

I have seen this before as well. The difference here is that child_image/mcuboot.conf will be merged with default MCUboot configurations, while child_image/mcuboot/prj.conf will be used instead of default MCUboot configurations. I did a quick test, and saw no differences from where the .conf was placed. So maybe you do not need to move the .conf file, and only the overlay is enough?

Added the overlay in https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/commit/b8a19e0c46e6e59f5fdbccee891c8f24432b1868

hellesvik-nordic commented 1 year ago

Another observation: Looks like child_image/mcuboot.overlay is ignored in 2.2.0. However, I can see the changes from child_image/mcuboot.overlay being applied to build/mcuboot/zephyr/zephyr.dts in 2.3.0. So might be related to a bug in 2.2.0. I will update all examples here to 2.3.0 soon, and will try to make this folder less complicated for that version. Closing this issue, as we have a fix