Skip to contentSkip to conversation

cmd: allow bootd without bootm

PATCH In review Mehmet Fide 3 participants 6 messages Aug 6 – Aug 14

lore
Share & tools
lore
#0 lore raw

v2 cover cmd: allow bootd without bootm

From: Mehmet Fide <[email protected]>

do_bootd() only runs the bootcmd environment variable, but it lives in cmd/bootm.c, which made CMD_BOOTD depend on CMD_BOOTM. The four boards that disable bootm therefore have no "boot" or "bootd" command even though the implementation would work for them. Move the code to its own file and drop the dependency.

Changes in v2, all in patch 2/2 and all from Simon's review:
- drop the CONFIG_CONSOLE_RECORD ifdef around the test object and put the entry next to the bdinfo line; UTF_CONSOLE already makes the runner skip the test when console recording is unavailable
- do not depend on the shell for the return value leg: 'false' is a builtin of the modern hush only, and sandbox_defconfig selects the old one, so the leg passed for the wrong reason. Use an unknown command, which fails in either parser, and match only the start of the complaint because the two parsers word it differently
- save bootcmd with env_get() and restore it at the end, so test ordering cannot be affected
- assert the recursion guard, as suggested. Doing it needs a note: with CONFIG_HUSH_PARSER, run_command() hands the string to the parser and drops its flag argument, so CMD_FLAG_BOOTD never reaches cmd_process() and the guard cannot be reached that way. Calling do_bootd() directly does not reach it either, since the guard sits in cmd_process(). The test therefore calls cmd_process() with the flag, and sets bootcmd to an echo that would show up if the guard ever let it through

Patch 1/2 is unchanged and carries Tom's Reviewed-by.

Both patches are on top of baa64b2f892. "ut cmd" on sandbox runs 14 tests with no failures, the new one included.

checkpatch reports two things I left as they are: no MAINTAINERS entry covers cmd/bootm.c, so the new cmd/bootd.c does not need one either, and "Possible new command - make sure you add a test" is what 2/2 does.

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 |  1 +
 test/cmd/bootd.c  | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 99 insertions(+), 26 deletions(-)
 create mode 100644 cmd/bootd.c
 create mode 100644 test/cmd/bootd.c
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 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.

---
 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
index 35ce42f8397..f8eed5a5bdf 100644
@@ -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
index ce772e5555b..7c3db81e524 100644
@@ -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
new file mode 100644
index 00000000000..d39b1bfe888
@@ -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
index ca7cec91fad..07fd995ebed 100644
@@ -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
Reviewed-by on v2 1/2
#2 lore raw
Quoted 33 lines · Mehmet Fide

cmd: allow bootd without bootm

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.

Quoted 8 lines

cmd/Kconfig | 3 +--

 cmd/Makefile |  1 +
 cmd/bootd.c  | 30 ++++++++++++++++++++++++++++++
 cmd/bootm.c  | 24 ------------------------
 4 files changed, 32 insertions(+), 26 deletions(-)
#3 lore raw

PATCH v2 2/2 test: cmd: add a test for bootd

In reply to Mehmet Fide

From: 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. Also assert the recursion guard in cmd_process(), which is part of the code bootd carries.

---
 test/cmd/Makefile |  1 +
 test/cmd/bootd.c  | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 test/cmd/bootd.c
test/cmd/Makefile +1 -0
index 8d36463879d..e734933d5f7 100644
@@ -17,6 +17,7 @@ ifdef CONFIG_CONSOLE_RECORD
 obj-$(CONFIG_CMD_ACPI) += acpi.o
 endif
 obj-$(CONFIG_CMD_BDI) += bdinfo.o
+obj-$(CONFIG_CMD_BOOTD) += bootd.o
 obj-$(CONFIG_CMD_CONFIG) += config.o
 obj-$(CONFIG_COREBOOT_SYSINFO) += coreboot.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
test/cmd/bootd.c new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.54.0
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] test: cmd: add a test for bootd

Hi Mehmet,

Quoted 11 lines · Mehmet Fide

test: cmd: add a test for bootd

command held in the bootcmd environment variable, and the return value of bootd is the one of that command. Also assert the recursion guard in cmd_process(), which is part of the code bootd carries.

test/cmd/Makefile | 1 +

 test/cmd/bootd.c  | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

Regards,
Simon

#5 lore raw

Re: [PATCH v2 2/2] test: cmd: add a test for bootd

In reply to Mehmet Fide
Quoted 8 lines · Mehmet Fide

From: 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. Also assert the recursion guard in cmd_process(), which is part of the code bootd carries.

Quoted 6 lines
---
 test/cmd/Makefile |  1 +
 test/cmd/bootd.c  | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 test/cmd/bootd.c

This causes most of CI to fail with:

=> ut cmd cmd_bootd_test
Test: cmd_bootd_test: bootd.c
hello bootd
hello bootd
Unknown command 'no_such_command' - try 'help' !

Signature · 1 line
Tom