[RESEND PATCH 05/10] sandbox: support the change of env location
Patrick Delaunay
patrick.delaunay at st.com
Wed Feb 12 19:44:56 CET 2020
Add support of environment location with a new sandbox command
'env_loc'.
When the user change the environment location with the command
'env_loc <location>' the env is reinitialized and saved;
the GD_FLG_ENV_DEFAULT flag is also updated.
When the user set the same env location, the environment is
re-loaded.
Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---
board/sandbox/sandbox.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c
index 01f356be31..023a71d5f0 100644
--- a/board/sandbox/sandbox.c
+++ b/board/sandbox/sandbox.c
@@ -21,6 +21,9 @@
*/
gd_t *gd;
+/* env location: current location used during test */
+static enum env_location sandbox_env_location = ENVL_NOWHERE;
+
/* Add a simple GPIO device */
U_BOOT_DEVICE(gpio_sandbox) = {
.name = "gpio_sandbox",
@@ -53,9 +56,44 @@ enum env_location env_get_location(enum env_operation op, int prio)
gd->env_load_prio = 0;
- return ENVL_NOWHERE;
+ return sandbox_env_location;
}
+static int do_env_loc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ enum env_location loc;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ loc = (enum env_location)simple_strtoul(argv[1], NULL, 10);
+ if (loc >= ENVL_COUNT)
+ return CMD_RET_FAILURE;
+
+ if (sandbox_env_location != loc) {
+ sandbox_env_location = loc;
+ if (loc == ENVL_NOWHERE) {
+ gd->flags |= GD_FLG_ENV_DEFAULT;
+ gd->env_valid = ENV_VALID;
+ } else {
+ if (gd->flags & GD_FLG_ENV_DEFAULT) {
+ gd->flags &= ~GD_FLG_ENV_DEFAULT;
+ if (!env_init())
+ env_save();
+ }
+ }
+ } else {
+ if (!env_init())
+ env_load();
+ }
+
+ return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(env_loc, 2, 1, do_env_loc,
+ "set the environment location", "[loc]"
+);
+
int dram_init(void)
{
gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
--
2.17.1
More information about the U-Boot
mailing list