diff options
author | Simon Glass <sjg@chromium.org> | 2011-10-14 13:25:18 +0000 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2011-10-23 23:32:45 +0200 |
commit | 4a9b413108f4bd274973398356b45c0346238bc9 (patch) | |
tree | dae25295771bffb5d81b5bfb84d3dba5d1cd7e94 /common | |
parent | 3668d8fa0417a3082aa57dd5e0db8fbe887c31e0 (diff) | |
download | u-boot-imx-4a9b413108f4bd274973398356b45c0346238bc9.zip u-boot-imx-4a9b413108f4bd274973398356b45c0346238bc9.tar.gz u-boot-imx-4a9b413108f4bd274973398356b45c0346238bc9.tar.bz2 |
Add getenv_ulong() to read an integer from an environment variable
This is not an uncommon operation in U-Boot, so let's put it in a common
function.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/cmd_nvedit.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 101bc49..fa99c44 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -540,6 +540,26 @@ int getenv_f(const char *name, char *buf, unsigned len) return -1; } +/** + * Decode the 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 + */ +ulong getenv_ulong(const char *name, int base, ulong 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_strtoul(str, NULL, base) : default_val; +} + #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |