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