From: Vince Bridgers <vbridger@opensource.altera.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] cmd: Add getenv_long to support reading signed integers from the uboot env
Date: Mon, 9 Feb 2015 08:44:32 -0600 [thread overview]
Message-ID: <1423493073-9462-2-git-send-email-vbridger@opensource.altera.com> (raw)
In-Reply-To: <1423493073-9462-1-git-send-email-vbridger@opensource.altera.com>
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(-)
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
--
1.9.1
next prev parent reply other threads:[~2015-02-09 14:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 14:44 [U-Boot] [PATCH 0/2] Add getenv_long and Micrel ksz9031 skew settings Vince Bridgers
2015-02-09 14:44 ` Vince Bridgers [this message]
2015-02-09 19:12 ` [U-Boot] [PATCH 1/2] cmd: Add getenv_long to support reading signed integers from the uboot env Marek Vasut
2015-02-09 14:44 ` [U-Boot] [PATCH 2/2] net: phy: Add ability to program the ksz9031 skew values " Vince Bridgers
2015-02-09 19:18 ` Marek Vasut
2015-02-09 21:31 ` Vince Bridgers
2015-02-10 18:51 ` Marek Vasut
2015-02-11 7:08 ` Stefan Roese
2015-02-11 8:07 ` Joe Hershberger
2015-02-11 8:26 ` Stefan Roese
2015-02-13 16:19 ` Vince Bridgers
2015-02-13 16:44 ` Stefan Roese
2015-02-15 14:43 ` Marek Vasut
2015-02-13 16:17 ` Vince Bridgers
2015-02-13 16:05 ` Vince Bridgers
2015-02-13 15:57 ` Vince Bridgers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423493073-9462-2-git-send-email-vbridger@opensource.altera.com \
--to=vbridger@opensource.altera.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox