dfu:cmd: get the default command arguments from environment 52/25652/1
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Thu, 7 Aug 2014 11:03:25 +0000 (13:03 +0200)
committerPrzemyslaw Marczak <p.marczak@samsung.com>
Thu, 7 Aug 2014 12:09:32 +0000 (14:09 +0200)
This change adds support to store the default DFU cmd line
arguments in the environment.

This is useful for users who usually use the same arguments
for dfu command and do the upgrade frequently.

DFU command use cases:
- dfu <usb ctrl> <if> <dev> [<list>] - use command line args
- dfu [<list>] - take the default command line args from env
And for both - optional list the initialized DFU entities.

To use the default dfu device configuration user should define:
- $dfu_usb_con - e.g. "0"
- $dfu_interface - e.g. "mmc"
- $dfu_device - e.g. "0"

Change-Id: I1c87677c0384a5f5a808ab9b7845d6da6f9ec980
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
common/cmd_dfu.c

index 433bddd5d2bdc83d9cf06fa943a44c08d9bba701..b33f9c906db2acef75e0af46f71a9215555a3d7c 100644 (file)
 
 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       if (argc < 4)
-               return CMD_RET_USAGE;
+       char *usb_controller;
+       char *interface;
+       char *devstring;
+       int argv_list = 0;
+       int ret, i = 0;
 
-       char *usb_controller = argv[1];
-       char *interface = argv[2];
-       char *devstring = argv[3];
+       switch (argc) {
+       case 2:
+               argv_list = 1;
+       case 1:
+               usb_controller = strdup(getenv("dfu_usb_con"));
+               interface = strdup(getenv("dfu_interface"));
+               devstring = strdup(getenv("dfu_device"));
 
-       int ret, i = 0;
+               if (!usb_controller || !interface || !devstring) {
+                       puts("DFU: default device environment is not set.\n");
+                       return CMD_RET_USAGE;
+               }
+               break;
+       case 5:
+               argv_list = 4;
+       case 4:
+               usb_controller = argv[1];
+               interface = argv[2];
+               devstring = argv[3];
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
 
        ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
                                                              NULL, 10));
        if (ret)
                goto done;
 
-       ret = CMD_RET_SUCCESS;
-       if (argc > 4 && strcmp(argv[4], "list") == 0) {
+       if (argv_list && !strcmp(argv[argv_list], "list")) {
                dfu_show_entities();
                goto done;
        }