cmd: ums: add getting the default parameters from env 44/247844/1
authorMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 17 Nov 2020 09:56:34 +0000 (10:56 +0100)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 17 Nov 2020 10:20:41 +0000 (11:20 +0100)
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

cmd/usb_mass_storage.c

index 14fa723..fe6095e 100644 (file)
@@ -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);
@@ -240,7 +251,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;
 }