Squashed 'tmk_core/' changes from d5c5ac6..8da1898
[tmk_keyboard.git] / tool / chibios / ch-bootloader-jump.patch
CommitLineData
28203e90 1diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
2index 51a79bb..42d07bd 100644
3--- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
4+++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
5@@ -105,6 +105,13 @@
6 #define CRT0_CALL_DESTRUCTORS TRUE\r
7 #endif\r
8 \r
9+/**\r
10+ * @brief Magic number for jumping to bootloader.\r
11+ */\r
12+#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)\r
13+#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF\r
14+#endif\r
15+\r
16 /*===========================================================================*/\r
17 /* Code section. */\r
18 /*===========================================================================*/\r
19@@ -124,6 +131,17 @@
20 .thumb_func\r
21 .global Reset_Handler\r
22 Reset_Handler:\r
23+\r
24+#ifdef STM32_BOOTLOADER_ADDRESS\r
25+ /* jump to bootloader code */\r
26+ ldr r0, =__ram0_end__-4\r
27+ ldr r1, =MAGIC_BOOTLOADER_NUMBER\r
28+ ldr r2, [r0, #0]\r
29+ str r0, [r0, #0] /* erase stored magic */\r
30+ cmp r2, r1\r
31+ beq Bootloader_Jump\r
32+#endif /* STM32_BOOTLOADER_ADDRESS */\r
33+\r
34 /* Interrupts are globally masked initially.*/\r
35 cpsid i\r
36 \r
37@@ -242,6 +260,21 @@ endfiniloop:
38 ldr r1, =__default_exit\r
39 bx r1\r
40 \r
41+#ifdef STM32_BOOTLOADER_ADDRESS\r
42+/*\r
43+ * Jump-to-bootloader function.\r
44+ */\r
45+\r
46+ .align 2\r
47+ .thumb_func\r
48+Bootloader_Jump:\r
49+ ldr r0, =STM32_BOOTLOADER_ADDRESS\r
50+ ldr r1, [r0, #0]\r
51+ mov sp, r1\r
52+ ldr r0, [r0, #4]\r
53+ bx r0\r
54+#endif /* STM32_BOOTLOADER_ADDRESS */\r
55+\r
56 #endif\r
57 \r
58 /** @} */\r
59diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
60index 4812a29..dca9f88 100644
61--- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
62+++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
63@@ -140,6 +140,13 @@
64 #define CRT0_CPACR_INIT 0x00F00000\r
65 #endif\r
66 \r
67+/**\r
68+ * @brief Magic number for jumping to bootloader.\r
69+ */\r
70+#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)\r
71+#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF\r
72+#endif\r
73+\r
74 /*===========================================================================*/\r
75 /* Code section. */\r
76 /*===========================================================================*/\r
77@@ -164,6 +171,17 @@
78 .thumb_func\r
79 .global Reset_Handler\r
80 Reset_Handler:\r
81+\r
82+#ifdef STM32_BOOTLOADER_ADDRESS\r
83+ /* jump to bootloader code */\r
84+ ldr r0, =__ram0_end__-4\r
85+ ldr r1, =MAGIC_BOOTLOADER_NUMBER\r
86+ ldr r2, [r0, #0]\r
87+ str r0, [r0, #0] /* erase stored magic */\r
88+ cmp r2, r1\r
89+ beq Bootloader_Jump\r
90+#endif /* STM32_BOOTLOADER_ADDRESS */\r
91+\r
92 /* Interrupts are globally masked initially.*/\r
93 cpsid i\r
94 \r
95@@ -305,6 +323,21 @@ endfiniloop:
96 /* Branching to the defined exit handler.*/\r
97 b __default_exit\r
98 \r
99+#ifdef STM32_BOOTLOADER_ADDRESS\r
100+/*\r
101+ * Jump-to-bootloader function.\r
102+ */\r
103+\r
104+ .align 2\r
105+ .thumb_func\r
106+Bootloader_Jump:\r
107+ ldr r0, =STM32_BOOTLOADER_ADDRESS\r
108+ ldr r1, [r0, #0]\r
109+ mov sp, r1\r
110+ ldr r0, [r0, #4]\r
111+ bx r0\r
112+#endif /* STM32_BOOTLOADER_ADDRESS */\r
113+\r
114 #endif /* !defined(__DOXYGEN__) */\r
115 \r
116 /** @} */\r
Imprint / Impressum