From 5e194bd8efe8dcd2fb6eaa13cec1a2a642c5254a Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 6 Apr 2016 16:33:14 +0200 Subject: [AVR] Discover newer bootloader at runtime Replaces #4280, only checks for the bootloader once Tested with Hoodloader2, should work with every LUFA-derived bootloader released after 2014 (.apitable_signatures section must be placed at end of the flash) BootloaderAPITable.S : .global BootloaderAPI_Signatures BootloaderAPI_Signatures: .long BOOT_START_ADDR ; Start address of the bootloader .word 0xDF00 ; Signature for the CDC class bootloader .word 0xDCFB ; Signature for a LUFA class bootloader makefile: BOOT_API_LD_FLAGS += $(call BOOT_SECTION_LD_FLAG, .apitable_signatures, BootloaderAPI_Signatures, 8) --- variants/leonardo/pins_arduino.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'variants') diff --git a/variants/leonardo/pins_arduino.h b/variants/leonardo/pins_arduino.h index 6027223..7e0f669 100644 --- a/variants/leonardo/pins_arduino.h +++ b/variants/leonardo/pins_arduino.h @@ -366,4 +366,22 @@ const uint8_t PROGMEM analog_pin_to_channel_PGM[] = { // Alias SerialUSB to Serial #define SerialUSB SERIAL_PORT_USBVIRTUAL +// Bootloader related fields +// Old Caterian bootloader places the MAGIC key into unsafe RAM locations (it can be rewritten +// by the running sketch before to actual reboot). +// Newer bootloaders, recognizable by the LUFA "signature" at the end of the flash, can handle both +// the usafe and the safe location. Check once (in USBCore.cpp) if the bootloader in new, then set the global +// _updatedLUFAbootloader variable to true/false and place the magic key consequently +#ifndef MAGIC_KEY +#define MAGIC_KEY 0x7777 +#endif + +#ifndef MAGIC_KEY_POS +#define MAGIC_KEY_POS 0x0800 +#endif + +#ifndef NEW_LUFA_SIGNATURE +#define NEW_LUFA_SIGNATURE 0xDCFB +#endif + #endif /* Pins_Arduino_h */ -- cgit v1.2.3-18-g5258