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 <m.szyprowski@samsung.com>
Change-Id: If725408159937dc50cb375d5c80455dac5cf9b37
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);
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;
}