Commit e1caa5841e8a9bc0ee658bdacae0519fa28e1e6a

Authored by York Sun
Committed by Tom Rini
1 parent 32fe36574e

env: Fix env_load_location

Commit 7d714a24d725 ("env: Support multiple environments") added
static variable env_load_location. When saving environmental
variables, this variable is presumed to have the value set before.
In case the value was set before relocation and U-Boot runs from a
NOR flash, this variable wasn't writable. This causes failure when
saving the environment. To save this location, global data must be
used instead.

Signed-off-by: York Sun <york.sun@nxp.com>
CC: Maxime Ripard <maxime.ripard@free-electrons.com>

Showing 3 changed files with 5 additions and 6 deletions Side-by-side Diff

... ... @@ -62,8 +62,6 @@
62 62 #endif
63 63 };
64 64  
65   -static enum env_location env_load_location = ENVL_UNKNOWN;
66   -
67 65 static bool env_has_inited(enum env_location location)
68 66 {
69 67 return gd->env_has_init & BIT(location);
70 68  
... ... @@ -108,11 +106,11 @@
108 106 if (prio >= ARRAY_SIZE(env_locations))
109 107 return ENVL_UNKNOWN;
110 108  
111   - env_load_location = env_locations[prio];
112   - return env_load_location;
  109 + gd->env_load_location = env_locations[prio];
  110 + return gd->env_load_location;
113 111  
114 112 case ENVOP_SAVE:
115   - return env_load_location;
  113 + return gd->env_load_location;
116 114 }
117 115  
118 116 return ENVL_UNKNOWN;
include/asm-generic/global_data.h
... ... @@ -51,6 +51,7 @@
51 51 unsigned long env_addr; /* Address of Environment struct */
52 52 unsigned long env_valid; /* Environment valid? enum env_valid */
53 53 unsigned long env_has_init; /* Bitmask of boolean of struct env_location offsets */
  54 + int env_load_location;
54 55  
55 56 unsigned long ram_top; /* Top address of RAM used by U-Boot */
56 57 unsigned long relocaddr; /* Start address of U-Boot in RAM */
include/environment.h
... ... @@ -188,6 +188,7 @@
188 188 };
189 189  
190 190 enum env_location {
  191 + ENVL_UNKNOWN,
191 192 ENVL_EEPROM,
192 193 ENVL_EXT4,
193 194 ENVL_FAT,
... ... @@ -202,7 +203,6 @@
202 203 ENVL_NOWHERE,
203 204  
204 205 ENVL_COUNT,
205   - ENVL_UNKNOWN,
206 206 };
207 207  
208 208 /* value for the various operations we want to perform on the env */