diff options
author | Lukasz Majewski <l.majewski@samsung.com> | 2013-09-11 14:53:35 +0200 |
---|---|---|
committer | Marek Vasut <marex@denx.de> | 2013-09-24 17:51:35 +0200 |
commit | 765c5ae5bc913d9f06c518a9491d97c35ea00735 (patch) | |
tree | bc35b4c73157b3db833fa840733dcddaba5761a2 | |
parent | 3668ce3c8008705f271bb55ee863638de3bf8067 (diff) | |
download | u-boot-imx-765c5ae5bc913d9f06c518a9491d97c35ea00735.zip u-boot-imx-765c5ae5bc913d9f06c518a9491d97c35ea00735.tar.gz u-boot-imx-765c5ae5bc913d9f06c518a9491d97c35ea00735.tar.bz2 |
dfu: Extract common DFU code to handle "dfu_alt_info" environment variable
New dfu_init_env_entities() function has been extracted from cmd_dfu.c and
stored at dfu core.
This is a dfu centric code, so it shall be processed in the core.
Change-Id: I756c5de922fa31399d8804eaadc004ee98844ec2
Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Heiko Schocher <hs@denx.de>
-rw-r--r-- | common/cmd_dfu.c | 16 | ||||
-rw-r--r-- | drivers/dfu/dfu.c | 23 | ||||
-rw-r--r-- | include/dfu.h | 1 |
3 files changed, 26 insertions, 14 deletions
diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c index 793c422..d3658cf 100644 --- a/common/cmd_dfu.c +++ b/common/cmd_dfu.c @@ -17,26 +17,15 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - const char *str_env; char *s = "dfu"; int ret, i = 0; - char *env_bkp; if (argc < 3) return CMD_RET_USAGE; - str_env = getenv("dfu_alt_info"); - if (str_env == NULL) { - printf("%s: \"dfu_alt_info\" env variable not defined!\n", - __func__); - return CMD_RET_FAILURE; - } - - env_bkp = strdup(str_env); - ret = dfu_config_entities(env_bkp, argv[1], - (int)simple_strtoul(argv[2], NULL, 10)); + ret = dfu_init_env_entities(argv[1], simple_strtoul(argv[2], NULL, 10)); if (ret) - return CMD_RET_FAILURE; + return ret; if (argc > 3 && strcmp(argv[3], "list") == 0) { dfu_show_entities(); @@ -67,7 +56,6 @@ exit: g_dnl_unregister(); done: dfu_free_entities(); - free(env_bkp); if (dfu_reset()) run_command("reset", 0); diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 2f1e2af..689f5db 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -41,6 +41,29 @@ static int dfu_find_alt_num(const char *s) return ++i; } +int dfu_init_env_entities(char *interface, int dev) +{ + const char *str_env; + char *env_bkp; + int ret; + + str_env = getenv("dfu_alt_info"); + if (!str_env) { + error("\"dfu_alt_info\" env variable not defined!\n"); + return -EINVAL; + } + + env_bkp = strdup(str_env); + ret = dfu_config_entities(env_bkp, interface, dev); + if (ret) { + error("DFU entities configuration failed!\n"); + return ret; + } + + free(env_bkp); + return 0; +} + static unsigned char *dfu_buf; static unsigned long dfu_buf_size = CONFIG_SYS_DFU_DATA_BUF_SIZE; diff --git a/include/dfu.h b/include/dfu.h index 7779710..392cef1 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -113,6 +113,7 @@ struct dfu_entity *dfu_get_entity(int alt); char *dfu_extract_token(char** e, int *n); void dfu_trigger_reset(void); bool dfu_reset(void); +int dfu_init_env_entities(char *interface, int dev); int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |