OTA on external flash fails after having loaded an image

Hello,

I'm, trying to configure an nrf5340 based board to use the secondary boot image on an external SPI Flash.

The flash has tree partitions:

  • 0: The second boot space.
  • 1: The storage partition.
  • 2: A littlefs partition.

The partition has been defined in the overlay configuration file in the following way:

&w25q256jveiq0 {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;
		slot1_partition: partition@0 {
			label = "image-1";
            reg = <0x00000000 0x000f0000>;
        };
		
		storage_partition: partition@f0000 {
			label = "storage";
            reg = <0x000f0000 0x00002000>;
        };

		lfs1_part: partition@f2000 {
			label = "littlefs_storage";
			reg =  <0x000f2000 0x00F0E000>;
		};
	};
};

The portion of configuration regarding the external flash is the following:

# External partitions
CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
CONFIG_PM_PARTITION_REGION_NVS_STORAGE_EXTERNAL=y
CONFIG_PM_PARTITION_SIZE_LITTLEFS=0xF0E000

# Prevent the QSPI NOR driver to be automatically included by partition manager
CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

At the first boot, typing "mcuboot" on the shell, the reported informations are the following:

rtt:~$ mcuboot

swap type: none
confirmed: 0

primary area (3):
  version: 2.0.0+0
  image size: 353164
  magic: unset
  swap type: none
  copy done: unset
  image ok: unset

failed to read secondary area (1) header: -5

The error happens because the flash partition is erased, and its content is all 0xFF.

Using the Android "Device Manager" App, the secondary image can be loaded without problems.

After the load has complete (test only), the "mcuboot" shell command shows the following:

rtt:~$ mcuboot

swap type: test
confirmed: 0

primary area (3):
  version: 2.0.0+0
  image size: 353164
  magic: unset
  swap type: none
  copy done: unset
  image ok: unset

secondary area (1):
  version: 2.0.1+0
  image size: 353164
  magic: good
  swap type: test
  copy done: unset
  image ok: unset

At this point, using the "Advanced" option in the Device Manager App, after performing a read operation, only the "Confirm" and "Erase" commands are available (the "Test" is grayed).

Pressing the "Confirm" command, nothing happens.

The same situation happens when issuing the "mcuboot confirm" command in the shell.

Following the function in the mcuboot_shell.c module with the gdb debugger, I notice that the boot_write_img_confirmed function is called.

This function calls the boot_set_confirmed function, that is commented in this way: "Marks the image with index 0 in the primary slot as confirmed."

In fact, the function calls the boot_set_confirmed_multi(0) sub-function.

At this point I'm confused: I need to confirm the image-1, not the primary image. How can I confirm the loaded image in the external flash? When using the OTA functions without the external flash, all works fine.

The Device Manager cannot perform any other operation, the only way to go back to a loadable situation is to perform an erase operation using the shell, with the command "mcuboot erase 1".

The erase function in the Device Manager do not works, it reports: "Bad state (6)".

After a successful erase operation performed with the shell, a load attempt with "test and confirm" results in the error "Image not confirmed".

Is there something wrong or missing in my configuration?

Thank you very much.

  • Hi, 

    The partition has been defined in the overlay configuration file in the following way:

    DTS Partitioning is ignored with MCUboot. Use Partition Manager instead.

    I would suggest you use the SMP Server sample which also has support for LittleFS already. Here is my example smp_svr_nRF5340_ExternalFlash.7z for NCS v2.4.0.

    Beware that this code/configuration is not fully tested or qualified and should be considered provided “as-is”. Please test it with your application and let me know if you find any issues.

    Regards,
    Amanda H.

  • Hi Amanda, thanks for your reply.

    The example you shared with me won't compile,
    there are some config options undefined on the zephyr system.

    I'm using Zephyr version v3.1.99-ncs1, nrf v2.1.0, mbedtls-nrf v3.1.0-ncs1.

    I tried to comment the config options that caused the failure:

    on prj.conf:
    #CONFIG_CRC=y
    #CONFIG_MCUMGR_GRP_OS_TASKSTAT=y
    #CONFIG_MCUMGR_GRP_IMG=y
    #CONFIG_MCUMGR_GRP_OS=y
    #CONFIG_MCUMGR_GRP_STAT=y

    on nrf5340dk_nrf5340_cpuapp.conf:
    #CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

    With those modifications, the cmake command completes without errors, but the ninja build stops with the following:

    /opt/nordicsemi/ncs2/nrf/modules/mcuboot/hooks/nrf53_hooks.c: In function 'boot_read_image_header_hook':
    /opt/nordicsemi/ncs2/nrf/modules/mcuboot/hooks/nrf53_hooks.c:29:27: error: 'PM_CPUNET_APP_SIZE' undeclared (first use in this function)
       29 |   img_head->ih_img_size = PM_CPUNET_APP_SIZE;
          |                           ^~~~~~~~~~~~~~~~~~
    

    It seems related to something wrong with the PM. In other projects, the PM_CPUNET_APP_SIZE is automatically defined in the file zephyr/include/generated/pm_config.h and mcuboot/zephyr/include/generated/pm_config.h.

    Do you have any idea?

    Regarding this: "DTS Partitioning is ignored with MCUboot. Use Partition Manager instead." it was just a test I've made after previous failed tests using PM; I suppose the definition added in the overlay does nothing.

    Regards,
    Gabriele.

  • Hi, 

    For NCS v2.1.0, please use the board config and overlay file from my example in the previous reply to build with v2.1.0 smp_svr sample.

    -Amanda H.  

  • Hi Amanda, thank for your suggestion.

    I've successfully tested the smp_svr application on the external QSPI flash of the nrf5340-DK board.

    In my hardware, the external flash is connected on the SPI interface. After some debug, I've verified that the mcuboot can correctly access the SPI flash, but it fails with this error:

    <wrn> mcuboot: Cannot upgrade: not a compatible amount of sectors: 236 vs 15

    After some investigation, I've found that the following configuration in mcuboot.conf seems ignored by the build:

    CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
    

    The generated autoconf.h contains the following:

    #define CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE 65536

    I already checked that the CONFIG_FLASH_PAGE_LAYOUT=y is set, the same configuration used in mcuboot.conf its used in the app, and the autoconf.h of the app contains the correct declaration of the page size, set to 4096.

    I don't know how to force CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096 in the mcuboot.conf, do you have any idea?

    Thank you.

  • GBDVE said:
    In my hardware, the external flash is connected on the SPI interface.

    The external SPI flash setting is different from the external QSPI flash of the nrf5340-DK board. 

    It would need an overlay file like this example and configs like this post

    -Amanda H.

Related