From ddcf168943cbe2f8e5fe1a1b7acef2c5851da841 Mon Sep 17 00:00:00 2001
From: Przemyslaw Marczak
Date: Thu, 12 Jun 2014 10:20:59 +0200
Subject: [PATCH] thor:cmd: get the default command arguments from environment
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.
Change-Id: I2e0984c909147c13191f6d6646d094c9f02c392a
Signed-off-by: Przemyslaw Marczak
---
cmd/thordown.c | 39 +++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
diff --git a/cmd/thordown.c b/cmd/thordown.c
index a3f6354..d4ef6b0 100644
--- a/cmd/thordown.c
+++ b/cmd/thordown.c
@@ -16,17 +16,34 @@
int do_thor_down(struct cmd_tbl *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(env_get("dfu_usb_con"));
+ interface = strdup(env_get("dfu_interface"));
+ devstring = strdup(env_get("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;
@@ -48,7 +65,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
ret = thor_init();
if (ret) {
- error("THOR DOWNLOAD failed: %d", ret);
+ printk("THOR DOWNLOAD failed: %d", ret);
if (ret == -EINTR)
ret = CMD_RET_SUCCESS;
else
@@ -83,6 +100,12 @@ done:
lcd_clear();
#endif
#endif
+bad_args:
+ if (argc == 1) {
+ free(usb_controller);
+ free(interface);
+ free(devstring);
+ }
return ret;
}
--
2.7.4