Blame view
common/cmd_usb.c
16.4 KB
e887afc9d
|
1 2 3 4 5 6 7 |
/* * (C) Copyright 2001 * Denis Peter, MPL AG Switzerland * * Most of this source has been derived from the Linux USB * project. * |
1a4596601
|
8 |
* SPDX-License-Identifier: GPL-2.0+ |
e887afc9d
|
9 10 11 12 |
*/ #include <common.h> #include <command.h> |
414eec35e
|
13 |
#include <asm/byteorder.h> |
b2fb47f18
|
14 |
#include <asm/unaligned.h> |
735dd97b1
|
15 |
#include <part.h> |
e887afc9d
|
16 |
#include <usb.h> |
e887afc9d
|
17 |
|
1968e615d
|
18 |
#ifdef CONFIG_USB_STORAGE |
d0ff51ba5
|
19 |
static int usb_stor_curr_dev = -1; /* current device */ |
1968e615d
|
20 |
#endif |
89d48367e
|
21 22 23 |
#ifdef CONFIG_USB_HOST_ETHER static int usb_ether_curr_dev = -1; /* current ethernet device */ #endif |
e887afc9d
|
24 |
|
a2663ea4f
|
25 |
/* some display routines (info command) */ |
088f1b199
|
26 |
static char *usb_get_class_desc(unsigned char dclass) |
e887afc9d
|
27 |
{ |
de39f8c19
|
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
switch (dclass) { case USB_CLASS_PER_INTERFACE: return "See Interface"; case USB_CLASS_AUDIO: return "Audio"; case USB_CLASS_COMM: return "Communication"; case USB_CLASS_HID: return "Human Interface"; case USB_CLASS_PRINTER: return "Printer"; case USB_CLASS_MASS_STORAGE: return "Mass Storage"; case USB_CLASS_HUB: return "Hub"; case USB_CLASS_DATA: return "CDC Data"; case USB_CLASS_VENDOR_SPEC: return "Vendor specific"; default: return ""; |
e887afc9d
|
49 50 |
} } |
088f1b199
|
51 52 |
static void usb_display_class_sub(unsigned char dclass, unsigned char subclass, unsigned char proto) |
e887afc9d
|
53 |
{ |
de39f8c19
|
54 55 56 57 58 59 60 61 62 |
switch (dclass) { case USB_CLASS_PER_INTERFACE: printf("See Interface"); break; case USB_CLASS_HID: printf("Human Interface, Subclass: "); switch (subclass) { case USB_SUB_HID_NONE: printf("None"); |
e887afc9d
|
63 |
break; |
de39f8c19
|
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
case USB_SUB_HID_BOOT: printf("Boot "); switch (proto) { case USB_PROT_HID_NONE: printf("None"); break; case USB_PROT_HID_KEYBOARD: printf("Keyboard"); break; case USB_PROT_HID_MOUSE: printf("Mouse"); break; default: printf("reserved"); break; |
e887afc9d
|
79 80 |
} break; |
de39f8c19
|
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
default: printf("reserved"); break; } break; case USB_CLASS_MASS_STORAGE: printf("Mass Storage, "); switch (subclass) { case US_SC_RBC: printf("RBC "); break; case US_SC_8020: printf("SFF-8020i (ATAPI)"); break; case US_SC_QIC: printf("QIC-157 (Tape)"); break; case US_SC_UFI: printf("UFI"); break; case US_SC_8070: printf("SFF-8070"); break; case US_SC_SCSI: printf("Transp. SCSI"); break; default: printf("reserved"); break; } printf(", "); switch (proto) { case US_PR_CB: printf("Command/Bulk"); break; case US_PR_CBI: printf("Command/Bulk/Int"); break; case US_PR_BULK: printf("Bulk only"); |
e887afc9d
|
121 122 |
break; default: |
de39f8c19
|
123 124 125 126 127 128 129 |
printf("reserved"); break; } break; default: printf("%s", usb_get_class_desc(dclass)); break; |
e887afc9d
|
130 131 |
} } |
088f1b199
|
132 |
static void usb_display_string(struct usb_device *dev, int index) |
e887afc9d
|
133 |
{ |
f57661394
|
134 |
ALLOC_CACHE_ALIGN_BUFFER(char, buffer, 256); |
de39f8c19
|
135 136 137 |
if (index != 0) { if (usb_string(dev, index, &buffer[0], 256) > 0) printf("String: \"%s\"", buffer); |
e887afc9d
|
138 139 |
} } |
088f1b199
|
140 |
static void usb_display_desc(struct usb_device *dev) |
e887afc9d
|
141 |
{ |
de39f8c19
|
142 143 144 |
if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) { printf("%d: %s, USB Revision %x.%x ", dev->devnum, |
8f8bd565f
|
145 |
usb_get_class_desc(dev->config.if_desc[0].desc.bInterfaceClass), |
de39f8c19
|
146 147 148 149 150 151 152 153 |
(dev->descriptor.bcdUSB>>8) & 0xff, dev->descriptor.bcdUSB & 0xff); if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial)) printf(" - %s %s %s ", dev->mf, dev->prod, dev->serial); |
e887afc9d
|
154 155 |
if (dev->descriptor.bDeviceClass) { printf(" - Class: "); |
de39f8c19
|
156 157 158 |
usb_display_class_sub(dev->descriptor.bDeviceClass, dev->descriptor.bDeviceSubClass, dev->descriptor.bDeviceProtocol); |
e887afc9d
|
159 160 |
printf(" "); |
de39f8c19
|
161 162 163 164 |
} else { printf(" - Class: (from Interface) %s ", usb_get_class_desc( |
8f8bd565f
|
165 |
dev->config.if_desc[0].desc.bInterfaceClass)); |
e887afc9d
|
166 |
} |
de39f8c19
|
167 168 169 170 171 172 173 174 175 |
printf(" - PacketSize: %d Configurations: %d ", dev->descriptor.bMaxPacketSize0, dev->descriptor.bNumConfigurations); printf(" - Vendor: 0x%04x Product 0x%04x Version %d.%d ", dev->descriptor.idVendor, dev->descriptor.idProduct, (dev->descriptor.bcdDevice>>8) & 0xff, dev->descriptor.bcdDevice & 0xff); |
e887afc9d
|
176 177 178 |
} } |
c60795f41
|
179 |
static void usb_display_conf_desc(struct usb_config_descriptor *config, |
088f1b199
|
180 |
struct usb_device *dev) |
e887afc9d
|
181 |
{ |
de39f8c19
|
182 183 184 185 186 187 |
printf(" Configuration: %d ", config->bConfigurationValue); printf(" - Interfaces: %d %s%s%dmA ", config->bNumInterfaces, (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ", (config->bmAttributes & 0x20) ? "Remote Wakeup " : "", |
8f8bd565f
|
188 |
config->bMaxPower*2); |
e887afc9d
|
189 190 |
if (config->iConfiguration) { printf(" - "); |
de39f8c19
|
191 |
usb_display_string(dev, config->iConfiguration); |
e887afc9d
|
192 193 194 195 |
printf(" "); } } |
088f1b199
|
196 197 |
static void usb_display_if_desc(struct usb_interface_descriptor *ifdesc, struct usb_device *dev) |
e887afc9d
|
198 |
{ |
de39f8c19
|
199 200 201 202 203 |
printf(" Interface: %d ", ifdesc->bInterfaceNumber); printf(" - Alternate Setting %d, Endpoints: %d ", ifdesc->bAlternateSetting, ifdesc->bNumEndpoints); |
e887afc9d
|
204 |
printf(" - Class "); |
de39f8c19
|
205 206 |
usb_display_class_sub(ifdesc->bInterfaceClass, ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol); |
e887afc9d
|
207 208 209 210 |
printf(" "); if (ifdesc->iInterface) { printf(" - "); |
de39f8c19
|
211 |
usb_display_string(dev, ifdesc->iInterface); |
e887afc9d
|
212 213 214 215 |
printf(" "); } } |
088f1b199
|
216 |
static void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc) |
e887afc9d
|
217 |
{ |
de39f8c19
|
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
printf(" - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf, (epdesc->bEndpointAddress & 0x80) ? "In" : "Out"); switch ((epdesc->bmAttributes & 0x03)) { case 0: printf("Control"); break; case 1: printf("Isochronous"); break; case 2: printf("Bulk"); break; case 3: printf("Interrupt"); break; |
e887afc9d
|
233 |
} |
b2fb47f18
|
234 |
printf(" MaxPacket %d", get_unaligned(&epdesc->wMaxPacketSize)); |
de39f8c19
|
235 236 |
if ((epdesc->bmAttributes & 0x03) == 0x3) printf(" Interval %dms", epdesc->bInterval); |
e887afc9d
|
237 238 239 240 241 |
printf(" "); } /* main routine to diasplay the configs, interfaces and endpoints */ |
088f1b199
|
242 |
static void usb_display_config(struct usb_device *dev) |
e887afc9d
|
243 |
{ |
8f8bd565f
|
244 245 |
struct usb_config *config; struct usb_interface *ifdesc; |
e887afc9d
|
246 |
struct usb_endpoint_descriptor *epdesc; |
de39f8c19
|
247 248 249 |
int i, ii; config = &dev->config; |
8f8bd565f
|
250 |
usb_display_conf_desc(&config->desc, dev); |
de39f8c19
|
251 252 |
for (i = 0; i < config->no_of_if; i++) { ifdesc = &config->if_desc[i]; |
8f8bd565f
|
253 |
usb_display_if_desc(&ifdesc->desc, dev); |
de39f8c19
|
254 255 |
for (ii = 0; ii < ifdesc->no_of_ep; ii++) { epdesc = &ifdesc->ep_desc[ii]; |
e887afc9d
|
256 257 258 259 260 261 |
usb_display_ep_desc(epdesc); } } printf(" "); } |
7d9aa8fd8
|
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
static struct usb_device *usb_find_device(int devnum) { struct usb_device *dev; int d; for (d = 0; d < USB_MAX_DEVICE; d++) { dev = usb_get_dev_index(d); if (dev == NULL) return NULL; if (dev->devnum == devnum) return dev; } return NULL; } |
f1c1f5402
|
277 278 |
static inline char *portspeed(int speed) { |
6497c6670
|
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
char *speed_str; switch (speed) { case USB_SPEED_SUPER: speed_str = "5 Gb/s"; break; case USB_SPEED_HIGH: speed_str = "480 Mb/s"; break; case USB_SPEED_LOW: speed_str = "1.5 Mb/s"; break; default: speed_str = "12 Mb/s"; break; } return speed_str; |
f1c1f5402
|
297 |
} |
e887afc9d
|
298 |
/* shows the device tree recursively */ |
088f1b199
|
299 |
static void usb_show_tree_graph(struct usb_device *dev, char *pre) |
e887afc9d
|
300 |
{ |
de39f8c19
|
301 |
int i, index; |
10f4dd784
|
302 |
int has_child, last_child; |
e887afc9d
|
303 |
|
de39f8c19
|
304 305 |
index = strlen(pre); printf(" %s", pre); |
e887afc9d
|
306 |
/* check if the device has connected children */ |
de39f8c19
|
307 308 309 310 |
has_child = 0; for (i = 0; i < dev->maxchild; i++) { if (dev->children[i] != NULL) has_child = 1; |
e887afc9d
|
311 312 |
} /* check if we are the last one */ |
de39f8c19
|
313 314 315 |
last_child = 1; if (dev->parent != NULL) { for (i = 0; i < dev->parent->maxchild; i++) { |
e887afc9d
|
316 |
/* search for children */ |
de39f8c19
|
317 318 319 320 |
if (dev->parent->children[i] == dev) { /* found our pointer, see if we have a * little sister */ |
de39f8c19
|
321 322 |
while (i++ < dev->parent->maxchild) { if (dev->parent->children[i] != NULL) { |
e887afc9d
|
323 |
/* found a sister */ |
de39f8c19
|
324 |
last_child = 0; |
e887afc9d
|
325 326 327 328 329 330 331 |
break; } /* if */ } /* while */ } /* device found */ } /* for all children of the parent */ printf("\b+-"); /* correct last child */ |
de39f8c19
|
332 333 |
if (last_child) pre[index-1] = ' '; |
e887afc9d
|
334 335 336 |
} /* if not root hub */ else printf(" "); |
de39f8c19
|
337 338 339 340 341 342 |
printf("%d ", dev->devnum); pre[index++] = ' '; pre[index++] = has_child ? '|' : ' '; pre[index] = 0; printf(" %s (%s, %dmA) ", usb_get_class_desc( |
8f8bd565f
|
343 |
dev->config.if_desc[0].desc.bInterfaceClass), |
f1c1f5402
|
344 |
portspeed(dev->speed), |
8f8bd565f
|
345 |
dev->config.desc.bMaxPower * 2); |
de39f8c19
|
346 347 348 349 350 351 352 353 354 355 |
if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial)) printf(" %s %s %s %s ", pre, dev->mf, dev->prod, dev->serial); printf(" %s ", pre); if (dev->maxchild > 0) { for (i = 0; i < dev->maxchild; i++) { if (dev->children[i] != NULL) { usb_show_tree_graph(dev->children[i], pre); pre[index] = 0; |
e887afc9d
|
356 357 358 359 360 361 |
} } } } /* main routine for the tree command */ |
088f1b199
|
362 |
static void usb_show_tree(struct usb_device *dev) |
e887afc9d
|
363 364 |
{ char preamble[32]; |
de39f8c19
|
365 366 |
memset(preamble, 0, 32); usb_show_tree_graph(dev, &preamble[0]); |
e887afc9d
|
367 |
} |
7d9aa8fd8
|
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
static int usb_test(struct usb_device *dev, int port, char* arg) { int mode; if (port > dev->maxchild) { printf("Device is no hub or does not have %d ports. ", port); return 1; } switch (arg[0]) { case 'J': case 'j': printf("Setting Test_J mode"); mode = USB_TEST_MODE_J; break; case 'K': case 'k': printf("Setting Test_K mode"); mode = USB_TEST_MODE_K; break; case 'S': case 's': printf("Setting Test_SE0_NAK mode"); mode = USB_TEST_MODE_SE0_NAK; break; case 'P': case 'p': printf("Setting Test_Packet mode"); mode = USB_TEST_MODE_PACKET; break; case 'F': case 'f': printf("Setting Test_Force_Enable mode"); mode = USB_TEST_MODE_FORCE_ENABLE; break; default: printf("Unrecognized test mode: %s Available modes: " "J, K, S[E0_NAK], P[acket], F[orce_Enable] ", arg); return 1; } if (port) printf(" on downstream facing port %d... ", port); else printf(" on upstream facing port... "); if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_FEATURE, port ? USB_RT_PORT : USB_RECIP_DEVICE, port ? USB_PORT_FEAT_TEST : USB_FEAT_TEST, (mode << 8) | port, NULL, 0, USB_CNTL_TIMEOUT) == -1) { printf("Error during SET_FEATURE. "); return 1; } else { printf("Test mode successfully set. Use 'usb start' " "to return to normal operation. "); return 0; } } |
e887afc9d
|
434 |
|
e887afc9d
|
435 436 437 438 |
/****************************************************************************** * usb boot command intepreter. Derived from diskboot */ #ifdef CONFIG_USB_STORAGE |
088f1b199
|
439 |
static int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
e887afc9d
|
440 |
{ |
7405a1331
|
441 |
return common_diskboot(cmdtp, "usb", argc, argv); |
e887afc9d
|
442 443 |
} #endif /* CONFIG_USB_STORAGE */ |
de39f8c19
|
444 |
/****************************************************************************** |
e887afc9d
|
445 446 |
* usb command intepreter */ |
088f1b199
|
447 |
static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
e887afc9d
|
448 449 450 451 |
{ int i; struct usb_device *dev = NULL; |
e51aae382
|
452 |
extern char usb_started; |
1968e615d
|
453 |
#ifdef CONFIG_USB_STORAGE |
e887afc9d
|
454 |
block_dev_desc_t *stor_dev; |
1968e615d
|
455 |
#endif |
e887afc9d
|
456 |
|
47e26b1bf
|
457 |
if (argc < 2) |
4c12eeb8b
|
458 |
return CMD_RET_USAGE; |
65d342541
|
459 |
|
9c998aa83
|
460 |
if ((strncmp(argv[1], "reset", 5) == 0) || |
de39f8c19
|
461 |
(strncmp(argv[1], "start", 5) == 0)) { |
573f14fe4
|
462 |
bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start"); |
e887afc9d
|
463 464 465 |
usb_stop(); printf("(Re)start USB... "); |
93c2582fe
|
466 |
if (usb_init() >= 0) { |
9c998aa83
|
467 |
#ifdef CONFIG_USB_STORAGE |
89d48367e
|
468 |
/* try to recognize storage devices immediately */ |
53677ef18
|
469 |
usb_stor_curr_dev = usb_stor_scan(1); |
9c998aa83
|
470 |
#endif |
89d48367e
|
471 472 473 474 |
#ifdef CONFIG_USB_HOST_ETHER /* try to recognize ethernet devices immediately */ usb_ether_curr_dev = usb_host_eth_scan(1); #endif |
93c2582fe
|
475 476 477 |
#ifdef CONFIG_USB_KEYBOARD drv_usb_kbd_init(); #endif |
89d48367e
|
478 |
} |
e887afc9d
|
479 480 |
return 0; } |
de39f8c19
|
481 |
if (strncmp(argv[1], "stop", 4) == 0) { |
e887afc9d
|
482 |
#ifdef CONFIG_USB_KEYBOARD |
de39f8c19
|
483 484 485 486 487 |
if (argc == 2) { if (usb_kbd_deregister() != 0) { printf("USB not stopped: usbkbd still" " using USB "); |
e887afc9d
|
488 489 |
return 1; } |
de39f8c19
|
490 491 492 |
} else { /* forced stop, switch console in to serial */ console_assign(stdin, "serial"); |
e887afc9d
|
493 494 495 496 497 498 499 500 |
usb_kbd_deregister(); } #endif printf("stopping USB.. "); usb_stop(); return 0; } |
e51aae382
|
501 502 503 504 505 |
if (!usb_started) { printf("USB is stopped. Please issue 'usb start' first. "); return 1; } |
de39f8c19
|
506 |
if (strncmp(argv[1], "tree", 4) == 0) { |
93c2582fe
|
507 508 509 510 511 512 513 514 515 |
puts("USB device tree: "); for (i = 0; i < USB_MAX_DEVICE; i++) { dev = usb_get_dev_index(i); if (dev == NULL) break; if (dev->parent == NULL) usb_show_tree(dev); } |
e887afc9d
|
516 517 |
return 0; } |
de39f8c19
|
518 |
if (strncmp(argv[1], "inf", 3) == 0) { |
e887afc9d
|
519 |
int d; |
de39f8c19
|
520 521 522 523 |
if (argc == 2) { for (d = 0; d < USB_MAX_DEVICE; d++) { dev = usb_get_dev_index(d); if (dev == NULL) |
e887afc9d
|
524 525 526 527 528 |
break; usb_display_desc(dev); usb_display_config(dev); } return 0; |
de39f8c19
|
529 |
} else { |
7d9aa8fd8
|
530 |
i = simple_strtoul(argv[2], NULL, 10); |
de39f8c19
|
531 532 |
printf("config for device %d ", i); |
7d9aa8fd8
|
533 |
dev = usb_find_device(i); |
de39f8c19
|
534 |
if (dev == NULL) { |
6052cbab4
|
535 536 |
printf("*** No device available *** "); |
e887afc9d
|
537 |
return 0; |
de39f8c19
|
538 |
} else { |
e887afc9d
|
539 540 541 542 543 544 |
usb_display_desc(dev); usb_display_config(dev); } } return 0; } |
7d9aa8fd8
|
545 546 547 548 549 550 551 552 553 554 555 556 557 |
if (strncmp(argv[1], "test", 4) == 0) { if (argc < 5) return CMD_RET_USAGE; i = simple_strtoul(argv[2], NULL, 10); dev = usb_find_device(i); if (dev == NULL) { printf("Device %d does not exist. ", i); return 1; } i = simple_strtoul(argv[3], NULL, 10); return usb_test(dev, i, argv[4]); } |
e887afc9d
|
558 |
#ifdef CONFIG_USB_STORAGE |
de39f8c19
|
559 |
if (strncmp(argv[1], "stor", 4) == 0) |
f6b44e0e4
|
560 |
return usb_stor_info(); |
9c998aa83
|
561 |
|
de39f8c19
|
562 |
if (strncmp(argv[1], "part", 4) == 0) { |
d4b5f3fa0
|
563 |
int devno, ok = 0; |
de39f8c19
|
564 |
if (argc == 2) { |
aaad108b8
|
565 |
for (devno = 0; ; ++devno) { |
de39f8c19
|
566 |
stor_dev = usb_stor_get_dev(devno); |
aaad108b8
|
567 568 |
if (stor_dev == NULL) break; |
de39f8c19
|
569 |
if (stor_dev->type != DEV_TYPE_UNKNOWN) { |
d4b5f3fa0
|
570 571 572 573 |
ok++; if (devno) printf(" "); |
060f28532
|
574 575 |
debug("print_part of %x ", devno); |
d4b5f3fa0
|
576 577 578 |
print_part(stor_dev); } } |
de39f8c19
|
579 580 581 |
} else { devno = simple_strtoul(argv[2], NULL, 16); stor_dev = usb_stor_get_dev(devno); |
aaad108b8
|
582 583 |
if (stor_dev != NULL && stor_dev->type != DEV_TYPE_UNKNOWN) { |
e887afc9d
|
584 |
ok++; |
060f28532
|
585 586 |
debug("print_part of %x ", devno); |
e887afc9d
|
587 588 589 590 591 592 593 594 595 596 597 |
print_part(stor_dev); } } if (!ok) { printf(" no USB devices available "); return 1; } return 0; } |
de39f8c19
|
598 599 |
if (strcmp(argv[1], "read") == 0) { if (usb_stor_curr_dev < 0) { |
e887afc9d
|
600 601 602 603 |
printf("no current device selected "); return 1; } |
de39f8c19
|
604 |
if (argc == 5) { |
e887afc9d
|
605 606 607 608 |
unsigned long addr = simple_strtoul(argv[2], NULL, 16); unsigned long blk = simple_strtoul(argv[3], NULL, 16); unsigned long cnt = simple_strtoul(argv[4], NULL, 16); unsigned long n; |
de39f8c19
|
609 610 611 612 613 614 615 616 617 618 |
printf(" USB read: device %d block # %ld, count %ld" " ... ", usb_stor_curr_dev, blk, cnt); stor_dev = usb_stor_get_dev(usb_stor_curr_dev); n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt, (ulong *)addr); printf("%ld blocks read: %s ", n, (n == cnt) ? "OK" : "ERROR"); if (n == cnt) |
e887afc9d
|
619 620 621 622 |
return 0; return 1; } } |
127e10842
|
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
if (strcmp(argv[1], "write") == 0) { if (usb_stor_curr_dev < 0) { printf("no current device selected "); return 1; } if (argc == 5) { unsigned long addr = simple_strtoul(argv[2], NULL, 16); unsigned long blk = simple_strtoul(argv[3], NULL, 16); unsigned long cnt = simple_strtoul(argv[4], NULL, 16); unsigned long n; printf(" USB write: device %d block # %ld, count %ld" " ... ", usb_stor_curr_dev, blk, cnt); stor_dev = usb_stor_get_dev(usb_stor_curr_dev); n = stor_dev->block_write(usb_stor_curr_dev, blk, cnt, (ulong *)addr); printf("%ld blocks write: %s ", n, (n == cnt) ? "OK" : "ERROR"); if (n == cnt) return 0; return 1; } } |
9c998aa83
|
648 649 |
if (strncmp(argv[1], "dev", 3) == 0) { if (argc == 3) { |
e887afc9d
|
650 |
int dev = (int)simple_strtoul(argv[2], NULL, 10); |
de39f8c19
|
651 652 |
printf(" USB device %d: ", dev); |
aaad108b8
|
653 654 |
stor_dev = usb_stor_get_dev(dev); if (stor_dev == NULL) { |
e887afc9d
|
655 656 657 658 |
printf("unknown device "); return 1; } |
de39f8c19
|
659 660 |
printf(" Device %d: ", dev); |
e887afc9d
|
661 |
dev_print(stor_dev); |
de39f8c19
|
662 |
if (stor_dev->type == DEV_TYPE_UNKNOWN) |
e887afc9d
|
663 |
return 1; |
e887afc9d
|
664 665 666 667 |
usb_stor_curr_dev = dev; printf("... is now current device "); return 0; |
de39f8c19
|
668 669 670 671 |
} else { printf(" USB device %d: ", usb_stor_curr_dev); stor_dev = usb_stor_get_dev(usb_stor_curr_dev); |
e887afc9d
|
672 |
dev_print(stor_dev); |
de39f8c19
|
673 |
if (stor_dev->type == DEV_TYPE_UNKNOWN) |
e887afc9d
|
674 |
return 1; |
e887afc9d
|
675 676 677 678 679 |
return 0; } return 0; } #endif /* CONFIG_USB_STORAGE */ |
4c12eeb8b
|
680 |
return CMD_RET_USAGE; |
e887afc9d
|
681 |
} |
0d4983930
|
682 683 |
U_BOOT_CMD( usb, 5, 1, do_usb, |
2fb2604d5
|
684 |
"USB sub-system", |
1af9f9633
|
685 686 687 688 |
"start - start (scan) USB controller " "usb reset - reset (rescan) USB controller " |
b3813a221
|
689 690 691 692 |
"usb stop [f] - stop USB [f]=force stop " "usb tree - show USB device tree " |
5cf91d6bd
|
693 694 |
"usb info [dev] - show available USB devices " |
7d9aa8fd8
|
695 696 697 698 699 700 701 |
"usb test [dev] [port] [mode] - set USB 2.0 test mode " " (specify port 0 to indicate the device's upstream port) " " Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable] " #ifdef CONFIG_USB_STORAGE |
b3813a221
|
702 703 |
"usb storage - show details of USB storage devices " |
342717f72
|
704 705 |
"usb dev [dev] - show or set current USB storage device " |
de39f8c19
|
706 |
"usb part [dev] - print partition table of one or all USB storage" |
7d9aa8fd8
|
707 708 |
" devices " |
5cf91d6bd
|
709 710 |
"usb read addr blk# cnt - read `cnt' blocks starting at block `blk#' " |
842404ea0
|
711 712 |
" to memory address `addr' " |
127e10842
|
713 714 715 |
"usb write addr blk# cnt - write `cnt' blocks starting at block `blk#' " " from memory address `addr'" |
7d9aa8fd8
|
716 |
#endif /* CONFIG_USB_STORAGE */ |
8bde7f776
|
717 |
); |
7d9aa8fd8
|
718 |
#ifdef CONFIG_USB_STORAGE |
0d4983930
|
719 720 |
U_BOOT_CMD( usbboot, 3, 1, do_usbboot, |
2fb2604d5
|
721 |
"boot from USB device", |
a89c33db9
|
722 |
"loadAddr dev:part" |
8bde7f776
|
723 |
); |
7d9aa8fd8
|
724 |
#endif /* CONFIG_USB_STORAGE */ |