cmd_usb.c 17 KB

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