aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-10-21 21:08:52 -0600
committerTom Rini <trini@konsulko.com>2021-11-16 14:35:09 -0500
commit78398652723b6fe743751ffb19d8256b7e3e0a4e (patch)
tree9e86d3aeaf5e46cd0e23bbb8bfc0e6e5406617e0
parent1d192d5bccc6e4b9e7112f720ccc47786694ee39 (diff)
downloadu-boot-WIP/2021-11-16-env-rework.zip
u-boot-WIP/2021-11-16-env-rework.tar.gz
u-boot-WIP/2021-11-16-env-rework.tar.bz2
bootm: Tidy up use of autostart env varWIP/2021-11-16-env-rework
This has different semantics in different places. Go with the bootm method and put it in a common function so that the behaviour is consistent in U-Boot. Update the docs. To be clear, this changes the way that 'bootelf' and standalone boot work. Before, if autostart was set to "fred" or "YES", for example, they would consider that a "yes". This may change behaviour for some boards, but the only in-tree boards which mention autostart use "no" to disable it, which will still work. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Wolfgang Denk <wd@denx.de>
-rw-r--r--boot/bootm_os.c5
-rw-r--r--cmd/bootm.c4
-rw-r--r--cmd/elf.c3
-rw-r--r--doc/usage/environment.rst5
-rw-r--r--env/common.c5
-rw-r--r--include/env.h7
6 files changed, 18 insertions, 11 deletions
diff --git a/boot/bootm_os.c b/boot/bootm_os.c
index e635c72..f31820c 100644
--- a/boot/bootm_os.c
+++ b/boot/bootm_os.c
@@ -26,12 +26,9 @@ DECLARE_GLOBAL_DATA_PTR;
static int do_bootm_standalone(int flag, int argc, char *const argv[],
bootm_headers_t *images)
{
- char *s;
int (*appl)(int, char *const[]);
- /* Don't start if "autostart" is set to "no" */
- s = env_get("autostart");
- if ((s != NULL) && !strcmp(s, "no")) {
+ if (!env_get_autostart()) {
env_set_hex("filesize", images->os.image_len);
return 0;
}
diff --git a/cmd/bootm.c b/cmd/bootm.c
index 92468d0..b82a872 100644
--- a/cmd/bootm.c
+++ b/cmd/bootm.c
@@ -140,9 +140,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
int bootm_maybe_autostart(struct cmd_tbl *cmdtp, const char *cmd)
{
- const char *ep = env_get("autostart");
-
- if (ep && !strcmp(ep, "yes")) {
+ if (env_get_autostart()) {
char *local_args[2];
local_args[0] = (char *)cmd;
local_args[1] = NULL;
diff --git a/cmd/elf.c b/cmd/elf.c
index d75b214..2b33c50 100644
--- a/cmd/elf.c
+++ b/cmd/elf.c
@@ -41,7 +41,6 @@ int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
unsigned long addr; /* Address of the ELF image */
unsigned long rc; /* Return value from user code */
char *sload = NULL;
- const char *ep = env_get("autostart");
int rcode = 0;
/* Consume 'bootelf' */
@@ -69,7 +68,7 @@ int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
else
addr = load_elf_image_shdr(addr);
- if (ep && !strcmp(ep, "no"))
+ if (!env_get_autostart())
return rcode;
printf("## Starting application at 0x%08lx ...\n", addr);
diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst
index 8ddc672..d295cc8 100644
--- a/doc/usage/environment.rst
+++ b/doc/usage/environment.rst
@@ -179,8 +179,9 @@ autostart
be automatically started (by internally calling
"bootm")
- If set to "no", a standalone image passed to the
- "bootm" command will be copied to the load address
+ If unset, or set to "1"/"yes"/"true" (case insensitive, just the first
+ character is enough), a standalone image
+ passed to the "bootm" command will be copied to the load address
(and eventually uncompressed), but NOT be started.
This can be used to load and uncompress arbitrary
data.
diff --git a/env/common.c b/env/common.c
index 208e2ad..ee957c0 100644
--- a/env/common.c
+++ b/env/common.c
@@ -235,6 +235,11 @@ int env_get_yesno(const char *var)
1 : 0;
}
+bool env_get_autostart(void)
+{
+ return env_get_yesno("autostart") == 1;
+}
+
/*
* Look up the variable from the default environment
*/
diff --git a/include/env.h b/include/env.h
index ee5e30d..ff8943e 100644
--- a/include/env.h
+++ b/include/env.h
@@ -134,6 +134,13 @@ int env_get_f(const char *name, char *buf, unsigned int len);
int env_get_yesno(const char *var);
/**
+ * env_get_autostart() - Check if autostart is enabled
+ *
+ * @return true if the "autostart" env var exists and is set to "yes"
+ */
+bool env_get_autostart(void);
+
+/**
* env_set() - set an environment variable
*
* This sets or deletes the value of an environment variable. For setting the