Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ch-bootloader-jump.patch 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
  2. index 38b4513..12a3f39 100644
  3. --- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
  4. +++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
  5. @@ -98,6 +98,13 @@
  6. #define CRT0_CALL_DESTRUCTORS TRUE
  7. #endif
  8. +/**
  9. + * @brief Magic number for jumping to bootloader.
  10. + */
  11. +#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)
  12. +#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF
  13. +#endif
  14. +
  15. /*===========================================================================*/
  16. /* Code section. */
  17. /*===========================================================================*/
  18. @@ -117,6 +124,17 @@
  19. .thumb_func
  20. .global Reset_Handler
  21. Reset_Handler:
  22. +
  23. +#ifdef BOOTLOADER_ADDRESS
  24. + /* jump to bootloader code */
  25. + ldr r0, =__ram0_end__-4
  26. + ldr r1, =MAGIC_BOOTLOADER_NUMBER
  27. + ldr r2, [r0, #0]
  28. + str r0, [r0, #0] /* erase stored magic */
  29. + cmp r2, r1
  30. + beq Bootloader_Jump
  31. +#endif /* BOOTLOADER_ADDRESS */
  32. +
  33. /* Interrupts are globally masked initially.*/
  34. cpsid i
  35. @@ -230,6 +248,21 @@ endfiniloop:
  36. ldr r1, =__default_exit
  37. bx r1
  38. +#ifdef BOOTLOADER_ADDRESS
  39. +/*
  40. + * Jump-to-bootloader function.
  41. + */
  42. +
  43. + .align 2
  44. + .thumb_func
  45. +Bootloader_Jump:
  46. + ldr r0, =BOOTLOADER_ADDRESS
  47. + ldr r1, [r0, #0]
  48. + mov sp, r1
  49. + ldr r0, [r0, #4]
  50. + bx r0
  51. +#endif /* BOOTLOADER_ADDRESS */
  52. +
  53. #endif
  54. /** @} */
  55. diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
  56. index fcfa4de..2d560da 100644
  57. --- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
  58. +++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
  59. @@ -133,6 +133,13 @@
  60. #define CRT0_CPACR_INIT 0x00F00000
  61. #endif
  62. +/**
  63. + * @brief Magic number for jumping to bootloader.
  64. + */
  65. +#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)
  66. +#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF
  67. +#endif
  68. +
  69. /*===========================================================================*/
  70. /* Code section. */
  71. /*===========================================================================*/
  72. @@ -157,6 +164,16 @@
  73. .thumb_func
  74. .global Reset_Handler
  75. Reset_Handler:
  76. +#ifdef BOOTLOADER_ADDRESS
  77. + /* jump to bootloader code */
  78. + ldr r0, =__ram0_end__-4
  79. + ldr r1, =MAGIC_BOOTLOADER_NUMBER
  80. + ldr r2, [r0, #0]
  81. + str r0, [r0, #0] /* erase stored magic */
  82. + cmp r2, r1
  83. + beq Bootloader_Jump
  84. +#endif /* BOOTLOADER_ADDRESS */
  85. +
  86. /* Interrupts are globally masked initially.*/
  87. cpsid i
  88. @@ -289,6 +306,21 @@ endfiniloop:
  89. /* Branching to the defined exit handler.*/
  90. b __default_exit
  91. +#ifdef BOOTLOADER_ADDRESS
  92. +/*
  93. + * Jump-to-bootloader function.
  94. + */
  95. +
  96. + .align 2
  97. + .thumb_func
  98. +Bootloader_Jump:
  99. + ldr r0, =BOOTLOADER_ADDRESS
  100. + ldr r1, [r0, #0]
  101. + mov sp, r1
  102. + ldr r0, [r0, #4]
  103. + bx r0
  104. +#endif /* BOOTLOADER_ADDRESS */
  105. +
  106. #endif /* !defined(__DOXYGEN__) */
  107. /** @} */