Parent directory

bootloader.mk

4914 bytes
  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
 16# If it's possible that multiple bootloaders can be used for one project,
 17# you can leave this unset, and the correct size will be selected
 18# automatically.
 19#
 20# Sets the bootloader defined in the keyboard's/keymap's rules.mk
 21#
 22# Current options for 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#
 32# If you need to provide your own implementation, you can set inside `rules.mk`
 33# `BOOTLOADER = custom` -- you'll need to provide your own implementations. See
 34# the respective file under `platforms/<PLATFORM>/bootloaders/custom.c` to see
 35# which functions may be overridden.
 36#
 37# BOOTLOADER_SIZE can still be defined manually, but it's recommended
 38# you add any possible configuration to this list
 39
 40FIRMWARE_FORMAT?=hex
 41
 42ifeq ($(strip $(BOOTLOADER)), custom)
 43    OPT_DEFS += -DBOOTLOADER_CUSTOM
 44    BOOTLOADER_TYPE = custom
 45endif
 46
 47ifeq ($(strip $(BOOTLOADER)), atmel-dfu)
 48    OPT_DEFS += -DBOOTLOADER_ATMEL_DFU
 49    OPT_DEFS += -DBOOTLOADER_DFU
 50    BOOTLOADER_TYPE = dfu
 51
 52    ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
 53        BOOTLOADER_SIZE = 4096
 54    endif
 55    ifneq (,$(filter $(MCU), at90usb1286 at90usb1287))
 56        BOOTLOADER_SIZE = 8192
 57    endif
 58endif
 59ifeq ($(strip $(BOOTLOADER)), lufa-dfu)
 60    OPT_DEFS += -DBOOTLOADER_LUFA_DFU
 61    OPT_DEFS += -DBOOTLOADER_DFU
 62    BOOTLOADER_TYPE = dfu
 63
 64    ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
 65        BOOTLOADER_SIZE ?= 4096
 66    endif
 67    ifneq (,$(filter $(MCU), at90usb1286 at90usb1287))
 68        BOOTLOADER_SIZE ?= 8192
 69    endif
 70endif
 71ifeq ($(strip $(BOOTLOADER)), qmk-dfu)
 72    OPT_DEFS += -DBOOTLOADER_QMK_DFU
 73    OPT_DEFS += -DBOOTLOADER_DFU
 74    BOOTLOADER_TYPE = dfu
 75
 76    ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
 77        BOOTLOADER_SIZE ?= 4096
 78    endif
 79    ifneq (,$(filter $(MCU), at90usb1286 at90usb1287))
 80        BOOTLOADER_SIZE ?= 8192
 81    endif
 82endif
 83ifeq ($(strip $(BOOTLOADER)), qmk-hid)
 84    OPT_DEFS += -DBOOTLOADER_QMK_HID
 85    OPT_DEFS += -DBOOTLOADER_HID
 86    BOOTLOADER_TYPE = dfu
 87
 88    BOOTLOADER_SIZE ?= 4096
 89endif
 90ifeq ($(strip $(BOOTLOADER)), halfkay)
 91    OPT_DEFS += -DBOOTLOADER_HALFKAY
 92    BOOTLOADER_TYPE = halfkay
 93
 94    # Teensy 2.0
 95    ifeq ($(strip $(MCU)), atmega32u4)
 96        BOOTLOADER_SIZE = 512
 97    endif
 98    # Teensy 2.0++
 99    ifeq ($(strip $(MCU)), at90usb1286)
100        BOOTLOADER_SIZE = 1024
101    endif
102endif
103ifeq ($(strip $(BOOTLOADER)), caterina)
104    OPT_DEFS += -DBOOTLOADER_CATERINA
105    BOOTLOADER_TYPE = caterina
106
107    BOOTLOADER_SIZE = 4096
108endif
109ifeq ($(strip $(BOOTLOADER)), bootloadhid)
110    OPT_DEFS += -DBOOTLOADER_BOOTLOADHID
111    BOOTLOADER_TYPE = bootloadhid
112
113    BOOTLOADER_SIZE = 4096
114endif
115ifeq ($(strip $(BOOTLOADER)), usbasploader)
116    OPT_DEFS += -DBOOTLOADER_USBASP
117    BOOTLOADER_TYPE = usbasploader
118
119    BOOTLOADER_SIZE = 4096
120endif
121ifeq ($(strip $(BOOTLOADER)), lufa-ms)
122    OPT_DEFS += -DBOOTLOADER_MS
123    BOOTLOADER_TYPE = dfu
124
125    BOOTLOADER_SIZE ?= 8192
126    FIRMWARE_FORMAT = bin
127cpfirmware: lufa_warning
128.INTERMEDIATE: lufa_warning
129lufa_warning: $(FIRMWARE_FORMAT)
130	$(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
131	$(info LUFA MASS STORAGE Bootloader selected)
132	$(info DO NOT USE THIS BOOTLOADER IN NEW PROJECTS!)
133	$(info It is extremely prone to bricking, and is only included to support existing boards.)
134	$(info @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)
135endif
136ifdef BOOTLOADER_SIZE
137    OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE))
138endif
139
140ifeq ($(strip $(BOOTLOADER_TYPE)),)
141    ifneq ($(strip $(BOOTLOADER)),)
142        $(call CATASTROPHIC_ERROR,Invalid BOOTLOADER,Invalid bootloader specified. Please set an appropriate bootloader in your rules.mk or info.json.)
143    else
144        $(call CATASTROPHIC_ERROR,Invalid BOOTLOADER,No bootloader specified. Please set an appropriate bootloader in your rules.mk or info.json.)
145    endif
146endif