cmd_usb_mass_storage.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics
  3. * Lukasz Majewski <l.majewski@samsung.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <errno.h>
  8. #include <common.h>
  9. #include <command.h>
  10. #include <g_dnl.h>
  11. #include <usb_mass_storage.h>
  12. int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
  13. int argc, char * const argv[])
  14. {
  15. char *ep;
  16. unsigned int dev_num = 0, offset = 0, part_size = 0;
  17. int rc;
  18. struct ums_board_info *ums_info;
  19. static char *s = "ums";
  20. if (argc < 2) {
  21. printf("usage: ums <dev> - e.g. ums 0\n");
  22. return 0;
  23. }
  24. dev_num = (int)simple_strtoul(argv[1], &ep, 16);
  25. if (dev_num) {
  26. puts("\nSet eMMC device to 0! - e.g. ums 0\n");
  27. goto fail;
  28. }
  29. board_usb_init();
  30. ums_info = board_ums_init(dev_num, offset, part_size);
  31. if (!ums_info) {
  32. printf("MMC: %d -> NOT available\n", dev_num);
  33. goto fail;
  34. }
  35. rc = fsg_init(ums_info);
  36. if (rc) {
  37. printf("cmd ums: fsg_init failed\n");
  38. goto fail;
  39. }
  40. g_dnl_register(s);
  41. while (1) {
  42. /* Handle control-c and timeouts */
  43. if (ctrlc()) {
  44. printf("The remote end did not respond in time.\n");
  45. goto exit;
  46. }
  47. usb_gadget_handle_interrupts();
  48. /* Check if USB cable has been detached */
  49. if (fsg_main_thread(NULL) == EIO)
  50. goto exit;
  51. }
  52. exit:
  53. g_dnl_unregister();
  54. return 0;
  55. fail:
  56. return -1;
  57. }
  58. U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
  59. "Use the UMS [User Mass Storage]",
  60. "ums - User Mass Storage Gadget"
  61. );