* [PATCH] commands: bootm: add proper support for boot script calling bootm
@ 2026-01-26 10:55 Ahmad Fatoum
2026-01-30 13:37 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-01-26 10:55 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] commands: bootm: add proper support for boot script calling bootm
2026-01-26 10:55 [PATCH] commands: bootm: add proper support for boot script calling bootm Ahmad Fatoum
@ 2026-01-30 13:37 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2026-01-30 13:37 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Mon, 26 Jan 2026 11:55:41 +0100, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] commands: bootm: add proper support for boot script calling bootm
https://git.pengutronix.de/cgit/barebox/commit/?id=4338ebfd4635 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-30 13:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-26 10:55 [PATCH] commands: bootm: add proper support for boot script calling bootm Ahmad Fatoum
2026-01-30 13:37 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox