summaryrefslogtreecommitdiff
path: root/env
diff options
context:
space:
mode:
Diffstat (limited to 'env')
-rw-r--r--env/Kconfig29
-rw-r--r--env/common.c16
-rw-r--r--env/eeprom.c2
-rw-r--r--env/env.c94
-rw-r--r--env/ext4.c54
-rw-r--r--env/fat.c34
-rw-r--r--env/flags.c66
-rw-r--r--env/flash.c2
-rw-r--r--env/mmc.c30
-rw-r--r--env/nand.c4
-rw-r--r--env/nowhere.c17
-rw-r--r--env/nvram.c2
-rw-r--r--env/onenand.c2
-rw-r--r--env/remote.c2
-rw-r--r--env/sata.c2
-rw-r--r--env/sf.c6
-rw-r--r--env/ubi.c4
17 files changed, 300 insertions, 66 deletions
diff --git a/env/Kconfig b/env/Kconfig
index 38e7fadbb9..5d0a8ecea0 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -6,6 +6,12 @@ config ENV_SUPPORT
config SAVEENV
def_bool y if CMD_SAVEENV
+config ENV_OVERWRITE
+ bool "Enable overwriting environment"
+ help
+ Use this to permit overriding of certain environmental variables
+ like Ethernet and Serial
+
config ENV_IS_NOWHERE
bool "Environment is not stored"
default y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
@@ -434,6 +440,10 @@ config ENV_FAT_DEVICE_AND_PART
If none, first valid partition in device D. If no
partition table then means device D.
+ If ENV_FAT_INTERFACE is set to "mmc" then device 'D' can be omitted,
+ leaving the string starting with a colon, and the boot device will
+ be used.
+
config ENV_FAT_FILE
string "Name of the FAT file to use for the environment"
depends on ENV_IS_IN_FAT
@@ -469,7 +479,7 @@ config ENV_EXT4_DEVICE_AND_PART
config ENV_EXT4_FILE
string "Name of the EXT4 file to use for the environment"
depends on ENV_IS_IN_EXT4
- default "uboot.env"
+ default "/uboot.env"
help
It's a string of the EXT4 file name. This file use to store the
environment (explicit path to the file)
@@ -604,6 +614,23 @@ config DELAY_ENVIRONMENT
later by U-Boot code. With CONFIG_OF_CONTROL this is instead
controlled by the value of /config/load-environment.
+config ENV_APPEND
+ bool "Always append the environment with new data"
+ default n
+ help
+ If defined, the environment hash table is only ever appended with new
+ data, but the existing hash table can never be dropped and reloaded
+ with newly imported data. This may be used in combination with static
+ flags to e.g. to protect variables which must not be modified.
+
+config ENV_WRITEABLE_LIST
+ bool "Permit write access only to listed variables"
+ default n
+ help
+ If defined, only environment variables which explicitly set the 'w'
+ writeable flag can be written and modified at runtime. No variables
+ can be otherwise created, written or imported into the environment.
+
config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations"
default n
diff --git a/env/common.c b/env/common.c
index 088b2aebb4..ed18378000 100644
--- a/env/common.c
+++ b/env/common.c
@@ -81,6 +81,7 @@ void env_set_default(const char *s, int flags)
debug("Using default environment\n");
}
+ flags |= H_DEFAULT;
if (himport_r(&env_htab, (char *)default_environment,
sizeof(default_environment), '\0', flags, 0,
0, NULL) == 0)
@@ -99,7 +100,7 @@ int env_set_default_vars(int nvars, char * const vars[], int flags)
* Special use-case: import from default environment
* (and use \0 as a separator)
*/
- flags |= H_NOCLEAR;
+ flags |= H_NOCLEAR | H_DEFAULT;
return himport_r(&env_htab, (const char *)default_environment,
sizeof(default_environment), '\0',
flags, 0, nvars, vars);
@@ -109,7 +110,7 @@ int env_set_default_vars(int nvars, char * const vars[], int flags)
* Check if CRC is valid and (if yes) import the environment.
* Note that "buf" may or may not be aligned.
*/
-int env_import(const char *buf, int check)
+int env_import(const char *buf, int check, int flags)
{
env_t *ep = (env_t *)buf;
@@ -124,7 +125,7 @@ int env_import(const char *buf, int check)
}
}
- if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0,
+ if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', flags, 0,
0, NULL)) {
gd->flags |= GD_FLG_ENV_READY;
return 0;
@@ -141,7 +142,8 @@ int env_import(const char *buf, int check)
static unsigned char env_flags;
int env_import_redund(const char *buf1, int buf1_read_fail,
- const char *buf2, int buf2_read_fail)
+ const char *buf2, int buf2_read_fail,
+ int flags)
{
int crc1_ok, crc2_ok;
env_t *ep, *tmp_env1, *tmp_env2;
@@ -161,10 +163,10 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
return -EIO;
} else if (!buf1_read_fail && buf2_read_fail) {
gd->env_valid = ENV_VALID;
- return env_import((char *)tmp_env1, 1);
+ return env_import((char *)tmp_env1, 1, flags);
} else if (buf1_read_fail && !buf2_read_fail) {
gd->env_valid = ENV_REDUND;
- return env_import((char *)tmp_env2, 1);
+ return env_import((char *)tmp_env2, 1, flags);
}
crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) ==
@@ -199,7 +201,7 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
ep = tmp_env2;
env_flags = ep->flags;
- return env_import((char *)ep, 0);
+ return env_import((char *)ep, 0, flags);
}
#endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
diff --git a/env/eeprom.c b/env/eeprom.c
index e8126cfe39..e300470ad0 100644
--- a/env/eeprom.c
+++ b/env/eeprom.c
@@ -188,7 +188,7 @@ static int env_eeprom_load(void)
eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
off, (uchar *)buf_env, CONFIG_ENV_SIZE);
- return env_import(buf_env, 1);
+ return env_import(buf_env, 1, H_EXTERNAL);
}
static int env_eeprom_save(void)
diff --git a/env/env.c b/env/env.c
index dcc25c030b..42c7d8155e 100644
--- a/env/env.c
+++ b/env/env.c
@@ -103,7 +103,7 @@ static void env_set_inited(enum env_location location)
* using the above enum value as the bit index. We need to
* make sure that we're not overflowing it.
*/
- BUILD_BUG_ON(ARRAY_SIZE(env_locations) > BITS_PER_LONG);
+ BUILD_BUG_ON(ENVL_COUNT > BITS_PER_LONG);
gd->env_has_init |= BIT(location);
}
@@ -131,8 +131,6 @@ __weak enum env_location env_get_location(enum env_operation op, int prio)
if (prio >= ARRAY_SIZE(env_locations))
return ENVL_UNKNOWN;
- gd->env_load_prio = prio;
-
return env_locations[prio];
}
@@ -189,9 +187,6 @@ int env_load(void)
for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) {
int ret;
- if (!drv->load)
- continue;
-
if (!env_has_inited(drv->location))
continue;
@@ -204,7 +199,11 @@ int env_load(void)
ret = drv->load();
if (!ret) {
printf("OK\n");
+ gd->env_load_prio = prio;
+
+#if !CONFIG_IS_ENABLED(ENV_APPEND)
return 0;
+#endif
} else if (ret == -ENOMSG) {
/* Handle "bad CRC" case */
if (best_prio == -1)
@@ -227,7 +226,36 @@ int env_load(void)
debug("Selecting environment with bad CRC\n");
else
best_prio = 0;
- env_get_location(ENVOP_LOAD, best_prio);
+
+ gd->env_load_prio = best_prio;
+
+ return -ENODEV;
+}
+
+int env_reload(void)
+{
+ struct env_driver *drv;
+
+ drv = env_driver_lookup(ENVOP_LOAD, gd->env_load_prio);
+ if (drv) {
+ int ret;
+
+ printf("Loading Environment from %s... ", drv->name);
+
+ if (!env_has_inited(drv->location)) {
+ printf("not initialized\n");
+ return -ENODEV;
+ }
+
+ ret = drv->load();
+ if (ret)
+ printf("Failed (%d)\n", ret);
+ else
+ printf("OK\n");
+
+ if (!ret)
+ return 0;
+ }
return -ENODEV;
}
@@ -240,13 +268,17 @@ int env_save(void)
if (drv) {
int ret;
- if (!drv->save)
+ printf("Saving Environment to %s... ", drv->name);
+ if (!drv->save) {
+ printf("not possible\n");
return -ENODEV;
+ }
- if (!env_has_inited(drv->location))
+ if (!env_has_inited(drv->location)) {
+ printf("not initialized\n");
return -ENODEV;
+ }
- printf("Saving Environment to %s... ", drv->name);
ret = drv->save();
if (ret)
printf("Failed (%d)\n", ret);
@@ -314,3 +346,45 @@ int env_init(void)
return ret;
}
+
+int env_select(const char *name)
+{
+ struct env_driver *drv;
+ const int n_ents = ll_entry_count(struct env_driver, env_driver);
+ struct env_driver *entry;
+ int prio;
+ bool found = false;
+
+ printf("Select Environment on %s: ", name);
+
+ /* search ENV driver by name */
+ drv = ll_entry_start(struct env_driver, env_driver);
+ for (entry = drv; entry != drv + n_ents; entry++) {
+ if (!strcmp(entry->name, name)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ printf("driver not found\n");
+ return -ENODEV;
+ }
+
+ /* search priority by driver */
+ for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
+ if (entry->location == env_get_location(ENVOP_LOAD, prio)) {
+ /* when priority change, reset the ENV flags */
+ if (gd->env_load_prio != prio) {
+ gd->env_load_prio = prio;
+ gd->env_valid = ENV_INVALID;
+ gd->flags &= ~GD_FLG_ENV_DEFAULT;
+ }
+ printf("OK\n");
+ return 0;
+ }
+ }
+ printf("priority not found\n");
+
+ return -ENODEV;
+}
diff --git a/env/ext4.c b/env/ext4.c
index 8e90bb71b7..f823b69409 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -32,6 +32,8 @@
#include <ext4fs.h>
#include <mmc.h>
+DECLARE_GLOBAL_DATA_PTR;
+
__weak const char *env_ext4_get_intf(void)
{
return (const char *)CONFIG_ENV_EXT4_INTERFACE;
@@ -42,9 +44,8 @@ __weak const char *env_ext4_get_dev_part(void)
return (const char *)CONFIG_ENV_EXT4_DEVICE_AND_PART;
}
-static int env_ext4_save(void)
+static int env_ext4_save_buffer(env_t *env_new)
{
- env_t env_new;
struct blk_desc *dev_desc = NULL;
struct disk_partition info;
int dev, part;
@@ -52,10 +53,6 @@ static int env_ext4_save(void)
const char *ifname = env_ext4_get_intf();
const char *dev_and_part = env_ext4_get_dev_part();
- err = env_export(&env_new);
- if (err)
- return err;
-
part = blk_get_device_part_str(ifname, dev_and_part,
&dev_desc, &info, 1);
if (part < 0)
@@ -70,7 +67,7 @@ static int env_ext4_save(void)
return 1;
}
- err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new,
+ err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)env_new,
sizeof(env_t), FILETYPE_REG);
ext4fs_close();
@@ -80,7 +77,42 @@ static int env_ext4_save(void)
return 1;
}
+ return 0;
+}
+
+static int env_ext4_save(void)
+{
+ env_t env_new;
+ int err;
+
+ err = env_export(&env_new);
+ if (err)
+ return err;
+
+ err = env_ext4_save_buffer(&env_new);
+ if (err)
+ return err;
+
+ gd->env_valid = ENV_VALID;
puts("done\n");
+
+ return 0;
+}
+
+static int env_ext4_erase(void)
+{
+ env_t env_new;
+ int err;
+
+ memset(&env_new, 0, sizeof(env_t));
+
+ err = env_ext4_save_buffer(&env_new);
+ if (err)
+ return err;
+
+ gd->env_valid = ENV_INVALID;
+ puts("done\n");
+
return 0;
}
@@ -124,7 +156,11 @@ static int env_ext4_load(void)
goto err_env_relocate;
}
- return env_import(buf, 1);
+ err = env_import(buf, 1, H_EXTERNAL);
+ if (!err)
+ gd->env_valid = ENV_VALID;
+
+ return err;
err_env_relocate:
env_set_default(NULL, 0);
@@ -137,4 +173,6 @@ U_BOOT_ENV_LOCATION(ext4) = {
ENV_NAME("EXT4")
.load = env_ext4_load,
.save = ENV_SAVE_PTR(env_ext4_save),
+ .erase = CONFIG_IS_ENABLED(CMD_ERASEENV) ? env_ext4_erase :
+ NULL,
};
diff --git a/env/fat.c b/env/fat.c
index 35a1955e63..71bf8bfa18 100644
--- a/env/fat.c
+++ b/env/fat.c
@@ -29,6 +29,34 @@
# define LOADENV
#endif
+__weak int mmc_get_env_dev(void)
+{
+#ifdef CONFIG_SYS_MMC_ENV_DEV
+ return CONFIG_SYS_MMC_ENV_DEV;
+#else
+ return 0;
+#endif
+}
+
+static char *env_fat_device_and_part(void)
+{
+#ifdef CONFIG_MMC
+ static char *part_str;
+
+ if (!part_str) {
+ part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
+ if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc") && part_str[0] == ':') {
+ part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
+ part_str[0] += mmc_get_env_dev();
+ }
+ }
+
+ return part_str;
+#else
+ return CONFIG_ENV_FAT_DEVICE_AND_PART;
+#endif
+}
+
static int env_fat_save(void)
{
env_t __aligned(ARCH_DMA_MINALIGN) env_new;
@@ -43,7 +71,7 @@ static int env_fat_save(void)
return err;
part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
- CONFIG_ENV_FAT_DEVICE_AND_PART,
+ env_fat_device_and_part(),
&dev_desc, &info, 1);
if (part < 0)
return 1;
@@ -89,7 +117,7 @@ static int env_fat_load(void)
#endif
part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
- CONFIG_ENV_FAT_DEVICE_AND_PART,
+ env_fat_device_and_part(),
&dev_desc, &info, 1);
if (part < 0)
goto err_env_relocate;
@@ -116,7 +144,7 @@ static int env_fat_load(void)
goto err_env_relocate;
}
- return env_import(buf, 1);
+ return env_import(buf, 1, H_EXTERNAL);
err_env_relocate:
env_set_default(NULL, 0);
diff --git a/env/flags.c b/env/flags.c
index b88fe7ba9c..df4aed26b2 100644
--- a/env/flags.c
+++ b/env/flags.c
@@ -28,8 +28,15 @@
#define ENV_FLAGS_NET_VARTYPE_REPS ""
#endif
+#ifdef CONFIG_ENV_WRITEABLE_LIST
+#define ENV_FLAGS_WRITEABLE_VARACCESS_REPS "w"
+#else
+#define ENV_FLAGS_WRITEABLE_VARACCESS_REPS ""
+#endif
+
static const char env_flags_vartype_rep[] = "sdxb" ENV_FLAGS_NET_VARTYPE_REPS;
-static const char env_flags_varaccess_rep[] = "aroc";
+static const char env_flags_varaccess_rep[] =
+ "aroc" ENV_FLAGS_WRITEABLE_VARACCESS_REPS;
static const int env_flags_varaccess_mask[] = {
0,
ENV_FLAGS_VARACCESS_PREVENT_DELETE |
@@ -38,7 +45,11 @@ static const int env_flags_varaccess_mask[] = {
ENV_FLAGS_VARACCESS_PREVENT_DELETE |
ENV_FLAGS_VARACCESS_PREVENT_OVERWR,
ENV_FLAGS_VARACCESS_PREVENT_DELETE |
- ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR};
+ ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR,
+#ifdef CONFIG_ENV_WRITEABLE_LIST
+ ENV_FLAGS_VARACCESS_WRITEABLE,
+#endif
+ };
#ifdef CONFIG_CMD_ENV_FLAGS
static const char * const env_flags_vartype_names[] = {
@@ -56,6 +67,9 @@ static const char * const env_flags_varaccess_names[] = {
"read-only",
"write-once",
"change-default",
+#ifdef CONFIG_ENV_WRITEABLE_LIST
+ "writeable",
+#endif
};
/*
@@ -130,21 +144,25 @@ enum env_flags_vartype env_flags_parse_vartype(const char *flags)
*/
enum env_flags_varaccess env_flags_parse_varaccess(const char *flags)
{
+ enum env_flags_varaccess va_default = env_flags_varaccess_any;
+ enum env_flags_varaccess va;
char *access;
if (strlen(flags) <= ENV_FLAGS_VARACCESS_LOC)
- return env_flags_varaccess_any;
+ return va_default;
access = strchr(env_flags_varaccess_rep,
flags[ENV_FLAGS_VARACCESS_LOC]);
- if (access != NULL)
- return (enum env_flags_varaccess)
+ if (access != NULL) {
+ va = (enum env_flags_varaccess)
(access - &env_flags_varaccess_rep[0]);
+ return va;
+ }
printf("## Warning: Unknown environment variable access method '%c'\n",
flags[ENV_FLAGS_VARACCESS_LOC]);
- return env_flags_varaccess_any;
+ return va_default;
}
/*
@@ -152,17 +170,21 @@ enum env_flags_varaccess env_flags_parse_varaccess(const char *flags)
*/
enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags)
{
+ enum env_flags_varaccess va_default = env_flags_varaccess_any;
+ enum env_flags_varaccess va;
int i;
for (i = 0; i < ARRAY_SIZE(env_flags_varaccess_mask); i++)
if (env_flags_varaccess_mask[i] ==
- (binflags & ENV_FLAGS_VARACCESS_BIN_MASK))
- return (enum env_flags_varaccess)i;
+ (binflags & ENV_FLAGS_VARACCESS_BIN_MASK)) {
+ va = (enum env_flags_varaccess)i;
+ return va;
+ }
printf("Warning: Non-standard access flags. (0x%x)\n",
binflags & ENV_FLAGS_VARACCESS_BIN_MASK);
- return env_flags_varaccess_any;
+ return va_default;
}
static inline int is_hex_prefix(const char *value)
@@ -326,13 +348,14 @@ enum env_flags_vartype env_flags_get_type(const char *name)
enum env_flags_varaccess env_flags_get_varaccess(const char *name)
{
const char *flags_list = env_get(ENV_FLAGS_VAR);
+ enum env_flags_varaccess va_default = env_flags_varaccess_any;
char flags[ENV_FLAGS_ATTR_MAX_LEN + 1];
if (env_flags_lookup(flags_list, name, flags))
- return env_flags_varaccess_any;
+ return va_default;
if (strlen(flags) <= ENV_FLAGS_VARACCESS_LOC)
- return env_flags_varaccess_any;
+ return va_default;
return env_flags_parse_varaccess(flags);
}
@@ -426,7 +449,11 @@ void env_flags_init(struct env_entry *var_entry)
int ret = 1;
if (first_call) {
+#ifdef CONFIG_ENV_WRITEABLE_LIST
+ flags_list = ENV_FLAGS_LIST_STATIC;
+#else
flags_list = env_get(ENV_FLAGS_VAR);
+#endif
first_call = 0;
}
/* look in the ".flags" and static for a reference to this variable */
@@ -523,9 +550,24 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
}
/* check for access permission */
+#ifdef CONFIG_ENV_WRITEABLE_LIST
+ if (flag & H_DEFAULT)
+ return 0; /* Default env is always OK */
+
+ /*
+ * External writeable variables can be overwritten by external env,
+ * anything else can not be overwritten by external env.
+ */
+ if ((flag & H_EXTERNAL) &&
+ !(item->flags & ENV_FLAGS_VARACCESS_WRITEABLE))
+ return 1;
+#endif
+
#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
- if (flag & H_FORCE)
+ if (flag & H_FORCE) {
+ printf("## Error: Can't force access to \"%s\"\n", name);
return 0;
+ }
#endif
switch (op) {
case env_op_delete:
diff --git a/env/flash.c b/env/flash.c
index 3198147c38..722d5adf8b 100644
--- a/env/flash.c
+++ b/env/flash.c
@@ -351,7 +351,7 @@ static int env_flash_load(void)
"reading environment; recovered successfully\n\n");
#endif /* CONFIG_ENV_ADDR_REDUND */
- return env_import((char *)flash_addr, 1);
+ return env_import((char *)flash_addr, 1, H_EXTERNAL);
}
#endif /* LOADENV */
diff --git a/env/mmc.c b/env/mmc.c
index a8b661db80..af7e5fbac3 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -24,14 +24,25 @@
DECLARE_GLOBAL_DATA_PTR;
+#if !defined(CONFIG_SYS_MMC_ENV_DEV)
+#define CONFIG_SYS_MMC_ENV_DEV 0
+#endif
+
+__weak int mmc_get_env_dev(void)
+{
+ return CONFIG_SYS_MMC_ENV_DEV;
+}
+
#if CONFIG_IS_ENABLED(OF_CONTROL)
-static inline int mmc_offset_try_partition(const char *str, s64 *val)
+static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
{
struct disk_partition info;
struct blk_desc *desc;
int len, i, ret;
+ char dev_str[4];
- ret = blk_get_device_by_str("mmc", STR(CONFIG_SYS_MMC_ENV_DEV), &desc);
+ snprintf(dev_str, sizeof(dev_str), "%d", mmc_get_env_dev());
+ ret = blk_get_device_by_str("mmc", dev_str, &desc);
if (ret < 0)
return (ret);
@@ -45,10 +56,10 @@ static inline int mmc_offset_try_partition(const char *str, s64 *val)
}
/* round up to info.blksz */
- len = (CONFIG_ENV_SIZE + info.blksz - 1) & ~(info.blksz - 1);
+ len = DIV_ROUND_UP(CONFIG_ENV_SIZE, info.blksz);
/* use the top of the partion for the environment */
- *val = (info.start + info.size - 1) - len / info.blksz;
+ *val = (info.start + info.size - (1 + copy) * len) * info.blksz;
return 0;
}
@@ -73,7 +84,7 @@ static inline s64 mmc_offset(int copy)
str = fdtdec_get_config_string(gd->fdt_blob, dt_prop.partition);
if (str) {
/* try to place the environment at end of the partition */
- err = mmc_offset_try_partition(str, &val);
+ err = mmc_offset_try_partition(str, copy, &val);
if (!err)
return val;
}
@@ -114,11 +125,6 @@ __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
return 0;
}
-__weak int mmc_get_env_dev(void)
-{
- return CONFIG_SYS_MMC_ENV_DEV;
-}
-
#ifdef CONFIG_SYS_MMC_ENV_PART
__weak uint mmc_get_env_part(struct mmc *mmc)
{
@@ -332,7 +338,7 @@ static int env_mmc_load(void)
read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2);
ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
- read2_fail);
+ read2_fail, H_EXTERNAL);
fini:
fini_mmc_for_env(mmc);
@@ -374,7 +380,7 @@ static int env_mmc_load(void)
goto fini;
}
- ret = env_import(buf, 1);
+ ret = env_import(buf, 1, H_EXTERNAL);
if (!ret) {
ep = (env_t *)buf;
gd->env_addr = (ulong)&ep->data;
diff --git a/env/nand.c b/env/nand.c
index 8b0027d304..0d7ee19bc2 100644
--- a/env/nand.c
+++ b/env/nand.c
@@ -331,7 +331,7 @@ static int env_nand_load(void)
read2_fail = readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2);
ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
- read2_fail);
+ read2_fail, H_EXTERNAL);
done:
free(tmp_env1);
@@ -372,7 +372,7 @@ static int env_nand_load(void)
return -EIO;
}
- return env_import(buf, 1);
+ return env_import(buf, 1, H_EXTERNAL);
#endif /* ! ENV_IS_EMBEDDED */
return 0;
diff --git a/env/nowhere.c b/env/nowhere.c
index f5b0a17652..d33fdf27d0 100644
--- a/env/nowhere.c
+++ b/env/nowhere.c
@@ -27,8 +27,25 @@ static int env_nowhere_init(void)
return 0;
}
+static int env_nowhere_load(void)
+{
+ /*
+ * for SPL, set env_valid = ENV_INVALID is enougth as env_get_char()
+ * return the default env if env_get is used
+ * and SPL don't used env_import to reduce its size
+ * For U-Boot proper, import the default environment to allow reload.
+ */
+ if (!IS_ENABLED(CONFIG_SPL_BUILD))
+ env_set_default(NULL, 0);
+
+ gd->env_valid = ENV_INVALID;
+
+ return 0;
+}
+
U_BOOT_ENV_LOCATION(nowhere) = {
.location = ENVL_NOWHERE,
.init = env_nowhere_init,
+ .load = env_nowhere_load,
ENV_NAME("nowhere")
};
diff --git a/env/nvram.c b/env/nvram.c
index 1a9fcf1c06..7c8ea26f96 100644
--- a/env/nvram.c
+++ b/env/nvram.c
@@ -64,7 +64,7 @@ static int env_nvram_load(void)
#else
memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
#endif
- return env_import(buf, 1);
+ return env_import(buf, 1, H_EXTERNAL);
}
static int env_nvram_save(void)
diff --git a/env/onenand.c b/env/onenand.c
index dfd4e939f8..a2477cef9b 100644
--- a/env/onenand.c
+++ b/env/onenand.c
@@ -55,7 +55,7 @@ static int env_onenand_load(void)
mtd->writesize = MAX_ONENAND_PAGESIZE;
#endif /* !ENV_IS_EMBEDDED */
- rc = env_import(buf, 1);
+ rc = env_import(buf, 1, H_EXTERNAL);
if (!rc)
gd->env_valid = ENV_VALID;
diff --git a/env/remote.c b/env/remote.c
index e3f0608b16..d93a137376 100644
--- a/env/remote.c
+++ b/env/remote.c
@@ -45,7 +45,7 @@ static int env_remote_save(void)
static int env_remote_load(void)
{
#ifndef ENV_IS_EMBEDDED
- return env_import((char *)env_ptr, 1);
+ return env_import((char *)env_ptr, 1, H_EXTERNAL);
#endif
return 0;
diff --git a/env/sata.c b/env/sata.c
index 8bfcc94306..9442cfcaf3 100644
--- a/env/sata.c
+++ b/env/sata.c
@@ -111,7 +111,7 @@ static void env_sata_load(void)
return -EIO;
}
- return env_import(buf, 1);
+ return env_import(buf, 1, H_EXTERNAL);
}
U_BOOT_ENV_LOCATION(sata) = {
diff --git a/env/sf.c b/env/sf.c
index 3e524f2947..937778aa37 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -172,7 +172,7 @@ static int env_sf_load(void)
CONFIG_ENV_SIZE, tmp_env2);
ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
- read2_fail);
+ read2_fail, H_EXTERNAL);
spi_flash_free(env_flash);
env_flash = NULL;
@@ -265,7 +265,7 @@ static int env_sf_load(void)
goto err_read;
}
- ret = env_import(buf, 1);
+ ret = env_import(buf, 1, H_EXTERNAL);
if (!ret)
gd->env_valid = ENV_VALID;
@@ -305,7 +305,7 @@ static int env_sf_init(void)
U_BOOT_ENV_LOCATION(sf) = {
.location = ENVL_SPI_FLASH,
- ENV_NAME("SPI Flash")
+ ENV_NAME("SPIFlash")
.load = env_sf_load,
.save = CONFIG_IS_ENABLED(SAVEENV) ? ENV_SAVE_PTR(env_sf_save) : NULL,
#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
diff --git a/env/ubi.c b/env/ubi.c
index 08aac47df2..5502efe28b 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -141,7 +141,7 @@ static int env_ubi_load(void)
CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME_REDUND);
return env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
- read2_fail);
+ read2_fail, H_EXTERNAL);
}
#else /* ! CONFIG_SYS_REDUNDAND_ENVIRONMENT */
static int env_ubi_load(void)
@@ -172,7 +172,7 @@ static int env_ubi_load(void)
return -EIO;
}
- return env_import(buf, 1);
+ return env_import(buf, 1, H_EXTERNAL);
}
#endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */