blob: 4d3bbd843a4de12844d693c75aa07b88713777df [file] [log] [blame]
Lukasz Majewskib528f712013-03-05 12:10:17 +01001/*
2 * Copyright (C) 2011 Samsung Electronics
3 * Lukasz Majewski <l.majewski@samsung.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskib528f712013-03-05 12:10:17 +01006 */
7
Lukasz Majewskib528f712013-03-05 12:10:17 +01008#include <common.h>
9#include <command.h>
10#include <g_dnl.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020011#include <usb.h>
Lukasz Majewskib528f712013-03-05 12:10:17 +010012#include <usb_mass_storage.h>
13
14int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
15 int argc, char * const argv[])
16{
Mateusz Zalega16297cf2013-10-04 19:22:26 +020017 if (argc < 3)
18 return CMD_RET_USAGE;
Lukasz Majewskib528f712013-03-05 12:10:17 +010019
Mateusz Zalega16297cf2013-10-04 19:22:26 +020020 const char *usb_controller = argv[1];
21 const char *mmc_devstring = argv[2];
Lukasz Majewskib528f712013-03-05 12:10:17 +010022
Przemyslaw Marczakf4dacf72013-10-23 14:30:43 +020023 unsigned int dev_num = simple_strtoul(mmc_devstring, NULL, 0);
24
25 struct ums *ums = ums_init(dev_num);
26 if (!ums)
27 return CMD_RET_FAILURE;
Lukasz Majewskib528f712013-03-05 12:10:17 +010028
Mateusz Zalega16297cf2013-10-04 19:22:26 +020029 unsigned int controller_index = (unsigned int)(simple_strtoul(
30 usb_controller, NULL, 0));
31 if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
32 error("Couldn't init USB controller.");
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020033 return CMD_RET_FAILURE;
Mateusz Zalega16297cf2013-10-04 19:22:26 +020034 }
Lukasz Majewskib528f712013-03-05 12:10:17 +010035
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020036 int rc = fsg_init(ums);
Mateusz Zalega16297cf2013-10-04 19:22:26 +020037 if (rc) {
38 error("fsg_init failed");
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020039 return CMD_RET_FAILURE;
Mateusz Zalega16297cf2013-10-04 19:22:26 +020040 }
41
42 g_dnl_register("ums");
Lukasz Majewskib528f712013-03-05 12:10:17 +010043
44 while (1) {
45 /* Handle control-c and timeouts */
46 if (ctrlc()) {
Mateusz Zalega16297cf2013-10-04 19:22:26 +020047 error("The remote end did not respond in time.");
Lukasz Majewskib528f712013-03-05 12:10:17 +010048 goto exit;
49 }
Mateusz Zalega16297cf2013-10-04 19:22:26 +020050
Lukasz Majewskib528f712013-03-05 12:10:17 +010051 usb_gadget_handle_interrupts();
52 /* Check if USB cable has been detached */
53 if (fsg_main_thread(NULL) == EIO)
54 goto exit;
55 }
56exit:
57 g_dnl_unregister();
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020058 return CMD_RET_SUCCESS;
Lukasz Majewskib528f712013-03-05 12:10:17 +010059}
60
61U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
62 "Use the UMS [User Mass Storage]",
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020063 "ums <USB_controller> <mmc_dev> e.g. ums 0 0"
Lukasz Majewskib528f712013-03-05 12:10:17 +010064);