diff mbox

[U-Boot,1/2] cmd: Add getenv_long to support reading signed integers from the uboot env

Message ID 1423493073-9462-2-git-send-email-vbridger@opensource.altera.com
State Not Applicable
Delegated to: Marek Vasut
Headers show

Commit Message

Vince Bridgers Feb. 9, 2015, 2:44 p.m. UTC
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 <vbridger@opensource.altera.com>
---
 common/cmd_nvedit.c | 22 +++++++++++++++++++++-
 include/common.h    |  1 +
 2 files changed, 22 insertions(+), 1 deletion(-)

Comments

Marek Vasut Feb. 9, 2015, 7:12 p.m. UTC | #1
On Monday, February 09, 2015 at 03:44:32 PM, Vince Bridgers wrote:
> 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 <vbridger@opensource.altera.com>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
diff mbox

Patch

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