From patchwork Mon Feb 9 14:44:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vince Bridgers X-Patchwork-Id: 438079 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 46BEC1400EA for ; Tue, 10 Feb 2015 07:36:47 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4FD914B5D3; Mon, 9 Feb 2015 21:36:39 +0100 (CET) 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 iuR_9XsHilal; Mon, 9 Feb 2015 21:36:39 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 77D304A058; Mon, 9 Feb 2015 21:36:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4B6FF4A029 for ; Mon, 9 Feb 2015 21:21:16 +0100 (CET) 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 nCHR6-eEUExb for ; Mon, 9 Feb 2015 21:21:16 +0100 (CET) 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 na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0072.outbound.protection.outlook.com [65.55.169.72]) by theia.denx.de (Postfix) with ESMTPS id 45EC04A020 for ; Mon, 9 Feb 2015 21:21:11 +0100 (CET) Received: from vince-HP-Z620-Workstation2.altera.com (64.129.157.38) by CY1PR0301MB0633.namprd03.prod.outlook.com (25.160.158.139) with Microsoft SMTP Server (TLS) id 15.1.87.13; Mon, 9 Feb 2015 18:49:06 +0000 From: Vince Bridgers To: Date: Mon, 9 Feb 2015 08:44:32 -0600 Message-ID: <1423493073-9462-2-git-send-email-vbridger@opensource.altera.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423493073-9462-1-git-send-email-vbridger@opensource.altera.com> References: <1423493073-9462-1-git-send-email-vbridger@opensource.altera.com> MIME-Version: 1.0 X-Originating-IP: [64.129.157.38] X-ClientProxiedBy: BN1PR02CA0025.namprd02.prod.outlook.com (10.141.56.25) To CY1PR0301MB0633.namprd03.prod.outlook.com (25.160.158.139) X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0633; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:CY1PR0301MB0633; X-Forefront-PRVS: 04825EA361 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(53416004)(77156002)(86362001)(2950100001)(50466002)(40100003)(47776003)(50226001)(76176999)(229853001)(110136001)(46102003)(19580405001)(62966003)(122386002)(33646002)(92566002)(66066001)(42186005)(50986999)(2351001)(48376002)(19580395003)(87976001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0633; H:vince-HP-Z620-Workstation2.altera.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB0633; X-OriginatorOrg: opensource.altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2015 18:49:06.3172 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB0633 X-Mailman-Approved-At: Mon, 09 Feb 2015 21:36:23 +0100 Cc: marex@denx.de, vbridger@altera.com, sr@denx.de Subject: [U-Boot] [PATCH 1/2] cmd: Add getenv_long to support reading signed integers from the uboot env X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch adds a function to read a signed integer from the uboot environment for the Micrel ksz9031 Phy driver to read postive and negatice skew values from the uboot environment. Signed-off-by: Vince Bridgers Reviewed-by: Marek Vasut --- common/cmd_nvedit.c | 22 +++++++++++++++++++++- include/common.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 855808c..ec23696 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -665,7 +665,27 @@ int getenv_f(const char *name, char *buf, unsigned len) } /** - * Decode the integer value of an environment variable and return it. + * Decode the signed integer 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 + */ +long getenv_long(const char *name, int base, long default_val) +{ + /* + * We can use getenv() here, even before relocation, since the + * environment variable value is an integer and thus short. + */ + const char *str = getenv(name); + + return str ? simple_strtol(str, NULL, base) : default_val; +} + +/** + * Decode the unsigned integer 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) diff --git a/include/common.h b/include/common.h index 97c8f79..55a8cb3 100644 --- a/include/common.h +++ b/include/common.h @@ -304,6 +304,7 @@ 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); +long getenv_long(const char *name, int base, long default_val); /** * getenv_hex() - Return an environment variable as a hex value