[U-Boot] [PATCH 2/8] Add setenv_uint() and setenv_addr()

Simon Glass sjg at chromium.org
Sat Oct 22 06:51:34 CEST 2011


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 at chromium.org>
---
 common/cmd_nvedit.c |   29 +++++++++++++++++++++++++++++
 include/common.h    |    2 ++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 101bc49..da7028c 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -377,6 +377,35 @@ 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)
+{
+	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 55f772d..99c2a37 100644
--- a/include/common.h
+++ b/include/common.h
@@ -294,6 +294,8 @@ int inline setenv    (const char *, const char *);
 #else
 int	setenv	     (const char *, const char *);
 #endif /* CONFIG_PPC */
+int setenv_ulong(const char *varname, ulong value);
+int setenv_addr(const char *varname, const void *addr);
 #ifdef CONFIG_ARM
 # include <asm/mach-types.h>
 # include <asm/setup.h>
-- 
1.7.3.1



More information about the U-Boot mailing list