zephyr: add cleanup ARM core before boot
This patch is needed as MCUBoot should be able to chain-load any
application, not only these built using zephyr.
Introduced cleanup on ARM core control register.
Might be required as for instance the application assumes
that it starts with thread mode configured as by default, not
according to zephyr-rtos configuration.
MCUBoot disables interrupt before application chain-load used
basepr register. This Patch introduce additional celenup on
NVIC register.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index 517ec60..9dbac7c 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -44,6 +44,10 @@
#include <usb/class/usb_dfu.h>
#endif
+#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
+#include <arm_cleanup.h>
+#endif
+
#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE)
#ifdef CONFIG_LOG_PROCESS_THREAD
#warning "The log internal thread for log processing can't transfer the log"\
@@ -126,7 +130,13 @@
/* Disable the USB to prevent it from firing interrupts */
usb_disable();
#endif
+#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
+ cleanup_arm_nvic(); /* cleanup NVIC registers */
+#endif
__set_MSP(vt->msp);
+#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
+ __set_CONTROL(0x00); /* application will configures core on its own */
+#endif
((void (*)(void))vt->reset)();
}