]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
env: Fix env_load_location
authorYork Sun <york.sun@nxp.com>
Wed, 7 Feb 2018 22:17:11 +0000 (14:17 -0800)
committerTom Rini <trini@konsulko.com>
Fri, 16 Feb 2018 16:12:41 +0000 (11:12 -0500)
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>
env/env.c
include/asm-generic/global_data.h
include/environment.h

index 9a89832c1aafc79ba4d59536306a0561e84e2db2..edfb575c0e01ee9a7c7ea147823612b22d0cf252 100644 (file)
--- a/env/env.c
+++ b/env/env.c
@@ -62,8 +62,6 @@ static enum env_location env_locations[] = {
 #endif
 };
 
-static enum env_location env_load_location = ENVL_UNKNOWN;
-
 static bool env_has_inited(enum env_location location)
 {
        return gd->env_has_init & BIT(location);
@@ -108,11 +106,11 @@ __weak enum env_location env_get_location(enum env_operation op, int prio)
                if (prio >= ARRAY_SIZE(env_locations))
                        return ENVL_UNKNOWN;
 
-               env_load_location = env_locations[prio];
-               return env_load_location;
+               gd->env_load_location = env_locations[prio];
+               return gd->env_load_location;
 
        case ENVOP_SAVE:
-               return env_load_location;
+               return gd->env_load_location;
        }
 
        return ENVL_UNKNOWN;
index 1de67e8e8f56d9aaa2deea47c1daf455375bb43a..c16ad73864a36e2957b6d80622345e2b80e14c6d 100644 (file)
@@ -51,6 +51,7 @@ typedef struct global_data {
        unsigned long env_addr;         /* Address  of Environment struct */
        unsigned long env_valid;        /* Environment valid? enum env_valid */
        unsigned long env_has_init;     /* Bitmask of boolean of struct env_location offsets */
+       int env_load_location;
 
        unsigned long ram_top;          /* Top address of RAM used by U-Boot */
        unsigned long relocaddr;        /* Start address of U-Boot in RAM */
index 6044b9e1b463e84c9bc20e7f1e8eac59fbc46168..d7037ccd9318b41227078ee707c04eaa35277ef1 100644 (file)
@@ -188,6 +188,7 @@ enum env_valid {
 };
 
 enum env_location {
+       ENVL_UNKNOWN,
        ENVL_EEPROM,
        ENVL_EXT4,
        ENVL_FAT,
@@ -202,7 +203,6 @@ enum env_location {
        ENVL_NOWHERE,
 
        ENVL_COUNT,
-       ENVL_UNKNOWN,
 };
 
 /* value for the various operations we want to perform on the env */