Patchwork [U-Boot,11/20] Update set_working_fdt_addr() to use setenv_addr()

login
register
mail settings
Submitter Simon Glass
Date Dec. 26, 2012, 6:57 p.m.
Message ID <1356548233-5570-12-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/208190/
State Superseded, archived
Delegated to: Simon Glass
Headers show

Comments

Simon Glass - Dec. 26, 2012, 6:57 p.m.
We might as well use this common function instead of repeating the same
code.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_fdt.c    |   11 ++---------
 common/cmd_nvedit.c |    8 ++++----
 include/common.h    |   14 +++++++++++++-
 3 files changed, 19 insertions(+), 14 deletions(-)
Simon Glass - Feb. 15, 2013, 11:54 p.m.
On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass <sjg@chromium.org> wrote:
> We might as well use this common function instead of repeating the same
> code.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to x86/master.

> ---
>  common/cmd_fdt.c    |   11 ++---------
>  common/cmd_nvedit.c |    8 ++++----
>  include/common.h    |   14 +++++++++++++-
>  3 files changed, 19 insertions(+), 14 deletions(-)

Patch

diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
index 9e2de34..0bdf7b6 100644
--- a/common/cmd_fdt.c
+++ b/common/cmd_fdt.c
@@ -56,12 +56,8 @@  struct fdt_header *working_fdt;
 
 void set_working_fdt_addr(void *addr)
 {
-	char buf[17];
-
 	working_fdt = addr;
-
-	sprintf(buf, "%lx", (unsigned long)addr);
-	setenv("fdtaddr", buf);
+	setenv_addr("fdtaddr", addr);
 }
 
 /*
@@ -348,10 +344,7 @@  static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			}
 			if (subcmd[0] == 's') {
 				/* get the num nodes at this level */
-				char buf[11];
-
-				sprintf(buf, "%d", curIndex + 1);
-				setenv(var, buf);
+				setenv_ulong(var, curIndex + 1);
 			} else {
 				/* node index not found */
 				printf("libfdt node not found\n");
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 7633f0c..44e88aa 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -295,17 +295,17 @@  int setenv_ulong(const char *varname, ulong value)
 }
 
 /**
- * Set an environment variable to an address in hex
+ * Set an environment variable to an value in hex
  *
  * @param varname	Environmet variable to set
- * @param addr		Value to set it to
+ * @param value		Value to set it to
  * @return 0 if ok, 1 on error
  */
-int setenv_addr(const char *varname, const void *addr)
+int setenv_hex(const char *varname, ulong value)
 {
 	char str[17];
 
-	sprintf(str, "%lx", (uintptr_t)addr);
+	sprintf(str, "%lx", value);
 	return setenv(varname, str);
 }
 
diff --git a/include/common.h b/include/common.h
index 08d01db..8ecaf56 100644
--- a/include/common.h
+++ b/include/common.h
@@ -349,7 +349,19 @@  int getenv_yesno(const char *var);
 int	saveenv	     (void);
 int	setenv	     (const char *, const char *);
 int setenv_ulong(const char *varname, ulong value);
-int setenv_addr(const char *varname, const void *addr);
+int setenv_hex(const char *varname, ulong value);
+/**
+ * setenv_addr - Set an environment variable to an address in hex
+ *
+ * @varname:	Environmet variable to set
+ * @addr:	Value to set it to
+ * @return 0 if ok, 1 on error
+ */
+static inline int setenv_addr(const char *varname, const void *addr)
+{
+	return setenv_hex(varname, (ulong)addr);
+}
+
 #ifdef CONFIG_ARM
 # include <asm/mach-types.h>
 # include <asm/setup.h>