aboutsummaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-06-17 22:35:17 +0200
committerHarald Welte <laforge@gnumonks.org>2018-06-29 20:07:31 +0200
commit80303c135b11be58ef3d47611d479279962a7404 (patch)
treeceb0d83d48ec5d22dd54051da65b52c979c01821 /firmware
parentd86cab0080367bb8a5df9cd9f3309906afc74b7a (diff)
DFU: only boot the application if it has a valid start
Diffstat (limited to 'firmware')
-rw-r--r--firmware/libboard/common/source/board_cstartup_gnu.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/firmware/libboard/common/source/board_cstartup_gnu.c b/firmware/libboard/common/source/board_cstartup_gnu.c
index f2d17af..15c70dd 100644
--- a/firmware/libboard/common/source/board_cstartup_gnu.c
+++ b/firmware/libboard/common/source/board_cstartup_gnu.c
@@ -159,9 +159,20 @@ void ResetException( void )
* not initialized yet */
g_dfu = &_g_dfu;
if ((g_dfu->magic != USB_DFU_MAGIC) && !USBDFU_OverrideEnterDFU()) {
- BootIntoApp();
- /* Infinite loop */
- while ( 1 ) ;
+ /* start application if valid
+ * the application starts with the vector table
+ * the first entry in the vector table is the initial stack pointer (SP) address
+ * the stack will be placed in RAM, which begins at 0x2000 0000
+ * there is up to 48 KB of RAM (0xc000)
+ * since the stack grown "downwards" it should start at the end of the RAM: max 0x2000 c000
+ * if the SP is not in this range (e.g. flash has been erased) there is no valid application
+ * the second entry in the vector table is the reset address, corresponding to the application start
+ */
+ if (((*((uint32_t*)(IFLASH_ADDR+BOARD_DFU_BOOT_SIZE)))&0xFFFF0000)==0x20000000) {
+ BootIntoApp();
+ /* Infinite loop */
+ while ( 1 ) ;
+ }
}
#endif