summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage')
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.c76
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.h63
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPITable.S102
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.c238
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.h99
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.txt225
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Config/AppConfig.h47
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Config/LUFAConfig.h93
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Descriptors.c157
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Descriptors.h88
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Lib/SCSI.c294
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Lib/SCSI.h84
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Lib/VirtualFAT.c482
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/Lib/VirtualFAT.h302
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/asf.xml156
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/doxyfile2365
-rw-r--r--tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/makefile68
17 files changed, 4939 insertions, 0 deletions
diff --git a/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.c b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.c
new file mode 100644
index 0000000000..cad59c8ca2
--- /dev/null
+++ b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.c
@@ -0,0 +1,76 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2014.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaims all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ *
+ * Bootloader user application API functions.
+ */
+
+#include "BootloaderAPI.h"
+
+void BootloaderAPI_ErasePage(const uint32_t Address)
+{
+ boot_page_erase_safe(Address);
+ boot_spm_busy_wait();
+ boot_rww_enable();
+}
+
+void BootloaderAPI_WritePage(const uint32_t Address)
+{
+ boot_page_write_safe(Address);
+ boot_spm_busy_wait();
+ boot_rww_enable();
+}
+
+void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word)
+{
+ boot_page_fill_safe(Address, Word);
+}
+
+uint8_t BootloaderAPI_ReadSignature(const uint16_t Address)
+{
+ return boot_signature_byte_get(Address);
+}
+
+uint8_t BootloaderAPI_ReadFuse(const uint16_t Address)
+{
+ return boot_lock_fuse_bits_get(Address);
+}
+
+uint8_t BootloaderAPI_ReadLock(void)
+{
+ return boot_lock_fuse_bits_get(GET_LOCK_BITS);
+}
+
+void BootloaderAPI_WriteLock(const uint8_t LockBits)
+{
+ boot_lock_bits_set_safe(LockBits);
+}
+
diff --git a/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.h b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.h
new file mode 100644
index 0000000000..0f0cd70405
--- /dev/null
+++ b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPI.h
@@ -0,0 +1,63 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2014.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaims all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ *
+ * Header file for BootloaderAPI.c.
+ */
+
+#ifndef _BOOTLOADER_API_H_
+#define _BOOTLOADER_API_H_
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/boot.h>
+ #include <stdbool.h>
+
+ #include <LUFA/Common/Common.h>
+
+ /* Macros: */
+ #if AUX_BOOT_SECTION_SIZE > 0
+ #define AUX_BOOT_SECTION __attribute__((section(".boot_aux")))
+ #else
+ #define AUX_BOOT_SECTION
+ #endif
+
+ /* Function Prototypes: */
+ void BootloaderAPI_ErasePage(const uint32_t Address);
+ void BootloaderAPI_WritePage(const uint32_t Address);
+ void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word);
+ uint8_t BootloaderAPI_ReadSignature(const uint16_t Address);
+ uint8_t BootloaderAPI_ReadFuse(const uint16_t Address);
+ uint8_t BootloaderAPI_ReadLock(void);
+ void BootloaderAPI_WriteLock(const uint8_t LockBits);
+
+#endif
+
diff --git a/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPITable.S b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPITable.S
new file mode 100644
index 0000000000..6844d4b01c
--- /dev/null
+++ b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderAPITable.S
@@ -0,0 +1,102 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2014.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaims all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#if AUX_BOOT_SECTION_SIZE > 0
+#warning Using a AUX bootloader section in addition to the defined bootloader space (see documentation).
+
+; Trampoline to jump over the AUX bootloader section to the start of the bootloader,
+; on devices where an AUX bootloader section is used.
+.section .boot_aux_trampoline, "ax"
+.global Boot_AUX_Trampoline
+Boot_AUX_Trampoline:
+ jmp BOOT_START_ADDR
+#endif
+
+; Trampolines to actual API implementations if the target address is outside the
+; range of a rjmp instruction (can happen with large bootloader sections)
+.section .apitable_trampolines, "ax"
+.global BootloaderAPI_Trampolines
+BootloaderAPI_Trampolines:
+
+ BootloaderAPI_ErasePage_Trampoline:
+ jmp BootloaderAPI_ErasePage
+ BootloaderAPI_WritePage_Trampoline:
+ jmp BootloaderAPI_WritePage
+ BootloaderAPI_FillWord_Trampoline:
+ jmp BootloaderAPI_FillWord
+ BootloaderAPI_ReadSignature_Trampoline:
+ jmp BootloaderAPI_ReadSignature
+ BootloaderAPI_ReadFuse_Trampoline:
+ jmp BootloaderAPI_ReadFuse
+ BootloaderAPI_ReadLock_Trampoline:
+ jmp BootloaderAPI_ReadLock
+ BootloaderAPI_WriteLock_Trampoline:
+ jmp BootloaderAPI_WriteLock
+ BootloaderAPI_UNUSED1:
+ ret
+ BootloaderAPI_UNUSED2:
+ ret
+ BootloaderAPI_UNUSED3:
+ ret
+ BootloaderAPI_UNUSED4:
+ ret
+ BootloaderAPI_UNUSED5:
+ ret
+
+
+
+; API function jump table
+.section .apitable_jumptable, "ax"
+.global BootloaderAPI_JumpTable
+BootloaderAPI_JumpTable:
+
+ rjmp BootloaderAPI_ErasePage_Trampoline
+ rjmp BootloaderAPI_WritePage_Trampoline
+ rjmp BootloaderAPI_FillWord_Trampoline
+ rjmp BootloaderAPI_ReadSignature_Trampoline
+ rjmp BootloaderAPI_ReadFuse_Trampoline
+ rjmp BootloaderAPI_ReadLock_Trampoline
+ rjmp BootloaderAPI_WriteLock_Trampoline
+ rjmp BootloaderAPI_UNUSED1 ; UNUSED ENTRY 1
+ rjmp BootloaderAPI_UNUSED2 ; UNUSED ENTRY 2
+ rjmp BootloaderAPI_UNUSED3 ; UNUSED ENTRY 3
+ rjmp BootloaderAPI_UNUSED4 ; UNUSED ENTRY 4
+ rjmp BootloaderAPI_UNUSED5 ; UNUSED ENTRY 5
+
+
+
+; Bootloader table signatures and information
+.section .apitable_signatures, "ax"
+.global BootloaderAPI_Signatures
+BootloaderAPI_Signatures:
+
+ .long BOOT_START_ADDR ; Start address of the bootloader
+ .word 0xDF30 ; Signature for the MS class bootloader, V1
+ .word 0xDCFB ; Signature for a LUFA class bootloader
diff --git a/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.c b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.c
new file mode 100644
index 0000000000..cfe0cdbf8f
--- /dev/null
+++ b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.c
@@ -0,0 +1,238 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2014.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaims all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ *
+ * Main source file for the Mass Storage class bootloader. This file contains the complete bootloader logic.
+ */
+
+#define INCLUDE_FROM_BOOTLOADER_MASSSTORAGE_C
+#include "BootloaderMassStorage.h"
+
+/** LUFA Mass Storage Class driver interface configuration and state information. This structure is
+ * passed to all Mass Storage Class driver functions, so that multiple instances of the same class
+ * within a device can be differentiated from one another.
+ */
+USB_ClassInfo_MS_Device_t Disk_MS_Interface =
+ {
+ .Config =
+ {
+ .InterfaceNumber = INTERFACE_ID_MassStorage,
+ .DataINEndpoint =
+ {
+ .Address = MASS_STORAGE_IN_EPADDR,
+ .Size = MASS_STORAGE_IO_EPSIZE,
+ .Banks = 1,
+ },
+ .DataOUTEndpoint =
+ {
+ .Address = MASS_STORAGE_OUT_EPADDR,
+ .Size = MASS_STORAGE_IO_EPSIZE,
+ .Banks = 1,
+ },
+ .TotalLUNs = 1,
+ },
+ };
+
+/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
+ * via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application
+ * started via a forced watchdog reset.
+ */
+bool RunBootloader = true;
+
+/** Magic lock for forced application start. If the HWBE fuse is programmed and BOOTRST is unprogrammed, the bootloader
+ * will start if the /HWB line of the AVR is held low and the system is reset. However, if the /HWB line is still held
+ * low when the application attempts to start via a watchdog reset, the bootloader will re-start. If set to the value
+ * \ref MAGIC_BOOT_KEY the special init function \ref Application_Jump_Check() will force the application to start.
+ */
+uint16_t MagicBootKey ATTR_NO_INIT;
+
+/** Indicates if the bootloader is allowed to exit immediately if \ref RunBootloader is \c false. During shutdown all
+ * pending commands must be processed before jumping to the user-application, thus this tracks the main program loop
+ * iterations since a SCSI command from the host was received.
+ */
+static uint8_t TicksSinceLastCommand = 0;
+
+
+/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
+ * start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
+ * this will force the user application to start via a software jump.
+ */
+void Application_Jump_Check(void)
+{
+ bool JumpToApplication = false;
+
+ #if (BOARD == BOARD_LEONARDO)
+ /* Enable pull-up on the IO13 pin so we can use it to select the mode */
+ PORTC |= (1 << 7);
+ Delay_MS(10);
+
+ /* If IO13 is not jumpered to ground, start the user application instead */
+ JumpToApplication |= ((PINC & (1 << 7)) != 0);
+
+ /* Disable pull-up after the check has completed */
+ PORTC &= ~(1 << 7);
+ #elif ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
+ /* Disable JTAG debugging */
+ JTAG_DISABLE();
+
+ /* Enable pull-up on the JTAG TCK pin so we can use it to select the mode */
+ PORTF |= (1 << 4);
+ Delay_MS(10);
+
+ /* If the TCK pin is not jumpered to ground, start the user application instead */
+ JumpToApplication |= ((PINF & (1 << 4)) != 0);
+
+ /* Re-enable JTAG debugging */
+ JTAG_ENABLE();
+ #endif
+
+ /* If the reset source was the bootloader and the key is correct, clear it and jump to the application */
+ if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
+ {
+ MagicBootKey = 0;
+ JumpToApplication = true;
+ }
+
+ if (JumpToApplication)
+ {
+ // cppcheck-suppress constStatement
+ ((void (*)(void))0x0000)();
+ }
+}
+
+/** Main program entry point. This routine configures the hardware required by the application, then
+ * enters a loop to run the application tasks in sequence.
+ */
+int main(void)
+{
+ SetupHardware();
+
+ LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
+ GlobalInterruptEnable();
+
+ while (RunBootloader || TicksSinceLastCommand++ < 0xFF)
+ {
+ MS_Device_USBTask(&Disk_MS_Interface);
+ USB_USBTask();
+ }
+
+ /* Disconnect from the host - USB interface will be reset later along with the AVR */
+ USB_Detach();
+
+ /* Unlock the forced application start mode of the bootloader if it is restarted */
+ MagicBootKey = MAGIC_BOOT_KEY;
+
+ /* Enable the watchdog and force a timeout to reset the AVR */
+ wdt_enable(WDTO_250MS);
+
+ for (;;);
+}
+
+/** Configures the board hardware and chip peripherals for the demo's functionality. */
+static void SetupHardware(void)
+{
+ /* Disable watchdog if enabled by bootloader/fuses */
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ /* Disable clock division */
+ clock_prescale_set(clock_div_1);
+
+ /* Relocate the interrupt vector table to the bootloader section */
+ MCUCR = (1 << IVCE);
+ MCUCR = (1 << IVSEL);
+
+ /* Hardware Initialization */
+ LEDs_Init();
+ USB_Init();
+
+ /* Bootloader active LED toggle timer initialization */
+ TIMSK1 = (1 << TOIE1);
+ TCCR1B = ((1 << CS11) | (1 << CS10));
+}
+
+/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */
+ISR(TIMER1_OVF_vect, ISR_BLOCK)
+{
+ LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
+}
+
+/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs. */
+void EVENT_USB_Device_Connect(void)
+{
+ /* Indicate USB enumerating */
+ LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
+}
+
+/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
+ * the status LEDs and stops the Mass Storage management task.
+ */
+void EVENT_USB_Device_Disconnect(void)
+{
+ /* Indicate USB not ready */
+ LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
+}
+
+/** Event handler for the library USB Configuration Changed event. */
+void EVENT_USB_Device_ConfigurationChanged(void)
+{
+ bool ConfigSuccess = true;
+
+ /* Setup Mass Storage Data Endpoints */
+ ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
+
+ /* Indicate endpoint configuration success or failure */
+ LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
+}
+
+/** Event handler for the library USB Control Request reception event. */
+void EVENT_USB_Device_ControlRequest(void)
+{
+ MS_Device_ProcessControlRequest(&Disk_MS_Interface);
+}
+
+/** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
+ *
+ * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
+ */
+bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
+{
+ bool CommandSuccess;
+
+ LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
+ CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
+ LEDs_SetAllLEDs(LEDMASK_USB_READY);
+
+ /* Signal that a command was processed, must not exit bootloader yet */
+ TicksSinceLastCommand = 0;
+
+ return CommandSuccess;
+}
diff --git a/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.h b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.h
new file mode 100644
index 0000000000..c1bd004106
--- /dev/null
+++ b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.h
@@ -0,0 +1,99 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2014.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaims all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ *
+ * Header file for BootloaderMassStorage.c.
+ */
+
+#ifndef _BOOTLOADER_MASS_STORAGE_H_
+#define _BOOTLOADER_MASS_STORAGE_H_
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/wdt.h>
+ #include <avr/power.h>
+ #include <avr/interrupt.h>
+ #include <string.h>
+
+ #include "Descriptors.h"
+ #include "Config/AppConfig.h"
+
+ #include "Lib/SCSI.h"
+
+ #include <LUFA/Drivers/Board/LEDs.h>
+ #include <LUFA/Drivers/USB/USB.h>
+ #include <LUFA/Platform/Platform.h>
+
+ /* Preprocessor Checks: */
+ #if !defined(__OPTIMIZE_SIZE__)
+ #error This bootloader requires that it be optimized for size, not speed, to fit into the target device. Change optimization settings and try again.
+ #endif
+
+ /* Macros: */
+ /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
+ #define LEDMASK_USB_NOTREADY LEDS_LED1
+
+ /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
+ #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
+
+ /** LED mask for the library LED driver, to indicate that the USB interface is ready. */
+ #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
+
+ /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
+ #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
+
+ /** LED mask for the library LED driver, to indicate that the USB interface is busy. */
+ #define LEDMASK_USB_BUSY LEDS_LED2
+
+ /** Magic bootloader key to unlock forced application start mode. */
+ #define MAGIC_BOOT_KEY 0xDC42
+
+ /* Global Variables: */
+ extern bool RunBootloader;
+
+ /* Function Prototypes: */
+ int main(void) AUX_BOOT_SECTION;
+
+ void Application_Jump_Check(void) ATTR_INIT_SECTION(3);
+
+ void EVENT_USB_Device_Connect(void) AUX_BOOT_SECTION;
+ void EVENT_USB_Device_Disconnect(void) AUX_BOOT_SECTION;
+ void EVENT_USB_Device_ConfigurationChanged(void) AUX_BOOT_SECTION;
+ void EVENT_USB_Device_ControlRequest(void) AUX_BOOT_SECTION;
+
+ bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo) AUX_BOOT_SECTION;
+
+ #if defined(INCLUDE_FROM_BOOTLOADER_MASSSTORAGE_C)
+ static void SetupHardware(void) AUX_BOOT_SECTION;
+ #endif
+
+#endif
+
diff --git a/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.txt b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.txt
new file mode 100644
index 0000000000..e094847933
--- /dev/null
+++ b/tmk_core/protocol/lufa/LUFA-git/Bootloaders/MassStorage/BootloaderMassStorage.txt
@@ -0,0 +1,225 @@
+/** \file
+ *
+ * This file contains special DoxyGen information for the generation of the main page and other special
+ * documentation pages. It is not a project source file.
+ */
+
+/** \mainpage Mass Storage Class USB AVR Bootloader
+ *
+ * \section Sec_Compat Demo Compatibility:
+ *
+ * The following list indicates what microcontrollers are compatible with this demo.
+ *
+ * \li Series 7 USB AVRs (AT90USBxxx7)
+ * \li Series 6 USB AVRs (AT90USBxxx6)
+ * \li Series 4 USB AVRs (ATMEGAxxU4) - <i>See \ref SSec_Aux_Space</i>
+ * \li ATMEGA32U2 - <i>See \ref SSec_Aux_Space</i>
+ *
+ * \section Sec_Info USB Information:
+ *
+ * The following table gives a rundown of the USB utilization of this demo.
+ *
+ * <table>
+ * <tr>
+ * <td><b>USB Mode:</b></td>
+ * <td>Device</td>
+ * </tr>
+ * <tr>
+ * <td><b>USB Class:</b></td>
+ * <td>Mass Storage Device</td>
+ * </tr>
+ * <tr>
+ * <td><b>USB Subclass:</b></td>
+ * <td>Bulk-Only Transport</td>
+ * </tr>
+ * <tr>
+ * <td><b>Relevant Standards:</b></td>
+ * <td>USBIF Mass Storage Standard \n
+ * USB Bulk-Only Transport Standard \n
+ * SCSI Primary Commands Specification \n
+ * SCSI Block Commands Specification</td>
+ * </tr>
+ * <tr>
+ * <td><b>Supported USB Speeds:</b></td>
+ * <td>Full Speed Mode</td>
+ * </tr>
+ * </table>
+ *
+ * \section Sec_Description Project Description:
+ *
+ * This bootloader enumerates to the host as a Mass Storage device, capable of reading and writing a new binary
+ * firmware image file, to load firmware onto the AVR.
+ *
+ * Out of the box this bootloader builds for the AT90USB1287 with an 8KB bootloader section size, and will fit
+ * into 6KB of bootloader space. If you wish to alter this size and/or change the AVR model, you will need to
+ * edit the MCU, FLASH_SIZE_KB and BOOT_SECTION_SIZE_KB values in the accompanying makefile.
+ *
+ * When the bootloader is running, the board's LED(s) will flash at regular intervals to distinguish the
+ * bootloader from the normal user application.
+ *
+ * \warning <b>THIS BOOTLOADER IS NOT SECURE.</b> Malicious entities can recover written data, even if the device
+ * lockbits are set.
+ *
+ * \section Sec_Running Running the Bootloader
+ *
+ * This bootloader is designed to be started via the HWB mechanism of the USB AVRs; ground the HWB pin (see device
+ * datasheet) then momentarily ground /RESET to start the bootloader. This assumes the HWBE fuse is set and the BOOTRST
+ * fuse is cleared.
+ *
+ * For board specific exceptions to the above, see below.
+ *
+ * \subsection SSec_XPLAIN Atmel Xplain Board
+ * Ground the USB AVR JTAG's \c TCK pin to ground when powering on the board to start the bootloader. This assumes the
+ * \c HWBE fuse is cleared and the \c BOOTRST fuse is set as the HWBE pin is not user accessible on this board.
+ *
+ * \subsection SSec_Leonardo Arduino Leonardo Board
+ * Ground \c IO13 when powering the board to start the bootloader. This assumes the \c HWBE fuse is cleared and the
+ * \c BOOTRST fuse is set as the HWBE pin is not user accessible on this board.
+ *
+ * \section Sec_Installation Driver Installation
+ *
+ * This bootloader uses the Mass Storage drivers inbuilt into all modern operating systems, thus no additional
+ * drivers need to be supplied for correct operation.
+ *
+ * \section Sec_HostApp Host Controller Application
+ *
+ * This bootloader is compatible with all operating systems that support the FAT12 file system format. To reprogram the
+ * device, overwrite a file stored on the virtual FAT filesystem with a new binary (BIN format) image. Remember to safely
+ * remove your device from the host using the host OS's ejection APIs, to ensure all data is correctly flushed to the
+ * bootloader's virtual filesystem and not cached in the OS's file system driver.
+ *
+ * The current device firmware can be read from the device by reading a file from the virtual FAT filesystem.
+ *
+ * \warning This bootloader is currently <b>incompatible with the Apple MacOS X OS Finder GUI</b>, due to the
+ * large amount of meta files this OS attempts to write to the disk along with the new binaries. On
+ * this platform, firmwares must be copied to the disk via the Terminal application only to prevent
+ * firmware corruption.
+ *
+ * \section Sec_API User Application API
+ *
+ * Several user application functions for FLASH and other special memory area manipulations are exposed by the bootloader,
+ * allowing the user application to call into the bootloader at runtime to read and write FLASH data.
+ *
+ * By default, the bootloader API jump table is located 32 bytes from the end of the device's FLASH memory, and follows the
+ * following layout:
+ *
+ * \code
+ * #define BOOTLOADER_API_TABLE_SIZE 32
+ * #define BOOTLOADER_API_TABLE_START ((FLASHEND + 1UL) - BOOTLOADER_API_TABLE_SIZE)
+ * #define BOOTLOADER_API_CALL(Index) (void*)((BOOTLOADER_API_TABLE_START + (Index * 2)) / 2)
+ *
+ * void (*BootloaderAPI_ErasePage)(uint32_t Address) = BOOTLOADER_API_CALL(0);
+ * void (*BootloaderAPI_WritePage)(uint32_t Address) = BOOTLOADER_API_CALL(1);
+ * void (*BootloaderAPI_FillWord)(uint32_t Address, uint16_t Word) = BOOTLOADER_API_CALL(2);
+ * uint8_t (*BootloaderAPI_ReadSignature)(uint16_t Address) = BOOTLOADER_API_CALL(3);
+ * uint8_t (*BootloaderAPI_ReadFuse)(uint16_t Address) = BOOTLOADER_API_CALL(4);
+ * uint8_t (*BootloaderAPI_ReadLock)(void) = BOOTLOADER_API_CALL(5);
+ * void (*BootloaderAPI_WriteLock)(uint8_t LockBits) = BOOTLOADER_API_CALL(6);
+ *
+ * #define BOOTLOADER_MAGIC_SIGNATURE_START (BOOTLOADER_API_TABLE_START + (BOOTLOADER_API_TABLE_SIZE - 2))
+ * #define BOOTLOADER_MAGIC_SIGNATURE 0xDCFB
+ *
+ * #define BOOTLOADER_CLASS_SIGNATURE_START (BOOTLOADER_API_TABLE_START + (BOOTLOADER_API_TABLE_SIZE - 4))
+ * #define BOOTLOADER_MASS_STORAGE_SIGNATURE 0xDF30
+ *
+ * #define BOOTLOADER_ADDRESS_START (BOOTLOADER_API_TABLE_START + (BOOTLOADER_API_TABLE_SIZE - 8))
+ * #define BOOTLOADER_ADDRESS_LENGTH 4
+ * \endcode
+ *
+ * From the application the API support of the bootloader can be detected by reading the FLASH memory bytes located at address
+ * \c BOOTLOADER_MAGIC_SIGNATURE_START and comparing them to the value \c BOOTLOADER_MAGIC_SIGNATURE. The class of bootloader
+ * can be determined by reading the FLASH memory bytes located at address \c BOOTLOADER_CLASS_SIGNATURE_START and comparing them
+ * to the value \c BOOTLOADER_MASS_STORAGE_SIGNATURE. The start address of the bootloader can be retrieved by reading the bytes
+ * of FLASH memory starting from address \c BOOTLOADER_ADDRESS_START.
+ *
+ * \subsection SSec_Aux_Space Auxiliary Bootloader Section
+ * To make the bootloader function on smaller devices (those with a physical bootloader section of smaller than 6KB) a second
+ * section of memory (called the <i>Auxiliary Bootloader Section</i>) is added before the start of the real bootloader section,
+ * and is filled with a portion of the bootloader code. This allows smaller devices to run the bootloader, at the cost of an
+ * additional portion of the device's FLASH (the bootloader section size in KB subtracted from the 6KB total size). A small
+ * trampoline is inserted at the start of the auxiliary section so that the bootloader will run normally in the case of a blank
+ * application section.
+ *
+ * On devices supporting a 8KB bootloader section size, the AUX section is not created in the final binary.
+ *
+ * \subsection SSec_API_MemLayout Device Memory Map
+ * The following illustration indicates the final memory map of the device when loaded with the bootloader.
+ *
+ * \verbatim
+ * +----------------------------+ 0x0000
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | User Application |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * | |
+ * +----------------------------+ FLASHEND - BOOT_SECTION_SIZE - BOOT_AUX_SECTION_SIZE
+ * | Booloader Start Trampoline |
+ * | (Not User App. Accessible) |
+ * +----------------------------+ FLASHEND - BOOT_SECTION_SIZE - BOOT_AUX_SECTION_SIZE + 4
+ * | |
+ * | Auxiliary Bootloader |
+ * | Space for Smaller Devices |
+ * | (Not User App. Accessible) |
+ * | |
+ * +----------------------------+ FLASHEND - BOOT_SECTION_SIZE
+ * | |
+ * | Bootloader Application |
+ * | (Not User App. Accessible) |
+ * | |
+ * +----------------------------+ FLASHEND - 96
+ * | API Table Trampolines |
+ * | (Not User App. Accessible) |
+ * +----------------------------+ FLASHEND - 32
+ * | Bootloader API Table |
+ * | (User App. Accessible) |
+ * +----------------------------+ FLASHEND - 8
+ * | Bootloader ID Constants |
+ * | (User App. Accessible) |
+ * +----------------------------+ FLASHEND
+ * \endverbatim
+ *
+ * \section Sec_KnownIssues Known Issues:
+ *
+ * \par In some cases, the application is not fully loaded into the device.
+ * Write-caching on some operating systems may interfere with the normal
+ * operation of the bootloader. Write caching should be disabled when using the
+ * Mass Storage bootloader, or the file system synced via an appropriate command
+ * (such as the OS's normal disk ejection command) before disconnecting the device.
+ *
+ * \par After loading an application, it is not run automatically on startup.
+ * Some USB AVR boards ship with the BOOTRST fuse set, causing the bootloader
+ * to run automatically when the device is reset. In most cases, the BOOTRST
+ * fuse should be disabled and the HWBE fuse used instead to run the bootloader
+ * when needed.
+ *
+ * \section Sec_Options Project Options
+ *
+ * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.
+ *
+ * <table>
+ * <tr>
+ * <th><b>Define Name:</b></th>
+ * <th><b>Location:</b></th>
+ *