blob: 99487f4d0f686a6db2bc4c87caf0282941fd1a00 [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
Przemyslaw Marczak351e9b22013-10-23 14:30:46 +02008#include <errno.h>
Lukasz Majewskib528f712013-03-05 12:10:17 +01009#include <common.h>
10#include <command.h>
11#include <g_dnl.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020012#include <usb.h>
Lukasz Majewskib528f712013-03-05 12:10:17 +010013#include <usb_mass_storage.h>
14
15int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
16 int argc, char * const argv[])
17{
Mateusz Zalega16297cf2013-10-04 19:22:26 +020018 if (argc < 3)
19 return CMD_RET_USAGE;
Lukasz Majewskib528f712013-03-05 12:10:17 +010020
Mateusz Zalega16297cf2013-10-04 19:22:26 +020021 const char *usb_controller = argv[1];
22 const char *mmc_devstring = argv[2];
Lukasz Majewskib528f712013-03-05 12:10:17 +010023
Przemyslaw Marczakf4dacf72013-10-23 14:30:43 +020024 unsigned int dev_num = simple_strtoul(mmc_devstring, NULL, 0);
25
26 struct ums *ums = ums_init(dev_num);
27 if (!ums)
28 return CMD_RET_FAILURE;
Lukasz Majewskib528f712013-03-05 12:10:17 +010029
Mateusz Zalega16297cf2013-10-04 19:22:26 +020030 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.");
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020034 return CMD_RET_FAILURE;
Mateusz Zalega16297cf2013-10-04 19:22:26 +020035 }
Lukasz Majewskib528f712013-03-05 12:10:17 +010036
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020037 int rc = fsg_init(ums);
Mateusz Zalega16297cf2013-10-04 19:22:26 +020038 if (rc) {
39 error("fsg_init failed");
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020040 return CMD_RET_FAILURE;
Mateusz Zalega16297cf2013-10-04 19:22:26 +020041 }
42
43 g_dnl_register("ums");
Lukasz Majewskib528f712013-03-05 12:10:17 +010044
45 while (1) {
Przemyslaw Marczak351e9b22013-10-23 14:30:46 +020046 usb_gadget_handle_interrupts();
47
48 rc = fsg_main_thread(NULL);
49 if (rc) {
50 /* Check I/O error */
51 if (rc == -EIO)
52 printf("\rCheck USB cable connection\n");
53
54 /* Check CTRL+C */
55 if (rc == -EPIPE)
56 printf("\rCTRL+C - Operation aborted\n");
57
Lukasz Majewskib528f712013-03-05 12:10:17 +010058 goto exit;
59 }
Lukasz Majewskib528f712013-03-05 12:10:17 +010060 }
61exit:
62 g_dnl_unregister();
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020063 return CMD_RET_SUCCESS;
Lukasz Majewskib528f712013-03-05 12:10:17 +010064}
65
66U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
67 "Use the UMS [User Mass Storage]",
Przemyslaw Marczak93c813b2013-10-23 14:30:42 +020068 "ums <USB_controller> <mmc_dev> e.g. ums 0 0"
Lukasz Majewskib528f712013-03-05 12:10:17 +010069);