From 93c813b3ac4b23df891992f93252c59231dec388 Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Wed, 23 Oct 2013 14:30:42 +0200 Subject: usb: ums: code refactoring to improve reusability on other boards. This patch introduces some cleanups to ums code. Changes: ums common: - introduce UMS_START_SECTOR and UMS_NUM_SECTORS as defined in usb_mass_storage.h both default values as 0 if board config doesn't define them common cleanup changes: - change name of struct "ums_board_info" to "ums" - "ums_device" fields are moved to struct ums and "dev_num" is removed - change function name: board_ums_init to ums_init - remove "extern" prefixes from usb_mass_storage.h cmd_usb_mass_storage: - change error() to printf() if need to print info message - change return values to command_ret_t type at ums command code - add command usage string Changes v2: ums common: - always returns number of read/write sectors - coding style clean-up ums gadget: - calculate amount of read/write from device returned value. Signed-off-by: Przemyslaw Marczak Cc: Marek Vasut --- common/cmd_usb_mass_storage.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'common') diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c index f583caf..f6ceba7 100644 --- a/common/cmd_usb_mass_storage.c +++ b/common/cmd_usb_mass_storage.c @@ -22,28 +22,26 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, unsigned int dev_num = (unsigned int)(simple_strtoul(mmc_devstring, NULL, 0)); - if (dev_num) { - error("Set eMMC device to 0! - e.g. ums 0"); - goto fail; - } + if (dev_num) + return CMD_RET_USAGE; 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."); - goto fail; + return CMD_RET_FAILURE; } - struct ums_board_info *ums_info = board_ums_init(dev_num, 0, 0); - if (!ums_info) { - error("MMC: %d -> NOT available", dev_num); - goto fail; + struct ums *ums = ums_init(dev_num); + if (!ums) { + printf("MMC: %u no such device\n", dev_num); + return CMD_RET_FAILURE; } - int rc = fsg_init(ums_info); + int rc = fsg_init(ums); if (rc) { error("fsg_init failed"); - goto fail; + return CMD_RET_FAILURE; } g_dnl_register("ums"); @@ -62,13 +60,10 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, } exit: g_dnl_unregister(); - return 0; - -fail: - return -1; + return CMD_RET_SUCCESS; } U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage, "Use the UMS [User Mass Storage]", - " " + "ums e.g. ums 0 0" ); -- cgit v1.1 From f4dacf7b95e9f7d4246db00facdbe366b5c30a5a Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Wed, 23 Oct 2013 14:30:43 +0200 Subject: usb: ums: allows using every mmc device with ums. Before this change ums command only allowed use of mmc 0. Now this argument can be set. Changes: - remove mmc device number checking because it is always positive number - remove printing "no such device" - it is done by find_mmc_device() Change-Id: I767e45151ad515c7bef19e6c13087374f5e23c11 Signed-off-by: Przemyslaw Marczak Cc: Marek Vasut --- common/cmd_usb_mass_storage.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'common') diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c index f6ceba7..4d3bbd8 100644 --- a/common/cmd_usb_mass_storage.c +++ b/common/cmd_usb_mass_storage.c @@ -20,10 +20,11 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, const char *usb_controller = argv[1]; const char *mmc_devstring = argv[2]; - unsigned int dev_num = (unsigned int)(simple_strtoul(mmc_devstring, - NULL, 0)); - if (dev_num) - return CMD_RET_USAGE; + unsigned int dev_num = simple_strtoul(mmc_devstring, NULL, 0); + + struct ums *ums = ums_init(dev_num); + if (!ums) + return CMD_RET_FAILURE; unsigned int controller_index = (unsigned int)(simple_strtoul( usb_controller, NULL, 0)); @@ -32,12 +33,6 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; } - struct ums *ums = ums_init(dev_num); - if (!ums) { - printf("MMC: %u no such device\n", dev_num); - return CMD_RET_FAILURE; - } - int rc = fsg_init(ums); if (rc) { error("fsg_init failed"); -- cgit v1.1 From 351e9b206934c2d4a6a0acd1547caf077e4e675c Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Wed, 23 Oct 2013 14:30:46 +0200 Subject: usb: ums: add ums exit feature by ctrl+c or by detach usb cable This patch allows exiting from UMS mode to u-boot prompt by detaching usb cable or by pressing ctrl+c. Add new config: CONFIG_USB_CABLE_CHECK. If defined then board file should provide function: usb_cable_connected() (include/usb.h) that return 1 if cable is connected and 0 otherwise. Changes v2: - add a note to the README Signed-off-by: Przemyslaw Marczak Cc: Marek Vasut --- common/cmd_usb_mass_storage.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c index 4d3bbd8..99487f4 100644 --- a/common/cmd_usb_mass_storage.c +++ b/common/cmd_usb_mass_storage.c @@ -5,6 +5,7 @@ * SPDX-License-Identifier: GPL-2.0+ */ +#include #include #include #include @@ -42,16 +43,20 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, g_dnl_register("ums"); while (1) { - /* Handle control-c and timeouts */ - if (ctrlc()) { - error("The remote end did not respond in time."); - goto exit; - } - usb_gadget_handle_interrupts(); - /* Check if USB cable has been detached */ - if (fsg_main_thread(NULL) == EIO) + + rc = fsg_main_thread(NULL); + if (rc) { + /* Check I/O error */ + if (rc == -EIO) + printf("\rCheck USB cable connection\n"); + + /* Check CTRL+C */ + if (rc == -EPIPE) + printf("\rCTRL+C - Operation aborted\n"); + goto exit; + } } exit: g_dnl_unregister(); -- cgit v1.1