From patchwork Tue Jun 16 07:40:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Delaunay X-Patchwork-Id: 242470 List-Id: U-Boot discussion From: patrick.delaunay at st.com (Patrick Delaunay) Date: Tue, 16 Jun 2020 09:40:44 +0200 Subject: [PATCH v2 5/9] sandbox: support the change of env location In-Reply-To: <20200616074048.7898-1-patrick.delaunay@st.com> References: <20200616074048.7898-1-patrick.delaunay@st.com> Message-ID: <20200616074048.7898-6-patrick.delaunay@st.com> Add support of environment location with a new sandbox command 'env_loc'. When the user change the environment location with the command 'env_loc ' 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 Reviewed-by: Simon Glass --- Changes in v2: - change cmd_tbl_t to struct cmd_tbl board/sandbox/sandbox.c | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c index 9cb5fe5c75..bd99141fa8 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -21,6 +22,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 +57,45 @@ 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(struct cmd_tbl *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;