@@ -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)
@@ -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
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(-)