bootloader.mk 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # Copyright 2017 Jack Humbert
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # If it's possible that multiple bootloaders can be used for one project,
  16. # you can leave this unset, and the correct size will be selected
  17. # automatically.
  18. #
  19. # Sets the bootloader defined in the keyboard's/keymap's rules.mk
  20. # Current options:
  21. #
  22. # AVR:
  23. # halfkay PJRC Teensy
  24. # caterina Pro Micro (Sparkfun/generic)
  25. # atmel-dfu Atmel factory DFU
  26. # lufa-dfu LUFA DFU
  27. # qmk-dfu QMK DFU (LUFA + blinkenlight)
  28. # qmk-hid QMK HID (LUFA + blinkenlight)
  29. # bootloadhid HIDBootFlash compatible (ATmega32A)
  30. # usbasploader USBaspLoader (ATmega328P)
  31. # ARM:
  32. # halfkay PJRC Teensy
  33. # kiibohd Input:Club Kiibohd bootloader (only used on their boards)
  34. # stm32duino STM32Duino (STM32F103x8)
  35. # stm32-dfu STM32 USB DFU in ROM
  36. # apm32-dfu APM32 USB DFU in ROM
  37. # RISC-V:
  38. # gd32v-dfu GD32V USB DFU in ROM
  39. #
  40. # If you need to provide your own implementation, you can set inside `rules.mk`
  41. # `BOOTLOADER = custom` -- you'll need to provide your own implementations. See
  42. # the respective file under `platforms/<PLATFORM>/bootloaders/custom.c` to see
  43. # which functions may be overridden.
  44. #
  45. # BOOTLOADER_SIZE can still be defined manually, but it's recommended
  46. # you add any possible configuration to this list
  47. ifeq ($(strip $(BOOTLOADER)), custom)
  48. OPT_DEFS += -DBOOTLOADER_CUSTOM
  49. BOOTLOADER_TYPE = custom
  50. endif
  51. ifeq ($(strip $(BOOTLOADER)), atmel-dfu)
  52. OPT_DEFS += -DBOOTLOADER_ATMEL_DFU
  53. OPT_DEFS += -DBOOTLOADER_DFU
  54. BOOTLOADER_TYPE = dfu
  55. ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
  56. BOOTLOADER_SIZE = 4096
  57. endif
  58. ifneq (,$(filter $(MCU), at90usb1286 at90usb1287))
  59. BOOTLOADER_SIZE = 8192
  60. endif
  61. endif
  62. ifeq ($(strip $(BOOTLOADER)), lufa-dfu)
  63. OPT_DEFS += -DBOOTLOADER_LUFA_DFU
  64. OPT_DEFS += -DBOOTLOADER_DFU
  65. BOOTLOADER_TYPE = dfu
  66. ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
  67. BOOTLOADER_SIZE ?= 4096
  68. endif
  69. ifneq (,$(filter $(MCU), at90usb1286 at90usb1287))
  70. BOOTLOADER_SIZE ?= 8192
  71. endif
  72. endif
  73. ifeq ($(strip $(BOOTLOADER)), qmk-dfu)
  74. OPT_DEFS += -DBOOTLOADER_QMK_DFU
  75. OPT_DEFS += -DBOOTLOADER_DFU
  76. BOOTLOADER_TYPE = dfu
  77. ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
  78. BOOTLOADER_SIZE ?= 4096
  79. endif
  80. ifneq (,$(filter $(MCU), at90usb1286 at90usb1287))
  81. BOOTLOADER_SIZE ?= 8192
  82. endif
  83. endif
  84. ifeq ($(strip $(BOOTLOADER)), qmk-hid)
  85. OPT_DEFS += -DBOOTLOADER_QMK_HID
  86. OPT_DEFS += -DBOOTLOADER_HID
  87. BOOTLOADER_TYPE = dfu
  88. BOOTLOADER_SIZE ?= 4096
  89. endif
  90. ifeq ($(strip $(BOOTLOADER)), halfkay)
  91. OPT_DEFS += -DBOOTLOADER_HALFKAY
  92. BOOTLOADER_TYPE = halfkay
  93. # Teensy 2.0
  94. ifeq ($(strip $(MCU)), atmega32u4)
  95. BOOTLOADER_SIZE = 512
  96. endif
  97. # Teensy 2.0++
  98. ifeq ($(strip $(MCU)), at90usb1286)
  99. BOOTLOADER_SIZE = 1024
  100. endif
  101. # Teensy LC, 3.x
  102. ifneq (,$(filter $(MCU_ORIG), MKL26Z64 MK20DX128 MK20DX256 MK66FX1M0))
  103. FIRMWARE_FORMAT = hex
  104. endif
  105. endif
  106. ifeq ($(strip $(BOOTLOADER)), caterina)
  107. OPT_DEFS += -DBOOTLOADER_CATERINA
  108. BOOTLOADER_TYPE = caterina
  109. BOOTLOADER_SIZE = 4096
  110. endif
  111. ifneq (,$(filter $(BOOTLOADER), bootloadhid bootloadHID))
  112. OPT_DEFS += -DBOOTLOADER_BOOTLOADHID
  113. BOOTLOADER_TYPE = bootloadhid
  114. BOOTLOADER_SIZE = 4096
  115. endif
  116. ifneq (,$(filter $(BOOTLOADER), usbasploader USBasp))
  117. OPT_DEFS += -DBOOTLOADER_USBASP
  118. BOOTLOADER_TYPE = usbasploader
  119. BOOTLOADER_SIZE = 4096
  120. endif
  121. ifeq ($(strip $(BOOTLOADER)), lufa-ms)
  122. OPT_DEFS += -DBOOTLOADER_MS
  123. BOOTLOADER_TYPE = dfu
  124. BOOTLOADER_SIZE ?= 8192
  125. FIRMWARE_FORMAT = bin
  126. cpfirmware: lufa_warning
  127. .INTERMEDIATE: lufa_warning
  128. lufa_warning: $(FIRMWARE_FORMAT)
  129. $(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
  130. $(info LUFA MASS STORAGE Bootloader selected)
  131. $(info DO NOT USE THIS BOOTLOADER IN NEW PROJECTS!)
  132. $(info It is extremely prone to bricking, and is only included to support existing boards.)
  133. $(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
  134. endif
  135. ifdef BOOTLOADER_SIZE
  136. OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE))
  137. endif
  138. ifeq ($(strip $(BOOTLOADER)), stm32-dfu)
  139. OPT_DEFS += -DBOOTLOADER_STM32_DFU
  140. BOOTLOADER_TYPE = stm32_dfu
  141. # Options to pass to dfu-util when flashing
  142. DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
  143. DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
  144. endif
  145. ifeq ($(strip $(BOOTLOADER)), apm32-dfu)
  146. OPT_DEFS += -DBOOTLOADER_APM32_DFU
  147. BOOTLOADER_TYPE = stm32_dfu
  148. # Options to pass to dfu-util when flashing
  149. DFU_ARGS ?= -d 314B:0106 -a 0 -s 0x08000000:leave
  150. DFU_SUFFIX_ARGS ?= -v 314B -p 0106
  151. endif
  152. ifeq ($(strip $(BOOTLOADER)), gd32v-dfu)
  153. OPT_DEFS += -DBOOTLOADER_GD32V_DFU
  154. BOOTLOADER_TYPE = gd32v_dfu
  155. # Options to pass to dfu-util when flashing
  156. DFU_ARGS ?= -d 28E9:0189 -a 0 -s 0x08000000:leave
  157. DFU_SUFFIX_ARGS ?= -v 28E9 -p 0189
  158. endif
  159. ifeq ($(strip $(BOOTLOADER)), kiibohd)
  160. OPT_DEFS += -DBOOTLOADER_KIIBOHD
  161. BOOTLOADER_TYPE = kiibohd
  162. ifeq ($(strip $(MCU_ORIG)), MK20DX128)
  163. MCU_LDSCRIPT = MK20DX128BLDR4
  164. endif
  165. ifeq ($(strip $(MCU_ORIG)), MK20DX256)
  166. MCU_LDSCRIPT = MK20DX256BLDR8
  167. endif
  168. # Options to pass to dfu-util when flashing
  169. DFU_ARGS = -d 1C11:B007
  170. DFU_SUFFIX_ARGS = -v 1C11 -p B007
  171. endif
  172. ifeq ($(strip $(BOOTLOADER)), stm32duino)
  173. OPT_DEFS += -DBOOTLOADER_STM32DUINO
  174. MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader
  175. BOARD = STM32_F103_STM32DUINO
  176. BOOTLOADER_TYPE = stm32duino
  177. # Options to pass to dfu-util when flashing
  178. DFU_ARGS = -d 1EAF:0003 -a 2 -R
  179. DFU_SUFFIX_ARGS = -v 1EAF -p 0003
  180. endif
  181. ifeq ($(strip $(BOOTLOADER)), tinyuf2)
  182. OPT_DEFS += -DBOOTLOADER_TINYUF2
  183. BOOTLOADER_TYPE = tinyuf2
  184. endif
  185. ifeq ($(strip $(BOOTLOADER)), rp2040)
  186. OPT_DEFS += -DBOOTLOADER_RP2040
  187. BOOTLOADER_TYPE = rp2040
  188. endif
  189. ifeq ($(strip $(BOOTLOADER)), halfkay)
  190. OPT_DEFS += -DBOOTLOADER_HALFKAY
  191. BOOTLOADER_TYPE = halfkay
  192. endif
  193. ifeq ($(strip $(BOOTLOADER)), md-boot)
  194. OPT_DEFS += -DBOOTLOADER_MD_BOOT
  195. BOOTLOADER_TYPE = md_boot
  196. endif
  197. ifeq ($(strip $(BOOTLOADER)), wb32-dfu)
  198. OPT_DEFS += -DBOOTLOADER_WB32_DFU
  199. BOOTLOADER_TYPE = wb32_dfu
  200. endif
  201. ifeq ($(strip $(BOOTLOADER_TYPE)),)
  202. $(call CATASTROPHIC_ERROR,Invalid BOOTLOADER,No bootloader specified. Please set an appropriate 'BOOTLOADER' in your keyboard's 'rules.mk' file.)
  203. endif