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