mcuboot icon indicating copy to clipboard operation
mcuboot copied to clipboard

zephyr: flash_area_get_device_id implementation broken for ARM devices

Open de-nordic opened this issue 10 months ago • 1 comments

There is a bug where flash_area_get_device_id will return flash area partition id instead of device id when compiled on ARM arch.

This happens because code returns flash_area.fa_id, where it should fa_device_id. The fa_device_id member does not exist in Zephyr variant of Flash Area API defined flash_area type.

This device id is only used by flash_device_base function, which is provided by system backend, to return offset where device FLASH to RAM mapping begins.

Current implementation of flash_device_base: https://github.com/mcu-tools/mcuboot/blob/c6f5db297c2f4a67e22517c98d6cd1d52fdc96cb/boot/zephyr/flash_map_extended.c#L43-L52 will fail to return for ID that is different than FLASH_DEVICE_ID, which will, for Zephyr, be hardcoded as 0 or 1, to identify internal and external memory respectively, and Flash Area device ID may be anything from 0 to 255.

Bug has been introduced with https://github.com/mcu-tools/mcuboot/pull/1661

de-nordic avatar Jan 23 '25 17:01 de-nordic