Skip to content

Commit 9fdc276

Browse files
authored
Updates bootloader settings, adds file size check (qmk#2029)
* pull fuse settings for bootloader jump * fix 32a chips * make automatic bootloader selection optional * quantify bootloaders * fixs qmk#164, speeds up dfu reset * fix for chips w/o usb * missing an n * fix bootloader sizes, use words for addresses * fix bmini, pearl, and [[ issue, make things quiet * ignore avr errors on arm for now * update settings for the light * document bootloader stuff * add bootloader title
1 parent 9113f33 commit 9fdc276

File tree

76 files changed

+484
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+484
-551
lines changed

bootloader.mk

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
# Current options:
22+
# atmel-dfu
23+
# lufa-dfu
24+
# qmk-dfu
25+
# halfkay
26+
# caterina
27+
# bootloadHID
28+
#
29+
# BOOTLOADER_SIZE can still be defined manually, but it's recommended
30+
# you add any possible configuration to this list
31+
32+
ifeq ($(strip $(BOOTLOADER)), atmel-dfu)
33+
OPT_DEFS += -DBOOTLOADER_ATMEL_DFU
34+
OPT_DEFS += -DBOOTLOADER_DFU
35+
BOOTLOADER_SIZE = 4096
36+
endif
37+
ifeq ($(strip $(BOOTLOADER)), lufa-dfu)
38+
OPT_DEFS += -DBOOTLOADER_LUFA_DFU
39+
OPT_DEFS += -DBOOTLOADER_DFU
40+
BOOTLOADER_SIZE = 4096
41+
endif
42+
ifeq ($(strip $(BOOTLOADER)), qmk-dfu)
43+
OPT_DEFS += -DBOOTLOADER_QMK_DFU
44+
OPT_DEFS += -DBOOTLOADER_DFU
45+
BOOTLOADER_SIZE = 4096
46+
endif
47+
ifeq ($(strip $(BOOTLOADER)), halfkay)
48+
OPT_DEFS += -DBOOTLOADER_HALFKAY
49+
BOOTLOADER_SIZE = 512
50+
endif
51+
ifeq ($(strip $(BOOTLOADER)), caterina)
52+
OPT_DEFS += -DBOOTLOADER_CATERINA
53+
BOOTLOADER_SIZE = 4096
54+
endif
55+
ifeq ($(strip $(BOOTLOADER)), bootloadHID)
56+
OPT_DEFS += -DBOOTLOADER_BOOTLOADHID
57+
BOOTLOADER_SIZE = 4096
58+
endif
59+
60+
ifdef BOOTLOADER_SIZE
61+
OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE))
62+
endif

build_keyboard.mk

+3-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ VPATH += $(USER_PATH)
230230
include common_features.mk
231231
include $(TMK_PATH)/protocol.mk
232232
include $(TMK_PATH)/common.mk
233+
include bootloader.mk
233234

234235
SRC += $(TMK_COMMON_SRC)
235236
OPT_DEFS += $(TMK_COMMON_DEFS)
@@ -266,10 +267,10 @@ $(KEYBOARD_OUTPUT)_INC := $(PROJECT_INC) $(GFXINC)
266267
$(KEYBOARD_OUTPUT)_CONFIG := $(PROJECT_CONFIG)
267268

268269
# Default target.
269-
all: build sizeafter
270+
all: build check-size
270271

271272
# Change the build target to build a HEX file or a library.
272-
build: elf hex
273+
build: elf cphex
273274
#build: elf hex eep lss sym
274275
#build: lib
275276

docs/flashing.md

+38-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
# Flashing Intrustructions
1+
# Flashing Intrustructions / Bootloader Information
22

33
There are quite a few different types of bootloaders that keyboards use, and just about all of the use a different flashing method. Luckily, projects like the [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) aim to be compatible with all the different types without having to think about it much, but this article will describe the different types of bootloaders, and available methods for flashing them.
44

5+
If you have a bootloader selected with the `BOOTLOADER` variable in your `rules.mk`, QMK will automatically calculate if your .hex file is the right size to be flashed to the device, and output the total size it bytes (along with the max). To run this process manually, compile with the target `check-size`, eg `make planck/rev4:default:check-size`.
6+
57
## DFU
68

