1 |
43d61cf0
|
(no author)
|
#ifndef _DFU_H
|
2 |
|
|
#define _DFU_H
|
3 |
|
|
|
4 |
|
|
/* USB Device Firmware Update Implementation for OpenPCD
|
5 |
|
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
6 |
|
|
*
|
7 |
|
|
* This ought to be compliant to the USB DFU Spec 1.0 as available from
|
8 |
|
|
* http://www.usb.org/developers/devclass_docs/usbdfu10.pdf
|
9 |
|
|
*
|
10 |
32985a29
|
laforge
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
43d61cf0
|
(no author)
|
*/
|
25 |
|
|
|
26 |
|
|
#include <sys/types.h>
|
27 |
|
|
#include <usb_ch9.h>
|
28 |
|
|
#include <usb_dfu.h>
|
29 |
28eb4a57
|
laforge
|
#include "../config.h"
|
30 |
43d61cf0
|
(no author)
|
|
31 |
|
|
/* USB DFU functional descriptor */
|
32 |
|
|
#define DFU_FUNC_DESC { \
|
33 |
|
|
.bLength = USB_DT_DFU_SIZE, \
|
34 |
|
|
.bDescriptorType = USB_DT_DFU, \
|
35 |
|
|
.bmAttributes = USB_DFU_CAN_UPLOAD | USB_DFU_CAN_DOWNLOAD, \
|
36 |
|
|
.wDetachTimeOut = 0xff00, \
|
37 |
|
|
.wTransferSize = AT91C_IFLASH_PAGE_SIZE, \
|
38 |
|
|
.bcdDFUVersion = 0x0100, \
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/* USB Interface descriptor in Runtime mode */
|
42 |
28eb4a57
|
laforge
|
#ifdef CONFIG_USB_STRING
|
43 |
43d61cf0
|
(no author)
|
#define DFU_RT_IF_DESC { \
|
44 |
5872753e
|
laforge
|
{ \
|
45 |
43d61cf0
|
(no author)
|
.bLength = USB_DT_INTERFACE_SIZE, \
|
46 |
|
|
.bDescriptorType = USB_DT_INTERFACE, \
|
47 |
|
|
.bInterfaceNumber = 0x01, \
|
48 |
|
|
.bAlternateSetting = 0x00, \
|
49 |
|
|
.bNumEndpoints = 0x00, \
|
50 |
|
|
.bInterfaceClass = 0xfe, \
|
51 |
|
|
.bInterfaceSubClass = 0x01, \
|
52 |
|
|
.bInterfaceProtocol = 0x01, \
|
53 |
|
|
.iInterface = 1, \
|
54 |
5872753e
|
laforge
|
}, { \
|
55 |
|
|
.bLength = USB_DT_INTERFACE_SIZE, \
|
56 |
|
|
.bDescriptorType = USB_DT_INTERFACE, \
|
57 |
|
|
.bInterfaceNumber = 0x02, \
|
58 |
|
|
.bAlternateSetting = 0x00, \
|
59 |
|
|
.bNumEndpoints = 0x00, \
|
60 |
|
|
.bInterfaceClass = 0xfe, \
|
61 |
|
|
.bInterfaceSubClass = 0x01, \
|
62 |
|
|
.bInterfaceProtocol = 0x01, \
|
63 |
|
|
.iInterface = 2, \
|
64 |
e3d1fd9b
|
Harald Welte
|
}, { \
|
65 |
|
|
.bLength = USB_DT_INTERFACE_SIZE, \
|
66 |
|
|
.bDescriptorType = USB_DT_INTERFACE, \
|
67 |
|
|
.bInterfaceNumber = 0x03, \
|
68 |
|
|
.bAlternateSetting = 0x00, \
|
69 |
|
|
.bNumEndpoints = 0x00, \
|
70 |
|
|
.bInterfaceClass = 0xfe, \
|
71 |
|
|
.bInterfaceSubClass = 0x01, \
|
72 |
|
|
.bInterfaceProtocol = 0x01, \
|
73 |
|
|
.iInterface = 3, \
|
74 |
5872753e
|
laforge
|
}, \
|
75 |
43d61cf0
|
(no author)
|
}
|
76 |
28eb4a57
|
laforge
|
#else
|
77 |
|
|
#define DFU_RT_IF_DESC { \
|
78 |
|
|
{ \
|
79 |
|
|
.bLength = USB_DT_INTERFACE_SIZE, \
|
80 |
|
|
.bDescriptorType = USB_DT_INTERFACE, \
|
81 |
|
|
.bInterfaceNumber = 0x01, \
|
82 |
|
|
.bAlternateSetting = 0x00, \
|
83 |
|
|
.bNumEndpoints = 0x00, \
|
84 |
|
|
.bInterfaceClass = 0xfe, \
|
85 |
|
|
.bInterfaceSubClass = 0x01, \
|
86 |
|
|
.bInterfaceProtocol = 0x01, \
|
87 |
|
|
.iInterface = 0, \
|
88 |
|
|
}, { \
|
89 |
|
|
.bLength = USB_DT_INTERFACE_SIZE, \
|
90 |
|
|
.bDescriptorType = USB_DT_INTERFACE, \
|
91 |
e3d1fd9b
|
Harald Welte
|
.bInterfaceNumber = 0x01, \
|
92 |
|
|
.bAlternateSetting = 0x01, \
|
93 |
|
|
.bNumEndpoints = 0x00, \
|
94 |
|
|
.bInterfaceClass = 0xfe, \
|
95 |
|
|
.bInterfaceSubClass = 0x01, \
|
96 |
|
|
.bInterfaceProtocol = 0x01, \
|
97 |
|
|
.iInterface = 0, \
|
98 |
|
|
}, { \
|
99 |
|
|
.bLength = USB_DT_INTERFACE_SIZE, \
|
100 |
|
|
.bDescriptorType = USB_DT_INTERFACE, \
|
101 |
|
|
.bInterfaceNumber = 0x01, \
|
102 |
|
|
.bAlternateSetting = 0x02, \
|
103 |
28eb4a57
|
laforge
|
.bNumEndpoints = 0x00, \
|
104 |
|
|
.bInterfaceClass = 0xfe, \
|
105 |
|
|
.bInterfaceSubClass = 0x01, \
|
106 |
|
|
.bInterfaceProtocol = 0x01, \
|
107 |
|
|
.iInterface = 0, \
|
108 |
|
|
}, \
|
109 |
|
|
}
|
110 |
|
|
#endif
|
111 |
43d61cf0
|
(no author)
|
|
112 |
b0317c72
|
(no author)
|
#define __dfufunctab __attribute__ ((section (".dfu.functab")))
|
113 |
a97e460b
|
laforge
|
#define __dfudata __attribute__ ((section (".data.shared")))
|
114 |
|
|
#define __dfufunc
|
115 |
|
|
#define __dfustruct const
|
116 |
569d11d8
|
laforge
|
|
117 |
1c2b1d22
|
laforge
|
#define DFU_API_LOCATION ((const struct dfuapi *) 0x00103fd0)
|
118 |
43d61cf0
|
(no author)
|
|
119 |
|
|
struct _dfu_desc {
|
120 |
|
|
struct usb_config_descriptor ucfg;
|
121 |
e3d1fd9b
|
Harald Welte
|
struct usb_interface_descriptor uif[3];
|
122 |
43d61cf0
|
(no author)
|
struct usb_dfu_func_descriptor func_dfu;
|
123 |
|
|
};
|
124 |
|
|
|
125 |
b0317c72
|
(no author)
|
struct dfuapi {
|
126 |
a97e460b
|
laforge
|
void (*udp_init)(void);
|
127 |
373c172a
|
Harald Welte
|
void (*ep0_send_data)(const char *data, uint32_t len, uint32_t wlen);
|
128 |
b0317c72
|
(no author)
|
void (*ep0_send_zlp)(void);
|
129 |
|
|
void (*ep0_send_stall)(void);
|
130 |
373c172a
|
Harald Welte
|
int (*dfu_ep0_handler)(uint8_t req_type, uint8_t req,
|
131 |
|
|
uint16_t val, uint16_t len);
|
132 |
b0317c72
|
(no author)
|
void (*dfu_switch)(void);
|
133 |
373c172a
|
Harald Welte
|
uint32_t *dfu_state;
|
134 |
83c18361
|
(no author)
|
const struct usb_device_descriptor *dfu_dev_descriptor;
|
135 |
|
|
const struct _dfu_desc *dfu_cfg_descriptor;
|
136 |
b0317c72
|
(no author)
|
};
|
137 |
|
|
|
138 |
43d61cf0
|
(no author)
|
|
139 |
|
|
#endif /* _DFU_H */
|