Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bootloader_jump() implementations #15450

Merged
merged 3 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ all: elf
VPATH += $(COMMON_VPATH)
PLATFORM:=TEST
PLATFORM_KEY:=test
BOOTLOADER_TYPE:=none

ifeq ($(strip $(DEBUG)), 1)
CONSOLE_ENABLE = yes
Expand Down
40 changes: 38 additions & 2 deletions builddefs/bootloader.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# bootloadhid HIDBootFlash compatible (ATmega32A)
# usbasploader USBaspLoader (ATmega328P)
# ARM:
# halfkay PJRC Teensy
# kiibohd Input:Club Kiibohd bootloader (only used on their boards)
# stm32duino STM32Duino (STM32F103x8)
# stm32-dfu STM32 USB DFU in ROM
Expand All @@ -43,6 +44,8 @@
ifeq ($(strip $(BOOTLOADER)), atmel-dfu)
OPT_DEFS += -DBOOTLOADER_ATMEL_DFU
OPT_DEFS += -DBOOTLOADER_DFU
BOOTLOADER_TYPE = dfu

ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
BOOTLOADER_SIZE = 4096
endif
Expand All @@ -53,6 +56,8 @@ endif
ifeq ($(strip $(BOOTLOADER)), lufa-dfu)
OPT_DEFS += -DBOOTLOADER_LUFA_DFU
OPT_DEFS += -DBOOTLOADER_DFU
BOOTLOADER_TYPE = dfu

ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
BOOTLOADER_SIZE ?= 4096
endif
Expand All @@ -63,6 +68,8 @@ endif
ifeq ($(strip $(BOOTLOADER)), qmk-dfu)
OPT_DEFS += -DBOOTLOADER_QMK_DFU
OPT_DEFS += -DBOOTLOADER_DFU
BOOTLOADER_TYPE = dfu

ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647))
BOOTLOADER_SIZE ?= 4096
endif
Expand All @@ -73,10 +80,14 @@ endif
ifeq ($(strip $(BOOTLOADER)), qmk-hid)
OPT_DEFS += -DBOOTLOADER_QMK_HID
OPT_DEFS += -DBOOTLOADER_HID
BOOTLOADER_TYPE = dfu

BOOTLOADER_SIZE ?= 4096
endif
ifeq ($(strip $(BOOTLOADER)), halfkay)
OPT_DEFS += -DBOOTLOADER_HALFKAY
BOOTLOADER_TYPE = halfkay

ifeq ($(strip $(MCU)), atmega32u4)
BOOTLOADER_SIZE = 512
endif
Expand All @@ -86,18 +97,26 @@ ifeq ($(strip $(BOOTLOADER)), halfkay)
endif
ifeq ($(strip $(BOOTLOADER)), caterina)
OPT_DEFS += -DBOOTLOADER_CATERINA
BOOTLOADER_TYPE = caterina

BOOTLOADER_SIZE = 4096
endif
ifneq (,$(filter $(BOOTLOADER), bootloadhid bootloadHID))
OPT_DEFS += -DBOOTLOADER_BOOTLOADHID
BOOTLOADER_TYPE = bootloadhid

BOOTLOADER_SIZE = 4096
endif
ifneq (,$(filter $(BOOTLOADER), usbasploader USBasp))
OPT_DEFS += -DBOOTLOADER_USBASP
BOOTLOADER_TYPE = usbasploader

BOOTLOADER_SIZE = 4096
endif
ifeq ($(strip $(BOOTLOADER)), lufa-ms)
OPT_DEFS += -DBOOTLOADER_MS
BOOTLOADER_TYPE = dfu

BOOTLOADER_SIZE ?= 8192
FIRMWARE_FORMAT = bin
cpfirmware: lufa_warning
Expand All @@ -115,27 +134,32 @@ endif

ifeq ($(strip $(BOOTLOADER)), stm32-dfu)
OPT_DEFS += -DBOOTLOADER_STM32_DFU
BOOTLOADER_TYPE = stm32_dfu

# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
endif
ifeq ($(strip $(BOOTLOADER)), apm32-dfu)
OPT_DEFS += -DBOOTLOADER_APM32_DFU
BOOTLOADER_TYPE = stm32_dfu

# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 314B:0106 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 314B -p 0106
endif
ifeq ($(strip $(BOOTLOADER)), gd32v-dfu)
OPT_DEFS += -DBOOTLOADER_GD32V_DFU
BOOTLOADER_TYPE = gd32v_dfu

# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 28E9:0189 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 28E9 -p 0189
endif
ifeq ($(strip $(BOOTLOADER)), kiibohd)
OPT_DEFS += -DBOOTLOADER_KIIBOHD
BOOTLOADER_TYPE = kiibohd

ifeq ($(strip $(MCU_ORIG)), MK20DX128)
MCU_LDSCRIPT = MK20DX128BLDR4
endif
Expand All @@ -151,13 +175,25 @@ ifeq ($(strip $(BOOTLOADER)), stm32duino)
OPT_DEFS += -DBOOTLOADER_STM32DUINO
MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader
BOARD = STM32_F103_STM32DUINO
# STM32F103 does NOT have an USB bootloader in ROM (only serial), so setting anything here does not make much sense
STM32_BOOTLOADER_ADDRESS = 0x80000000
BOOTLOADER_TYPE = stm32duino

# Options to pass to dfu-util when flashing
DFU_ARGS = -d 1EAF:0003 -a 2 -R
DFU_SUFFIX_ARGS = -v 1EAF -p 0003
endif
ifeq ($(strip $(BOOTLOADER)), tinyuf2)
OPT_DEFS += -DBOOTLOADER_TINYUF2
BOOTLOADER_TYPE = tinyuf2
endif
ifeq ($(strip $(BOOTLOADER)), halfkay)
OPT_DEFS += -DBOOTLOADER_HALFKAY
BOOTLOADER_TYPE = halfkay
endif
ifeq ($(strip $(BOOTLOADER)), md-boot)
OPT_DEFS += -DBOOTLOADER_MD_BOOT
BOOTLOADER_TYPE = md_boot
endif

