cmd_usb.c 18 KB

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