diff options
Diffstat (limited to 'Bootloaders/HID')
-rw-r--r-- | Bootloaders/HID/BootloaderHID.c | 198 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.h | 71 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.txt | 105 | ||||
-rw-r--r-- | Bootloaders/HID/Config/LUFAConfig.h | 93 | ||||
-rw-r--r-- | Bootloaders/HID/Descriptors.c | 187 | ||||
-rw-r--r-- | Bootloaders/HID/Descriptors.h | 80 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp/.gitignore | 1 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp/Makefile | 40 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp/Makefile.bsd | 21 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp/gpl3.txt | 674 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c | 1013 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp_Python/hid_bootloader_loader.py | 120 | ||||
-rw-r--r-- | Bootloaders/HID/asf.xml | 123 | ||||
-rw-r--r-- | Bootloaders/HID/doxyfile | 2398 | ||||
-rw-r--r-- | Bootloaders/HID/makefile | 55 |
15 files changed, 5179 insertions, 0 deletions
diff --git a/Bootloaders/HID/BootloaderHID.c b/Bootloaders/HID/BootloaderHID.c new file mode 100644 index 0000000000..fa1dd5873e --- /dev/null +++ b/Bootloaders/HID/BootloaderHID.c @@ -0,0 +1,198 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2017. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2017 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 HID class bootloader. This file contains the complete bootloader logic. + */ + +#include "BootloaderHID.h" + +/** 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. + */ +static 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; + + +/** 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) +{ + /* 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)) + { + /* Turn off the watchdog */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Clear the boot key and jump to the user application */ + MagicBootKey = 0; + + // cppcheck-suppress constStatement + ((void (*)(void))0x0000)(); + } +} + +/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously + * runs the bootloader processing routine until instructed to soft-exit. + */ +int main(void) +{ + /* Setup hardware required for the bootloader */ + SetupHardware(); + + /* Enable global interrupts so that the USB stack can function */ + GlobalInterruptEnable(); + + while (RunBootloader) + 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 all hardware required for the bootloader. */ +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); + + /* Initialize USB subsystem */ + USB_Init(); +} + +/** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready + * to relay data to and from the attached USB host. + */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + /* Setup HID Report Endpoint */ + Endpoint_ConfigureEndpoint(HID_IN_EPADDR, EP_TYPE_INTERRUPT, HID_IN_EPSIZE, 1); +} + +/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to + * the device from the USB host before passing along unhandled control requests to the library for processing + * internally. + */ +void EVENT_USB_Device_ControlRequest(void) +{ + /* Ignore any requests that aren't directed to the HID interface */ + if ((USB_ControlRequest.bmRequestType & (CONTROL_REQTYPE_TYPE | CONTROL_REQTYPE_RECIPIENT)) != + (REQTYPE_CLASS | REQREC_INTERFACE)) + { + return; + } + + /* Process HID specific control requests */ + switch (USB_ControlRequest.bRequest) + { + case HID_REQ_SetReport: + Endpoint_ClearSETUP(); + + /* Wait until the command has been sent by the host */ + while (!(Endpoint_IsOUTReceived())); + + /* Read in the write destination address */ + #if (FLASHEND > 0xFFFF) + uint32_t PageAddress = ((uint32_t)Endpoint_Read_16_LE() << 8); + #else + uint16_t PageAddress = Endpoint_Read_16_LE(); + #endif + + /* Check if the command is a program page command, or a start application command */ + #if (FLASHEND > 0xFFFF) + if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION) + #else + if (PageAddress == COMMAND_STARTAPPLICATION) + #endif + { + RunBootloader = false; + } + else if (PageAddress < BOOT_START_ADDR) + { + /* Erase the given FLASH page, ready to be programmed */ + boot_page_erase(PageAddress); + boot_spm_busy_wait(); + + /* Write each of the FLASH page's bytes in sequence */ + for (uint8_t PageWord = 0; PageWord < (SPM_PAGESIZE / 2); PageWord++) + { + /* Check if endpoint is empty - if so clear it and wait until ready for next packet */ + if (!(Endpoint_BytesInEndpoint())) + { + Endpoint_ClearOUT(); + while (!(Endpoint_IsOUTReceived())); + } + + /* Write the next data word to the FLASH page */ + boot_page_fill(PageAddress + ((uint16_t)PageWord << 1), Endpoint_Read_16_LE()); + } + + /* Write the filled FLASH page to memory */ + boot_page_write(PageAddress); + boot_spm_busy_wait(); + + /* Re-enable RWW section */ + boot_rww_enable(); + } + + Endpoint_ClearOUT(); + + Endpoint_ClearStatusStage(); + break; + } +} + diff --git a/Bootloaders/HID/BootloaderHID.h b/Bootloaders/HID/BootloaderHID.h new file mode 100644 index 0000000000..62ee07de30 --- /dev/null +++ b/Bootloaders/HID/BootloaderHID.h @@ -0,0 +1,71 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2017. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2017 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 BootloaderHID.c. + */ + +#ifndef _BOOTLOADERHID_H_ +#define _BOOTLOADERHID_H_ + + /* Includes: */ + #include <avr/io.h> + #include <avr/wdt.h> + #include <avr/boot.h> + #include <avr/power.h> + #include <avr/interrupt.h> + #include <stdbool.h> + + #include "Descriptors.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: */ + /** Bootloader special address to start the user application */ + #define COMMAND_STARTAPPLICATION 0xFFFF + + /** Magic bootloader key to unlock forced application start mode. */ + #define MAGIC_BOOT_KEY 0xDC42 + + /* Function Prototypes: */ + static void SetupHardware(void); + + void Application_Jump_Check(void) ATTR_INIT_SECTION(3); + + void EVENT_USB_Device_ConfigurationChanged(void); + +#endif diff --git a/Bootloaders/HID/BootloaderHID.txt b/Bootloaders/HID/BootloaderHID.txt new file mode 100644 index 0000000000..e340703c41 --- /dev/null +++ b/Bootloaders/HID/BootloaderHID.txt @@ -0,0 +1,105 @@ +/** \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 HID Class USB AVR Bootloader + * + * \section SSec_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) + * \li Series 2 USB AVRs (AT90USBxx2, ATMEGAxxU2) + * + * \section SSec_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>Human Interface Device Class (HID)</td> + * </tr> + * <tr> + * <td><b>USB Subclass:</b></td> + * <td>N/A</td> + * </tr> + * <tr> + * <td><b>Relevant Standards:</b></td> + * <td>USBIF HID Class Standard \n + * Teensy Programming Protocol Specification</td> + * </tr> + * <tr> + * <td><b>Supported USB Speeds:</b></td> + * <td>Low Speed Mode \n + * Full Speed Mode</td> + * </tr> + * </table> + * + * \section SSec_Description Project Description: + * + * This bootloader enumerates to the host as a HID Class device, allowing for device FLASH programming through + * the supplied command line software, which is a modified version of Paul's TeensyHID Command Line loader code + * from PJRC (used with permission). This bootloader is deliberately non-compatible with the proprietary PJRC + * HalfKay bootloader GUI; only the command line interface software accompanying this bootloader will work with it. + * + * Out of the box this bootloader builds for the AT90USB1287 with an 8KB bootloader section size, and will fit + * into 2KB of bootloader space for the Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for + * all other models. 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. + * + * \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 \c HWB mechanism of the USB AVRs; ground the \c HWB pin (see device + * datasheet) then momentarily ground \c /RESET to start the bootloader. This assumes the \c HWBE fuse is set and the + * \c BOOTRST fuse is cleared. + * + * \section Sec_Installation Driver Installation + * + * This bootloader uses the HID class driver inbuilt into all modern operating systems, thus no additional drivers + * need to be supplied for correct operation. + * + * \section Sec_HostApp Host Controller Application + * + * Due to licensing issues, the supplied bootloader is compatible with the HalfKay bootloader protocol designed + * by PJRC, but is <b>not compatible with the cross-platform loader GUI</b>. A modified version of the open source + * cross-platform TeensyLoader application is supplied, which can be compiled under most operating systems. The + * command-line loader application should remain compatible with genuine Teensy boards in addition to boards using + * this custom bootloader. + * + * Once compiled, programs can be loaded into the AVR's FLASH memory through the following example command: + * \code + * hid_bootloader_cli -mmcu=at90usb1287 Mouse.hex + * \endcode + * + * \section Sec_KnownIssues Known Issues: + * + * \par After loading an application, it is not run automatically on startup. + * Some USB AVR boards ship with the \c BOOTRST fuse set, causing the bootloader + * to run automatically when the device is reset. This booloader requires the + * \c BOOTRST be disabled and the HWBE fuse used instead to run the bootloader + * when needed. + * + * \section SSec_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> + * <td> + * None + * </td> + * </tr> + * </table> + */ diff --git a/Bootloaders/HID/Config/LUFAConfig.h b/Bootloaders/HID/Config/LUFAConfig.h new file mode 100644 index 0000000000..5aa0e765bf --- /dev/null +++ b/Bootloaders/HID/Config/LUFAConfig.h @@ -0,0 +1,93 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2017. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2017 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 + * \brief LUFA Library Configuration Header File + * + * This header file is used to configure LUFA's compile time options, + * as an alternative to the compile time constants supplied through + * a makefile. + * + * For information on what each token does, refer to the LUFA + * manual section "Summary of Compile Tokens". + */ + +#ifndef _LUFA_CONFIG_H_ +#define _LUFA_CONFIG_H_ + + #if (ARCH == ARCH_AVR8) + + /* Non-USB Related Configuration Tokens: */ +// #define DISABLE_TERMINAL_CODES + + /* USB Class Driver Related Tokens: */ +// #define HID_HOST_BOOT_PROTOCOL_ONLY +// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} +// #define HID_USAGE_STACK_DEPTH {Insert Value Here} +// #define HID_MAX_COLLECTIONS {Insert Value Here} +// #define HID_MAX_REPORTITEMS {Insert Value Here} +// #define HID_MAX_REPORT_IDS {Insert Value Here} +// #define NO_CLASS_DRIVER_AUTOFLUSH + + /* General USB Driver Related Tokens: */ + #define ORDERED_EP_CONFIG + #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) + #define USB_DEVICE_ONLY +// #define USB_HOST_ONLY +// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} +// #define NO_LIMITED_CONTROLLER_CONNECT + #define NO_SOF_EVENTS + + /* USB Device Mode Driver Related Tokens: */ + #define USE_RAM_DESCRIPTORS +// #define USE_FLASH_DESCRIPTORS +// #define USE_EEPROM_DESCRIPTORS + #define NO_INTERNAL_SERIAL + #define FIXED_CONTROL_ENDPOINT_SIZE 8 + #define DEVICE_STATE_AS_GPIOR 0 + #define FIXED_NUM_CONFIGURATIONS 1 +// #define CONTROL_ONLY_DEVICE +// #define INTERRUPT_CONTROL_ENDPOINT + #define NO_DEVICE_REMOTE_WAKEUP + #define NO_DEVICE_SELF_POWER + + /* USB Host Mode Driver Related Tokens: */ +// #define HOST_STATE_AS_GPIOR {Insert Value Here} +// #define USB_HOST_TIMEOUT_MS {Insert Value Here} +// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} +// #define NO_AUTO_VBUS_MANAGEMENT +// #define INVERTED_VBUS_ENABLE_LINE + + #else + + #error Unsupported architecture for this LUFA configuration file. + + #endif +#endif diff --git a/Bootloaders/HID/Descriptors.c b/Bootloaders/HID/Descriptors.c new file mode 100644 index 0000000000..854ae1b636 --- /dev/null +++ b/Bootloaders/HID/Descriptors.c @@ -0,0 +1,187 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2017. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2017 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 + * + * USB Device Descriptors, for library use when in USB device mode. Descriptors are special + * computer-readable structures which the host requests upon device enumeration, to determine + * the device's capabilities and functions. + */ + +#include "Descriptors.h" + +/** HID class report descriptor. This is a special descriptor constructed with values from the + * USBIF HID class specification to describe the reports and capabilities of the HID device. This + * descriptor is parsed by the host and its contents used to determine what data (and in what encoding) + * the device will send, and what it may be sent back from the host. Refer to the HID specification for + * more details on HID report descriptors. + */ +const USB_Descriptor_HIDReport_Datatype_t HIDReport[] = +{ + HID_RI_USAGE_PAGE(16, 0xFFDC), /* Vendor Page 0xDC */ + HID_RI_USAGE(8, 0xFB), /* Vendor Usage 0xFB */ + HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */ + HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0xFF), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_REPORT_COUNT(16, (sizeof(uint16_t) + SPM_PAGESIZE)), + HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), + HID_RI_END_COLLECTION(0), +}; + +/** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall + * device characteristics, including the supported USB version, control endpoint size and the + * number of device configurations. The descriptor is read out by the USB host when the enumeration + * process begins. + */ +const USB_Descriptor_Device_t DeviceDescriptor = +{ + .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, + + .USBSpecification = VERSION_BCD(1,1,0), + .Class = USB_CSCP_NoDeviceClass, + .SubClass = USB_CSCP_NoDeviceSubclass, + .Protocol = USB_CSCP_NoDeviceProtocol, + + .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, + + .VendorID = 0x03EB, + .ProductID = 0x2067, + .ReleaseNumber = VERSION_BCD(0,0,1), + + .ManufacturerStrIndex = NO_DESCRIPTOR, + .ProductStrIndex = NO_DESCRIPTOR, + .SerialNumStrIndex = NO_DESCRIPTOR, + + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS +}; + +/** Configuration descriptor structure. This descriptor, located in SRAM memory, describes the usage + * of the device in one of its supported configurations, including information about any device interfaces + * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting + * a configuration so that the host may correctly communicate with the USB device. + */ +const USB_Descriptor_Configuration_t ConfigurationDescriptor = +{ + .Config = + { + .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, + + .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), + .TotalInterfaces = 1, + + .ConfigurationNumber = 1, + .ConfigurationStrIndex = NO_DESCRIPTOR, + + .ConfigAttributes = USB_CONFIG_ATTR_RESERVED, + + .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) + }, + + .HID_Interface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + + .InterfaceNumber = INTERFACE_ID_GenericHID, + .AlternateSetting = 0x00, + + .TotalEndpoints = 1, + + .Class = HID_CSCP_HIDClass, + .SubClass = HID_CSCP_NonBootSubclass, + .Protocol = HID_CSCP_NonBootProtocol, + + .InterfaceStrIndex = NO_DESCRIPTOR + }, + + .HID_VendorHID = + { + .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, + + .HIDSpec = VERSION_BCD(1,1,1), + .CountryCode = 0x00, + .TotalReportDescriptors = 1, + .HIDReportType = HID_DTYPE_Report, + .HIDReportLength = sizeof(HIDReport) + }, + + .HID_ReportINEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = HID_IN_EPADDR, + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = HID_IN_EPSIZE, + .PollingIntervalMS = 0x05 + }, +}; + +/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" + * documentation) by the application code so that the address and size of a requested descriptor can be given + * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function + * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the + * USB host. + */ +uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint16_t wIndex, + const void** const DescriptorAddress) +{ + const uint8_t DescriptorType = (wValue >> 8); + + const void* Address = NULL; + uint16_t Size = NO_DESCRIPTOR; + + /* If/Else If chain compiles slightly smaller than a switch case */ + if (DescriptorType == DTYPE_Device) + { + Address = &DeviceDescriptor; + Size = sizeof(USB_Descriptor_Device_t); + } + else if (DescriptorType == DTYPE_Configuration) + { + Address = &ConfigurationDescriptor; + Size = sizeof(USB_Descriptor_Configuration_t); + } + else if (DescriptorType == HID_DTYPE_HID) + { + Address = &ConfigurationDescriptor.HID_VendorHID; + Size = sizeof(USB_HID_Descriptor_HID_t); + } + else if (DescriptorType == HID_DTYPE_Report) + { + Address = &HIDReport; + Size = sizeof(HIDReport); + } + + *DescriptorAddress = Address; + return Size; +} + diff --git a/Bootloaders/HID/Descriptors.h b/Bootloaders/HID/Descriptors.h new file mode 100644 index 0000000000..5516b16354 --- /dev/null +++ b/Bootloaders/HID/Descriptors.h @@ -0,0 +1,80 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2017. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2017 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 Descriptors.c. + */ + +#ifndef _DESCRIPTORS_H_ +#define _DESCRIPTORS_H_ + + /* Includes: */ + #include <LUFA/Drivers/USB/USB.h> + + /* Type Defines: */ + /** Type define for the device configuration descriptor structure. This must be defined in the + * application code, as the configuration descriptor contains several sub-descriptors which + * vary between devices, and which describe the device's usage to the host. + */ + typedef struct + { + USB_Descriptor_Configuration_Header_t Config; + + // Generic HID Interface + USB_Descriptor_Interface_t HID_Interface; + USB_HID_Descriptor_HID_t HID_VendorHID; + USB_Descriptor_Endpoint_t HID_ReportINEndpoint; + } USB_Descriptor_Configuration_t; + + /** Enum for the device interface descriptor IDs within the device. Each interface descriptor + * should have a unique ID index associated with it, which can be used to refer to the + * interface from other descriptors. + */ + enum InterfaceDescriptors_t + { + INTERFACE_ID_GenericHID = 0, /**< GenericHID interface descriptor ID */ + }; + + /* Macros: */ + /** Endpoint address of the HID data IN endpoint. */ + #define HID_IN_EPADDR (ENDPOINT_DIR_IN | 1) + + /** Size in bytes of the HID reporting IN endpoint. */ + #define HID_IN_EPSIZE 64 + + /* Function Prototypes: */ + uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint16_t wIndex, + const void** const DescriptorAddress) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); + +#endif + diff --git a/Bootloaders/HID/HostLoaderApp/.gitignore b/Bootloaders/HID/HostLoaderApp/.gitignore new file mode 100644 index 0000000000..4e73d1ec5b --- /dev/null +++ b/Bootloaders/HID/HostLoaderApp/.gitignore @@ -0,0 +1 @@ +hid_bootloader_cli diff --git a/Bootloaders/HID/HostLoaderApp/Makefile b/Bootloaders/HID/HostLoaderApp/Makefile new file mode 100644 index 0000000000..d7d6458a5c --- /dev/null +++ b/Bootloaders/HID/HostLoaderApp/Makefile @@ -0,0 +1,40 @@ +OS ?= LINUX +#OS ?= WINDOWS +#OS ?= MACOSX +#OS ?= BSD + +ifeq ($(OS), LINUX) # also works on FreeBSD +CC ?= gcc +CFLAGS ?= -O2 -Wall +hid_bootloader_cli: hid_bootloader_cli.c + $(CC) $(CFLAGS) -s -DUSE_LIBUSB -o hid_bootloader_cli hid_bootloader_cli.c -lusb + + +else ifeq ($(OS), WINDOWS) +CC = i586-mingw32msvc-gcc +CFLAGS ?= -O2 -Wall +LDLIB = -lsetupapi -lhid +hid_bootloader_cli.exe: hid_bootloader_cli.c + $(CC) $(CFLAGS) -s -DUSE_WIN32 -o hid_bootloader_cli.exe hid_bootloader_cli.c $(LDLIB) + + +else ifeq ($(OS), MACOSX) +CC ?= gcc +SDK ?= /Developer/SDKs/MacOSX10.5.sdk +CFLAGS ?= -O2 -Wall +hid_bootloader_cli: hid_bootloader_cli.c + $(CC) $(CFLAGS) -DUSE_APPLE_IOKIT -isysroot $(SDK) -o hid_bootloader_cli hid_bootloader_cli.c -Wl,-syslibroot,$(SDK) -framework IOKit -framework CoreFoundation + + +else ifeq ($(OS), BSD) # works on NetBSD and OpenBSD +CC ?= gcct +CFLAGS ?= -O2 -Wall +hid_bootloader_cli: hid_bootloader_cli.c + $(CC) $(CFLAGS) -s -DUSE_UHID -o hid_bootloader_cli hid_bootloader_cli.c + + +endif + + +clean: + rm -f hid_bootloader_cli hid_bootloader_cli.exe diff --git a/Bootloaders/HID/HostLoaderApp/Makefile.bsd b/Bootloaders/HID/HostLoaderApp/Makefile.bsd new file mode 100644 index 0000000000..a15a664053 --- /dev/null +++ b/Bootloaders/HID/HostLoaderApp/Makefile.bsd @@ -0,0 +1,21 @@ +OS ?= FreeBSD +#OS ?= NetBSD +#OS ?= OpenBSD + +CFLAGS ?= -O2 -Wall +CC ?= gcc + +.if $(OS) == "FreeBSD" +CFLAGS += -DUSE_LIBUSB +LIBS = -lusb +.elif $(OS) == "NetBSD" || $(OS) == "OpenBSD" +CFLAGS += -DUSE_UHID +LIBS = +.endif + + +hid_bootloader_cli: hid_bootloader_cli.c + $(CC) $(CFLAGS) -s -o hid_bootloader_cli hid_bootloader_cli.c $(LIBS) + +clean: + rm -f hid_bootloader_cli diff --git a/Bootloaders/HID/HostLoaderApp/gpl3.txt b/Bootloaders/HID/HostLoaderApp/gpl3.txt new file mode 100644 index 0000000000..94a9ed024d --- /dev/null +++ b/Bootloaders/HID/HostLoaderApp/gpl3.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for |