From patchwork Tue Sep 10 13:29:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majewski?= X-Patchwork-Id: 273876 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 42DE12C0106 for ; Tue, 10 Sep 2013 23:31:05 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6FA544A097; Tue, 10 Sep 2013 15:30:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hsyC6aM0T0nH; Tue, 10 Sep 2013 15:30:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B2FC24A09F; Tue, 10 Sep 2013 15:30:30 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 245234A09F for ; Tue, 10 Sep 2013 15:30:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NRkoPDv9Lqh1 for ; Tue, 10 Sep 2013 15:30:23 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by theia.denx.de (Postfix) with ESMTP id 36A0E4A023 for ; Tue, 10 Sep 2013 15:30:11 +0200 (CEST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MSW009FAW6APIF0@mailout1.samsung.com> for u-boot@lists.denx.de; Tue, 10 Sep 2013 22:30:10 +0900 (KST) X-AuditID: cbfee61b-b7f776d0000016c8-a1-522f1ee1c47a Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id D8.9C.05832.1EE1F225; Tue, 10 Sep 2013 22:30:10 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MSW00KJLW5HFV70@mmp1.samsung.com>; Tue, 10 Sep 2013 22:30:09 +0900 (KST) From: Lukasz Majewski To: u-boot@lists.denx.de Date: Tue, 10 Sep 2013 15:29:25 +0200 Message-id: <1378819765-20159-5-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1378819765-20159-1-git-send-email-l.majewski@samsung.com> References: <1378819765-20159-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBLMWRmVeSWpSXmKPExsVy+t9jAd1HcvpBBtt2MlrsuHOf2eLNI26L Nw83M1q8aWtktNh1ezKLxeTF85kt3u7tZHdg95j3cyKTx7xZJ1g8zt7ZweixbtpbZo++LasY PY7f2M4UwBbFZZOSmpNZllqkb5fAldG/dhlbwVvRipb/b9gbGC8LdjFyckgImEjsON3KBmGL SVy4tx7I5uIQEljEKNHUs4YdJCEk0MUkcaK/FMRmE9CT+Hz3KROILSIgIfGr/yojSAOzwD1G iUcdG1hBEsICiRJ/Fl9h6WLk4GARUJXo+OAKEuYVcJNonf+DCWKZvMTT+31gizkF3CUW/tnP ArHLTeLj8h0sExh5FzAyrGIUTS1ILihOSs810itOzC0uzUvXS87P3cQIDq9n0jsYVzVYHGIU 4GBU4uENOKYbJMSaWFZcmXuIUYKDWUmEl0tcP0iINyWxsiq1KD++qDQntfgQozQHi5I478FW 60AhgfTEktTs1NSC1CKYLBMHp1QDY1VPW9m69fF/9iifXLD329Ldd0V99/e/Xfhu23WGLYV9 U/c+tyz3bWLXqon26N1Tnxt1pWqinEsqO1NDUaDClJM2v82/63dceTnLMKYlc9/pmWrhresT bDd1Lni6wlduSt/FxV4C/YrMIX+nKDuurDng5xJR1Ve+9fu8vMPrmFIcGeXNrCRXKbEUZyQa ajEXFScCAF942WArAgAA Cc: Marek Vasut , Pantelis Antoniou , Tom Rini Subject: [U-Boot] [PATCH 4/4] dfu: Extract common DFU code to handle "dfu_alt_info" environment variable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Tested-by: Heiko Schocher --- common/cmd_dfu.c | 16 ++-------------- drivers/dfu/dfu.c | 23 +++++++++++++++++++++++ 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 180d083..8eca5db 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 8838f9c..58db1ef 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -114,6 +114,7 @@ char *dfu_extract_token(char** e, int *n); void dfu_trigger_reset(void); int dfu_get_alt(const char *name); 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);