cmd: allow bootd without bootm
cover cmd: allow bootd without bootm
From: Mehmet Fide <[email protected]>
The bootd command is a two line wrapper around run_command(env_get("bootcmd")), but its code lives in cmd/bootm.c, so it only links when CMD_BOOTM is enabled. Commit 1fd04cf46baf ("cmd: Correct dependencies for CMD_BOOTD") expressed that in Kconfig as "depends on CMD_BOOTM". The build reason is real, but the dependency reads as a functional one, and it leaves the boards that disable CMD_BOOTM without "boot" or "bootd" even though the implementation works there.
Patch 1 moves the command into cmd/bootd.c and drops the dependency, keeping the current default so that no board in tree changes. Patch 2 adds the test that bootd never had.
While testing I noticed something unrelated that this series does not touch:
on sandbox the "avoid bootd recursion" guard in cmd_process() never fires, so a bootcmd of "bootd" recurses until the stack is exhausted. That behaves identically before and after this series.
Mehmet Fide (2):
cmd: allow bootd without bootm
test: cmd: add a test for bootd
cmd/Kconfig | 3 +-- cmd/Makefile | 1 + cmd/bootd.c | 30 ++++++++++++++++++++++++++++++ cmd/bootm.c | 24 ------------------------ test/cmd/Makefile | 3 +++ test/cmd/bootd.c | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 cmd/bootd.c create mode 100644 test/cmd/bootd.c
base-commit: 94b349bd902d9e38e1846c157fadd9054c34680a
Signature · 1 line
2.54.0
PATCH 1/2 cmd: allow bootd without bootm
From: Mehmet Fide <[email protected]>
do_bootd() runs the "bootcmd" environment variable through run_command() and does nothing else. It uses no bootm functionality, and neither does the "bootd" recursion guard in cmd_process(). doc/usage/cmd/bootd.rst documents it that way, with an example that sets bootcmd to "echo Hello World".
Commit 1fd04cf46baf ("cmd: Correct dependencies for CMD_BOOTD") made CMD_BOOTD depend on CMD_BOOTM because the build fails otherwise:common/command.c is compiled unconditionally and references do_bootd(), whose definition sits in cmd/bootm.c, which is only compiled when CMD_BOOTM=y. The dependency therefore describes where the code lives rather than what it needs, and the boards that disable CMD_BOOTM (colibri_vf, iot_devkit, mx6memcal and r8a78000_ironhide_cm33) cannot offer "boot" or "bootd" at all, although the implementation would work there.
Move do_bootd() and its two command registrations into cmd/bootd.c, compiled from CMD_BOOTD, and drop the artificial dependency. To leave every board in tree unchanged, CMD_BOOTD now defaults to y only when CMD_BOOTM is enabled, which is precisely the set of boards that have it today. Boards without bootm can enable it deliberately.
Tested on sandbox: bootd, the "boot" alias, the return value taken from a failing bootcmd and the recursion guard all behave as before. Also tested on a Colibri VF50 (vf610) board built with CMD_BOOTM=n and CMD_BOOTD=y, a combination that could not be selected before: "boot" and "bootd" run bootcmd and bring up the OS, and a bootcmd of "false" returns 1. A colibri_vf_defconfig build with CMD_BOOTD left off is byte identical to the previous one apart from the version string; enabling CMD_BOOTD costs 272 bytes.
---
Notes:
checkpatch reports two things on this patch that I left as they are:
- "does MAINTAINERS need updating?": no MAINTAINERS entry covers cmd/bootm.c, so the new cmd/bootd.c does not need one either.
- "Lines should not end with a '('": that is the U_BOOT_CMD idiom, and both registrations are moved verbatim.
cmd/Kconfig | 3 +-- cmd/Makefile | 1 + cmd/bootd.c | 30 ++++++++++++++++++++++++++++++ cmd/bootm.c | 24 ------------------------ 4 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 cmd/bootd.c
cmd/Kconfig +1 -2
@@ -300,8 +300,7 @@ menu "Boot commands" config CMD_BOOTD bool "bootd" - depends on CMD_BOOTM - default y + default y if CMD_BOOTM help Run the command stored in the environment "bootcmd", i.e. "bootd" does the same thing as "run bootcmd".
cmd/Makefile +1 -0
@@ -6,6 +6,7 @@ ifndef CONFIG_XPL_BUILD # core command obj-y += boot.o +obj-$(CONFIG_CMD_BOOTD) += bootd.o obj-$(CONFIG_CMD_BOOTM) += bootm.o obj-$(CONFIG_CMD_HELP) += help.o obj-y += panic.o
cmd/bootd.c new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2000-2009 +* Wolfgang Denk, DENX Software Engineering, [email protected]. +*/ + +/* +* bootd - boot default, i.e. run the command in the "bootcmd" environment +* variable +*/ +#include <command.h> +#include <env.h> + +int do_bootd (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) +{ +return run_command (env_get ("bootcmd" ), flag); +} + +U_BOOT_CMD ( + boot,1 ,1 , do_bootd, +"boot default, i.e., run 'bootcmd'" , +"" +); + +/* keep old command name "bootd" for backward compatibility */ +U_BOOT_CMD ( + bootd,1 ,1 , do_bootd, +"boot default, i.e., run 'bootcmd'" , +"" +);
cmd/bootm.c +0 -24
@@ -229,30 +229,6 @@ U_BOOT_CMD("boot application image from memory" , bootm_help_text ); -/*******************************************************************/ -/* bootd - boot default image */ -/*******************************************************************/ -#if defined(CONFIG_CMD_BOOTD ) -int do_bootd (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) -{ -return run_command (env_get ("bootcmd" ), flag); -} - -U_BOOT_CMD ( - boot,1 ,1 , do_bootd, -"boot default, i.e., run 'bootcmd'" , -"" -); - -/* keep old command name "bootd" for backward compatibility */ -U_BOOT_CMD ( - bootd,1 ,1 , do_bootd, -"boot default, i.e., run 'bootcmd'" , -"" -); - -#endif -/*******************************************************************/ /* iminfo - print header info for a requested image */ /*******************************************************************/
Signature · 1 line
2.54.0
Quoted 33 lines · Mehmet Fide
From: Mehmet Fide <[email protected]>
do_bootd()runs the "bootcmd" environment variable throughrun_command()and does nothing else. It uses no bootm functionality, and neither does the "bootd" recursion guard incmd_process().doc/usage/cmd/bootd.rstdocuments it that way, with an example that sets bootcmd to "echo Hello World".Commit
1fd04cf46baf("cmd: Correct dependencies forCMD_BOOTD") madeCMD_BOOTDdepend onCMD_BOOTMbecause the build fails otherwise:common/command.cis compiled unconditionally and referencesdo_bootd(), whose definition sits incmd/bootm.c, which is only compiled when CMD_BOOTM=y. The dependency therefore describes where the code lives rather than what it needs, and the boards that disableCMD_BOOTM(colibri_vf,iot_devkit, mx6memcal andr8a78000_ironhide_cm33) cannot offer "boot" or "bootd" at all, although the implementation would work there.Move
do_bootd()and its two command registrations intocmd/bootd.c, compiled fromCMD_BOOTD, and drop the artificial dependency. To leave every board in tree unchanged,CMD_BOOTDnow defaults to y only whenCMD_BOOTMis enabled, which is precisely the set of boards that have it today. Boards without bootm can enable it deliberately.Tested on sandbox: bootd, the "boot" alias, the return value taken from a failing bootcmd and the recursion guard all behave as before. Also tested on a Colibri VF50 (vf610) board built with CMD_BOOTM=n and CMD_BOOTD=y, a combination that could not be selected before: "boot" and "bootd" run bootcmd and bring up the OS, and a bootcmd of "false" returns 1. A
colibri_vf_defconfigbuild withCMD_BOOTDleft off is byte identical to the previous one apart from the version string; enablingCMD_BOOTDcosts 272 bytes.
Quoted 1 line
Signed-off-by Mehmet Fide <[email protected]>
Signature · 1 line
Tom
Quoted 33 lines · Mehmet Fide
cmd: allow bootd without bootm
do_bootd()runs the "bootcmd" environment variable throughrun_command()and does nothing else. It uses no bootm functionality, and neither does the "bootd" recursion guard incmd_process().doc/usage/cmd/bootd.rstdocuments it that way, with an example that sets bootcmd to "echo Hello World".Commit
1fd04cf46baf("cmd: Correct dependencies forCMD_BOOTD") madeCMD_BOOTDdepend onCMD_BOOTMbecause the build fails otherwise:common/command.cis compiled unconditionally and referencesdo_bootd(), whose definition sits incmd/bootm.c, which is only compiled when CMD_BOOTM=y. The dependency therefore describes where the code lives rather than what it needs, and the boards that disableCMD_BOOTM(colibri_vf,iot_devkit, mx6memcal andr8a78000_ironhide_cm33) cannot offer "boot" or "bootd" at all, although the implementation would work there.Move
do_bootd()and its two command registrations intocmd/bootd.c, compiled fromCMD_BOOTD, and drop the artificial dependency. To leave every board in tree unchanged,CMD_BOOTDnow defaults to y only whenCMD_BOOTMis enabled, which is precisely the set of boards that have it today. Boards without bootm can enable it deliberately.Tested on sandbox: bootd, the "boot" alias, the return value taken from a failing bootcmd and the recursion guard all behave as before. Also tested on a Colibri VF50 (vf610) board built with CMD_BOOTM=n and CMD_BOOTD=y, a combination that could not be selected before: "boot" and "bootd" run bootcmd and bring up the OS, and a bootcmd of "false" returns 1. A
colibri_vf_defconfigbuild withCMD_BOOTDleft off is byte identical to the previous one apart from the version string; enablingCMD_BOOTDcosts 272 bytes.
Quoted 8 lines
Signed-off-by Mehmet Fide <[email protected]>Reviewed-by Tom Rini <[email protected]>cmd/Kconfig | 3 +--
cmd/Makefile | 1 + cmd/bootd.c | 30 ++++++++++++++++++++++++++++++ cmd/bootm.c | 24 ------------------------ 4 files changed, 32 insertions(+), 26 deletions(-)
PATCH 2/2 test: cmd: add a test for bootd
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
There is no test for the bootd command. Add one to the cmd suite that covers the documented behaviour: bootd and its "boot" alias run the command held in the bootcmd environment variable, and the return value of bootd is the one of that command.
---
Notes:
checkpatch asks for a blank line before CMD_TEST(); test/cmd/command.c and test/cmd/exit.c place the macro directly after the closing brace, so this follows the surrounding tests.
test/cmd/Makefile | 3 +++ test/cmd/bootd.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/cmd/bootd.c
test/cmd/Makefile +3 -0
@@ -17,6 +17,9 @@ ifdef CONFIG_CONSOLE_RECORD obj-$(CONFIG_CMD_ACPI) += acpi.o endif obj-$(CONFIG_CMD_BDI) += bdinfo.o +ifdef CONFIG_CONSOLE_RECORD +obj-$(CONFIG_CMD_BOOTD) += bootd.o +endif obj-$(CONFIG_CMD_CONFIG) += config.o obj-$(CONFIG_COREBOOT_SYSINFO) += coreboot.o obj-$(CONFIG_CMD_FDT) += fdt.o
test/cmd/bootd.c new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Tests for the bootd command +* +* Copyright 2026 Mehmet Fide <[email protected]> +*/ + +#include <command.h> +#include <env.h> +#include <test/cmd.h> +#include <test/ut.h> + +/* Check that bootd and its "boot" alias run the bootcmd variable */ +static int cmd_bootd_test (struct unit_test_state *uts) +{ +ut_assertok (env_set ("bootcmd" ,"echo hello bootd" )); + +ut_assertok (run_command ("bootd" ,0 )); +ut_assert_nextline ("hello bootd" ); +ut_assert_console_end (); + +ut_assertok (run_command ("boot" ,0 )); +ut_assert_nextline ("hello bootd" ); +ut_assert_console_end (); + +/* the return value is the one of the command in bootcmd */ +ut_assertok (env_set ("bootcmd" ,"false" )); +ut_asserteq (1 ,run_command ("bootd" ,0 )); +ut_assert_console_end (); + +ut_assertok (env_set ("bootcmd" ,NULL )); + +return 0 ; +} +CMD_TEST (cmd_bootd_test,UTF_CONSOLE );
Signature · 1 line
2.54.0
Re: [PATCH 2/2] test: cmd: add a test for bootd
Hi Mehmet,
Quoted 15 lines · Mehmet Fide
test: cmd: add a test for bootd
There is no test for the bootd command. Add one to the cmd suite that covers the documented behaviour: bootd and its "boot" alias run the command held in the bootcmd environment variable, and the return value of bootd is the one of that command.
Signed-off-by Mehmet Fide <[email protected]>test/cmd/Makefile | 3 +++
test/cmd/bootd.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
test/cmd/Makefile ifdef CONFIG_CONSOLE_RECORD · line 22
Quoted 6 lines
test/cmd/Makefile +3
-0@@ -17,6 +17,9 @@ ifdef CONFIG_CONSOLE_RECORD obj-$(CONFIG_CMD_ACPI) += acpi.o endif obj-$(CONFIG_CMD_BDI) += bdinfo.o +ifdef CONFIG_CONSOLE_RECORD +obj-$(CONFIG_CMD_BOOTD) += bootd.o +endif
The CONFIG_CONSOLE_RECORD ifdef is not needed. UTF_CONSOLE means the runner skips the test when console recording is unavailable, and bdinfo.o just above has no such guard. Please add 'obj-$(CONFIG_CMD_BOOTD) += bootd.o' next to the bdinfo line.
test/cmd/bootd.c line 4
Quoted 6 lines
test/cmd/bootd.c +4
-0@@ -0,0 +1,35 @@ +/* the return value is the one of the command in bootcmd */ +ut_assertok (env_set ("bootcmd" ,"false" )); +ut_asserteq (1 ,run_command ("bootd" ,0 )); +ut_assert_console_end ();
'false' is a hush builtin, so this leg only works when the sandbox build uses that parser. Please either note the assumption in a comment or pick something that does not depend on the shell.
test/cmd/bootd.c line 3
Quoted 5 lines
test/cmd/bootd.c +3
-0@@ -0,0 +1,35 @@ +static int cmd_bootd_test (struct unit_test_state *uts) +{ +ut_assertok (env_set ("bootcmd" ,"echo hello bootd" ));
The test clobbers 'bootcmd' and unsets it at the end without preserving the previous value. Please save it with env_get() and restore it in cleanup, so a later test that relies on the environment is not affected by ordering.
test/cmd/bootd.c line 5
Quoted 7 lines
test/cmd/bootd.c +5
-0@@ -0,0 +1,35 @@ +ut_assertok (env_set ("bootcmd" ,NULL )); + +return 0 ; +} +CMD_TEST (cmd_bootd_test,UTF_CONSOLE );
The cover letter mentions the recursion guard in cmd_process() never fires on sandbox, so I won't ask for a test of that here, but it would be nice to assert that do_bootd() itself, when invoked with CMD_FLAG_BOOTD and bootcmd='bootd', does not recurse - that part of the guard lives in the code you moved, and you can exercise it directly with cmd_process_error() or by calling do_bootd() with the flag set. What do you think?
Regards,
Simon