]> git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_usb_mass_storage.c
Merge branch 'master' of git://git.denx.de/u-boot-usb
[people/ms/u-boot.git] / common / cmd_usb_mass_storage.c
1 /*
2 * Copyright (C) 2011 Samsung Electronics
3 * Lukasz Majewski <l.majewski@samsung.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8 #include <common.h>
9 #include <command.h>
10 #include <g_dnl.h>
11 #include <usb.h>
12 #include <usb_mass_storage.h>
13
14 int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
15 int argc, char * const argv[])
16 {
17 if (argc < 3)
18 return CMD_RET_USAGE;
19
20 const char *usb_controller = argv[1];
21 const char *mmc_devstring = argv[2];
22
23 unsigned int dev_num = (unsigned int)(simple_strtoul(mmc_devstring,
24 NULL, 0));
25 if (dev_num) {
26 error("Set eMMC device to 0! - e.g. ums 0");
27 goto fail;
28 }
29
30 unsigned int controller_index = (unsigned int)(simple_strtoul(
31 usb_controller, NULL, 0));
32 if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
33 error("Couldn't init USB controller.");
34 goto fail;
35 }
36
37 struct ums_board_info *ums_info = board_ums_init(dev_num, 0, 0);
38 if (!ums_info) {
39 error("MMC: %d -> NOT available", dev_num);
40 goto fail;
41 }
42
43 int rc = fsg_init(ums_info);
44 if (rc) {
45 error("fsg_init failed");
46 goto fail;
47 }
48
49 g_dnl_register("ums");
50
51 while (1) {
52 /* Handle control-c and timeouts */
53 if (ctrlc()) {
54 error("The remote end did not respond in time.");
55 goto exit;
56 }
57
58 usb_gadget_handle_interrupts();
59 /* Check if USB cable has been detached */
60 if (fsg_main_thread(NULL) == EIO)
61 goto exit;
62 }
63 exit:
64 g_dnl_unregister();
65 return 0;
66
67 fail:
68 return -1;
69 }
70
71 U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
72 "Use the UMS [User Mass Storage]",
73 "<USB_controller> <mmc_dev>"
74 );