public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/4] dfu:cmd: get the default command arguments from environment
@ 2014-06-12 14:25 Przemyslaw Marczak
  2014-06-12 14:25 ` [U-Boot] [PATCH 2/4] thor:cmd: " Przemyslaw Marczak
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Przemyslaw Marczak @ 2014-06-12 14:25 UTC (permalink / raw)
  To: u-boot

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"

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Marek Vasut <marex@denx.de>
---
 common/cmd_dfu.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
index a03538d..7c6bb6b 100644
--- a/common/cmd_dfu.c
+++ b/common/cmd_dfu.c
@@ -15,21 +15,42 @@
 
 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)
 		return ret;
 
-	if (argc > 4 && strcmp(argv[4], "list") == 0) {
+	if (argv_list && !strcmp(argv[argv_list], "list")) {
 		dfu_show_entities();
 		goto done;
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-06-16 14:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-12 14:25 [U-Boot] [PATCH 1/4] dfu:cmd: get the default command arguments from environment Przemyslaw Marczak
2014-06-12 14:25 ` [U-Boot] [PATCH 2/4] thor:cmd: " Przemyslaw Marczak
2014-06-12 14:25 ` [U-Boot] [PATCH 3/4] trats2:config: add default dfu device environment setup Przemyslaw Marczak
2014-06-12 14:25 ` [U-Boot] [PATCH 4/4] trats:config: " Przemyslaw Marczak
2014-06-12 16:39 ` [U-Boot] [PATCH 1/4] dfu:cmd: get the default command arguments from environment Stephen Warren
2014-06-13  8:28   ` Przemyslaw Marczak
2014-06-13 16:35     ` Stephen Warren
2014-06-16 14:07       ` Przemyslaw Marczak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox