Skip to content

Commit 715bc06

Browse files
committed
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 <[email protected]>
1 parent b994ba2 commit 715bc06

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

boot/zephyr/flash_map_extended.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ int flash_area_sector_from_off(off_t off, struct flash_sector *sector)
141141

142142
uint8_t flash_area_get_device_id(const struct flash_area *fa)
143143
{
144-
(void)fa;
145-
return FLASH_DEVICE_ID;
144+
#if defined(CONFIG_ARM)
145+
return fa->fa_id;
146+
#else
147+
(void)fa;
148+
return FLASH_DEVICE_ID;
149+
#endif
146150
}
147151

148152
#define ERASED_VAL 0xff

boot/zephyr/main.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,20 @@ static void do_boot(struct boot_rsp *rsp)
153153
/* Get ram address for image */
154154
vt = (struct arm_vector_table *)(rsp->br_hdr->ih_load_addr + rsp->br_hdr->ih_hdr_size);
155155
#else
156-
uintptr_t flash_base;
157156
int rc;
157+
const struct flash_area *fap;
158+
static uint32_t dst[2];
158159

159160
/* Jump to flash image */
160-
rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
161+
rc = flash_area_open(rsp->br_flash_dev_id, &fap);
161162
assert(rc == 0);
162163

163-
vt = (struct arm_vector_table *)(flash_base +
164-
rsp->br_image_off +
165-
rsp->br_hdr->ih_hdr_size);
164+
rc = flash_area_read(fap, rsp->br_hdr->ih_hdr_size, dst, 8);
165+
assert(rc == 0);
166+
167+
flash_area_close(fap);
168+
169+
vt = (struct arm_vector_table *)dst;
166170
#endif
167171

168172
if (IS_ENABLED(CONFIG_SYSTEM_TIMER_HAS_DISABLE_SUPPORT)) {

0 commit comments

Comments
 (0)