From 5bda256a9e86245b9f77315ec1acca9e2f303792 Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Sun, 8 Sep 2019 18:12:21 +0200 Subject: [PATCH 1/6] Enable bootloader skip based on reset source --- Bootloaders/DFU/BootloaderDFU.c | 12 ++++++++---- Bootloaders/DFU/makefile | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index 883afef03..9f309ba48 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -136,8 +136,10 @@ void Application_Jump_Check(void) if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST)) { /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */ - //if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) - // JumpToApplication = true; + if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) + { + JumpToApplication = true; + } /* Clear reset source */ MCUSR &= ~(1 << EXTRF); @@ -146,8 +148,10 @@ void Application_Jump_Check(void) { /* If the reset source was the bootloader and the key is correct, clear it and jump to the application; * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */ - //if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) - // JumpToApplication = true; + if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) + { + JumpToApplication = true; + } /* Clear reset source */ MCUSR &= ~(1 << WDRF); diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile index 3df99a57d..1ccd76ece 100644 --- a/Bootloaders/DFU/makefile +++ b/Bootloaders/DFU/makefile @@ -11,6 +11,7 @@ # Run "make help" for target help. +LTO = Y MCU ?= atmega32u4 ARCH ?= AVR8 BOARD = QMK From 051c877e06468b2ad798265f80ef549bcb6621ba Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Sun, 8 Sep 2019 18:15:42 +0200 Subject: [PATCH 2/6] Only enable reset source detection if avr-gcc == 8.3.x --- Bootloaders/DFU/BootloaderDFU.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index 9f309ba48..e964bb62f 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -135,23 +135,27 @@ void Application_Jump_Check(void) /* Check if the device's BOOTRST fuse is set */ if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST)) { + #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */ if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) { JumpToApplication = true; } + #endif /* Clear reset source */ MCUSR &= ~(1 << EXTRF); } else { + #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 /* If the reset source was the bootloader and the key is correct, clear it and jump to the application; * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */ if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) { JumpToApplication = true; } + #endif /* Clear reset source */ MCUSR &= ~(1 << WDRF); From a8b4ed181872985f85827d745d2aff16ffe6745c Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Sun, 8 Sep 2019 18:25:54 +0200 Subject: [PATCH 3/6] Moved LTO rule --- Bootloaders/DFU/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile index 1ccd76ece..96c4c589c 100644 --- a/Bootloaders/DFU/makefile +++ b/Bootloaders/DFU/makefile @@ -11,7 +11,6 @@ # Run "make help" for target help. -LTO = Y MCU ?= atmega32u4 ARCH ?= AVR8 BOARD = QMK @@ -23,6 +22,7 @@ SRC = $(TARGET).c Descriptors.c BootloaderAPI.c BootloaderAPITable.S $( LUFA_PATH = ../../LUFA CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START_OFFSET) LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START_OFFSET) $(BOOT_API_LD_FLAGS) +LTO = Y # Flash size and bootloader section sizes of the target, in KB. These must # match the target's total FLASH size and the bootloader size set in the From 321580492e1f9a1f2143210dccd275c22a5d1df9 Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Sun, 8 Sep 2019 19:23:41 +0200 Subject: [PATCH 4/6] made the reset check dependent on a define --- Bootloaders/DFU/BootloaderDFU.c | 4 ++-- Bootloaders/DFU/makefile | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index e964bb62f..d3fa9da19 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -135,7 +135,7 @@ void Application_Jump_Check(void) /* Check if the device's BOOTRST fuse is set */ if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST)) { - #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 + #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 && defined(CHECK_RESET_SOURCE) /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */ if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) { @@ -148,7 +148,7 @@ void Application_Jump_Check(void) } else { - #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 + #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 && defined(CHECK_RESET_SOURCE) /* If the reset source was the bootloader and the key is correct, clear it and jump to the application; * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */ if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile index 96c4c589c..ac0cfab59 100644 --- a/Bootloaders/DFU/makefile +++ b/Bootloaders/DFU/makefile @@ -43,6 +43,10 @@ BOOT_API_LD_FLAGS = $(call BOOT_SECTION_LD_FLAG, .apitable_trampolines, Boot BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, .apitable_jumptable, BootloaderAPI_JumpTable, 32) BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, .apitable_signatures, BootloaderAPI_Signatures, 8) +ifeq ($(strip $(CHECK_RESET_SOURCE)), yes) + OPT_DEFS += -DCHECK_RESET_SOURCE +endif + # Default target all: From 4abe33a779515a1f5c59ded0d5aa6404ca243f3a Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Mon, 9 Sep 2019 00:07:00 +0200 Subject: [PATCH 5/6] Added OPT_DEFS to the LUFA DMBS module --- LUFA/Build/DMBS/DMBS/gcc.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LUFA/Build/DMBS/DMBS/gcc.mk b/LUFA/Build/DMBS/DMBS/gcc.mk index 73065dcec..b8b61194f 100644 --- a/LUFA/Build/DMBS/DMBS/gcc.mk +++ b/LUFA/Build/DMBS/DMBS/gcc.mk @@ -136,6 +136,9 @@ ifeq ($(LTO), Y) BASE_CC_FLAGS += -flto -fuse-linker-plugin BASE_LD_FLAGS += -flto -fuse-linker-plugin endif +ifneq ($(OPT_DEFS),) + BASE_CC_FLAGS += $(OPT_DEFS) +endif # Additional language specific compiler flags BASE_C_FLAGS := -x c -O$(OPTIMIZATION) -std=$(C_STANDARD) -Wstrict-prototypes From 3bfb76cb4def4eb91d62b8dfd73f2052a8072fba Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Sun, 22 Sep 2019 19:18:36 +0200 Subject: [PATCH 6/6] Changed jump logic to work with software resets --- Bootloaders/DFU/BootloaderDFU.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index d3fa9da19..18770e70d 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -135,30 +135,21 @@ void Application_Jump_Check(void) /* Check if the device's BOOTRST fuse is set */ if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST)) { - #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 && defined(CHECK_RESET_SOURCE) - /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */ - if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) + /* If the reset source was a power on reset or a brown out reset or the key is correct, clear it and jump to the application */ + if (MCUSR & ((1 << PORF) | (1 << BORF)) || (MagicBootKey == MAGIC_BOOT_KEY)) { JumpToApplication = true; } - #endif - /* Clear reset source */ - MCUSR &= ~(1 << EXTRF); + /* Clear reset sources */ + MCUSR &= ~((1 << PORF) | (1 << BORF)); } else { - #if __GNUC__ == 8 && __GNUC_MINOR__ == 3 && defined(CHECK_RESET_SOURCE) - /* If the reset source was the bootloader and the key is correct, clear it and jump to the application; - * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */ - if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) - { + /* If the reset source was the bootloader the key is correct. Jump to the application; + * this can happen if the HWBE fuse is set, and the HWB pin is low during the watchdog reset */ + if (MagicBootKey == MAGIC_BOOT_KEY) JumpToApplication = true; - } - #endif - - /* Clear reset source */ - MCUSR &= ~(1 << WDRF); } #endif