summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-07-31 14:09:50 +0200
committerHarald Welte <laforge@gnumonks.org>2011-07-31 14:16:19 +0200
commit390df0f0b66e53c7ea19770a343e8340ed319b77 (patch)
tree4218385c734d4bcd5ace0742d130639a8b032509
parent245e794b26158fded2025508e7c63be52d0e60b4 (diff)
AT91LIB: Add DFU interface descriptors to CCID
A board can now define BOARD_USB_DFU which will cause the USB DFU interface descriptors for the sam7dfu bootloader to be appended automatically.
-rw-r--r--at91lib/boards/simtrace/board.h2
-rw-r--r--at91lib/usb/device/ccid/cciddriver.c30
-rw-r--r--at91lib/usb/device/dfu/dfu.c50
-rw-r--r--at91lib/usb/device/dfu/dfu.h75
-rw-r--r--usb-device-ccid-project/Makefile6
5 files changed, 149 insertions, 14 deletions
diff --git a/at91lib/boards/simtrace/board.h b/at91lib/boards/simtrace/board.h
index 8e8290d..af6eae4 100644
--- a/at91lib/boards/simtrace/board.h
+++ b/at91lib/boards/simtrace/board.h
@@ -240,5 +240,7 @@
#define PINS_ISO7816 PIN_USART0_TXD, PIN_USART0_SCK, PIN_ISO7816_RSTMC
//------------------------------------------------------------------------------
+#define BOARD_USB_DFU
+
#endif //#ifndef BOARD_H
diff --git a/at91lib/usb/device/ccid/cciddriver.c b/at91lib/usb/device/ccid/cciddriver.c
index aa32270..495a897 100644
--- a/at91lib/usb/device/ccid/cciddriver.c
+++ b/at91lib/usb/device/ccid/cciddriver.c
@@ -49,6 +49,7 @@
#include <usb/device/core/USBDDriver.h>
#include <usb/common/core/USBGenericRequest.h>
#include <usb/common/core/USBStringDescriptor.h>
+#include <usb/device/dfu/dfu.h>
#include <usb/device/ccid/cciddriver.h>
#include <usb/device/ccid/cciddriverdescriptors.h>
#include <iso7816/iso7816_4.h>
@@ -89,7 +90,9 @@ typedef struct {
USBEndpointDescriptor bulkIn;
/// Interrupt OUT endpoint descriptor
USBEndpointDescriptor interruptIn;
-
+#ifdef BOARD_USB_DFU
+ USBInterfaceDescriptor dfu_interface[DFU_NUM_IF];
+#endif
} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
//------------------------------------------------------------------------------
@@ -157,7 +160,7 @@ static const CCIDDriverConfigurationDescriptors configurationDescriptorsFS = {
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(CCIDDriverConfigurationDescriptors),
- 1, // One interface in this configuration
+ 1+DFU_NUM_IF, // One interface in this configuration
1, // This is configuration #1
0, // No associated string descriptor
BOARD_USB_BMATTRIBUTES,
@@ -232,7 +235,8 @@ static const CCIDDriverConfigurationDescriptors configurationDescriptorsFS = {
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
0x10
- }
+ },
+ DFU_IF_DESCRIPTORS
};
#ifdef BOARD_USB_UDPHS
@@ -243,7 +247,7 @@ static const CCIDDriverConfigurationDescriptors configurationDescriptorsHS = {
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(CCIDDriverConfigurationDescriptors),
- 1, // One interface in this configuration
+ 1+DFU_NUM_IF, // One interface in this configuration
1, // This is configuration #1
0, // No associated string descriptor
BOARD_USB_BMATTRIBUTES,
@@ -318,7 +322,8 @@ static const CCIDDriverConfigurationDescriptors configurationDescriptorsHS = {
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_HS),
0x10
- }
+ },
+ DFU_IF_DESCRIPTORS
};
/// Qualifier descriptor
@@ -343,7 +348,7 @@ static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationFS = {
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CCIDDriverConfigurationDescriptors),
- 1, // One interface in this configuration
+ 1+DFU_NUM_IF, // One interface in this configuration
1, // This is configuration #1
0, // No associated string descriptor
BOARD_USB_BMATTRIBUTES,
@@ -418,7 +423,8 @@ static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationFS = {
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
0x10
- }
+ },
+ DFU_IF_DESCRIPTORS
};
/// OtherSpeed configuration descriptor in High Speed mode
@@ -429,7 +435,7 @@ static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationHS = {
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CCIDDriverConfigurationDescriptors),
- 1, // One interface in this configuration
+ 1+DFU_NUM_IF, // One interface in this configuration
1, // This is configuration #1
0, // No associated string descriptor
BOARD_USB_BMATTRIBUTES,
@@ -504,7 +510,8 @@ static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationHS = {
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
USBEndpointDescriptor_MAXINTERRUPTSIZE_HS),
0x10
- }
+ },
+ DFU_IF_DESCRIPTORS
};
#endif
@@ -583,7 +590,8 @@ static const unsigned char *stringDescriptors[] = {
languageIdDescriptor,
manufacturerDescriptor,
productDescriptor,
- serialNumberDescriptor
+ serialNumberDescriptor,
+ DFU_STRING_DESCRIPTORS
};
@@ -608,7 +616,7 @@ const USBDDriverDescriptors ccidDriverDescriptors = {
0, // No other-speed configuration HS
#endif
stringDescriptors,
- 4 // Four string descriptors in array
+ 4+DFU_NUM_STRINGS // Four string descriptors in array
};
//------------------------------------------------------------------------------
diff --git a/at91lib/usb/device/dfu/dfu.c b/at91lib/usb/device/dfu/dfu.c
new file mode 100644
index 0000000..89b5f3a
--- /dev/null
+++ b/at91lib/usb/device/dfu/dfu.c
@@ -0,0 +1,50 @@
+
+#include <usb/common/core/USBInterfaceDescriptor.h>
+#include <usb/common/core/USBGenericDescriptor.h>
+#include <usb/device/dfu/dfu.h>
+
+
+/* String 1 "SimTrace DFU Interface - Application Partition" */
+const struct USBStringDescriptor USBDFU_string1 = {
+ .hdr = {
+ .bLength = sizeof(USBGenericDescriptor) + 46 * sizeof(unsigned short),
+ .bDescriptorType = USBGenericDescriptor_STRING,
+ },
+ .wData = { 0x0053, 0x0069, 0x006d, 0x0054, 0x0072, 0x0061,
+ 0x0063, 0x0065, 0x0020, 0x0044, 0x0046, 0x0055,
+ 0x0020, 0x0049, 0x006e, 0x0074, 0x0065, 0x0072,
+ 0x0066, 0x0061, 0x0063, 0x0065, 0x0020, 0x002d,
+ 0x0020, 0x0041, 0x0070, 0x0070, 0x006c, 0x0069,
+ 0x0063, 0x0061, 0x0074, 0x0069, 0x006f, 0x006e,
+ 0x0020, 0x0050, 0x0061, 0x0072, 0x0074, 0x0069,
+ 0x0074, 0x0069, 0x006f, 0x006e, },
+};
+
+/* String 2 "SimTrace DFU Interface - Bootloader Partition" */
+const struct USBStringDescriptor USBDFU_string2 = {
+ .hdr = {
+ .bLength = sizeof(USBGenericDescriptor) + 45 * sizeof(unsigned short),
+ .bDescriptorType = USBGenericDescriptor_STRING,
+ },
+ .wData = { 0x0053, 0x0069, 0x006d, 0x0054, 0x0072, 0x0061,
+ 0x0063, 0x0065, 0x0020, 0x0044, 0x0046, 0x0055,
+ 0x0020, 0x0049, 0x006e, 0x0074, 0x0065, 0x0072,
+ 0x0066, 0x0061, 0x0063, 0x0065, 0x0020, 0x002d,
+ 0x0020, 0x0042, 0x006f, 0x006f, 0x0074, 0x006c,
+ 0x006f, 0x0061, 0x0064, 0x0065, 0x0072, 0x0020,
+ 0x0050, 0x0061, 0x0072, 0x0074, 0x0069, 0x0074,
+ 0x0069, 0x006f, 0x006e, },
+};
+
+/* String 3 "SimTrace DFU Interface - RAM" */
+const struct USBStringDescriptor USBDFU_string3 = {
+ .hdr = {
+ .bLength = sizeof(USBGenericDescriptor) + 28 * sizeof(unsigned short),
+ .bDescriptorType = USBGenericDescriptor_STRING,
+ },
+ .wData = { 0x0053, 0x0069, 0x006d, 0x0054, 0x0072, 0x0061,
+ 0x0063, 0x0065, 0x0020, 0x0044, 0x0046, 0x0055,
+ 0x0020, 0x0049, 0x006e, 0x0074, 0x0065, 0x0072,
+ 0x0066, 0x0061, 0x0063, 0x0065, 0x0020, 0x002d,
+ 0x0020, 0x0052, 0x0041, 0x004d, },
+};
diff --git a/at91lib/usb/device/dfu/dfu.h b/at91lib/usb/device/dfu/dfu.h
new file mode 100644
index 0000000..f1323c1
--- /dev/null
+++ b/at91lib/usb/device/dfu/dfu.h
@@ -0,0 +1,75 @@
+#ifndef _USB_DFU_DESC_H
+#define _USB_DFU_DESC_H
+
+#include <usb/common/core/USBGenericDescriptor.h>
+
+#define CONFIG_DFU_NUM_APP_IF 1
+#define CONFIG_DFU_NUM_APP_STR 4
+
+struct USBStringDescriptor {
+ USBGenericDescriptor hdr;
+ unsigned short wData[];
+} __attribute__((packed));
+
+
+#ifdef BOARD_USB_DFU
+
+#define DFU_NUM_IF 3
+#define DFU_IF_DESCRIPTORS { \
+ { \
+ .bLength = sizeof(USBInterfaceDescriptor), \
+ .bDescriptorType = USBGenericDescriptor_INTERFACE, \
+ .bInterfaceNumber = CONFIG_DFU_NUM_APP_IF, \
+ .bAlternateSetting = 0, \
+ .bNumEndpoints = 0, \
+ .bInterfaceClass = 0xFE, \
+ .bInterfaceSubClass = 0x01, \
+ .bInterfaceProtocol = 0x01, \
+ .iInterface = CONFIG_DFU_NUM_APP_STR, \
+ }, \
+ { \
+ .bLength = sizeof(USBInterfaceDescriptor), \
+ .bDescriptorType = USBGenericDescriptor_INTERFACE, \
+ .bInterfaceNumber = CONFIG_DFU_NUM_APP_IF+1, \
+ .bAlternateSetting = 0, \
+ .bNumEndpoints = 0, \
+ .bInterfaceClass = 0xFE, \
+ .bInterfaceSubClass = 0x01, \
+ .bInterfaceProtocol = 0x01, \
+ .iInterface = CONFIG_DFU_NUM_APP_STR+1, \
+ }, \
+ { \
+ .bLength = sizeof(USBInterfaceDescriptor), \
+ .bDescriptorType = USBGenericDescriptor_INTERFACE, \
+ .bInterfaceNumber = CONFIG_DFU_NUM_APP_IF+2, \
+ .bAlternateSetting = 0, \
+ .bNumEndpoints = 0, \
+ .bInterfaceClass = 0xFE, \
+ .bInterfaceSubClass = 0x01, \
+ .bInterfaceProtocol = 0x01, \
+ .iInterface = CONFIG_DFU_NUM_APP_STR+2, \
+ }, \
+}
+
+extern const struct USBStringDescriptor USBDFU_string1;
+extern const struct USBStringDescriptor USBDFU_string2;
+extern const struct USBStringDescriptor USBDFU_string3;
+
+#define DFU_NUM_STRINGS 3
+#define DFU_STRING_DESCRIPTORS \
+ &USBDFU_string1, \
+ &USBDFU_string2, \
+ &USBDFU_string3,
+
+#else /* BOARD_USB_DFU */
+
+/* no DFU bootloader is being used */
+#define DFU_NUM_IF 0
+#define DFU_IF_DESCRIPTORS
+
+#define DFU_NUM_STRINGS 0
+#define DFU_STRING_DESCRIPTORS
+
+#endif /* BOARD_USB_DFU */
+
+#endif
diff --git a/usb-device-ccid-project/Makefile b/usb-device-ccid-project/Makefile
index 337ecd9..4cb38b4 100644
--- a/usb-device-ccid-project/Makefile
+++ b/usb-device-ccid-project/Makefile
@@ -68,7 +68,7 @@ OBJ = obj
#-------------------------------------------------------------------------------
# Tool suffix when cross-compiling
-CROSS_COMPILE = arm-none-eabi-
+CROSS_COMPILE = arm-elf-
# Compilation tools
CC = $(CROSS_COMPILE)gcc
@@ -97,7 +97,7 @@ UTILITY = $(AT91LIB)/utility
USB = $(AT91LIB)/usb
COMP = $(AT91LIB)/components
-VPATH += $(USB)/common/core $(USB)/device/core
+VPATH += $(USB)/common/core $(USB)/device/core $(USB)/device/dfu
VPATH += $(UTILITY)
VPATH += $(PERIPH)/dbgu $(PERIPH)/pio $(PERIPH)/pit $(PERIPH)/aic $(PERIPH)/pmc
VPATH += $(PERIPH)/cp15
@@ -116,7 +116,7 @@ C_OBJECTS += USBDDriverCb_IfSettingChanged.o
C_OBJECTS += USBSetAddressRequest.o USBGenericDescriptor.o USBInterfaceRequest.o
C_OBJECTS += USBGenericRequest.o USBGetDescriptorRequest.o
C_OBJECTS += USBSetConfigurationRequest.o USBFeatureRequest.o
-C_OBJECTS += USBEndpointDescriptor.o USBConfigurationDescriptor.o
+C_OBJECTS += USBEndpointDescriptor.o USBConfigurationDescriptor.o dfu.o
C_OBJECTS += led.o math.o stdio.o
C_OBJECTS += aic.o dbgu.o pio.o pio_it.o pit.o pmc.o cp15.o
C_OBJECTS += board_memories.o board_lowlevel.o
personal git repositories of Harald Welte. Your mileage may vary