All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Tom Rini <trini@konsulko.com>, Wolfgang Denk <wd@denx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v6 7/7] bootm: Tidy up use of autostart env var
Date: Thu, 14 Oct 2021 12:22:57 -0600	[thread overview]
Message-ID: <20211014182257.468649-6-sjg@chromium.org> (raw)
In-Reply-To: <20211014182257.468649-1-sjg@chromium.org>

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.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Wolfgang Denk <wd@denx.de>
---

Changes in v6:
- Add new patch to tidy up use of autostart env var

 cmd/bootm.c               | 4 +---
 cmd/elf.c                 | 3 +--
 common/bootm_os.c         | 5 +----
 doc/usage/environment.rst | 4 ++--
 env/common.c              | 7 +++++++
 include/env.h             | 7 +++++++
 6 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/cmd/bootm.c b/cmd/bootm.c
index 92468d09a1f..b82a872a86c 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 d75b21461c2..2b33c50bd02 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/common/bootm_os.c b/common/bootm_os.c
index 39623f9126b..f30dcebbf7d 100644
--- a/common/bootm_os.c
+++ b/common/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/doc/usage/environment.rst b/doc/usage/environment.rst
index ef9cd20715a..99285115f29 100644
--- a/doc/usage/environment.rst
+++ b/doc/usage/environment.rst
@@ -144,8 +144,8 @@ 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 anything other than "yes", 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 81e9e0b2aaf..ef9502a34f7 100644
--- a/env/common.c
+++ b/env/common.c
@@ -47,6 +47,13 @@ int env_get_yesno(const char *var)
 		1 : 0;
 }
 
+bool env_get_autostart(void)
+{
+	const char *val = env_get("autostart");
+
+	return val && !strcmp(val, "yes");
+}
+
 /*
  * Look up the variable from the default environment
  */
diff --git a/include/env.h b/include/env.h
index d5e2bcb530f..fdad495691f 100644
--- a/include/env.h
+++ b/include/env.h
@@ -143,6 +143,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
  *
-- 
2.33.0.1079.g6e70778dc9-goog


  parent reply	other threads:[~2021-10-14 18:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14 18:22 [PATCH v6 0/7] env: Allow environment in text files Simon Glass
2021-10-14 18:22 ` [PATCH v6 1/7] binman: Allow timeout to occur in the image or its section Simon Glass
2021-10-14 18:22 ` [PATCH v6 2/7] sandbox: Drop distro_boot Simon Glass
2021-10-14 18:22 ` [PATCH v6 3/7] doc: Move environment documentation to rST Simon Glass
2021-10-14 18:22 ` [PATCH v6 4/7] env: Allow U-Boot scripts to be placed in a .env file Simon Glass
2021-10-15 14:32   ` Wolfgang Denk
2021-10-15 15:15     ` Simon Glass
2021-10-18 11:58       ` Wolfgang Denk
2021-10-18 13:37         ` Tom Rini
2021-10-18 14:10           ` Wolfgang Denk
2021-10-18 14:24             ` Tom Rini
2021-10-19 10:33               ` Wolfgang Denk
2021-10-18 18:12             ` Simon Glass
2021-10-19 10:38               ` Wolfgang Denk
2021-10-18 18:12         ` Simon Glass
2021-10-19 10:46           ` Wolfgang Denk
2021-10-19 14:11             ` Simon Glass
2021-10-19 16:09               ` Wolfgang Denk
2021-10-19 16:14                 ` Simon Glass
2021-10-14 18:22 ` [PATCH v6 5/7] sandbox: Use a text-based environment Simon Glass
2021-10-14 18:22 ` [PATCH v6 6/7] doc: Improve environment documentation Simon Glass
2021-10-14 18:22 ` Simon Glass [this message]
2021-10-15 14:45   ` [PATCH v6 7/7] bootm: Tidy up use of autostart env var Wolfgang Denk
2021-10-24 19:53     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014182257.468649-6-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=wd@denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.