This source file includes following definitions.
- ezload_reset
- ezload_download
- ezload_downloads_and_reset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/device.h>
44 #include <sys/malloc.h>
45 #include <sys/conf.h>
46
47 #include <dev/usb/usb.h>
48 #include <dev/usb/usbdi.h>
49 #include <dev/usb/usbdi_util.h>
50
51 #include <dev/usb/ezload.h>
52
53
54
55
56
57
58 #define ANCHOR_LOAD_INTERNAL 0xA0
59
60
61 #define ANCHOR_MAX_INTERNAL_ADDRESS 0x1B3F
62
63
64
65
66 #define ANCHOR_CPUCS_REG 0x7F92
67 #define ANCHOR_RESET 0x01
68
69
70
71
72
73
74 #define ANCHOR_CHUNK 16
75
76
77
78
79
80
81
82
83 #ifdef USB_DEBUG
84 #define DPRINTF(x) if (ezloaddebug) printf x
85 #define DPRINTFN(n,x) if (ezloaddebug>(n)) printf x
86 int ezloaddebug = 0;
87 #else
88 #define DPRINTF(x)
89 #define DPRINTFN(n,x)
90 #endif
91
92 usbd_status
93 ezload_reset(usbd_device_handle dev, int reset)
94 {
95 usb_device_request_t req;
96 uByte rst;
97
98 DPRINTF(("ezload_reset: reset=%d\n", reset));
99
100 rst = reset ? ANCHOR_RESET : 0;
101 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
102 req.bRequest = ANCHOR_LOAD_INTERNAL;
103 USETW(req.wValue, ANCHOR_CPUCS_REG);
104 USETW(req.wIndex, 0);
105 USETW(req.wLength, 1);
106 return (usbd_do_request(dev, &req, &rst));
107 }
108
109 usbd_status
110 ezload_download(usbd_device_handle dev, const char *name, const u_char *buf,
111 size_t buflen)
112 {
113 usb_device_request_t req;
114 usbd_status err = 0;
115 u_int8_t length;
116 u_int16_t address;
117 u_int len, offs;
118
119 for (;;) {
120 length = *buf++;
121 if (length == 0)
122 break;
123
124 address = UGETW(buf); buf += 2;
125 #if 0
126 if (address + length > ANCHOR_MAX_INTERNAL_ADDRESS)
127 return (USBD_INVAL);
128 #endif
129
130 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
131 req.bRequest = ANCHOR_LOAD_INTERNAL;
132 USETW(req.wIndex, 0);
133 for (offs = 0; offs < length; offs += ANCHOR_CHUNK) {
134 len = length - offs;
135 if (len > ANCHOR_CHUNK)
136 len = ANCHOR_CHUNK;
137 USETW(req.wValue, address + offs);
138 USETW(req.wLength, len);
139 DPRINTFN(2,("ezload_download: addr=0x%x len=%d\n",
140 address + offs, len));
141 err = usbd_do_request(dev, &req, (u_char *)buf);
142 if (err)
143 break;
144
145 buf += len;
146 }
147 if (err)
148 break;
149 }
150
151 return (err);
152 }
153
154 usbd_status
155 ezload_downloads_and_reset(usbd_device_handle dev, char **names)
156 {
157 usbd_status err;
158 size_t buflen;
159 u_char *buf;
160 int error;
161
162
163 err = ezload_reset(dev, 1);
164 if (err)
165 return (err);
166 usbd_delay_ms(dev, 250);
167
168 while (*names != NULL) {
169 error = loadfirmware(*names, &buf, &buflen);
170 if (error)
171 return (error);
172
173 err = ezload_download(dev, *names, buf, buflen);
174 free(buf, M_DEVBUF);
175 if (err)
176 return (err);
177 names++;
178 }
179 if (err)
180 return (err);
181 usbd_delay_ms(dev, 250);
182
183 err = ezload_reset(dev, 0);
184 usbd_delay_ms(dev, 250);
185 return (err);
186 }