Blame view
common/cmd_usb_mass_storage.c
1.93 KB
b528f7139 usb:gadget: USB M... |
1 2 3 4 |
/* * Copyright (C) 2011 Samsung Electronics * Lukasz Majewski <l.majewski@samsung.com> * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
b528f7139 usb:gadget: USB M... |
6 |
*/ |
351e9b206 usb: ums: add ums... |
7 |
#include <errno.h> |
b528f7139 usb:gadget: USB M... |
8 9 10 |
#include <common.h> #include <command.h> #include <g_dnl.h> |
16297cfb2 usb: new board-sp... |
11 |
#include <usb.h> |
b528f7139 usb:gadget: USB M... |
12 13 14 15 16 |
#include <usb_mass_storage.h> int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
16297cfb2 usb: new board-sp... |
17 18 |
if (argc < 3) return CMD_RET_USAGE; |
b528f7139 usb:gadget: USB M... |
19 |
|
16297cfb2 usb: new board-sp... |
20 21 |
const char *usb_controller = argv[1]; const char *mmc_devstring = argv[2]; |
b528f7139 usb:gadget: USB M... |
22 |
|
f4dacf7b9 usb: ums: allows ... |
23 24 25 26 27 |
unsigned int dev_num = simple_strtoul(mmc_devstring, NULL, 0); struct ums *ums = ums_init(dev_num); if (!ums) return CMD_RET_FAILURE; |
b528f7139 usb:gadget: USB M... |
28 |
|
16297cfb2 usb: new board-sp... |
29 30 31 32 |
unsigned int controller_index = (unsigned int)(simple_strtoul( usb_controller, NULL, 0)); if (board_usb_init(controller_index, USB_INIT_DEVICE)) { error("Couldn't init USB controller."); |
93c813b3a usb: ums: code re... |
33 |
return CMD_RET_FAILURE; |
16297cfb2 usb: new board-sp... |
34 |
} |
b528f7139 usb:gadget: USB M... |
35 |
|
93c813b3a usb: ums: code re... |
36 |
int rc = fsg_init(ums); |
b528f7139 usb:gadget: USB M... |
37 |
if (rc) { |
16297cfb2 usb: new board-sp... |
38 |
error("fsg_init failed"); |
93c813b3a usb: ums: code re... |
39 |
return CMD_RET_FAILURE; |
b528f7139 usb:gadget: USB M... |
40 |
} |
16297cfb2 usb: new board-sp... |
41 |
g_dnl_register("ums"); |
b528f7139 usb:gadget: USB M... |
42 |
|
3603e31db usb: ums: wait fo... |
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
/* Timeout unit: seconds */ int cable_ready_timeout = UMS_CABLE_READY_TIMEOUT; if (!usb_cable_connected()) { puts("Please connect USB cable. "); while (!usb_cable_connected()) { if (ctrlc()) { puts("\rCTRL+C - Operation aborted. "); goto exit; } if (!cable_ready_timeout) { puts("\rUSB cable not detected. " \ "Command exit. "); goto exit; } printf("\rAuto exit in: %.2d s.", cable_ready_timeout); mdelay(1000); cable_ready_timeout--; } puts("\r "); } |
b528f7139 usb:gadget: USB M... |
71 |
while (1) { |
b528f7139 usb:gadget: USB M... |
72 |
usb_gadget_handle_interrupts(); |
351e9b206 usb: ums: add ums... |
73 74 75 76 77 78 79 80 81 82 83 84 |
rc = fsg_main_thread(NULL); if (rc) { /* Check I/O error */ if (rc == -EIO) printf("\rCheck USB cable connection "); /* Check CTRL+C */ if (rc == -EPIPE) printf("\rCTRL+C - Operation aborted "); |
b528f7139 usb:gadget: USB M... |
85 |
goto exit; |
351e9b206 usb: ums: add ums... |
86 |
} |
b528f7139 usb:gadget: USB M... |
87 88 89 |
} exit: g_dnl_unregister(); |
93c813b3a usb: ums: code re... |
90 |
return CMD_RET_SUCCESS; |
b528f7139 usb:gadget: USB M... |
91 92 93 94 |
} U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage, "Use the UMS [User Mass Storage]", |
93c813b3a usb: ums: code re... |
95 |
"ums <USB_controller> <mmc_dev> e.g. ums 0 0" |
b528f7139 usb:gadget: USB M... |
96 |
); |