diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index 883afef03..18770e70d 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -135,22 +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 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 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; + } - /* Clear reset source */ - MCUSR &= ~(1 << EXTRF); + /* Clear reset sources */ + MCUSR &= ~((1 << PORF) | (1 << BORF)); } else { - /* 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; - - /* Clear reset source */ - MCUSR &= ~(1 << WDRF); + /* 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 diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile index b9b7a73d4..d3ae8d926 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: 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