diff options
author | Simon Glass <sjg@chromium.org> | 2013-04-20 08:42:43 +0000 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2013-05-01 11:17:21 -0400 |
commit | 76b8f79c299ee8029c64c14a65cb0615bad77319 (patch) | |
tree | 083278d0544b8f486c3224fcff4703ebaafd40c5 /common/cmd_nvedit.c | |
parent | d14da91307d8378ea9a99044165e83b79dec67a1 (diff) | |
download | u-boot-imx-76b8f79c299ee8029c64c14a65cb0615bad77319.zip u-boot-imx-76b8f79c299ee8029c64c14a65cb0615bad77319.tar.gz u-boot-imx-76b8f79c299ee8029c64c14a65cb0615bad77319.tar.bz2 |
Add getenv_hex() to return an environment variable as hex
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 <sjg@chromium.org>
Diffstat (limited to 'common/cmd_nvedit.c')
-rw-r--r-- | common/cmd_nvedit.c | 15 |
1 files changed, 15 insertions, 0 deletions
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[]) { |