blob: ccf7195946e19491edb931d84cd4b159921112dc [file] [log] [blame]
Lukasz Majewski44a6ac92013-03-05 12:10:17 +01001/*
2 * Copyright (C) 2011 Samsung Electronics
3 * Lukasz Majewski <l.majewski@samsung.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski44a6ac92013-03-05 12:10:17 +01006 */
7
Lukasz Majewski44a6ac92013-03-05 12:10:17 +01008#include <common.h>
9#include <command.h>
10#include <g_dnl.h>
11#include <usb_mass_storage.h>
12
13int 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 }
61exit:
62 g_dnl_unregister();
63 return 0;
64
65fail:
66 return -1;
67}
68
69U_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);