diff options
author | Simon Glass <sjg@chromium.org> | 2011-10-24 17:59:59 (GMT) |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2011-10-26 19:32:42 (GMT) |
commit | d67f10ce0f5a4c114437ac6fb5891ae38e3054f8 (patch) | |
tree | eedd7aed103d877971c4ac2ad9d59a51cf0f8ce7 | |
parent | 3cce8a5496452285e1828984ad3945417205cfc3 (diff) | |
download | u-boot-d67f10ce0f5a4c114437ac6fb5891ae38e3054f8.tar.xz |
Add setenv_ulong() and setenv_addr()
It seems we put numbers and addresses into environment variables a lot.
We should have some functions to do this.
Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | common/cmd_nvedit.c | 30 | ||||
-rw-r--r-- | include/common.h | 2 |
2 files changed, 32 insertions, 0 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index fa99c44..4e27ba0 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -377,6 +377,36 @@ int setenv(const char *varname, const char *varvalue) return _do_env_set(0, 3, (char * const *)argv); } +/** + * Set an environment variable to an integer value + * + * @param varname Environmet variable to set + * @param value Value to set it to + * @return 0 if ok, 1 on error + */ +int setenv_ulong(const char *varname, ulong value) +{ + /* TODO: this should be unsigned */ + char *str = simple_itoa(value); + + return setenv(varname, str); +} + +/** + * Set an environment variable to an address in hex + * + * @param varname Environmet variable to set + * @param addr Value to set it to + * @return 0 if ok, 1 on error + */ +int setenv_addr(const char *varname, const void *addr) +{ + char str[17]; + + sprintf(str, "%x", (uintptr_t)addr); + return setenv(varname, str); +} + int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 2) diff --git a/include/common.h b/include/common.h index 8b719ea..9166ca1 100644 --- a/include/common.h +++ b/include/common.h @@ -303,6 +303,8 @@ int saveenv (void); int inline setenv (const char *, const char *); #else int setenv (const char *, const char *); +int setenv_ulong(const char *varname, ulong value); +int setenv_addr(const char *varname, const void *addr); #endif /* CONFIG_PPC */ #ifdef CONFIG_ARM # include <asm/mach-types.h> |