From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] commands: bootm: add proper support for boot script calling bootm
Date: Mon, 26 Jan 2026 11:55:41 +0100 [thread overview]
Message-ID: <20260126105541.1859911-1-a.fatoum@pengutronix.de> (raw)
If a boot script calls bootm and it returns whether due to error or dry
run, bootscript_boot() will just call bootm again leading to confusing
output.
Let's detect whether bootm was called and skip calling it again in that
case. This will allow boot scripts to do cleanup in future.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/bootm.c | 9 +++++++++
common/boot.c | 7 +++++++
include/command.h | 9 +++++++++
3 files changed, 25 insertions(+)
diff --git a/commands/bootm.c b/commands/bootm.c
index 3936623b5199..24bce5ce6b64 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -36,6 +36,13 @@
#define BOOTM_OPTS BOOTM_OPTS_COMMON
#endif
+static unsigned command_attempts;
+
+unsigned bootm_command_attempts(void)
+{
+ return command_attempts;
+}
+
static int do_bootm(int argc, char *argv[])
{
int opt;
@@ -44,6 +51,8 @@ static int do_bootm(int argc, char *argv[])
bootm_data_init_defaults(&data);
+ command_attempts++;
+
while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) {
switch(opt) {
case 'c':
diff --git a/common/boot.c b/common/boot.c
index af07d218f059..78d990f1617e 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -75,6 +75,7 @@ struct bootentry_script {
static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
{
struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
+ int bootm_nattempts;
int ret;
struct bootm_data backup = {}, data = {};
@@ -89,12 +90,18 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
globalvar_add_simple("linux.bootargs.dyn.ip", NULL);
globalvar_add_simple("linux.bootargs.dyn.root", NULL);
+ bootm_nattempts = bootm_command_attempts();
+
ret = run_command(bs->scriptpath);
if (ret) {
pr_err("Running script '%s' failed: %pe\n", bs->scriptpath, ERR_PTR(ret));
goto out;
}
+ /* No point in repeating bootm if script already called it */
+ if (bootm_nattempts != bootm_command_attempts())
+ goto out;
+
bootm_data_init_defaults(&data);
if (verbose)
diff --git a/include/command.h b/include/command.h
index 378e1458a589..fb140cb8e250 100644
--- a/include/command.h
+++ b/include/command.h
@@ -122,4 +122,13 @@ static const __maybe_unused char cmd_##_name##_help[] =
int register_command(struct command *);
+#ifdef CONFIG_CMD_BOOTM
+unsigned bootm_command_attempts(void);
+#else
+static inline unsigned bootm_command_attempts(void)
+{
+ return 0;
+}
+#endif
+
#endif /* __COMMAND_H */
--
2.47.3
next reply other threads:[~2026-01-26 10:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-26 10:55 Ahmad Fatoum [this message]
2026-01-30 13:37 ` Sascha Hauer
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=20260126105541.1859911-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox