cmd_usb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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 <part.h>
  31. #include <usb.h>
  32. #ifdef CONFIG_USB_STORAGE
  33. static int usb_stor_curr_dev = -1; /* current device */
  34. #endif
  35. /* some display routines (info command) */
  36. char *usb_get_class_desc(unsigned char dclass)
  37. {
  38. switch (dclass) {
  39. case USB_CLASS_PER_INTERFACE:
  40. return "See Interface";
  41. case USB_CLASS_AUDIO:
  42. return "Audio";
  43. case USB_CLASS_COMM:
  44. return "Communication";
  45. case USB_CLASS_HID:
  46. return "Human Interface";
  47. case USB_CLASS_PRINTER:
  48. return "Printer";
  49. case USB_CLASS_MASS_STORAGE:
  50. return "Mass Storage";
  51. case USB_CLASS_HUB:
  52. return "Hub";
  53. case USB_CLASS_DATA:
  54. return "CDC Data";
  55. case USB_CLASS_VENDOR_SPEC:
  56. return "Vendor specific";
  57. default:
  58. return "";
  59. }
  60. }
  61. void usb_display_class_sub(unsigned char dclass, unsigned char subclass,
  62. unsigned char proto)
  63. {
  64. switch (dclass) {
  65. case USB_CLASS_PER_INTERFACE:
  66. printf("See Interface");
  67. break;
  68. case USB_CLASS_HID:
  69. printf("Human Interface, Subclass: ");
  70. switch (subclass) {
  71. case USB_SUB_HID_NONE:
  72. printf("None");
  73. break;
  74. case USB_SUB_HID_BOOT:
  75. printf("Boot ");
  76. switch (proto) {
  77. case USB_PROT_HID_NONE:
  78. printf("None");
  79. break;
  80. case USB_PROT_HID_KEYBOARD:
  81. printf("Keyboard");
  82. break;
  83. case USB_PROT_HID_MOUSE:
  84. printf("Mouse");
  85. break;
  86. default:
  87. printf("reserved");
  88. break;
  89. }
  90. break;
  91. default:
  92. printf("reserved");
  93. break;
  94. }
  95. break;
  96. case USB_CLASS_MASS_STORAGE:
  97. printf("Mass Storage, ");
  98. switch (subclass) {
  99. case US_SC_RBC:
  100. printf("RBC ");
  101. break;
  102. case US_SC_8020:
  103. printf("SFF-8020i (ATAPI)");
  104. break;
  105. case US_SC_QIC:
  106. printf("QIC-157 (Tape)");
  107. break;
  108. case US_SC_UFI:
  109. printf("UFI");
  110. break;
  111. case US_SC_8070:
  112. printf("SFF-8070");
  113. break;
  114. case US_SC_SCSI:
  115. printf("Transp. SCSI");
  116. break;
  117. default:
  118. printf("reserved");
  119. break;
  120. }
  121. printf(", ");
  122. switch (proto) {
  123. case US_PR_CB:
  124. printf("Command/Bulk");
  125. break;
  126. case US_PR_CBI:
  127. printf("Command/Bulk/Int");
  128. break;
  129. case US_PR_BULK:
  130. printf("Bulk only");
  131. break;
  132. default:
  133. printf("reserved");
  134. break;
  135. }
  136. break;
  137. default:
  138. printf("%s", usb_get_class_desc(dclass));
  139. break;
  140. }
  141. }
  142. void usb_display_string(struct usb_device *dev, int index)
  143. {
  144. char buffer[256];
  145. if (index != 0) {
  146. if (usb_string(dev, index, &buffer[0], 256) > 0)
  147. printf("String: \"%s\"", buffer);
  148. }
  149. }
  150. void usb_display_desc(struct usb_device *dev)
  151. {
  152. if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) {
  153. printf("%d: %s, USB Revision %x.%x\n", dev->devnum,
  154. usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
  155. (dev->descriptor.bcdUSB>>8) & 0xff,
  156. dev->descriptor.bcdUSB & 0xff);
  157. if (strlen(dev->mf) || strlen(dev->prod) ||
  158. strlen(dev->serial))
  159. printf(" - %s %s %s\n", dev->mf, dev->prod,
  160. dev->serial);
  161. if (dev->descriptor.bDeviceClass) {
  162. printf(" - Class: ");
  163. usb_display_class_sub(dev->descriptor.bDeviceClass,
  164. dev->descriptor.bDeviceSubClass,
  165. dev->descriptor.bDeviceProtocol);
  166. printf("\n");
  167. } else {
  168. printf(" - Class: (from Interface) %s\n",
  169. usb_get_class_desc(
  170. dev->config.if_desc[0].bInterfaceClass));
  171. }
  172. printf(" - PacketSize: %d Configurations: %d\n",
  173. dev->descriptor.bMaxPacketSize0,
  174. dev->descriptor.bNumConfigurations);
  175. printf(" - Vendor: 0x%04x Product 0x%04x Version %d.%d\n",
  176. dev->descriptor.idVendor, dev->descriptor.idProduct,
  177. (dev->descriptor.bcdDevice>>8) & 0xff,
  178. dev->descriptor.bcdDevice & 0xff);
  179. }
  180. }
  181. void usb_display_conf_desc(struct usb_config_descriptor *config,
  182. struct usb_device *dev)
  183. {
  184. printf(" Configuration: %d\n", config->bConfigurationValue);
  185. printf(" - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces,
  186. (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
  187. (config->bmAttributes & 0x20) ? "Remote Wakeup " : "",
  188. config->MaxPower*2);
  189. if (config->iConfiguration) {
  190. printf(" - ");
  191. usb_display_string(dev, config->iConfiguration);
  192. printf("\n");
  193. }
  194. }
  195. void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,
  196. struct usb_device *dev)
  197. {
  198. printf(" Interface: %d\n", ifdesc->bInterfaceNumber);
  199. printf(" - Alternate Setting %d, Endpoints: %d\n",
  200. ifdesc->bAlternateSetting, ifdesc->bNumEndpoints);
  201. printf(" - Class ");
  202. usb_display_class_sub(ifdesc->bInterfaceClass,
  203. ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol);
  204. printf("\n");
  205. if (ifdesc->iInterface) {
  206. printf(" - ");
  207. usb_display_string(dev, ifdesc->iInterface);
  208. printf("\n");
  209. }
  210. }
  211. void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
  212. {
  213. printf(" - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf,
  214. (epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
  215. switch ((epdesc->bmAttributes & 0x03)) {
  216. case 0:
  217. printf("Control");
  218. break;
  219. case 1:
  220. printf("Isochronous");
  221. break;
  222. case 2:
  223. printf("Bulk");
  224. break;
  225. case 3:
  226. printf("Interrupt");
  227. break;
  228. }
  229. printf(" MaxPacket %d", epdesc->wMaxPacketSize);
  230. if ((epdesc->bmAttributes & 0x03) == 0x3)
  231. printf(" Interval %dms", epdesc->bInterval);
  232. printf("\n");
  233. }
  234. /* main routine to diasplay the configs, interfaces and endpoints */
  235. void usb_display_config(struct usb_device *dev)
  236. {
  237. struct usb_config_descriptor *config;
  238. struct usb_interface_descriptor *ifdesc;
  239. struct usb_endpoint_descriptor *epdesc;
  240. int i, ii;
  241. config = &dev->config;
  242. usb_display_conf_desc(config, dev);
  243. for (i = 0; i < config->no_of_if; i++) {
  244. ifdesc = &config->if_desc[i];
  245. usb_display_if_desc(ifdesc, dev);
  246. for (ii = 0; ii < ifdesc->no_of_ep; ii++) {
  247. epdesc = &ifdesc->ep_desc[ii];
  248. usb_display_ep_desc(epdesc);
  249. }
  250. }
  251. printf("\n");
  252. }
  253. static inline char *portspeed(int speed)
  254. {
  255. if (speed == USB_SPEED_HIGH)
  256. return "480 Mb/s";
  257. else if (speed == USB_SPEED_LOW)
  258. return "1.5 Mb/s";
  259. else
  260. return "12 Mb/s";
  261. }
  262. /* shows the device tree recursively */
  263. void usb_show_tree_graph(struct usb_device *dev, char *pre)
  264. {
  265. int i, index;
  266. int has_child, last_child, port;
  267. index = strlen(pre);
  268. printf(" %s", pre);
  269. /* check if the device has connected children */
  270. has_child = 0;
  271. for (i = 0; i < dev->maxchild; i++) {
  272. if (dev->children[i] != NULL)
  273. has_child = 1;
  274. }
  275. /* check if we are the last one */
  276. last_child = 1;
  277. if (dev->parent != NULL) {
  278. for (i = 0; i < dev->parent->maxchild; i++) {
  279. /* search for children */
  280. if (dev->parent->children[i] == dev) {
  281. /* found our pointer, see if we have a
  282. * little sister
  283. */
  284. port = i;
  285. while (i++ < dev->parent->maxchild) {
  286. if (dev->parent->children[i] != NULL) {
  287. /* found a sister */
  288. last_child = 0;
  289. break;
  290. } /* if */
  291. } /* while */
  292. } /* device found */
  293. } /* for all children of the parent */
  294. printf("\b+-");
  295. /* correct last child */
  296. if (last_child)
  297. pre[index-1] = ' ';
  298. } /* if not root hub */
  299. else
  300. printf(" ");
  301. printf("%d ", dev->devnum);
  302. pre[index++] = ' ';
  303. pre[index++] = has_child ? '|' : ' ';
  304. pre[index] = 0;
  305. printf(" %s (%s, %dmA)\n", usb_get_class_desc(
  306. dev->config.if_desc[0].bInterfaceClass),
  307. portspeed(dev->speed),
  308. dev->config.MaxPower * 2);
  309. if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
  310. printf(" %s %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
  311. printf(" %s\n", pre);
  312. if (dev->maxchild > 0) {
  313. for (i = 0; i < dev->maxchild; i++) {
  314. if (dev->children[i] != NULL) {
  315. usb_show_tree_graph(dev->children[i], pre);
  316. pre[index] = 0;
  317. }
  318. }
  319. }
  320. }
  321. /* main routine for the tree command */
  322. void usb_show_tree(struct usb_device *dev)
  323. {
  324. char preamble[32];
  325. memset(preamble, 0, 32);
  326. usb_show_tree_graph(dev, &preamble[0]);
  327. }
  328. /******************************************************************************
  329. * usb boot command intepreter. Derived from diskboot
  330. */
  331. #ifdef CONFIG_USB_STORAGE
  332. int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  333. {
  334. char *boot_device = NULL;
  335. char *ep;
  336. int dev, part = 1, rcode;
  337. ulong addr, cnt;
  338. disk_partition_t info;
  339. image_header_t *hdr;
  340. block_dev_desc_t *stor_dev;
  341. #if defined(CONFIG_FIT)
  342. const void *fit_hdr = NULL;
  343. #endif
  344. switch (argc) {
  345. case 1:
  346. addr = CONFIG_SYS_LOAD_ADDR;
  347. boot_device = getenv("bootdevice");
  348. break;
  349. case 2:
  350. addr = simple_strtoul(argv[1], NULL, 16);
  351. boot_device = getenv("bootdevice");
  352. break;
  353. case 3:
  354. addr = simple_strtoul(argv[1], NULL, 16);
  355. boot_device = argv[2];
  356. break;
  357. default:
  358. cmd_usage(cmdtp);
  359. return 1;
  360. }
  361. if (!boot_device) {
  362. puts("\n** No boot device **\n");
  363. return 1;
  364. }
  365. dev = simple_strtoul(boot_device, &ep, 16);
  366. stor_dev = usb_stor_get_dev(dev);
  367. if (stor_dev->type == DEV_TYPE_UNKNOWN) {
  368. printf("\n** Device %d not available\n", dev);
  369. return 1;
  370. }
  371. if (stor_dev->block_read == NULL) {
  372. printf("storage device not initialized. Use usb scan\n");
  373. return 1;
  374. }
  375. if (*ep) {
  376. if (*ep != ':') {
  377. puts("\n** Invalid boot device, use `dev[:part]' **\n");
  378. return 1;
  379. }
  380. part = simple_strtoul(++ep, NULL, 16);
  381. }
  382. if (get_partition_info(stor_dev, part, &info)) {
  383. /* try to boot raw .... */
  384. strncpy((char *)&info.type[0], BOOT_PART_TYPE,
  385. sizeof(BOOT_PART_TYPE));
  386. strncpy((char *)&info.name[0], "Raw", 4);
  387. info.start = 0;
  388. info.blksz = 0x200;
  389. info.size = 2880;
  390. printf("error reading partinfo...try to boot raw\n");
  391. }
  392. if ((strncmp((char *)info.type, BOOT_PART_TYPE,
  393. sizeof(info.type)) != 0) &&
  394. (strncmp((char *)info.type, BOOT_PART_COMP,
  395. sizeof(info.type)) != 0)) {
  396. printf("\n** Invalid partition type \"%.32s\""
  397. " (expect \"" BOOT_PART_TYPE "\")\n",
  398. info.type);
  399. return 1;
  400. }
  401. printf("\nLoading from USB device %d, partition %d: "
  402. "Name: %.32s Type: %.32s\n",
  403. dev, part, info.name, info.type);
  404. debug("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
  405. info.start, info.size, info.blksz);
  406. if (stor_dev->block_read(dev, info.start, 1, (ulong *)addr) != 1) {
  407. printf("** Read error on %d:%d\n", dev, part);
  408. return 1;
  409. }
  410. switch (genimg_get_format((void *)addr)) {
  411. case IMAGE_FORMAT_LEGACY:
  412. hdr = (image_header_t *)addr;
  413. if (!image_check_hcrc(hdr)) {
  414. puts("\n** Bad Header Checksum **\n");
  415. return 1;
  416. }
  417. image_print_contents(hdr);
  418. cnt = image_get_image_size(hdr);
  419. break;
  420. #if defined(CONFIG_FIT)
  421. case IMAGE_FORMAT_FIT:
  422. fit_hdr = (const void *)addr;
  423. puts("Fit image detected...\n");
  424. cnt = fit_get_size(fit_hdr);
  425. break;
  426. #endif
  427. default:
  428. puts("** Unknown image type\n");
  429. return 1;
  430. }
  431. cnt += info.blksz - 1;
  432. cnt /= info.blksz;
  433. cnt -= 1;
  434. if (stor_dev->block_read(dev, info.start+1, cnt,
  435. (ulong *)(addr+info.blksz)) != cnt) {
  436. printf("\n** Read error on %d:%d\n", dev, part);
  437. return 1;
  438. }
  439. #if defined(CONFIG_FIT)
  440. /* This cannot be done earlier, we need complete FIT image in RAM
  441. * first
  442. */
  443. if (genimg_get_format((void *)addr) == IMAGE_FORMAT_FIT) {
  444. if (!fit_check_format(fit_hdr)) {
  445. puts("** Bad FIT image format\n");
  446. return 1;
  447. }
  448. fit_print_contents(fit_hdr);
  449. }
  450. #endif
  451. /* Loading ok, update default load address */
  452. load_addr = addr;
  453. flush_cache(addr, (cnt+1)*info.blksz);
  454. /* Check if we should attempt an auto-start */
  455. if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) {
  456. char *local_args[2];
  457. extern int do_bootm(cmd_tbl_t *, int, int, char *[]);
  458. local_args[0] = argv[0];
  459. local_args[1] = NULL;
  460. printf("Automatic boot of image at addr 0x%08lX ...\n", addr);
  461. rcode = do_bootm(cmdtp, 0, 1, local_args);
  462. return rcode;
  463. }
  464. return 0;
  465. }
  466. #endif /* CONFIG_USB_STORAGE */
  467. /******************************************************************************
  468. * usb command intepreter
  469. */
  470. int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  471. {
  472. int i;
  473. struct usb_device *dev = NULL;
  474. extern char usb_started;
  475. #ifdef CONFIG_USB_STORAGE
  476. block_dev_desc_t *stor_dev;
  477. #endif
  478. if ((strncmp(argv[1], "reset", 5) == 0) ||
  479. (strncmp(argv[1], "start", 5) == 0)) {
  480. usb_stop();
  481. printf("(Re)start USB...\n");
  482. i = usb_init();
  483. #ifdef CONFIG_USB_STORAGE
  484. /* try to recognize storage devices immediately */
  485. if (i >= 0)
  486. usb_stor_curr_dev = usb_stor_scan(1);
  487. #endif
  488. return 0;
  489. }
  490. if (strncmp(argv[1], "stop", 4) == 0) {
  491. #ifdef CONFIG_USB_KEYBOARD
  492. if (argc == 2) {
  493. if (usb_kbd_deregister() != 0) {
  494. printf("USB not stopped: usbkbd still"
  495. " using USB\n");
  496. return 1;
  497. }
  498. } else {
  499. /* forced stop, switch console in to serial */
  500. console_assign(stdin, "serial");
  501. usb_kbd_deregister();
  502. }
  503. #endif
  504. printf("stopping USB..\n");
  505. usb_stop();
  506. return 0;
  507. }
  508. if (!usb_started) {
  509. printf("USB is stopped. Please issue 'usb start' first.\n");
  510. return 1;
  511. }
  512. if (strncmp(argv[1], "tree", 4) == 0) {
  513. printf("\nDevice Tree:\n");
  514. usb_show_tree(usb_get_dev_index(0));
  515. return 0;
  516. }
  517. if (strncmp(argv[1], "inf", 3) == 0) {
  518. int d;
  519. if (argc == 2) {
  520. for (d = 0; d < USB_MAX_DEVICE; d++) {
  521. dev = usb_get_dev_index(d);
  522. if (dev == NULL)
  523. break;
  524. usb_display_desc(dev);
  525. usb_display_config(dev);
  526. }
  527. return 0;
  528. } else {
  529. int d;
  530. i = simple_strtoul(argv[2], NULL, 16);
  531. printf("config for device %d\n", i);
  532. for (d = 0; d < USB_MAX_DEVICE; d++) {
  533. dev = usb_get_dev_index(d);
  534. if (dev == NULL)
  535. break;
  536. if (dev->devnum == i)
  537. break;
  538. }
  539. if (dev == NULL) {
  540. printf("*** NO Device avaiable ***\n");
  541. return 0;
  542. } else {
  543. usb_display_desc(dev);
  544. usb_display_config(dev);
  545. }
  546. }
  547. return 0;
  548. }
  549. #ifdef CONFIG_USB_STORAGE
  550. if (strncmp(argv[1], "stor", 4) == 0)
  551. return usb_stor_info();
  552. if (strncmp(argv[1], "part", 4) == 0) {
  553. int devno, ok = 0;
  554. if (argc == 2) {
  555. for (devno = 0; devno < USB_MAX_STOR_DEV; ++devno) {
  556. stor_dev = usb_stor_get_dev(devno);
  557. if (stor_dev->type != DEV_TYPE_UNKNOWN) {
  558. ok++;
  559. if (devno)
  560. printf("\n");
  561. printf("print_part of %x\n", devno);
  562. print_part(stor_dev);
  563. }
  564. }
  565. } else {
  566. devno = simple_strtoul(argv[2], NULL, 16);
  567. stor_dev = usb_stor_get_dev(devno);
  568. if (stor_dev->type != DEV_TYPE_UNKNOWN) {
  569. ok++;
  570. printf("print_part of %x\n", devno);
  571. print_part(stor_dev);
  572. }
  573. }
  574. if (!ok) {
  575. printf("\nno USB devices available\n");
  576. return 1;
  577. }
  578. return 0;
  579. }
  580. if (strcmp(argv[1], "read") == 0) {
  581. if (usb_stor_curr_dev < 0) {
  582. printf("no current device selected\n");
  583. return 1;
  584. }
  585. if (argc == 5) {
  586. unsigned long addr = simple_strtoul(argv[2], NULL, 16);
  587. unsigned long blk = simple_strtoul(argv[3], NULL, 16);
  588. unsigned long cnt = simple_strtoul(argv[4], NULL, 16);
  589. unsigned long n;
  590. printf("\nUSB read: device %d block # %ld, count %ld"
  591. " ... ", usb_stor_curr_dev, blk, cnt);
  592. stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
  593. n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt,
  594. (ulong *)addr);
  595. printf("%ld blocks read: %s\n", n,
  596. (n == cnt) ? "OK" : "ERROR");
  597. if (n == cnt)
  598. return 0;
  599. return 1;
  600. }
  601. }
  602. if (strncmp(argv[1], "dev", 3) == 0) {
  603. if (argc == 3) {
  604. int dev = (int)simple_strtoul(argv[2], NULL, 10);
  605. printf("\nUSB device %d: ", dev);
  606. if (dev >= USB_MAX_STOR_DEV) {
  607. printf("unknown device\n");
  608. return 1;
  609. }
  610. printf("\n Device %d: ", dev);
  611. stor_dev = usb_stor_get_dev(dev);
  612. dev_print(stor_dev);
  613. if (stor_dev->type == DEV_TYPE_UNKNOWN)
  614. return 1;
  615. usb_stor_curr_dev = dev;
  616. printf("... is now current device\n");
  617. return 0;
  618. } else {
  619. printf("\nUSB device %d: ", usb_stor_curr_dev);
  620. stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
  621. dev_print(stor_dev);
  622. if (stor_dev->type == DEV_TYPE_UNKNOWN)
  623. return 1;
  624. return 0;
  625. }
  626. return 0;
  627. }
  628. #endif /* CONFIG_USB_STORAGE */
  629. cmd_usage(cmdtp);
  630. return 1;
  631. }
  632. #ifdef CONFIG_USB_STORAGE
  633. U_BOOT_CMD(
  634. usb, 5, 1, do_usb,
  635. "USB sub-system",
  636. "reset - reset (rescan) USB controller\n"
  637. "usb stop [f] - stop USB [f]=force stop\n"
  638. "usb tree - show USB device tree\n"
  639. "usb info [dev] - show available USB devices\n"
  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'"
  646. );
  647. U_BOOT_CMD(
  648. usbboot, 3, 1, do_usbboot,
  649. "boot from USB device",
  650. "loadAddr dev:part"
  651. );
  652. #else
  653. U_BOOT_CMD(
  654. usb, 5, 1, do_usb,
  655. "USB sub-system",
  656. "reset - reset (rescan) USB controller\n"
  657. "usb tree - show USB device tree\n"
  658. "usb info [dev] - show available USB devices"
  659. );
  660. #endif