cmd_usb_mass_storage.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics
  3. * Lukasz Majewski <l.majewski@samsung.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <errno.h>
  21. #include <common.h>
  22. #include <command.h>
  23. #include <g_dnl.h>
  24. #include <usb_mass_storage.h>
  25. int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
  26. int argc, char * const argv[])
  27. {
  28. char *ep;
  29. unsigned int dev_num = 0, offset = 0, part_size = 0;
  30. int rc;
  31. struct ums_board_info *ums_info;
  32. static char *s = "ums";
  33. if (argc < 2) {
  34. printf("usage: ums <dev> - e.g. ums 0\n");
  35. return 0;
  36. }
  37. dev_num = (int)simple_strtoul(argv[1], &ep, 16);
  38. if (dev_num) {
  39. puts("\nSet eMMC device to 0! - e.g. ums 0\n");
  40. goto fail;
  41. }
  42. board_usb_init();
  43. ums_info = board_ums_init(dev_num, offset, part_size);
  44. if (!ums_info) {
  45. printf("MMC: %d -> NOT available\n", dev_num);
  46. goto fail;
  47. }
  48. rc = fsg_init(ums_info);
  49. if (rc) {
  50. printf("cmd ums: fsg_init failed\n");
  51. goto fail;
  52. }
  53. g_dnl_register(s);
  54. while (1) {
  55. /* Handle control-c and timeouts */
  56. if (ctrlc()) {
  57. printf("The remote end did not respond in time.\n");
  58. goto exit;
  59. }
  60. usb_gadget_handle_interrupts();
  61. /* Check if USB cable has been detached */
  62. if (fsg_main_thread(NULL) == EIO)
  63. goto exit;
  64. }
  65. exit:
  66. g_dnl_unregister();
  67. return 0;
  68. fail:
  69. return -1;
  70. }
  71. U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
  72. "Use the UMS [User Mass Storage]",
  73. "ums - User Mass Storage Gadget"
  74. );