Skip to content
Snippets Groups Projects
Commit a7eb1d66 authored by Joe Hershberger's avatar Joe Hershberger Committed by Tom Rini
Browse files

mtd: Make mtdparts work with pre-reloc env


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: default avatarJoe Hershberger <joe.hershberger@ni.com>
parent 147162da
No related branches found
No related tags found
No related merge requests found
...@@ -106,6 +106,8 @@ ...@@ -106,6 +106,8 @@
#include <onenand_uboot.h> #include <onenand_uboot.h>
#endif #endif
DECLARE_GLOBAL_DATA_PTR;
/* special size referring to all the remaining space in a partition */ /* special size referring to all the remaining space in a partition */
#define SIZE_REMAINING 0xFFFFFFFF #define SIZE_REMAINING 0xFFFFFFFF
...@@ -1537,6 +1539,7 @@ static int parse_mtdparts(const char *const mtdparts) ...@@ -1537,6 +1539,7 @@ static int parse_mtdparts(const char *const mtdparts)
const char *p = mtdparts; const char *p = mtdparts;
struct mtd_device *dev; struct mtd_device *dev;
int err = 1; int err = 1;
char tmp_parts[MTDPARTS_MAXLEN];
debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p); debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
...@@ -1547,7 +1550,12 @@ static int parse_mtdparts(const char *const mtdparts) ...@@ -1547,7 +1550,12 @@ static int parse_mtdparts(const char *const mtdparts)
} }
/* re-read 'mtdparts' variable, mtd_devices_init may be updating env */ /* 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) { if (strncmp(p, "mtdparts=", 9) != 0) {
printf("mtdparts variable doesn't start with 'mtdparts='\n"); printf("mtdparts variable doesn't start with 'mtdparts='\n");
...@@ -1705,6 +1713,7 @@ int mtdparts_init(void) ...@@ -1705,6 +1713,7 @@ int mtdparts_init(void)
const char *current_partition; const char *current_partition;
int ids_changed; int ids_changed;
char tmp_ep[PARTITION_MAXLEN]; char tmp_ep[PARTITION_MAXLEN];
char tmp_parts[MTDPARTS_MAXLEN];
debug("\n---mtdparts_init---\n"); debug("\n---mtdparts_init---\n");
if (!initialized) { if (!initialized) {
...@@ -1718,7 +1727,17 @@ int mtdparts_init(void) ...@@ -1718,7 +1727,17 @@ int mtdparts_init(void)
/* get variables */ /* get variables */
ids = getenv("mtdids"); 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"); current_partition = getenv("partition");
/* save it for later parsing, cannot rely on current partition pointer /* save it for later parsing, cannot rely on current partition pointer
......
...@@ -273,6 +273,10 @@ int setenv(const char *varname, const char *varvalue) ...@@ -273,6 +273,10 @@ int setenv(const char *varname, const char *varvalue)
{ {
const char * const argv[4] = { "setenv", varname, varvalue, NULL }; 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') if (varvalue == NULL || varvalue[0] == '\0')
return _do_env_set(0, 2, (char * const *)argv); return _do_env_set(0, 2, (char * const *)argv);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment