bootloader.mk 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. ifeq ($(strip $(MCU)), atmega32u4)
  94. BOOTLOADER_SIZE = 512
  95. endif
  96. ifeq ($(strip $(MCU)), at90usb1286)
  97. BOOTLOADER_SIZE = 1024
  98. endif
  99. endif
  100. ifeq ($(strip $(BOOTLOADER)), caterina)
  101. OPT_DEFS += -DBOOTLOADER_CATERINA
  102. BOOTLOADER_TYPE = caterina
  103. BOOTLOADER_SIZE = 4096
  104. endif
  105. ifneq (,$(filter $(BOOTLOADER), bootloadhid bootloadHID))
  106. OPT_DEFS += -DBOOTLOADER_BOOTLOADHID
  107. BOOTLOADER_TYPE = bootloadhid
  108. BOOTLOADER_SIZE = 4096
  109. endif
  110. ifneq (,$(filter $(BOOTLOADER), usbasploader USBasp))
  111. OPT_DEFS += -DBOOTLOADER_USBASP
  112. BOOTLOADER_TYPE = usbasploader
  113. BOOTLOADER_SIZE = 4096
  114. endif
  115. ifeq ($(strip $(BOOTLOADER)), lufa-ms)
  116. OPT_DEFS += -DBOOTLOADER_MS
  117. BOOTLOADER_TYPE = dfu
  118. BOOTLOADER_SIZE ?= 8192
  119. FIRMWARE_FORMAT = bin
  120. cpfirmware: lufa_warning
  121. .INTERMEDIATE: lufa_warning
  122. lufa_warning: $(FIRMWARE_FORMAT)
  123. $(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
  124. $(info LUFA MASS STORAGE Bootloader selected)
  125. $(info DO NOT USE THIS BOOTLOADER IN NEW PROJECTS!)
  126. $(info It is extremely prone to bricking, and is only included to support existing boards.)
  127. $(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
  128. endif
  129. ifdef BOOTLOADER_SIZE
  130. OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE))
  131. endif
  132. ifeq ($(strip $(BOOTLOADER)), stm32-dfu)
  133. OPT_DEFS += -DBOOTLOADER_STM32_DFU
  134. BOOTLOADER_TYPE = stm32_dfu
  135. # Options to pass to dfu-util when flashing
  136. DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
  137. DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
  138. endif
  139. ifeq ($(strip $(BOOTLOADER)), apm32-dfu)
  140. OPT_DEFS += -DBOOTLOADER_APM32_DFU
  141. BOOTLOADER_TYPE = stm32_dfu
  142. # Options to pass to dfu-util when flashing
  143. DFU_ARGS ?= -d 314B:0106 -a 0 -s 0x08000000:leave
  144. DFU_SUFFIX_ARGS ?= -v 314B -p 0106
  145. endif
  146. ifeq ($(strip $(BOOTLOADER)), gd32v-dfu)
  147. OPT_DEFS += -DBOOTLOADER_GD32V_DFU
  148. BOOTLOADER_TYPE = gd32v_dfu
  149. # Options to pass to dfu-util when flashing
  150. DFU_ARGS ?= -d 28E9:0189 -a 0 -s 0x08000000:leave
  151. DFU_SUFFIX_ARGS ?= -v 28E9 -p 0189
  152. endif
  153. ifeq ($(strip $(BOOTLOADER)), kiibohd)
  154. OPT_DEFS += -DBOOTLOADER_KIIBOHD
  155. BOOTLOADER_TYPE = kiibohd
  156. ifeq ($(strip $(MCU_ORIG)), MK20DX128)
  157. MCU_LDSCRIPT = MK20DX128BLDR4
  158. endif
  159. ifeq ($(strip $(MCU_ORIG)), MK20DX256)
  160. MCU_LDSCRIPT = MK20DX256BLDR8
  161. endif
  162. # Options to pass to dfu-util when flashing
  163. DFU_ARGS = -d 1C11:B007
  164. DFU_SUFFIX_ARGS = -v 1C11 -p B007
  165. endif
  166. ifeq ($(strip $(BOOTLOADER)), stm32duino)
  167. OPT_DEFS += -DBOOTLOADER_STM32DUINO
  168. MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader
  169. BOARD = STM32_F103_STM32DUINO
  170. BOOTLOADER_TYPE = stm32duino
  171. # Options to pass to dfu-util when flashing
  172. DFU_ARGS = -d 1EAF:0003 -a 2 -R
  173. DFU_SUFFIX_ARGS = -v 1EAF -p 0003
  174. endif
  175. ifeq ($(strip $(BOOTLOADER)), tinyuf2)
  176. OPT_DEFS += -DBOOTLOADER_TINYUF2
  177. BOOTLOADER_TYPE = tinyuf2
  178. endif
  179. ifeq ($(strip $(BOOTLOADER)), halfkay)
  180. OPT_DEFS += -DBOOTLOADER_HALFKAY
  181. BOOTLOADER_TYPE = halfkay
  182. endif
  183. ifeq ($(strip $(BOOTLOADER)), md-boot)
  184. OPT_DEFS += -DBOOTLOADER_MD_BOOT
  185. BOOTLOADER_TYPE = md_boot
  186. endif
  187. ifeq ($(strip $(BOOTLOADER)), wb32-dfu)
  188. OPT_DEFS += -DBOOTLOADER_WB32_DFU
  189. BOOTLOADER_TYPE = wb32_dfu
  190. endif
  191. ifeq ($(strip $(BOOTLOADER_TYPE)),)
  192. $(call CATASTROPHIC_ERROR,Invalid BOOTLOADER,No bootloader specified. Please set an appropriate 'BOOTLOADER' in your keyboard's 'rules.mk' file.)
  193. endif