From 5a9ccdf9eef0614c79101688ecb042d6ba5c965d Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 17 Nov 2020 10:56:34 +0100 Subject: [PATCH] cmd: ums: add getting the default parameters from env Add reading command parameters from the environment. The same environment variables are used as for the "dfu" and "thor" commands. This allows to specify USB controller ("dfu_usb_con"), device interface ("dfu_interface") and device number ("dfu_device"). Such change allows to call "ums" without any parameters for the default storage device. Signed-off-by: Marek Szyprowski Change-Id: If725408159937dc50cb375d5c80455dac5cf9b37 --- cmd/usb_mass_storage.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index c3cc197..5975e70 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -146,16 +146,27 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag, int rc; int cable_ready_timeout __maybe_unused; - if (argc < 3) - return CMD_RET_USAGE; - - usb_controller = argv[1]; - if (argc >= 4) { - devtype = argv[2]; - devnum = argv[3]; + if (argc == 1) { + usb_controller = strdup(env_get("dfu_usb_con")); + devtype = strdup(env_get("dfu_interface")); + devnum = strdup(env_get("dfu_device")); + if (!usb_controller || !devtype || !devnum) { + puts("DFU: default device environment is not set.\n"); + rc = CMD_RET_USAGE; + goto cleanup_free; + } } else { - devtype = "mmc"; - devnum = argv[2]; + if (argc < 3) + return CMD_RET_USAGE; + + usb_controller = argv[1]; + if (argc >= 4) { + devtype = argv[2]; + devnum = argv[3]; + } else { + devtype = "mmc"; + devnum = argv[2]; + } } rc = ums_init(devtype, devnum); @@ -250,7 +261,12 @@ cleanup_board: usb_gadget_release(controller_index); cleanup_ums_init: ums_fini(); - +cleanup_free: + if (argc == 1) { + free((void *)usb_controller); + free((void *)devtype); + free((void *)devnum); + } return rc; } -- 2.7.4