From ea306dfbb4caa5e2f8e29abdba564a155443c112 Mon Sep 17 00:00:00 2001 From: Mahesh Mahadevan Date: Tue, 6 Feb 2024 21:06:54 -0600 Subject: [PATCH] zephyr: arm: Update reading the flash image reset vector This change uses the flash functions to read the applications reset vector. This allow flexibility on which flash device the application is programmed. For e.g: MCUBoot can be programmed and running from Internal Flash while Zephyr can be loaded from a different Flash device. This change is made for ARM platform, it can be extended to non-ARM platforms as well. Signed-off-by: Mahesh Mahadevan --- boot/zephyr/flash_map_extended.c | 8 ++++++-- boot/zephyr/main.c | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c index d0744afbd..4631da75b 100644 --- a/boot/zephyr/flash_map_extended.c +++ b/boot/zephyr/flash_map_extended.c @@ -141,8 +141,12 @@ int flash_area_sector_from_off(off_t off, struct flash_sector *sector) uint8_t flash_area_get_device_id(const struct flash_area *fa) { - (void)fa; - return FLASH_DEVICE_ID; +#if defined(CONFIG_ARM) + return fa->fa_id; +#else + (void)fa; + return FLASH_DEVICE_ID; +#endif } #define ERASED_VAL 0xff diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c index 686e02eb9..95da276bd 100644 --- a/boot/zephyr/main.c +++ b/boot/zephyr/main.c @@ -157,16 +157,26 @@ static void do_boot(struct boot_rsp *rsp) /* Get ram address for image */ vt = (struct arm_vector_table *)(rsp->br_hdr->ih_load_addr + rsp->br_hdr->ih_hdr_size); #else - uintptr_t flash_base; int rc; + const struct flash_area *fap; + static uint32_t dst[2]; /* Jump to flash image */ - rc = flash_device_base(rsp->br_flash_dev_id, &flash_base); + rc = flash_area_open(rsp->br_flash_dev_id, &fap); + assert(rc == 0); + + rc = flash_area_read(fap, rsp->br_hdr->ih_hdr_size, dst, sizeof(dst)); assert(rc == 0); +#ifndef CONFIG_ASSERT + /* Enter a lock up as asserts are disabled */ + if (rc != 0) { + while (1); + } +#endif + + flash_area_close(fap); - vt = (struct arm_vector_table *)(flash_base + - rsp->br_image_off + - rsp->br_hdr->ih_hdr_size); + vt = (struct arm_vector_table *)dst; #endif if (IS_ENABLED(CONFIG_SYSTEM_TIMER_HAS_DISABLE_SUPPORT)) {