Implement jump-to-bootloader.
This commit is contained in:
parent
8152d279a4
commit
d057e5157e
@ -1,7 +1,16 @@
|
||||
/* TODO */
|
||||
/* ... chip dependent ... */
|
||||
|
||||
#include "bootloader.h"
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
#ifdef BOOTLOADER_ADDRESS
|
||||
#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
|
||||
extern uint32_t __ram0_end__;
|
||||
|
||||
void bootloader_jump(void) {
|
||||
*((unsigned long *)(SYMVAL(__ram0_end__) - 4)) = 0xDEADBEEF; // set magic flag => reset handler will jump into boot loader
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#else /* BOOTLOADER_ADDRESS */
|
||||
void bootloader_jump(void) {}
|
||||
#endif /* BOOTLOADER_ADDRESS */
|
||||
|
||||
|
115
tmk_core/tool/chibios/ch-bootloader-jump.patch
Normal file
115
tmk_core/tool/chibios/ch-bootloader-jump.patch
Normal file
@ -0,0 +1,115 @@
|
||||
diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
|
||||
index 38b4513..12a3f39 100644
|
||||
--- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
|
||||
+++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
|
||||
@@ -98,6 +98,13 @@
|
||||
#define CRT0_CALL_DESTRUCTORS TRUE
|
||||
#endif
|
||||
|
||||
+/**
|
||||
+ * @brief Magic number for jumping to bootloader.
|
||||
+ */
|
||||
+#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)
|
||||
+#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF
|
||||
+#endif
|
||||
+
|
||||
/*===========================================================================*/
|
||||
/* Code section. */
|
||||
/*===========================================================================*/
|
||||
@@ -117,6 +124,17 @@
|
||||
.thumb_func
|
||||
.global Reset_Handler
|
||||
Reset_Handler:
|
||||
+
|
||||
+#ifdef BOOTLOADER_ADDRESS
|
||||
+ /* jump to bootloader code */
|
||||
+ ldr r0, =__ram0_end__-4
|
||||
+ ldr r1, =MAGIC_BOOTLOADER_NUMBER
|
||||
+ ldr r2, [r0, #0]
|
||||
+ str r0, [r0, #0] /* erase stored magic */
|
||||
+ cmp r2, r1
|
||||
+ beq Bootloader_Jump
|
||||
+#endif /* BOOTLOADER_ADDRESS */
|
||||
+
|
||||
/* Interrupts are globally masked initially.*/
|
||||
cpsid i
|
||||
|
||||
@@ -230,6 +248,21 @@ endfiniloop:
|
||||
ldr r1, =__default_exit
|
||||
bx r1
|
||||
|
||||
+#ifdef BOOTLOADER_ADDRESS
|
||||
+/*
|
||||
+ * Jump-to-bootloader function.
|
||||
+ */
|
||||
+
|
||||
+ .align 2
|
||||
+ .thumb_func
|
||||
+Bootloader_Jump:
|
||||
+ ldr r0, =BOOTLOADER_ADDRESS
|
||||
+ ldr r1, [r0, #0]
|
||||
+ mov sp, r1
|
||||
+ ldr r0, [r0, #4]
|
||||
+ bx r0
|
||||
+#endif /* BOOTLOADER_ADDRESS */
|
||||
+
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
|
||||
index fcfa4de..2d560da 100644
|
||||
--- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
|
||||
+++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
|
||||
@@ -133,6 +133,13 @@
|
||||
#define CRT0_CPACR_INIT 0x00F00000
|
||||
#endif
|
||||
|
||||
+/**
|
||||
+ * @brief Magic number for jumping to bootloader.
|
||||
+ */
|
||||
+#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)
|
||||
+#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF
|
||||
+#endif
|
||||
+
|
||||
/*===========================================================================*/
|
||||
/* Code section. */
|
||||
/*===========================================================================*/
|
||||
@@ -157,6 +164,16 @@
|
||||
.thumb_func
|
||||
.global Reset_Handler
|
||||
Reset_Handler:
|
||||
+#ifdef BOOTLOADER_ADDRESS
|
||||
+ /* jump to bootloader code */
|
||||
+ ldr r0, =__ram0_end__-4
|
||||
+ ldr r1, =MAGIC_BOOTLOADER_NUMBER
|
||||
+ ldr r2, [r0, #0]
|
||||
+ str r0, [r0, #0] /* erase stored magic */
|
||||
+ cmp r2, r1
|
||||
+ beq Bootloader_Jump
|
||||
+#endif /* BOOTLOADER_ADDRESS */
|
||||
+
|
||||
/* Interrupts are globally masked initially.*/
|
||||
cpsid i
|
||||
|
||||
@@ -289,6 +306,21 @@ endfiniloop:
|
||||
/* Branching to the defined exit handler.*/
|
||||
b __default_exit
|
||||
|
||||
+#ifdef BOOTLOADER_ADDRESS
|
||||
+/*
|
||||
+ * Jump-to-bootloader function.
|
||||
+ */
|
||||
+
|
||||
+ .align 2
|
||||
+ .thumb_func
|
||||
+Bootloader_Jump:
|
||||
+ ldr r0, =BOOTLOADER_ADDRESS
|
||||
+ ldr r1, [r0, #0]
|
||||
+ mov sp, r1
|
||||
+ ldr r0, [r0, #4]
|
||||
+ bx r0
|
||||
+#endif /* BOOTLOADER_ADDRESS */
|
||||
+
|
||||
#endif /* !defined(__DOXYGEN__) */
|
||||
|
||||
/** @} */
|
@ -81,6 +81,10 @@ endif
|
||||
# Version string
|
||||
OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null)
|
||||
|
||||
# Bootloader address
|
||||
ifdef BOOTLOADER_ADDRESS
|
||||
OPT_DEFS += -DBOOTLOADER_ADDRESS=$(BOOTLOADER_ADDRESS)
|
||||
endif
|
||||
|
||||
# Search Path
|
||||
VPATH += $(TMK_DIR)/common
|
||||
|
Reference in New Issue
Block a user