Patchwork [U-Boot,v2,4/6] mtd: Make mtdparts work with pre-reloc env

login
register
mail settings
Submitter Joe Hershberger
Date March 26, 2013, 9:53 p.m.
Message ID <1364334811-3118-5-git-send-email-joe.hershberger@ni.com>
Download mbox | patch
Permalink /patch/231547/
State Superseded
Delegated to: Tom Rini
Headers show

Comments

Joe Hershberger - March 26, 2013, 9:53 p.m.
The env in UBI needs to look up the mtd partition as part of relocation,
which happens before relocation.  Make the mtdparts code capable of
working on the default env to start with.

The code tries to set values in the env as well, but again, the env
isn't there yet, so add a check to setenv to not allow sets before the
env is relocated.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---
Changes in v2: None

 common/cmd_mtdparts.c | 23 +++++++++++++++++++++--
 common/cmd_nvedit.c   |  4 ++++
 2 files changed, 25 insertions(+), 2 deletions(-)

Patch

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 06fc171..e72dc38 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -106,6 +106,8 @@ 
 #include <onenand_uboot.h>
 #endif
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* special size referring to all the remaining space in a partition */
 #define SIZE_REMAINING		0xFFFFFFFF
 
@@ -1539,6 +1541,7 @@  static int parse_mtdparts(const char *const mtdparts)
 	const char *p = mtdparts;
 	struct mtd_device *dev;
 	int err = 1;
+	char tmp_parts[MTDPARTS_MAXLEN];
 
 	debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
 
@@ -1549,7 +1552,12 @@  static int parse_mtdparts(const char *const mtdparts)
 	}
 
 	/* re-read 'mtdparts' variable, mtd_devices_init may be updating env */
-	p = getenv("mtdparts");
+	if (gd->flags & GD_FLG_ENV_READY) {
+		p = getenv("mtdparts");
+	} else {
+		p = tmp_parts;
+		getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+	}
 
 	if (strncmp(p, "mtdparts=", 9) != 0) {
 		printf("mtdparts variable doesn't start with 'mtdparts='\n");
@@ -1707,6 +1715,7 @@  int mtdparts_init(void)
 	const char *current_partition;
 	int ids_changed;
 	char tmp_ep[PARTITION_MAXLEN];
+	char tmp_parts[MTDPARTS_MAXLEN];
 
 	debug("\n---mtdparts_init---\n");
 	if (!initialized) {
@@ -1720,7 +1729,17 @@  int mtdparts_init(void)
 
 	/* get variables */
 	ids = getenv("mtdids");
-	parts = getenv("mtdparts");
+	/*
+	 * The mtdparts variable tends to be long. If we need to access it
+	 * before the env is relocated, then we need to use our own stack
+	 * buffer.  gd->env_buf will be too small.
+	 */
+	if (gd->flags & GD_FLG_ENV_READY) {
+		parts = getenv("mtdparts");
+	} else {
+		parts = tmp_parts;
+		getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+	}
 	current_partition = getenv("partition");
 
 	/* save it for later parsing, cannot rely on current partition pointer
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 7633f0c..c7c6440 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -273,6 +273,10 @@  int setenv(const char *varname, const char *varvalue)
 {
 	const char * const argv[4] = { "setenv", varname, varvalue, NULL };
 
+	/* before import into hashtable */
+	if (!(gd->flags & GD_FLG_ENV_READY))
+		return 1;
+
 	if (varvalue == NULL || varvalue[0] == '\0')
 		return _do_env_set(0, 2, (char * const *)argv);
 	else