[U-Boot] [PATCH v3 09/18] env: Add a bootfile env handler

Joe Hershberger joe.hershberger at ni.com
Thu Nov 1 17:39:46 CET 2012


Remove the hard-coded bootfile handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---

 common/cmd_nvedit.c    |  9 ---------
 include/env_callback.h |  1 +
 net/net.c              | 17 +++++++++++++++++
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 12949aa..b3d0894 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -50,9 +50,6 @@
 #include <serial.h>
 #include <linux/stddef.h>
 #include <asm/byteorder.h>
-#if defined(CONFIG_CMD_NET)
-#include <net.h>
-#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -327,12 +324,6 @@ int env_change_ok(const ENTRY *item, const char *newval, enum env_op op,
 		load_addr = simple_strtoul(newval, NULL, 16);
 		return 0;
 	}
-#if defined(CONFIG_CMD_NET)
-	else if (strcmp(name, "bootfile") == 0) {
-		copy_filename(BootFile, newval, sizeof(BootFile));
-		return 0;
-	}
-#endif
 	return 0;
 }
 
diff --git a/include/env_callback.h b/include/env_callback.h
index 1a25e3f..caf2cc4 100644
--- a/include/env_callback.h
+++ b/include/env_callback.h
@@ -39,6 +39,7 @@
  * a new assogiation in the ".callbacks" environment variable.
  */
 #define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \
+	"bootfile:bootfile," \
 	CONFIG_ENV_CALLBACK_LIST_STATIC
 
 struct env_clbk_tbl {
diff --git a/net/net.c b/net/net.c
index c1fe00a..65be934 100644
--- a/net/net.c
+++ b/net/net.c
@@ -82,6 +82,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <environment.h>
 #include <net.h>
 #if defined(CONFIG_STATUS_LED)
 #include <miiphy.h>
@@ -208,6 +209,22 @@ static int NetTryCount;
 
 /**********************************************************************/
 
+static int on_bootfile(const char *name, const char *value, enum env_op op,
+	int flags)
+{
+	switch (op) {
+	case env_op_create:
+	case env_op_overwrite:
+		copy_filename(BootFile, value, sizeof(BootFile));
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+
 /*
  * Check if autoload is enabled. If so, use either NFS or TFTP to download
  * the boot file.
-- 
1.7.11.5



More information about the U-Boot mailing list