]>
Commit | Line | Data |
---|---|---|
f22b11c1 ŁM |
1 | /* |
2 | * dfu.c -- DFU back-end routines | |
3 | * | |
4 | * Copyright (C) 2012 Samsung Electronics | |
5 | * author: Lukasz Majewski <[email protected]> | |
6 | * | |
1a459660 | 7 | * SPDX-License-Identifier: GPL-2.0+ |
f22b11c1 ŁM |
8 | */ |
9 | ||
10 | #include <common.h> | |
e7e75c70 | 11 | #include <errno.h> |
f22b11c1 ŁM |
12 | #include <malloc.h> |
13 | #include <mmc.h> | |
14 | #include <fat.h> | |
15 | #include <dfu.h> | |
bd694244 | 16 | #include <hash.h> |
f22b11c1 ŁM |
17 | #include <linux/list.h> |
18 | #include <linux/compiler.h> | |
19 | ||
1cc03c5c | 20 | static bool dfu_detach_request; |
f22b11c1 ŁM |
21 | static LIST_HEAD(dfu_list); |
22 | static int dfu_alt_num; | |
b627eb46 | 23 | static int alt_num_cnt; |
bd694244 | 24 | static struct hash_algo *dfu_hash_algo; |
f22b11c1 | 25 | |
1cc03c5c ŁM |
26 | /* |
27 | * The purpose of the dfu_usb_get_reset() function is to | |
28 | * provide information if after USB_DETACH request | |
29 | * being sent the dfu-util performed reset of USB | |
30 | * bus. | |
31 | * | |
32 | * Described behaviour is the only way to distinct if | |
33 | * user has typed -e (detach) or -R (reset) when invoking | |
34 | * dfu-util command. | |
35 | * | |
36 | */ | |
37 | __weak bool dfu_usb_get_reset(void) | |
38 | { | |
39 | return true; | |
40 | } | |
41 | ||
42 | bool dfu_detach(void) | |
43 | { | |
44 | return dfu_detach_request; | |
45 | } | |
46 | ||
47 | void dfu_trigger_detach(void) | |
6bed7ce5 | 48 | { |
1cc03c5c | 49 | dfu_detach_request = true; |
6bed7ce5 ŁM |
50 | } |
51 | ||
1cc03c5c | 52 | void dfu_clear_detach(void) |
6bed7ce5 | 53 | { |
1cc03c5c | 54 | dfu_detach_request = false; |
6bed7ce5 ŁM |
55 | } |
56 | ||
f22b11c1 ŁM |
57 | static int dfu_find_alt_num(const char *s) |
58 | { | |
59 | int i = 0; | |
60 | ||
61 | for (; *s; s++) | |
62 | if (*s == ';') | |
63 | i++; | |
64 | ||
65 | return ++i; | |
66 | } | |
67 | ||
dd64827e | 68 | int dfu_init_env_entities(char *interface, char *devstr) |
765c5ae5 ŁM |
69 | { |
70 | const char *str_env; | |
71 | char *env_bkp; | |
72 | int ret; | |
73 | ||
74 | str_env = getenv("dfu_alt_info"); | |
75 | if (!str_env) { | |
76 | error("\"dfu_alt_info\" env variable not defined!\n"); | |
77 | return -EINVAL; | |
78 | } | |
79 | ||
80 | env_bkp = strdup(str_env); | |
dd64827e | 81 | ret = dfu_config_entities(env_bkp, interface, devstr); |
765c5ae5 ŁM |
82 | if (ret) { |
83 | error("DFU entities configuration failed!\n"); | |
84 | return ret; | |
85 | } | |
86 | ||
87 | free(env_bkp); | |
88 | return 0; | |
89 | } | |
90 | ||
e7e75c70 HS |
91 | static unsigned char *dfu_buf; |
92 | static unsigned long dfu_buf_size = CONFIG_SYS_DFU_DATA_BUF_SIZE; | |
93 | ||
d4278263 | 94 | unsigned char *dfu_free_buf(void) |
e7e75c70 HS |
95 | { |
96 | free(dfu_buf); | |
97 | dfu_buf = NULL; | |
98 | return dfu_buf; | |
99 | } | |
100 | ||
4fb12789 ŁM |
101 | unsigned long dfu_get_buf_size(void) |
102 | { | |
103 | return dfu_buf_size; | |
104 | } | |
105 | ||
7ac1b410 | 106 | unsigned char *dfu_get_buf(struct dfu_entity *dfu) |
e7e75c70 HS |
107 | { |
108 | char *s; | |
109 | ||
110 | if (dfu_buf != NULL) | |
111 | return dfu_buf; | |
112 | ||
113 | s = getenv("dfu_bufsiz"); | |
114 | dfu_buf_size = s ? (unsigned long)simple_strtol(s, NULL, 16) : | |
115 | CONFIG_SYS_DFU_DATA_BUF_SIZE; | |
7ac1b410 SW |
116 | if (dfu->max_buf_size && dfu_buf_size > dfu->max_buf_size) |
117 | dfu_buf_size = dfu->max_buf_size; | |
e7e75c70 HS |
118 | |
119 | dfu_buf = memalign(CONFIG_SYS_CACHELINE_SIZE, dfu_buf_size); | |
120 | if (dfu_buf == NULL) | |
121 | printf("%s: Could not memalign 0x%lx bytes\n", | |
122 | __func__, dfu_buf_size); | |
123 | ||
124 | return dfu_buf; | |
125 | } | |
f22b11c1 | 126 | |
bd694244 ŁM |
127 | static char *dfu_get_hash_algo(void) |
128 | { | |
129 | char *s; | |
130 | ||
131 | s = getenv("dfu_hash_algo"); | |
3d83e675 | 132 | if (!s) |
bd694244 ŁM |
133 | return NULL; |
134 | ||
3d83e675 ŁM |
135 | if (!strcmp(s, "crc32")) { |
136 | debug("%s: DFU hash method: %s\n", __func__, s); | |
137 | return s; | |
138 | } | |
139 | ||
140 | error("DFU hash method: %s not supported!\n", s); | |
bd694244 ŁM |
141 | return NULL; |
142 | } | |
143 | ||
ea2453d5 PA |
144 | static int dfu_write_buffer_drain(struct dfu_entity *dfu) |
145 | { | |
146 | long w_size; | |
147 | int ret; | |
148 | ||
149 | /* flush size? */ | |
150 | w_size = dfu->i_buf - dfu->i_buf_start; | |
151 | if (w_size == 0) | |
152 | return 0; | |
153 | ||
bd694244 ŁM |
154 | if (dfu_hash_algo) |
155 | dfu_hash_algo->hash_update(dfu_hash_algo, &dfu->crc, | |
156 | dfu->i_buf_start, w_size, 0); | |
ea2453d5 PA |
157 | |
158 | ret = dfu->write_medium(dfu, dfu->offset, dfu->i_buf_start, &w_size); | |
159 | if (ret) | |
160 | debug("%s: Write error!\n", __func__); | |
161 | ||
162 | /* point back */ | |
163 | dfu->i_buf = dfu->i_buf_start; | |
164 | ||
165 | /* update offset */ | |
166 | dfu->offset += w_size; | |
167 | ||
168 | puts("#"); | |
169 | ||
170 | return ret; | |
171 | } | |
172 | ||
3ee9593f SW |
173 | void dfu_write_transaction_cleanup(struct dfu_entity *dfu) |
174 | { | |
175 | /* clear everything */ | |
176 | dfu_free_buf(); | |
177 | dfu->crc = 0; | |
178 | dfu->offset = 0; | |
179 | dfu->i_blk_seq_num = 0; | |
180 | dfu->i_buf_start = dfu_buf; | |
181 | dfu->i_buf_end = dfu_buf; | |
182 | dfu->i_buf = dfu->i_buf_start; | |
183 | dfu->inited = 0; | |
184 | } | |
185 | ||
a2199afe HS |
186 | int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) |
187 | { | |
188 | int ret = 0; | |
189 | ||
1aa4bdc8 PM |
190 | ret = dfu_write_buffer_drain(dfu); |
191 | if (ret) | |
192 | return ret; | |
193 | ||
a2199afe HS |
194 | if (dfu->flush_medium) |
195 | ret = dfu->flush_medium(dfu); | |
196 | ||
bd694244 ŁM |
197 | if (dfu_hash_algo) |
198 | printf("\nDFU complete %s: 0x%08x\n", dfu_hash_algo->name, | |
199 | dfu->crc); | |
a2199afe | 200 | |
3ee9593f | 201 | dfu_write_transaction_cleanup(dfu); |
a2199afe HS |
202 | |
203 | return ret; | |
204 | } | |
205 | ||
f22b11c1 ŁM |
206 | int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) |
207 | { | |
3ee9593f | 208 | int ret; |
f22b11c1 | 209 | |
ea2453d5 PA |
210 | debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x offset: 0x%llx bufoffset: 0x%x\n", |
211 | __func__, dfu->name, buf, size, blk_seq_num, dfu->offset, | |
212 | dfu->i_buf - dfu->i_buf_start); | |
f22b11c1 | 213 | |
ea2453d5 PA |
214 | if (!dfu->inited) { |
215 | /* initial state */ | |
216 | dfu->crc = 0; | |
217 | dfu->offset = 0; | |
c6631764 | 218 | dfu->bad_skip = 0; |
ea2453d5 | 219 | dfu->i_blk_seq_num = 0; |
7ac1b410 | 220 | dfu->i_buf_start = dfu_get_buf(dfu); |
e7e75c70 HS |
221 | if (dfu->i_buf_start == NULL) |
222 | return -ENOMEM; | |
7ac1b410 | 223 | dfu->i_buf_end = dfu_get_buf(dfu) + dfu_buf_size; |
ea2453d5 PA |
224 | dfu->i_buf = dfu->i_buf_start; |
225 | ||
226 | dfu->inited = 1; | |
f22b11c1 ŁM |
227 | } |
228 | ||
ea2453d5 | 229 | if (dfu->i_blk_seq_num != blk_seq_num) { |
f22b11c1 | 230 | printf("%s: Wrong sequence number! [%d] [%d]\n", |
ea2453d5 | 231 | __func__, dfu->i_blk_seq_num, blk_seq_num); |
3ee9593f | 232 | dfu_write_transaction_cleanup(dfu); |
f22b11c1 ŁM |
233 | return -1; |
234 | } | |
235 | ||
ea2453d5 PA |
236 | /* DFU 1.1 standard says: |
237 | * The wBlockNum field is a block sequence number. It increments each | |
238 | * time a block is transferred, wrapping to zero from 65,535. It is used | |
239 | * to provide useful context to the DFU loader in the device." | |
240 | * | |
241 | * This means that it's a 16 bit counter that roll-overs at | |
242 | * 0xffff -> 0x0000. By having a typical 4K transfer block | |
243 | * we roll-over at exactly 256MB. Not very fun to debug. | |
244 | * | |
245 | * Handling rollover, and having an inited variable, | |
246 | * makes things work. | |
247 | */ | |
248 | ||
249 | /* handle rollover */ | |
250 | dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff; | |
251 | ||
252 | /* flush buffer if overflow */ | |
253 | if ((dfu->i_buf + size) > dfu->i_buf_end) { | |
3ee9593f SW |
254 | ret = dfu_write_buffer_drain(dfu); |
255 | if (ret) { | |
256 | dfu_write_transaction_cleanup(dfu); | |
257 | return ret; | |
258 | } | |
ea2453d5 | 259 | } |
f22b11c1 | 260 | |
ea2453d5 PA |
261 | /* we should be in buffer now (if not then size too large) */ |
262 | if ((dfu->i_buf + size) > dfu->i_buf_end) { | |
a7d2c3cd ŁM |
263 | error("Buffer overflow! (0x%p + 0x%x > 0x%p)\n", dfu->i_buf, |
264 | size, dfu->i_buf_end); | |
3ee9593f | 265 | dfu_write_transaction_cleanup(dfu); |
ea2453d5 PA |
266 | return -1; |
267 | } | |
268 | ||
269 | memcpy(dfu->i_buf, buf, size); | |
270 | dfu->i_buf += size; | |
271 | ||
272 | /* if end or if buffer full flush */ | |
273 | if (size == 0 || (dfu->i_buf + size) > dfu->i_buf_end) { | |
3ee9593f SW |
274 | ret = dfu_write_buffer_drain(dfu); |
275 | if (ret) { | |
276 | dfu_write_transaction_cleanup(dfu); | |
277 | return ret; | |
278 | } | |
ea2453d5 PA |
279 | } |
280 | ||
3ee9593f | 281 | return 0; |
ea2453d5 PA |
282 | } |
283 | ||
284 | static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf, int size) | |
285 | { | |
286 | long chunk; | |
287 | int ret, readn; | |
288 | ||
289 | readn = 0; | |
290 | while (size > 0) { | |
291 | /* get chunk that can be read */ | |
b4141195 | 292 | chunk = min((long)size, dfu->b_left); |
ea2453d5 PA |
293 | /* consume */ |
294 | if (chunk > 0) { | |
295 | memcpy(buf, dfu->i_buf, chunk); | |
bd694244 ŁM |
296 | if (dfu_hash_algo) |
297 | dfu_hash_algo->hash_update(dfu_hash_algo, | |
298 | &dfu->crc, buf, | |
299 | chunk, 0); | |
300 | ||
ea2453d5 PA |
301 | dfu->i_buf += chunk; |
302 | dfu->b_left -= chunk; | |
303 | size -= chunk; | |
304 | buf += chunk; | |
305 | readn += chunk; | |
306 | } | |
307 | ||
308 | /* all done */ | |
309 | if (size > 0) { | |
310 | /* no more to read */ | |
311 | if (dfu->r_left == 0) | |
312 | break; | |
313 | ||
314 | dfu->i_buf = dfu->i_buf_start; | |
315 | dfu->b_left = dfu->i_buf_end - dfu->i_buf_start; | |
316 | ||
317 | /* got to read, but buffer is empty */ | |
318 | if (dfu->b_left > dfu->r_left) | |
319 | dfu->b_left = dfu->r_left; | |
320 | ret = dfu->read_medium(dfu, dfu->offset, dfu->i_buf, | |
321 | &dfu->b_left); | |
322 | if (ret != 0) { | |
323 | debug("%s: Read error!\n", __func__); | |
324 | return ret; | |
325 | } | |
326 | dfu->offset += dfu->b_left; | |
327 | dfu->r_left -= dfu->b_left; | |
328 | ||
329 | puts("#"); | |
330 | } | |
331 | } | |
332 | ||
333 | return readn; | |
f22b11c1 ŁM |
334 | } |
335 | ||
336 | int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) | |
337 | { | |
f22b11c1 ŁM |
338 | int ret = 0; |
339 | ||
340 | debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x i_buf: 0x%p\n", | |
ea2453d5 PA |
341 | __func__, dfu->name, buf, size, blk_seq_num, dfu->i_buf); |
342 | ||
343 | if (!dfu->inited) { | |
7ac1b410 | 344 | dfu->i_buf_start = dfu_get_buf(dfu); |
9df49553 ŁM |
345 | if (dfu->i_buf_start == NULL) |
346 | return -ENOMEM; | |
347 | ||
0e285b50 SW |
348 | dfu->r_left = dfu->get_medium_size(dfu); |
349 | if (dfu->r_left < 0) | |
350 | return dfu->r_left; | |
351 | switch (dfu->layout) { | |
352 | case DFU_RAW_ADDR: | |
353 | case DFU_RAM_ADDR: | |
354 | break; | |
355 | default: | |
67ab0a5e | 356 | if (dfu->r_left > dfu_buf_size) { |
0e285b50 SW |
357 | printf("%s: File too big for buffer\n", |
358 | __func__); | |
359 | return -EOVERFLOW; | |
360 | } | |
ea2453d5 PA |
361 | } |
362 | ||
363 | debug("%s: %s %ld [B]\n", __func__, dfu->name, dfu->r_left); | |
364 | ||
365 | dfu->i_blk_seq_num = 0; | |
366 | dfu->crc = 0; | |
367 | dfu->offset = 0; | |
7ac1b410 | 368 | dfu->i_buf_end = dfu_get_buf(dfu) + dfu_buf_size; |
ea2453d5 | 369 | dfu->i_buf = dfu->i_buf_start; |
0e285b50 | 370 | dfu->b_left = 0; |
ea2453d5 | 371 | |
c6631764 PA |
372 | dfu->bad_skip = 0; |
373 | ||
ea2453d5 | 374 | dfu->inited = 1; |
f22b11c1 ŁM |
375 | } |
376 | ||
ea2453d5 | 377 | if (dfu->i_blk_seq_num != blk_seq_num) { |
f22b11c1 | 378 | printf("%s: Wrong sequence number! [%d] [%d]\n", |
ea2453d5 | 379 | __func__, dfu->i_blk_seq_num, blk_seq_num); |
f22b11c1 ŁM |
380 | return -1; |
381 | } | |
ea2453d5 PA |
382 | /* handle rollover */ |
383 | dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff; | |
f22b11c1 | 384 | |
ea2453d5 PA |
385 | ret = dfu_read_buffer_fill(dfu, buf, size); |
386 | if (ret < 0) { | |
387 | printf("%s: Failed to fill buffer\n", __func__); | |
388 | return -1; | |
f22b11c1 | 389 | } |
ea2453d5 PA |
390 | |
391 | if (ret < size) { | |
bd694244 ŁM |
392 | if (dfu_hash_algo) |
393 | debug("%s: %s %s: 0x%x\n", __func__, dfu->name, | |
394 | dfu_hash_algo->name, dfu->crc); | |
ea2453d5 PA |
395 | puts("\nUPLOAD ... done\nCtrl+C to exit ...\n"); |
396 | ||
e7e75c70 | 397 | dfu_free_buf(); |
ea2453d5 PA |
398 | dfu->i_blk_seq_num = 0; |
399 | dfu->crc = 0; | |
400 | dfu->offset = 0; | |
401 | dfu->i_buf_start = dfu_buf; | |
e7e75c70 | 402 | dfu->i_buf_end = dfu_buf; |
ea2453d5 PA |
403 | dfu->i_buf = dfu->i_buf_start; |
404 | dfu->b_left = 0; | |
405 | ||
c6631764 PA |
406 | dfu->bad_skip = 0; |
407 | ||
ea2453d5 PA |
408 | dfu->inited = 0; |
409 | } | |
410 | ||
f22b11c1 ŁM |
411 | return ret; |
412 | } | |
413 | ||
414 | static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, | |
dd64827e | 415 | char *interface, char *devstr) |
f22b11c1 ŁM |
416 | { |
417 | char *st; | |
418 | ||
dd64827e | 419 | debug("%s: %s interface: %s dev: %s\n", __func__, s, interface, devstr); |
f22b11c1 ŁM |
420 | st = strsep(&s, " "); |
421 | strcpy(dfu->name, st); | |
422 | ||
f22b11c1 | 423 | dfu->alt = alt; |
7ac1b410 | 424 | dfu->max_buf_size = 0; |
cb7bd2e0 | 425 | dfu->free_entity = NULL; |
f22b11c1 ŁM |
426 | |
427 | /* Specific for mmc device */ | |
428 | if (strcmp(interface, "mmc") == 0) { | |
dd64827e | 429 | if (dfu_fill_entity_mmc(dfu, devstr, s)) |
f22b11c1 | 430 | return -1; |
c6631764 | 431 | } else if (strcmp(interface, "nand") == 0) { |
dd64827e | 432 | if (dfu_fill_entity_nand(dfu, devstr, s)) |
c6631764 | 433 | return -1; |
a9479f04 | 434 | } else if (strcmp(interface, "ram") == 0) { |
dd64827e | 435 | if (dfu_fill_entity_ram(dfu, devstr, s)) |
a9479f04 | 436 | return -1; |
6f12ebf6 SW |
437 | } else if (strcmp(interface, "sf") == 0) { |
438 | if (dfu_fill_entity_sf(dfu, devstr, s)) | |
439 | return -1; | |
f22b11c1 ŁM |
440 | } else { |
441 | printf("%s: Device %s not (yet) supported!\n", | |
442 | __func__, interface); | |
443 | return -1; | |
444 | } | |
445 | ||
446 | return 0; | |
447 | } | |
448 | ||
449 | void dfu_free_entities(void) | |
450 | { | |
451 | struct dfu_entity *dfu, *p, *t = NULL; | |
452 | ||
453 | list_for_each_entry_safe_reverse(dfu, p, &dfu_list, list) { | |
454 | list_del(&dfu->list); | |
cb7bd2e0 SW |
455 | if (dfu->free_entity) |
456 | dfu->free_entity(dfu); | |
f22b11c1 ŁM |
457 | t = dfu; |
458 | } | |
459 | if (t) | |
460 | free(t); | |
461 | INIT_LIST_HEAD(&dfu_list); | |
b627eb46 PM |
462 | |
463 | alt_num_cnt = 0; | |
f22b11c1 ŁM |
464 | } |
465 | ||
dd64827e | 466 | int dfu_config_entities(char *env, char *interface, char *devstr) |
f22b11c1 ŁM |
467 | { |
468 | struct dfu_entity *dfu; | |
469 | int i, ret; | |
470 | char *s; | |
471 | ||
472 | dfu_alt_num = dfu_find_alt_num(env); | |
473 | debug("%s: dfu_alt_num=%d\n", __func__, dfu_alt_num); | |
474 | ||
bd694244 ŁM |
475 | dfu_hash_algo = NULL; |
476 | s = dfu_get_hash_algo(); | |
477 | if (s) { | |
478 | ret = hash_lookup_algo(s, &dfu_hash_algo); | |
479 | if (ret) | |
480 | error("Hash algorithm %s not supported\n", s); | |
481 | } | |
482 | ||
f22b11c1 ŁM |
483 | dfu = calloc(sizeof(*dfu), dfu_alt_num); |
484 | if (!dfu) | |
485 | return -1; | |
486 | for (i = 0; i < dfu_alt_num; i++) { | |
487 | ||
488 | s = strsep(&env, ";"); | |
dd64827e SW |
489 | ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface, |
490 | devstr); | |
f22b11c1 ŁM |
491 | if (ret) |
492 | return -1; | |
493 | ||
494 | list_add_tail(&dfu[i].list, &dfu_list); | |
b627eb46 | 495 | alt_num_cnt++; |
f22b11c1 ŁM |
496 | } |
497 | ||
498 | return 0; | |
499 | } | |
500 | ||
501 | const char *dfu_get_dev_type(enum dfu_device_type t) | |
502 | { | |
a9479f04 | 503 | const char *dev_t[] = {NULL, "eMMC", "OneNAND", "NAND", "RAM" }; |
f22b11c1 ŁM |
504 | return dev_t[t]; |
505 | } | |
506 | ||
507 | const char *dfu_get_layout(enum dfu_layout l) | |
508 | { | |
509 | const char *dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2", | |
a9479f04 | 510 | "EXT3", "EXT4", "RAM_ADDR" }; |
f22b11c1 ŁM |
511 | return dfu_layout[l]; |
512 | } | |
513 | ||
514 | void dfu_show_entities(void) | |
515 | { | |
516 | struct dfu_entity *dfu; | |
517 | ||
518 | puts("DFU alt settings list:\n"); | |
519 | ||
520 | list_for_each_entry(dfu, &dfu_list, list) { | |
521 | printf("dev: %s alt: %d name: %s layout: %s\n", | |
522 | dfu_get_dev_type(dfu->dev_type), dfu->alt, | |
523 | dfu->name, dfu_get_layout(dfu->layout)); | |
524 | } | |
525 | } | |
526 | ||
527 | int dfu_get_alt_number(void) | |
528 | { | |
529 | return dfu_alt_num; | |
530 | } | |
531 | ||
532 | struct dfu_entity *dfu_get_entity(int alt) | |
533 | { | |
534 | struct dfu_entity *dfu; | |
535 | ||
536 | list_for_each_entry(dfu, &dfu_list, list) { | |
537 | if (dfu->alt == alt) | |
538 | return dfu; | |
539 | } | |
540 | ||
541 | return NULL; | |
542 | } | |
fed936ed ŁM |
543 | |
544 | int dfu_get_alt(char *name) | |
545 | { | |
546 | struct dfu_entity *dfu; | |
547 | ||
548 | list_for_each_entry(dfu, &dfu_list, list) { | |
549 | if (!strncmp(dfu->name, name, strlen(dfu->name))) | |
550 | return dfu->alt; | |
551 | } | |
552 | ||
553 | return -ENODEV; | |
554 | } |