From patchwork Sat Oct 22 04:51:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 121136 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 55DCD1007D3 for ; Sat, 22 Oct 2011 15:52:23 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9C08F295B8; Sat, 22 Oct 2011 06:52:21 +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 byyW629aY1pl; Sat, 22 Oct 2011 06:52:21 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E227129565; Sat, 22 Oct 2011 06:52:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 04ADF294ED for ; Sat, 22 Oct 2011 06:52:18 +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 RYQzYIpN4Md0 for ; Sat, 22 Oct 2011 06:52:17 +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 smtp-out.google.com (smtp-out.google.com [216.239.44.51]) by theia.denx.de (Postfix) with ESMTPS id 4A40929457 for ; Sat, 22 Oct 2011 06:52:17 +0200 (CEST) Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id p9M4qEQ3013006; Fri, 21 Oct 2011 21:52:14 -0700 Received: from glucid-laptop-imager.hot.corp.google.com ([172.19.240.38]) by wpaz21.hot.corp.google.com with ESMTP id p9M4qDo5016152; Fri, 21 Oct 2011 21:52:13 -0700 Received: by glucid-laptop-imager.hot.corp.google.com (Postfix, from userid 121222) id 5330A34E683; Fri, 21 Oct 2011 21:52:13 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Fri, 21 Oct 2011 21:51:34 -0700 Message-Id: <1319259100-11376-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1319259100-11376-1-git-send-email-sjg@chromium.org> References: <1319259100-11376-1-git-send-email-sjg@chromium.org> X-System-Of-Record: true Subject: [U-Boot] [PATCH 2/8] Add setenv_uint() and setenv_addr() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 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 It seems we put numbers and addresses into environment variables a lot. We should have some functions to do this. Signed-off-by: Simon Glass --- common/cmd_nvedit.c | 29 +++++++++++++++++++++++++++++ include/common.h | 2 ++ 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 101bc49..da7028c 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -377,6 +377,35 @@ int setenv(const char *varname, const char *varvalue) return _do_env_set(0, 3, (char * const *)argv); } +/** + * Set an environment variable to an integer value + * + * @param varname Environmet variable to set + * @param value Value to set it to + * @return 0 if ok, 1 on error + */ +int setenv_ulong(const char *varname, ulong value) +{ + char *str = simple_itoa(value); + + return setenv(varname, str); +} + +/** + * Set an environment variable to an address in hex + * + * @param varname Environmet variable to set + * @param addr Value to set it to + * @return 0 if ok, 1 on error + */ +int setenv_addr(const char *varname, const void *addr) +{ + char str[17]; + + sprintf(str, "%x", (uintptr_t)addr); + return setenv(varname, str); +} + int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) diff --git a/include/common.h b/include/common.h index 55f772d..99c2a37 100644 --- a/include/common.h +++ b/include/common.h @@ -294,6 +294,8 @@ int inline setenv (const char *, const char *); #else int setenv (const char *, const char *); #endif /* CONFIG_PPC */ +int setenv_ulong(const char *varname, ulong value); +int setenv_addr(const char *varname, const void *addr); #ifdef CONFIG_ARM # include # include