From 1070a628985dfaeec2b737aac4144dbbf02b0677 Mon Sep 17 00:00:00 2001
From: Przemyslaw Marczak
Date: Thu, 7 Aug 2014 13:03:25 +0200
Subject: [PATCH] dfu:cmd: get the default command arguments from environment
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 [] - use command line args
- dfu [] - 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
---
cmd/dfu.c | 45 ++++++++++++++++++++++++++++++++++-----------
1 file changed, 34 insertions(+), 11 deletions(-)
diff --git a/cmd/dfu.c b/cmd/dfu.c
index d8aae26223..82b968c0d1 100644
--- a/cmd/dfu.c
+++ b/cmd/dfu.c
@@ -21,16 +21,36 @@
static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ char *usb_controller;
+ char *interface;
+ char *devstring;
+ int argv_list = 0;
+ int ret, i = 0;
bool dfu_reset = false;
- if (argc < 4)
+ 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"));
+ if (!usb_controller || !interface || !devstring) {
+ puts("DFU: default device environment is not set.\n");
+ ret = CMD_RET_USAGE;
+ goto bad_args;
+ }
+ break;
+ case 5:
+ argv_list = 4;
+ case 4:
+ usb_controller = argv[1];
+ interface = argv[2];
+ devstring = argv[3];
+ break;
+ default:
return CMD_RET_USAGE;
-
- char *usb_controller = argv[1];
- char *interface = argv[2];
- char *devstring = argv[3];
-
- int ret, i = 0;
+ }
#ifdef CONFIG_DFU_TFTP
unsigned long addr = 0;
if (!strcmp(argv[1], "tftp")) {
@@ -40,13 +60,11 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return update_tftp(addr, interface, devstring);
}
#endif
-
ret = dfu_init_env_entities(interface, devstring);
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;
}
@@ -112,7 +130,12 @@ done:
run_command("reset", 0);
g_dnl_clear_detach();
-
+bad_args:
+ if (argc == 1) {
+ free(usb_controller);
+ free(interface);
+ free(devstring);
+ }
return ret;
}
--
2.34.1