Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Samsung Electronics |
| 3 | * Lukasz Majewski <l.majewski@samsung.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <g_dnl.h> |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 11 | #include <usb.h> |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 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 | { |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 17 | if (argc < 3) |
| 18 | return CMD_RET_USAGE; |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 19 | |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 20 | const char *usb_controller = argv[1]; |
| 21 | const char *mmc_devstring = argv[2]; |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 22 | |
Przemyslaw Marczak | f4dacf7 | 2013-10-23 14:30:43 +0200 | [diff] [blame^] | 23 | 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 Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 28 | |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 29 | 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 Marczak | 93c813b | 2013-10-23 14:30:42 +0200 | [diff] [blame] | 33 | return CMD_RET_FAILURE; |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 34 | } |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 35 | |
Przemyslaw Marczak | 93c813b | 2013-10-23 14:30:42 +0200 | [diff] [blame] | 36 | int rc = fsg_init(ums); |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 37 | if (rc) { |
| 38 | error("fsg_init failed"); |
Przemyslaw Marczak | 93c813b | 2013-10-23 14:30:42 +0200 | [diff] [blame] | 39 | return CMD_RET_FAILURE; |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | g_dnl_register("ums"); |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 43 | |
| 44 | while (1) { |
| 45 | /* Handle control-c and timeouts */ |
| 46 | if (ctrlc()) { |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 47 | error("The remote end did not respond in time."); |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 48 | goto exit; |
| 49 | } |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 50 | |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 51 | usb_gadget_handle_interrupts(); |
| 52 | /* Check if USB cable has been detached */ |
| 53 | if (fsg_main_thread(NULL) == EIO) |
| 54 | goto exit; |
| 55 | } |
| 56 | exit: |
| 57 | g_dnl_unregister(); |
Przemyslaw Marczak | 93c813b | 2013-10-23 14:30:42 +0200 | [diff] [blame] | 58 | return CMD_RET_SUCCESS; |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage, |
| 62 | "Use the UMS [User Mass Storage]", |
Przemyslaw Marczak | 93c813b | 2013-10-23 14:30:42 +0200 | [diff] [blame] | 63 | "ums <USB_controller> <mmc_dev> e.g. ums 0 0" |
Lukasz Majewski | b528f71 | 2013-03-05 12:10:17 +0100 | [diff] [blame] | 64 | ); |