From 7d4bca50419f2b2e57f92e9bec1cbbbe6d846fc1 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Mon, 13 Nov 2017 17:41:23 +0100 Subject: Always read key to check for new LUFA bootloader Instead of checking for the NEW_LUFA_SIGNATURE once in program memory and then setting a flag which is used for further checks, a function is used that always checks program memory directly. If a flag is used, there's a slight chance that its location in RAM could fall on MAGIC_KEY_POS. In this case, an aborted USB auto-reset sequence may fail. --- cores/arduino/CDC.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cores/arduino/CDC.cpp') diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp index 39373f6..142f8f6 100644 --- a/cores/arduino/CDC.cpp +++ b/cores/arduino/CDC.cpp @@ -36,8 +36,6 @@ static volatile int32_t breakValue = -1; static u8 wdtcsr_save; -bool _updatedLUFAbootloader = false; - #define WEAK __attribute__ ((weak)) extern const CDCDescriptor _cdcInterface PROGMEM; @@ -59,6 +57,11 @@ const CDCDescriptor _cdcInterface = D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0) }; +bool isLUFAbootloader() +{ + return pgm_read_word(FLASHEND - 1) == NEW_LUFA_SIGNATURE; +} + int CDC_GetInterface(u8* interfaceNum) { interfaceNum[0] += 2; // uses 2 @@ -108,7 +111,7 @@ bool CDC_Setup(USBSetup& setup) #if MAGIC_KEY_POS != (RAMEND-1) // For future boards save the key in the inproblematic RAMEND // Which is reserved for the main() return value (which will never return) - if (_updatedLUFAbootloader) { + if (isLUFAbootloader()) { // horray, we got a new bootloader! magic_key_pos = (RAMEND-1); } -- cgit v1.2.3-18-g5258