From patchwork Sat Apr 20 18:42:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 238169 X-Patchwork-Delegate: sjg@chromium.org 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 BE43B2C0082 for ; Sun, 21 Apr 2013 04:46:52 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5CCE44A47B; Sat, 20 Apr 2013 20:45:55 +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 bW2ulA3RaP06; Sat, 20 Apr 2013 20:45:55 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5E2544A47C; Sat, 20 Apr 2013 20:44:23 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 852F24A446 for ; Sat, 20 Apr 2013 20:43:56 +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 x9giOrW5p2xP for ; Sat, 20 Apr 2013 20:43:55 +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 mail-vc0-f202.google.com (mail-vc0-f202.google.com [209.85.220.202]) by theia.denx.de (Postfix) with ESMTPS id 6AFD74A3C9 for ; Sat, 20 Apr 2013 20:43:18 +0200 (CEST) Received: by mail-vc0-f202.google.com with SMTP id m16so545592vca.5 for ; Sat, 20 Apr 2013 11:43:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=/dhzMhtdBWOtj8gWYt1UifhcA27S7VGnw1qjfqJAiGQ=; b=dxTQFq+PPr/r6qSzPvHPoU4knEoLyFJs426UJWCvyziYKRVOm0Hr5M0j6acWQpWCdx WOcYvQx/J+zw3Lrt8IYbq7sfShmKbZN9R0kGPmTSa/NUQMgwH/H4V9csnaluUMj51tek qfufKtix1/TwRxDNQPc78KXmzHFhV9RGSs+i/ksbTMnT7R0mM4C5aMwYrYcS/Eft5vrY LvBX+ZPeH38ToX9sMRi/gNiarbS98vztOIzM4dWMqpBnczOF/Wmr70J+efb+9dMYmxsZ j9nADjQyefoRoJI8QEY6hsY9l1eBaZa8o4LkmEqCvhgB34v3RT4a/uZUS9ckENhRL3Q7 Z1iQ== X-Received: by 10.236.91.109 with SMTP id g73mr10000717yhf.23.1366483395358; Sat, 20 Apr 2013 11:43:15 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id k57si333520yhi.3.2013.04.20.11.43.15 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 20 Apr 2013 11:43:15 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 384BC5A40F3; Sat, 20 Apr 2013 11:43:15 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 19575160982; Sat, 20 Apr 2013 11:43:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 20 Apr 2013 11:42:43 -0700 Message-Id: <1366483372-16523-9-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366483372-16523-1-git-send-email-sjg@chromium.org> References: <1366483372-16523-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQkfqhF1yRJDhTSVH/GKX3sCJMfjTmKHMmrSYkr7tZWDK1dRXP962i8xqVHRB4EzpGBiQfZ+s6nf7oRwuHZ7Kx6wFe0y3kwk4tQ/PcrOfua71tquQCfzui2kbAjkYExdCVpy76SO1w4MCgCbz08rlgHo9MC8DkWss7jJ5nv/jP+uE80NZvlSOUuEeTxtJiC6vIMXGvo8 Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [PATCH v3 08/17] Add getenv_hex() to return an environment variable as hex 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 This conversion is required in a number of places in U-Boot. Add a standard function to provide this feature, so we avoid all the different variations in the way it is coded. Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None common/cmd_nvedit.c | 15 +++++++++++++++ include/common.h | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 68b0f4f..d893aa1 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -315,6 +315,21 @@ int setenv_hex(const char *varname, ulong value) return setenv(varname, str); } +ulong getenv_hex(const char *varname, ulong default_val) +{ + const char *s; + ulong value; + char *endp; + + s = getenv(varname); + if (s) + value = simple_strtoul(s, &endp, 16); + if (!s || endp == s) + return default_val; + + return value; +} + #ifndef CONFIG_SPL_BUILD static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/include/common.h b/include/common.h index 76c79ae..28aa4b9 100644 --- a/include/common.h +++ b/include/common.h @@ -352,6 +352,19 @@ int envmatch (uchar *, int); char *getenv (const char *); int getenv_f (const char *name, char *buf, unsigned len); ulong getenv_ulong(const char *name, int base, ulong default_val); + +/** + * getenv_hex() - Return an environment variable as a hex value + * + * Decode an environment as a hex number (it may or may not have a 0x + * prefix). If the environment variable cannot be found, or does not start + * with hex digits, the default value is returned. + * + * @varname: Variable to decode + * @default_val: Value to return on error + */ +ulong getenv_hex(const char *varname, ulong default_val); + /* * Read an environment variable as a boolean * Return -1 if variable does not exist (default to true)