From patchwork Fri Oct 14 16:48:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 119856 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 C5744B6F9A for ; Sat, 15 Oct 2011 03:49:09 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7952328DA6; Fri, 14 Oct 2011 18:49:08 +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 nuaMxFN4FwgM; Fri, 14 Oct 2011 18:49:08 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4DCED28D34; Fri, 14 Oct 2011 18:49:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E492228D34 for ; Fri, 14 Oct 2011 18:49:04 +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 oluTO5tzFMEH for ; Fri, 14 Oct 2011 18:49:04 +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 0562228D14 for ; Fri, 14 Oct 2011 18:49:03 +0200 (CEST) Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by smtp-out.google.com with ESMTP id p9EGn0rQ010366; Fri, 14 Oct 2011 09:49:00 -0700 Received: from sglass.mtv.corp.google.com (sglass.mtv.corp.google.com [172.22.72.144]) by wpaz9.hot.corp.google.com with ESMTP id p9EGmxDY026281; Fri, 14 Oct 2011 09:48:59 -0700 Received: by sglass.mtv.corp.google.com (Postfix, from userid 121222) id 42B0D1409E5; Fri, 14 Oct 2011 09:48:59 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Fri, 14 Oct 2011 09:48:27 -0700 Message-Id: <1318610916-6975-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.3.1 X-System-Of-Record: true Subject: [U-Boot] [PATCH v2 01/10] Add getenv_ulong() to read an integer from an environment variable 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 This is not an uncommon operation in U-Boot, so let's put it in a common function. Signed-off-by: Simon Glass Acked-by: Mike Frysinger --- Changes in v2: - Fix commit title from getenv_int() to getenv_ulong() common/cmd_nvedit.c | 7 +++++++ include/common.h | 12 ++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 101bc49..337ae9a 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -540,6 +540,13 @@ int getenv_f(const char *name, char *buf, unsigned len) return -1; } +ulong getenv_ulong(const char *name, int base, ulong default_val) +{ + const char *str = getenv(name); + + return str ? simple_strtoul(str, NULL, base) : default_val; +} + #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) diff --git a/include/common.h b/include/common.h index eb19a44..c2796e2 100644 --- a/include/common.h +++ b/include/common.h @@ -288,6 +288,18 @@ void env_relocate (void); int envmatch (uchar *, int); char *getenv (const char *); int getenv_f (const char *name, char *buf, unsigned len); + +/** + * Decode the value of an environment variable and return it. + * + * @param name Name of environemnt variable + * @param base Number base to use (normally 10, or 16 for hex) + * @param default_val Default value to return if the variable is not + * found + * @return the decoded value, or default_val if not found + */ +ulong getenv_ulong(const char *name, int base, ulong default_val); + int saveenv (void); #ifdef CONFIG_PPC /* ARM version to be fixed! */ int inline setenv (const char *, const char *);