MCUboot reading image header from slot located in external flash

Hello,

I'm building a system on nRF5340 which would support upgrading of CPUAPP and CPUNET applications. There is not enough space in internal flash to place all of these images in the  internal flash. Therefore I want to place secondary slots of both images into the external flash.

I came across this code in mcuboot which I don't quite understand.

https://github.com/nrfconnect/sdk-mcuboot/blob/5fd4ff5df6c1bd08d1eef975a4f31fa2ad703e82/boot/bootutil/src/loader.c#L895-L907

secondary_fa->fa_off is interpreted as address and assigned to hdr. Later on hdr is dereferenced.

As I understand, fa_off is an offset from the start of a flash memory, not an absolute address. And even if it were an absolute address, this would require MCUboot to configure external flash to be in XIP mode. I don't think MCUboot does that.

I tried reading header from that slot using flash_area_read, as done in the boot_read_image_header, and that gives me a different value of ih_magic, compared to just dereferencing: hdr->ih_magic.

struct image_header out_hdr;
flash_area_read(secondary_fa, 0, &out_hdr, sizeof(out_hdr));

printk("ih_magic=0x%08x\n", out_hdr.ih_magic);

So my question is whether the reference code is correct, or should it be using boot_read_image_header?

Thanks

Related