]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
Implement jump-to-bootloader.
authorflabbergast <s3+flabbergast@sdfeu.org>
Tue, 8 Sep 2015 15:07:34 +0000 (16:07 +0100)
committerflabbergast <s3+flabbergast@sdfeu.org>
Tue, 8 Sep 2015 15:07:34 +0000 (16:07 +0100)
tmk_core/common/chibios/bootloader.c
tmk_core/tool/chibios/ch-bootloader-jump.patch [new file with mode: 0644]
tmk_core/tool/chibios/common.mk

index 6c34e2e060f67b20afce2cad6b962da224a401a9..93f2e3785a5b003a6ea70550e5299612491352be 100644 (file)
@@ -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 */
+
diff --git a/tmk_core/tool/chibios/ch-bootloader-jump.patch b/tmk_core/tool/chibios/ch-bootloader-jump.patch
new file mode 100644 (file)
index 0000000..7f33e8a
--- /dev/null
@@ -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\r
+ #endif\r
\r
++/**\r
++ * @brief   Magic number for jumping to bootloader.\r
++ */\r
++#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)\r
++#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF\r
++#endif\r
++\r
+ /*===========================================================================*/\r
+ /* Code section.                                                             */\r
+ /*===========================================================================*/\r
+@@ -117,6 +124,17 @@
+                 .thumb_func\r
+                 .global Reset_Handler\r
+ Reset_Handler:\r
++\r
++#ifdef BOOTLOADER_ADDRESS\r
++                /* jump to bootloader code */\r
++                ldr        r0, =__ram0_end__-4\r
++                ldr        r1, =MAGIC_BOOTLOADER_NUMBER\r
++                ldr        r2, [r0, #0]\r
++                str        r0, [r0, #0] /* erase stored magic */\r
++                cmp        r2, r1\r
++                beq        Bootloader_Jump\r
++#endif /* BOOTLOADER_ADDRESS */\r
++\r
+                 /* Interrupts are globally masked initially.*/\r
+                 cpsid   i\r
\r
+@@ -230,6 +248,21 @@ endfiniloop:
+                 ldr     r1, =__default_exit\r
+                 bx      r1\r
\r
++#ifdef BOOTLOADER_ADDRESS\r
++/*\r
++ * Jump-to-bootloader function.\r
++ */\r
++\r
++                .align  2\r
++                .thumb_func\r
++Bootloader_Jump:\r
++                ldr     r0, =BOOTLOADER_ADDRESS\r
++                ldr     r1, [r0, #0]\r
++                mov     sp, r1\r
++                ldr     r0, [r0, #4]\r
++                bx      r0\r
++#endif /* BOOTLOADER_ADDRESS */\r
++\r
+ #endif\r
\r
+ /** @} */\r
+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\r
+ #endif\r
\r
++/**\r
++ * @brief   Magic number for jumping to bootloader.\r
++ */\r
++#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)\r
++#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF\r
++#endif\r
++\r
+ /*===========================================================================*/\r
+ /* Code section.                                                             */\r
+ /*===========================================================================*/\r
+@@ -157,6 +164,16 @@
+                 .thumb_func\r
+                 .global Reset_Handler\r
+ Reset_Handler:\r
++#ifdef BOOTLOADER_ADDRESS\r
++                /* jump to bootloader code */\r
++                ldr        r0, =__ram0_end__-4\r
++                ldr        r1, =MAGIC_BOOTLOADER_NUMBER\r
++                ldr        r2, [r0, #0]\r
++                str        r0, [r0, #0] /* erase stored magic */\r
++                cmp        r2, r1\r
++                beq        Bootloader_Jump\r
++#endif /* BOOTLOADER_ADDRESS */\r
++\r
+                 /* Interrupts are globally masked initially.*/\r
+                 cpsid   i\r
\r
+@@ -289,6 +306,21 @@ endfiniloop:
+                 /* Branching to the defined exit handler.*/\r
+                 b       __default_exit\r
\r
++#ifdef BOOTLOADER_ADDRESS\r
++/*\r
++ * Jump-to-bootloader function.\r
++ */\r
++\r
++                .align  2\r
++                .thumb_func\r
++Bootloader_Jump:\r
++                ldr     r0, =BOOTLOADER_ADDRESS\r
++                ldr     r1, [r0, #0]\r
++                mov     sp, r1\r
++                ldr     r0, [r0, #4]\r
++                bx      r0\r
++#endif /* BOOTLOADER_ADDRESS */\r
++\r
+ #endif /* !defined(__DOXYGEN__) */\r
\r
+ /** @} */\r
index 952ec4939a81d2a79f19c5ce4282f0e4b0fd963f..0e9935dc7064977473dfeb40601e9cf50065b0e9 100644 (file)
@@ -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