[U-Boot] [RFC PATCH v2 2/5] env: Add a loadaddr env handler

Joe Hershberger joe.hershberger at ni.com
Fri Sep 28 00:47:37 CEST 2012


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

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

 common/cmd_load.c      | 24 ++++++++++++++++++++++--
 common/cmd_nvedit.c    | 10 +---------
 include/env_callback.h |  1 +
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/common/cmd_load.c b/common/cmd_load.c
index f4d66de..8849596 100644
--- a/common/cmd_load.c
+++ b/common/cmd_load.c
@@ -30,9 +30,14 @@
 #include <net.h>
 #include <exports.h>
 #include <xyzModem.h>
+#include <environment.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+ulong load_addr = CONFIG_SYS_LOAD_ADDR;	/* Default Load Address */
+ulong save_addr;			/* Default Save Address */
+ulong save_size;			/* Default Save Size (in bytes) */
+
 #if defined(CONFIG_CMD_LOADB)
 static ulong load_serial_ymodem (ulong offset);
 #endif
@@ -50,6 +55,21 @@ static int do_echo = 1;
 
 /* -------------------------------------------------------------------- */
 
+static int on_loadaddr(const char *name, const char *value, enum env_op op)
+{
+	switch (op) {
+	case env_op_create:
+	case env_op_overwrite:
+		load_addr = simple_strtoul(value, NULL, 16);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
+
 #if defined(CONFIG_CMD_LOADS)
 int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
@@ -257,8 +277,8 @@ read_record (char *buf, ulong len)
 
 int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	ulong offset = 0;
-	ulong size   = 0;
+	ulong offset = save_addr;
+	ulong size   = save_size;
 #ifdef	CONFIG_SYS_LOADS_BAUD_CHANGE
 	int save_baudrate, current_baudrate;
 
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index fd05e72..9e8ea12 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -79,10 +79,6 @@ SPI_FLASH|NVRAM|MMC|FAT|REMOTE} or CONFIG_ENV_IS_NOWHERE
  */
 #define	MAX_ENV_SIZE	(1 << 20)	/* 1 MiB */
 
-ulong load_addr = CONFIG_SYS_LOAD_ADDR;	/* Default Load Address */
-ulong save_addr;			/* Default Save Address */
-ulong save_size;			/* Default Save Size (in bytes) */
-
 /*
  * Table with supported baudrates (defined in config_xyz.h)
  */
@@ -341,12 +337,8 @@ int _do_env_set(int flag, int argc, char * const argv[])
 	 * Some variables should be updated when the corresponding
 	 * entry in the environment is changed
 	 */
-	if (strcmp(argv[1], "loadaddr") == 0) {
-		load_addr = simple_strtoul(argv[2], NULL, 16);
-		return 0;
-	}
 #if defined(CONFIG_CMD_NET)
-	else if (strcmp(argv[1], "bootfile") == 0) {
+	if (strcmp(argv[1], "bootfile") == 0) {
 		copy_filename(BootFile, argv[2], sizeof(BootFile));
 		return 0;
 	}
diff --git a/include/env_callback.h b/include/env_callback.h
index 76ac865..9c1cbe9 100644
--- a/include/env_callback.h
+++ b/include/env_callback.h
@@ -36,6 +36,7 @@
  * a new assogiation in the ".callbacks" environment variable.
  */
 #define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \
+	"loadaddr:loadaddr," \
 	CONFIG_ENV_CALLBACK_LIST_STATIC
 
 enum env_op {
-- 
1.7.11.5



More information about the U-Boot mailing list