Use flash_device_base() when booting.
Use flash_device_base() in the boot code to compute a real address,
given the offset returned by boot_go().
Provide an implementation on mynewt that preserves existing
behavior. If mynewt needs to support devices with nonzero flash base
addresses, this can be migrated to the core OS.
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index c6f4376..054c466 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <assert.h>
#include <zephyr.h>
#include <flash.h>
#include <asm_inline.h>
@@ -25,6 +26,7 @@
#include "bootutil/bootutil_log.h"
#include "bootutil/image.h"
#include "bootutil/bootutil.h"
+#include "flash_map/flash_map.h"
struct device *boot_flash_device;
@@ -39,13 +41,19 @@
static void do_boot(struct boot_rsp *rsp)
{
struct arm_vector_table *vt;
+ uintptr_t flash_base;
+ int rc;
/* The beginning of the image is the ARM vector table, containing
* the initial stack pointer address and the reset vector
* consecutively. Manually set the stack pointer and jump into the
* reset vector
*/
- vt = (struct arm_vector_table *)(rsp->br_image_off +
+ rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
+ assert(rc == 0);
+
+ vt = (struct arm_vector_table *)(flash_base +
+ rsp->br_image_off +
rsp->br_hdr->ih_hdr_size);
irq_lock();
sys_clock_disable();
@@ -59,9 +67,15 @@
*/
static void do_boot(struct boot_rsp *rsp)
{
+ uintptr_t flash_base;
void *start;
+ int rc;
- start = (void *)(rsp->br_image_off + rsp->br_hdr->ih_hdr_size);
+ rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
+ assert(rc == 0);
+
+ start = (void *)(flash_base + rsp->br_image_off +
+ rsp->br_hdr->ih_hdr_size);
/* Lock interrupts and dive into the entry point */
irq_lock();