Skip to content

Commit

Permalink
Merge branch '2020-07-31-more-env-updates'
Browse files Browse the repository at this point in the history
- Fix EFI selftest to not force setting serial# environment (and also
  get the U-Boot prompt dynamically).
- Support for append only environment and other related features.
- Improved ext4 environment support
- Fix the case of fw_setenv being used on flash devices that were not
  already locked.
  • Loading branch information
trini committed Jul 31, 2020
2 parents 719f421 + db82015 commit a2d051e
Show file tree
Hide file tree
Showing 33 changed files with 507 additions and 65 deletions.
15 changes: 15 additions & 0 deletions board/sandbox/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cpu_func.h>
#include <cros_ec.h>
#include <dm.h>
#include <env_internal.h>
#include <init.h>
#include <led.h>
#include <os.h>
Expand Down Expand Up @@ -44,6 +45,20 @@ unsigned long timer_read_counter(void)
}
#endif

/* specific order for sandbox: nowhere is the first value, used by default */
static enum env_location env_locations[] = {
ENVL_NOWHERE,
ENVL_EXT4,
};

enum env_location env_get_location(enum env_operation op, int prio)
{
if (prio >= ARRAY_SIZE(env_locations))
return ENVL_UNKNOWN;

return env_locations[prio];
}