ifeq ($(strip $(BOOTLOADER_TYPE)),)
BOOTLOADER_TYPE = none
endif
2 changes: 1 addition & 1 deletion data/schemas/keyboard.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"bootloader": {
"type": "string",
"enum": ["atmel-dfu", "bootloadhid", "bootloadHID", "caterina", "halfkay", "kiibohd", "lufa-dfu", "lufa-ms", "micronucleus", "qmk-dfu", "qmk-hid", "stm32-dfu", "stm32duino", "gd32v-dfu", "wb32-dfu", "unknown", "usbasploader", "USBasp", "tinyuf2"],
"enum": ["atmel-dfu", "bootloadhid", "bootloadHID", "caterina", "halfkay", "kiibohd", "lufa-dfu", "lufa-ms", "md-boot", "micronucleus", "qmk-dfu", "qmk-hid", "stm32-dfu", "stm32duino", "gd32v-dfu", "wb32-dfu", "unknown", "usbasploader", "USBasp", "tinyuf2"],
},
"bootloader_instructions": {
"type": "string",
Expand Down
3 changes: 3 additions & 0 deletions keyboards/handwired/onekey/teensy_32/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# MCU name
MCU = MK20DX256

# Bootloader selection
BOOTLOADER = halfkay

# Enter lower-power sleep mode when on the ChibiOS idle thread
OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE
3 changes: 3 additions & 0 deletions keyboards/handwired/onekey/teensy_lc/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
MCU = MKL26Z64
USE_CHIBIOS_CONTRIB = yes

# Bootloader selection
BOOTLOADER = halfkay

# Enter lower-power sleep mode when on the ChibiOS idle thread
OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE
3 changes: 3 additions & 0 deletions keyboards/massdrop/alt/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SRC += config_led.c
ARM_ATSAM = SAMD51J18A
MCU = cortex-m4

# Bootloader selection
BOOTLOADER = md-boot

# Build Options
# comment out to disable the options.
#
Expand Down
3 changes: 3 additions & 0 deletions keyboards/massdrop/ctrl/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SRC += config_led.c
ARM_ATSAM = SAMD51J18A
MCU = cortex-m4

# Bootloader selection
BOOTLOADER = md-boot

# Build Options
# comment out to disable the options.
#
Expand Down
4 changes: 2 additions & 2 deletions keyboards/mechlovin/olly/jf/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MCU = atmega32a
F_CPU = 16000000

# Bootloader selection
BOOTLOADER = USBasp
BOOTLOADER = usbasploader

# Build Options
# change yes to no to disable
Expand All @@ -21,4 +21,4 @@ RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
AUDIO_ENABLE = no # Audio output
CUSTOM_MATRIX = lite

SRC += matrix.c
SRC += matrix.c
2 changes: 1 addition & 1 deletion keyboards/rocketboard_16/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MCU = STM32F103
MCU_LDSCRIPT = STM32F103xB_stm32duino_bootloader
OPT_DEFS += -DBOOTLOADER_STM32DUINO
BOARD = STM32_F103_STM32DUINO
STM32_BOOTLOADER_ADDRESS = 0x80000000
BOOTLOADER_TYPE = stm32duino
DFU_ARGS = -d 1EAF:0003 -a 2 -R
DFU_SUFFIX_ARGS = -v 1EAF -p 0003

Expand Down
2 changes: 1 addition & 1 deletion keyboards/tgr/jane/v2ce/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MCU = atmega32a

# Bootloader selection
BOOTLOADER = bootloadHID
BOOTLOADER = bootloadhid

# Build Options
# change yes to no to disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/

#include "bootloader.h"

#include "samd51j18a.h"
#include "md_bootloader.h"

// Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
void bootloader_jump(void) {
#ifdef KEYBOARD_massdrop_ctrl
// CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
// WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
extern uint32_t _eram;

#define BOOTLOADER_MAGIC 0x3B9ACA00
#define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4)

// CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
void bootloader_jump(void) {
uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; // The version to match (NULL terminated by compiler)
uint8_t *ver_check = ver_ram_method; // Pointer to version match string for traversal
uint8_t *ver_rom = (uint8_t *)0x21A0; // Pointer to address in ROM where this specific bootloader version would exist
Expand All @@ -34,24 +39,28 @@ void bootloader_jump(void) {
if (!*ver_check) { // If check version pointer is NULL, all characters have matched
*MAGIC_ADDR = BOOTLOADER_MAGIC; // Set magic number into RAM
NVIC_SystemReset(); // Perform system reset
while (1) {
} // Won't get here

while (1); // Won't get here
}
#endif
}

#else

// Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
void bootloader_jump(void) {
WDT->CTRLA.bit.ENABLE = 0;
while (WDT->SYNCBUSY.bit.ENABLE) {
}
while (WDT->CTRLA.bit.ENABLE) {
}

while (WDT->SYNCBUSY.bit.ENABLE);
while (WDT->CTRLA.bit.ENABLE);

WDT->CONFIG.bit.WINDOW = 0;
WDT->CONFIG.bit.PER = 0;
WDT->EWCTRL.bit.EWOFFSET = 0;
WDT->CTRLA.bit.ENABLE = 1;
while (WDT->SYNCBUSY.bit.ENABLE) {
}
while (!WDT->CTRLA.bit.ENABLE) {
}
while (1) {
} // Wait on timeout

while (WDT->SYNCBUSY.bit.ENABLE);
while (!WDT->CTRLA.bit.ENABLE);

while (1); // Wait on timeout
}
#endif
Loading