79
Atmel's DFU bootloader comes on all atmega32u4 chips by default, and is used by many keyboards that have their own ICs on their PCBs (Older OLKB boards, Clueboards). Some keyboards may also use LUFA's DFU bootloader (or QMK's fork) (Newer OLKB boards) that adds in additional features specific to that hardware.
810

9-
These bootloaders are usually 4096 bytes for the atmega32u4 chip.
11+
To ensure compatability with the DFU bootloader, make sure this block is present your `rules.mk` (optionally with `lufa-dfu` or `qmk-dfu` instead):
12+
13+
# Bootloader
14+
# This definition is optional, and if your keyboard supports multiple bootloaders of
15+
# different sizes, comment this out, and the correct address will be loaded
16+
# automatically (+60). See bootloader.mk for all options.
17+
BOOTLOADER = atmel-dfu
1018

1119
Compatible flashers:
1220

@@ -26,15 +34,32 @@ or:
2634

2735
make <keyboard>:<keymap>:dfu
2836

37+
### QMK DFU
38+
39+
QMK has a fork of the LUFA DFU bootloader that allows for a simple matrix scan for exiting the bootloader and returning to the application, as well as flashing an LED/making a ticking noise with a speaker when things are happening. To enable these features, use this block in your `config.h` (The key that exits the bootloader needs to be hooked-up to the INPUT and OUTPUT defined here):
40+
41+
#define QMK_ESC_OUTPUT F1 // usually COL
42+
#define QMK_ESC_INPUT D5 // usually ROW
43+
#define QMK_LED E6
44+
#define QMK_SPEAKER C6
45+
46+
The Manufacturer and Product names are automatically pulled from your `config.h`, and "Bootloader" is added to the product.
47+
48+
To generate this bootloader, use the `bootloader` target, eg `make planck/rev4:default:bootloader`.
49+
50+
To generate a production-ready .hex file (containing the application and the bootloader), use the `production` target, eg `make planck/rev4:default:production`.
51+
2952
## Caterina
3053

3154
Arduino boards and their clones use the [Caterina bootloader](https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/bootloaders/caterina) (any keyboard built with a Pro Micro, or clone), and uses the avr109 protocol to communicate through virtual serial. Bootloaders like [A-Star](https://www.pololu.com/docs/0J61/9) are based on Caterina.
3255

33-
This block of code allows for Caterina compatibility in QMK:
56+
To ensure compatability with the Caterina bootloader, make sure this block is present your `rules.mk`:
3457

35-
#define CATERINA_BOOTLOADER
36-
37-
These bootloaders are usually 4096 bytes for the atmega32u4 chip.
58+
# Bootloader
59+
# This definition is optional, and if your keyboard supports multiple bootloaders of
60+
# different sizes, comment this out, and the correct address will be loaded
61+
# automatically (+60). See bootloader.mk for all options.
62+
BOOTLOADER = caterina
3863

3964
Compatible flashers:
4065

@@ -57,7 +82,13 @@ or
5782

5883
Halfkay is a super-slim protocol developed by PJRC that uses HID, and come on all Teensys (namely the 2.0).
5984

60-
This bootloader is 512 bytes.
85+
To ensure compatability with the Halfkay bootloader, make sure this block is present your `rules.mk`:
86+
87+
# Bootloader
88+
# This definition is optional, and if your keyboard supports multiple bootloaders of
89+
# different sizes, comment this out, and the correct address will be loaded
90+
# automatically (+60). See bootloader.mk for all options.
91+
BOOTLOADER = halfkay
6192

6293
Compatible flashers:
6394

keyboards/atreus/rules.mk

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ifdef TEENSY2
55
ATREUS_UPLOAD_COMMAND = teensy_loader_cli -w -mmcu=$(MCU) $(TARGET).hex
66
else
77
OPT_DEFS += -DATREUS_ASTAR
8-
OPT_DEFS += -DCATERINA_BOOTLOADER
98
ATREUS_UPLOAD_COMMAND = while [ ! -r $(USB) ]; do sleep 1; done; \
109
avrdude -p $(MCU) -c avr109 -U flash:w:$(TARGET).hex -P $(USB)
1110
endif
@@ -27,7 +26,6 @@ MCU = atmega32u4
2726
# software delays.
2827
F_CPU = 16000000
2928

30-
3129
#
3230
# LUFA specific
3331
#
@@ -47,19 +45,20 @@ ARCH = AVR8
4745
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
4846
F_USB = $(F_CPU)
4947

48+
# Bootloader
49+
# This definition is optional, and if your keyboard supports multiple bootloaders of
50+
# different sizes, comment this out, and the correct address will be loaded
51+
# automatically (+60). See bootloader.mk for all options.
52+
ifdef TEENSY2
53+
BOOTLOADER = halfkay
54+
else
55+
BOOTLOADER = caterina
56+
endif
57+
5058
# Interrupt driven control endpoint task(+60)
5159
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
5260

5361

54-
# Boot Section Size in *bytes*
55-
# Teensy halfKay 512
56-
# Teensy++ halfKay 1024
57-
# Atmel DFU loader 4096
58-
# LUFA bootloader 4096
59-
# USBaspLoader 2048
60-
OPT_DEFS += -DBOOTLOADER_SIZE=4096
61-
62-
6362
# Build Options
6463
# comment out to disable the options.
6564
#

keyboards/atreus62/config.h

-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3838
#define MATRIX_ROW_PINS { D2, D3, D1, D0, D4 }
3939
#define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3, B2, B6, B5, B4, E6, D7, C6 }
4040

41-
#define CATERINA_BOOTLOADER
42-
4341
/* COL2ROW or ROW2COL */
4442
#define DIODE_DIRECTION ROW2COL
4543

keyboards/atreus62/rules.mk

+6-9
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ ARCH = AVR8
3535
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
3636
F_USB = $(F_CPU)
3737

38+
# Bootloader
39+
# This definition is optional, and if your keyboard supports multiple bootloaders of
40+
# different sizes, comment this out, and the correct address will be loaded
41+
# automatically (+60). See bootloader.mk for all options.
42+
BOOTLOADER = caterina
43+
3844
# Interrupt driven control endpoint task(+60)
3945
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
4046

41-
42-
# Boot Section Size in *bytes*
43-
# Teensy halfKay 512
44-
# Teensy++ halfKay 1024
45-
# Atmel DFU loader 4096
46-
# LUFA bootloader 4096
47-
# USBaspLoader 2048
48-
OPT_DEFS += -DBOOTLOADER_SIZE=4096
49-
5047
# Build Options
5148
# change to "no" to disable the options, or define them in the Makefile in
5249
# the appropriate keymap folder that will get included automatically

keyboards/bfake/config.h

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4141
#define RGBLIGHT_ANIMATIONS
4242

4343
#define NO_UART 1
44-
#define BOOTLOADHID_BOOTLOADER 1
4544

4645
/* key combination for command */
4746
#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))

keyboards/bfake/rules.mk

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ NO_SUSPEND_POWER_DOWN = yes
2424
# processor frequency
2525
F_CPU = 12000000
2626

27+
# Bootloader
28+
# This definition is optional, and if your keyboard supports multiple bootloaders of
29+
# different sizes, comment this out, and the correct address will be loaded
30+
# automatically (+60). See bootloader.mk for all options.
31+
BOOTLOADER = bootloadHID
32+
2733
# build options
2834
BOOTMAGIC_ENABLE = yes
2935
MOUSEKEY_ENABLE = yes
@@ -35,7 +41,6 @@ RGBLIGHT_ENABLE = yes
3541
RGBLIGHT_CUSTOM_DRIVER = yes
3642

3743
OPT_DEFS = -DDEBUG_LEVEL=0
38-
OPT_DEFS += -DBOOTLOADER_SIZE=2048
3944

4045
# custom matrix setup
4146
CUSTOM_MATRIX = yes

keyboards/bmini/config.h

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3434
#define RGBLIGHT_ANIMATIONS
3535

3636
#define NO_UART 1
37-
#define BOOTLOADHID_BOOTLOADER 1
3837

3938
/* key combination for command */
4039
#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))

keyboards/bmini/rules.mk

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ NO_SUSPEND_POWER_DOWN = yes
2424
# processor frequency
2525
F_CPU = 12000000
2626

27+
# Bootloader
28+
# This definition is optional, and if your keyboard supports multiple bootloaders of
29+
# different sizes, comment this out, and the correct address will be loaded
30+
# automatically (+60). See bootloader.mk for all options.
31+
BOOTLOADER = bootloadHID
32+
2733
# build options
2834
BOOTMAGIC_ENABLE = yes
2935
MOUSEKEY_ENABLE = yes
@@ -35,7 +41,6 @@ RGBLIGHT_ENABLE = yes
3541
RGBLIGHT_CUSTOM_DRIVER = yes
3642

3743
OPT_DEFS = -DDEBUG_LEVEL=0
38-
OPT_DEFS += -DBOOTLOADER_SIZE=2048
3944

4045
# custom matrix setup
4146
CUSTOM_MATRIX = yes

keyboards/chimera_ortho/rules.mk

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
OPT_DEFS += -DCHIMERA_ORTHO_PROMICRO
3-
OPT_DEFS += -DCATERINA_BOOTLOADER
43
CHIMERA_ORTHO_UPLOAD_COMMAND = while [ ! -r $(USB) ]; do sleep 1; done; \
54
avrdude -p $(MCU) -c avr109 -U flash:w:$(TARGET).hex -P $(USB)
65

@@ -45,19 +44,15 @@ ARCH = AVR8
4544
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
4645
F_USB = $(F_CPU)
4746

47+
# Bootloader
48+
# This definition is optional, and if your keyboard supports multiple bootloaders of
49+
# different sizes, comment this out, and the correct address will be loaded
50+
# automatically (+60). See bootloader.mk for all options.
51+
BOOTLOADER = caterina
52+
4853
# Interrupt driven control endpoint task(+60)
4954
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
5055

51-
52-
# Boot Section Size in *bytes*
53-
# Teensy halfKay 512
54-
# Teensy++ halfKay 1024
55-
# Atmel DFU loader 4096
56-
# LUFA bootloader 4096
57-
# USBaspLoader 2048
58-
OPT_DEFS += -DBOOTLOADER_SIZE=4096
59-
60-
6156
# Build Options
6257
# comment out to disable the options.
6358
#
-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
BLUETOOTH = AdafruitBLE
22
ADAFRUIT_BLE_ENABLE = yes
3-
OPT_DEFS += -DCATERINA_BOOTLOADER
43
F_CPU = 8000000

keyboards/converter/usb_usb/rules.mk

+6-10
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,15 @@ ARCH = AVR8
4343
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
4444
F_USB = $(F_CPU)
4545

46+
# Bootloader
47+
# This definition is optional, and if your keyboard supports multiple bootloaders of
48+
# different sizes, comment this out, and the correct address will be loaded
49+
# automatically (+60). See bootloader.mk for all options.
50+
BOOTLOADER = caterina
51+
4652
# Interrupt driven control endpoint task
4753
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
4854

49-
50-
# Boot Section Size in *bytes*
51-
# Teensy halfKay 512
52-
# Teensy++ halfKay 1024
53-
# Atmel DFU loader 4096
54-
# LUFA bootloader 4096
55-
# USBaspLoader 2048
56-
OPT_DEFS += -DBOOTLOADER_SIZE=4096
57-
58-
5955
# Build Options
6056
# comment out to disable the options.
6157
#

keyboards/deltasplit75/rules.mk

+6-9
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ ARCH = AVR8
3939
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
4040
F_USB = $(F_CPU)
4141

42+
# Bootloader
43+
# This definition is optional, and if your keyboard supports multiple bootloaders of
44+
# different sizes, comment this out, and the correct address will be loaded
45+
# automatically (+60). See bootloader.mk for all options.
46+
BOOTLOADER = caterina
47+
4248
# Interrupt driven control endpoint task(+60)
4349
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
4450

45-
46-
# Boot Section Size in *bytes*
47-
# Teensy halfKay 512
48-
# Teensy++ halfKay 1024
49-
# Atmel DFU loader 4096
50-
# LUFA bootloader 4096
51-
# USBaspLoader 2048
52-
OPT_DEFS += -DBOOTLOADER_SIZE=4096
53-
5451
# Build Options
5552
# change to "no" to disable the options, or define them in the Makefile in
5653
# the appropriate keymap folder that will get included automatically

keyboards/deltasplit75/v2/config.h

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3737
#define MATRIX_ROW_PINS { F4, F5, F6, F7, B1, B3, B2 }
3838
#define MATRIX_COL_PINS { B6, B5, B4, E6, D7, C6, D4, D1}
3939

40-
#define CATERINA_BOOTLOADER
41-
4240
/* COL2ROW or ROW2COL */
4341
#define DIODE_DIRECTION COL2ROW
4442

0 commit comments

Comments
 (0)