Skip to content

Commit 453096b

Browse files
mmahadevan108d3zd3z
authored andcommitted
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 <mahesh.mahadevan@nxp.com>
1 parent 02267cf commit 453096b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-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: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,26 @@ static void do_boot(struct boot_rsp *rsp)
157157
/* Get ram address for image */
158158
vt = (struct arm_vector_table *)(rsp->br_hdr->ih_load_addr + rsp->br_hdr->ih_hdr_size);
159159
#else
160-
uintptr_t flash_base;
161160
int rc;
161+
const struct flash_area *fap;
162+
static uint32_t dst[2];
162163

163164
/* Jump to flash image */
164-
rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
165+
rc = flash_area_open(rsp->br_flash_dev_id, &fap);
166+
assert(rc == 0);
167+
168+
rc = flash_area_read(fap, rsp->br_hdr->ih_hdr_size, dst, sizeof(dst));
165169
assert(rc == 0);
170+
#ifndef CONFIG_ASSERT
171+
/* Enter a lock up as asserts are disabled */
172+
if (rc != 0) {
173+
while (1);
174+
}
175+
#endif
176+
177+
flash_area_close(fap);
166178

167-
vt = (struct arm_vector_table *)(flash_base +
168-
rsp->br_image_off +
169-
rsp->br_hdr->ih_hdr_size);
179+
vt = (struct arm_vector_table *)dst;
170180
#endif
171181

172182
if (IS_ENABLED(CONFIG_SYSTEM_TIMER_HAS_DISABLE_SUPPORT)) {

0 commit comments

Comments
 (0)