thor:cmd: get the default command arguments from environment 62/63962/6
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Thu, 12 Jun 2014 08:20:59 +0000 (10:20 +0200)
committerJoonyoung Shim <jy0922.shim@samsung.com>
Fri, 1 Apr 2016 01:08:15 +0000 (18:08 -0700)
This change adds support to getting the default DFU cmd line
arguments from the environment.

DFU and THOR uses the same command line arguments,
so the DFU command environment setup can be used also with THOR.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Conflicts:
common/cmd_thordown.c

[jino.cho: Fixed conflicts from original commit of tizen.org]
Signed-off-by: jino.cho <jino.cho@samsung.com>
Change-Id: I167927ff47f7c105fd1794da21c6742a10c7593a

common/cmd_thordown.c

index 436b7f56315eb5985016d4d597c6c8ba94959885..f0e50436d5daad16781098e3feffc1929a96a9b5 100644 (file)
 
 int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       if (argc < 4)
-               return CMD_RET_USAGE;
-
-       char *usb_controller = argv[1];
-       char *interface = argv[2];
-       char *devstring = argv[3];
-
+       char *usb_controller;
+       char *interface;
+       char *devstring;
        int ret;
 
        puts("TIZEN \"THOR\" Downloader\n");
 
+       switch (argc) {
+       case 1:
+               usb_controller = strdup(getenv("dfu_usb_con"));
+               interface = strdup(getenv("dfu_interface"));
+               devstring = strdup(getenv("dfu_device"));
+
+               if (!usb_controller || !interface || !devstring) {
+                       puts("DFU: default device environment is not set.\n");
+                       ret = CMD_RET_USAGE;
+                       goto bad_args;
+               }
+               break;
+       case 4:
+               usb_controller = argv[1];
+               interface = argv[2];
+               devstring = argv[3];
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
        ret = dfu_init_env_entities(interface, devstring);
        if (ret)
                goto done;
@@ -60,6 +77,12 @@ exit:
 done:
        dfu_free_entities();
 
+bad_args:
+       if (argc == 1) {
+               free(usb_controller);
+               free(interface);
+               free(devstring);
+       }
        return ret;
 }