int dram_init(void)
{
gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Expand Down
11 changes: 11 additions & 0 deletions cmd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,17 @@ config CMD_NVEDIT_INFO
[-q] : quiet output
The result of multiple evaluations will be combined with AND.

config CMD_NVEDIT_LOAD
bool "env load"
help
Load all environment variables from the compiled-in persistent
storage.

config CMD_NVEDIT_SELECT
bool "env select"
help
Select the compiled-in persistent storage of environment variables.

endmenu

menu "Memory commands"
Expand Down
29 changes: 29 additions & 0 deletions cmd/nvedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,23 @@ U_BOOT_CMD(
);
#endif
#endif

#if defined(CONFIG_CMD_NVEDIT_LOAD)
static int do_env_load(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
return env_reload() ? 1 : 0;
}
#endif

#if defined(CONFIG_CMD_NVEDIT_SELECT)
static int do_env_select(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
return env_select(argv[1]) ? 1 : 0;
}
#endif

#endif /* CONFIG_SPL_BUILD */

int env_match(uchar *s1, int i2)
Expand Down Expand Up @@ -1346,6 +1363,9 @@ static struct cmd_tbl cmd_env_sub[] = {
#endif
#if defined(CONFIG_CMD_NVEDIT_INFO)
U_BOOT_CMD_MKENT(info, 3, 0, do_env_info, "", ""),
#endif
#if defined(CONFIG_CMD_NVEDIT_LOAD)
U_BOOT_CMD_MKENT(load, 1, 0, do_env_load, "", ""),
#endif
U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
#if defined(CONFIG_CMD_RUN)
Expand All @@ -1356,6 +1376,9 @@ static struct cmd_tbl cmd_env_sub[] = {
#if defined(CONFIG_CMD_ERASEENV)
U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""),
#endif
#endif
#if defined(CONFIG_CMD_NVEDIT_SELECT)
U_BOOT_CMD_MKENT(select, 2, 0, do_env_select, "", ""),
#endif
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
#if defined(CONFIG_CMD_ENV_EXISTS)
Expand Down Expand Up @@ -1442,6 +1465,12 @@ static char env_help_text[] =
"env erase - erase environment\n"
#endif
#endif
#if defined(CONFIG_CMD_NVEDIT_LOAD)
"env load - load environment\n"
#endif
#if defined(CONFIG_CMD_NVEDIT_SELECT)
"env select [target] - select environment target\n"
#endif
#if defined(CONFIG_CMD_NVEDIT_EFI)
"env set -e [-nv][-bs][-rt][-at][-a][-i addr,size][-v] name [arg ...]\n"
" - set UEFI variable; unset if '-i' or 'arg' not specified\n"
Expand Down
7 changes: 7 additions & 0 deletions configs/sandbox64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ CONFIG_CMD_BOOTEFI_HELLO=y
# CONFIG_CMD_ELF is not set
CONFIG_CMD_ASKENV=y
CONFIG_CMD_GREPENV=y
CONFIG_CMD_ERASEENV=y
CONFIG_CMD_ENV_CALLBACK=y
CONFIG_CMD_ENV_FLAGS=y
CONFIG_CMD_NVEDIT_EFI=y
CONFIG_CMD_NVEDIT_INFO=y
CONFIG_CMD_NVEDIT_LOAD=y
CONFIG_CMD_NVEDIT_SELECT=y
CONFIG_LOOPW=y
CONFIG_CMD_MD5SUM=y
CONFIG_CMD_MEMINFO=y
Expand Down Expand Up @@ -83,6 +86,10 @@ CONFIG_OF_CONTROL=y
CONFIG_OF_LIVE=y
CONFIG_OF_HOSTFILE=y
CONFIG_BOOTP_SEND_HOSTNAME=y
CONFIG_ENV_IS_NOWHERE=y
CONFIG_ENV_IS_IN_EXT4=y
CONFIG_ENV_EXT4_INTERFACE="host"
CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
CONFIG_NETCONSOLE=y
CONFIG_IP_DEFRAG=y
CONFIG_REGMAP=y
Expand Down
7 changes: 7 additions & 0 deletions configs/sandbox_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ CONFIG_CMD_ABOOTIMG=y
# CONFIG_CMD_ELF is not set
CONFIG_CMD_ASKENV=y
CONFIG_CMD_GREPENV=y
CONFIG_CMD_ERASEENV=y
CONFIG_CMD_ENV_CALLBACK=y
CONFIG_CMD_ENV_FLAGS=y
CONFIG_CMD_NVEDIT_EFI=y
CONFIG_CMD_NVEDIT_INFO=y
CONFIG_CMD_NVEDIT_LOAD=y
CONFIG_CMD_NVEDIT_SELECT=y
CONFIG_LOOPW=y
CONFIG_CMD_MD5SUM=y
CONFIG_CMD_MEMINFO=y
Expand Down Expand Up @@ -94,6 +97,10 @@ CONFIG_OF_CONTROL=y
CONFIG_OF_LIVE=y
CONFIG_OF_HOSTFILE=y
CONFIG_BOOTP_SEND_HOSTNAME=y
CONFIG_ENV_IS_NOWHERE=y
CONFIG_ENV_IS_IN_EXT4=y
CONFIG_ENV_EXT4_INTERFACE="host"
CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
CONFIG_NETCONSOLE=y
CONFIG_IP_DEFRAG=y
CONFIG_REGMAP=y
Expand Down
7 changes: 7 additions & 0 deletions configs/sandbox_flattree_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ CONFIG_CMD_BOOTEFI_HELLO=y
# CONFIG_CMD_ELF is not set
CONFIG_CMD_ASKENV=y
CONFIG_CMD_GREPENV=y
CONFIG_CMD_ERASEENV=y
CONFIG_CMD_NVEDIT_INFO=y
CONFIG_CMD_NVEDIT_LOAD=y
CONFIG_CMD_NVEDIT_SELECT=y
CONFIG_LOOPW=y
CONFIG_CMD_MD5SUM=y
CONFIG_CMD_MEMINFO=y
Expand Down Expand Up @@ -66,6 +69,10 @@ CONFIG_AMIGA_PARTITION=y
CONFIG_OF_CONTROL=y
CONFIG_OF_HOSTFILE=y
CONFIG_BOOTP_SEND_HOSTNAME=y
CONFIG_ENV_IS_NOWHERE=y
CONFIG_ENV_IS_IN_EXT4=y
CONFIG_ENV_EXT4_INTERFACE="host"
CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
CONFIG_NETCONSOLE=y
CONFIG_IP_DEFRAG=y
CONFIG_REGMAP=y
Expand Down
7 changes: 7 additions & 0 deletions configs/sandbox_spl_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ CONFIG_CMD_BOOTEFI_HELLO=y
# CONFIG_CMD_ELF is not set
CONFIG_CMD_ASKENV=y
CONFIG_CMD_GREPENV=y
CONFIG_CMD_ERASEENV=y
CONFIG_CMD_ENV_CALLBACK=y
CONFIG_CMD_ENV_FLAGS=y
CONFIG_CMD_NVEDIT_INFO=y
CONFIG_CMD_NVEDIT_LOAD=y
CONFIG_CMD_NVEDIT_SELECT=y
CONFIG_LOOPW=y
CONFIG_CMD_MD5SUM=y
CONFIG_CMD_MEMINFO=y
Expand Down Expand Up @@ -83,6 +86,10 @@ CONFIG_SPL_OF_CONTROL=y
CONFIG_OF_HOSTFILE=y
CONFIG_SPL_OF_PLATDATA=y
CONFIG_BOOTP_SEND_HOSTNAME=y
CONFIG_ENV_IS_NOWHERE=y
CONFIG_ENV_IS_IN_EXT4=y
CONFIG_ENV_EXT4_INTERFACE="host"
CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0"
CONFIG_NETCONSOLE=y
CONFIG_IP_DEFRAG=y
CONFIG_SPL_DM=y
Expand Down
19 changes: 18 additions & 1 deletion env/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -479,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)
Expand Down Expand Up @@ -614,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
Expand Down
16 changes: 9 additions & 7 deletions env/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) ==
Expand Down Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion env/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit a2d051e

Please sign in to comment.