From 07300fe8ecc4fdf506cda6790c2bd102133be0fb 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 47e8b70cd1..a56ed7b04c 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -143,16 +143,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); @@ -248,7 +259,12 @@ cleanup_board: udc_device_put(udc); cleanup_ums_init: ums_fini(); - +cleanup_free: + if (argc == 1) { + free((void *)usb_controller); + free((void *)devtype); + free((void *)devnum); + } return rc; } -- 2.34.1