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