Project

General

Profile

Download (4.24 KB) Statistics
| Branch: | Tag: | Revision:
1
#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
 *  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
 */
25

    
26
#include <sys/types.h>
27
#include <usb_ch9.h>
28
#include <usb_dfu.h>
29
#include "../config.h"
30

    
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
#ifdef CONFIG_USB_STRING
43
#define DFU_RT_IF_DESC	{						\
44
	{								\
45
	.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
	}, {								\
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
	}, {								\
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
	},								\
75
}
76
#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
	.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
	.bNumEndpoints		= 0x00,					\
104
	.bInterfaceClass	= 0xfe,					\
105
	.bInterfaceSubClass	= 0x01,					\
106
	.bInterfaceProtocol	= 0x01,					\
107
	.iInterface		= 0,					\
108
	},								\
109
}
110
#endif
111

    
112
#define __dfufunctab  __attribute__ ((section (".dfu.functab")))
113
#define __dfudata __attribute__ ((section (".data.shared")))
114
#define __dfufunc 
115
#define __dfustruct const
116

    
117
#define DFU_API_LOCATION	((const struct dfuapi *) 0x00103fd0)
118

    
119
struct _dfu_desc {
120
	struct usb_config_descriptor ucfg;
121
	struct usb_interface_descriptor uif[3];
122
	struct usb_dfu_func_descriptor func_dfu;
123
};
124

    
125
struct dfuapi {
126
	void (*udp_init)(void);
127
	void (*ep0_send_data)(const char *data, uint32_t len, uint32_t wlen);
128
	void (*ep0_send_zlp)(void);
129
	void (*ep0_send_stall)(void);
130
	int  (*dfu_ep0_handler)(uint8_t req_type, uint8_t req,
131
				     uint16_t val, uint16_t len);
132
	void (*dfu_switch)(void);
133
	uint32_t *dfu_state;
134
	const struct usb_device_descriptor *dfu_dev_descriptor;
135
	const struct _dfu_desc *dfu_cfg_descriptor;
136
};
137

    
138

    
139
#endif /* _DFU_H */
(4-4/4)
Add picture from clipboard (Maximum size: 48.8 MB)