Skip to contentSkip to conversation

boot: implement devboot in C

PATCH Applied Sascha Hauer 1 participant 8 messages Nov 13 – Nov 24 Documentation

lore
Share & tools
lore
#0 lore raw

v2 cover boot: implement devboot in C

devboot is a script on top of the boot command, and the devboot boot target needed to boot with it by default is another one on top of that. Booting with devboot thus means nested boot commands, and booting with it by default means rewriting global.boot.default as devboot@<target>. Also, boot overrides get lost when a boot script calls boot or bootm itself, and the boot menu ignores them altogether.

This series hands overrides on to whatever a boot entry boots, applies them to entries booted from the menu, and turns devboot into what it really is, an option to the boot command: boot -D, or global.boot.devboot=1 to enable it independently of the boot targets. The devboot command remains as a shorthand for boot -D. The devboot boot target is removed, see the migration guide entry for how to replace it.

The series is based on the "Add and use file_exists() helper" and "boot:
revert boot related globalvars after booting" series.

Assisted-by Claude:claude-opus-5-5

---
Changes in v2:
- New patch "commands: boot: apply -o overrides to boot entries in the menu"
- "boot: implement devboot in C":
- devboot also applies to the boot menu
- depend on BOOTM_OPTIONAL_SIGNED_IMAGES and refuse devboot when signed images are forced at runtime
- use globalvar_get() and pushd()/popd()
- add a migration guide entry for the removed devboot boot target
- rework commit message
- Rebase onto the current "boot: revert boot related globalvars after booting" series
- Collect tags
- Link to v1: https://lore.barebox.org/[email protected]

---
Sascha Hauer (6):
boot: report the exit status of failing boot scripts
hush: export source_script()
boot: hand overrides on to nested boots and the bootm command
commands: boot: apply -o overrides to boot entries in the menu
boot: implement devboot in C
sandbox: defconfig: enable boot overrides and devboot

 .../migration-master/devboot-boot-option.rst       |  22 +++
 Documentation/user/devboot.rst                     |  81 ++++----
 arch/sandbox/configs/sandbox_defconfig             |   2 +
 commands/boot.c                                    |  30 ++-
 commands/bootm.c                                   |   3 +-
 common/Kconfig                                     |  12 +-
 common/Makefile                                    |   1 +
 common/boot.c                                      |  63 ++++---
 common/bootchooser.c                               |  13 +-
 common/bootm.c                                     |  22 ++-
 common/devboot.c                                   | 206 +++++++++++++++++++++
 common/hush.c                                      |  17 +-
 defaultenv/defaultenv-2-base/bin/devboot           |  52 +-----
 defaultenv/defaultenv-2-base/boot/devboot          |   8 -
 include/boot.h                                     |   9 +
 include/bootchooser.h                              |   2 +-
 include/bootm.h                                    |   3 +
 include/devboot.h                                  |  31 ++++
 include/shell.h                                    |   8 +
 test/py/test_boot_overrides.py                     |  92 +++++++++
 test/py/test_boot_script.py                        |  13 ++
 test/py/test_devboot.py                            | 131 +++++++++++++
 22 files changed, 691 insertions(+), 130 deletions(-)

---
base-commit: 8df700d8f4fc86df09dca13e53fb7c1d64cc9680
change-id: 20261030-devboot-af494560e196

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>
#1 lore raw

PATCH v2 1/6 boot: report the exit status of failing boot scripts

When a boot script exits with a non-zero status, execute_binfmt() returns that status as a positive value. bootscript_boot() passes it to strerror(-ret) and boot_entry() to %pe, both of which expect a negative errno, resulting in messages like:

ERROR: Running script '/env/boot/mmc' failed: error -1
ERROR: Booting entry 'mmc' failed: 0000000000000001

Allow boot entries to return a boot script's exit status and have boot_entry() report it as such. bootscript_boot() now only reports errors of its own, so a failing script results in a single

ERROR: Booting entry 'mmc' failed: exit status 1

---
 common/boot.c               | 11 +++++++----
 include/boot.h              |  1 +
 test/py/test_boot_script.py | 13 +++++++++++++
 3 files changed, 21 insertions(+), 4 deletions(-)
common/boot.c +7 -4
index 023eaf5145..b993cabf65 100644
@@ -115,10 +115,11 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 	 * without the shell expanding or splitting it first.
 	 */
 	ret = execute_binfmt(bs->args ? 2 : 1, argv);
-	if (ret) {
-		pr_err("Running script '%s' failed: %s\n", bs->entry.path, strerror(-ret));
+	if (ret < 0)
+		pr_err("Running script '%s' failed: %pe\n", bs->entry.path, ERR_PTR(ret));
+	/* positive values are the exit status, reported by boot_entry() */
+	if (ret)
 		return ret;
-	}
 
 	/* No point in repeating bootm if script already called it */
 	if (bootm_nattempts != bootm_command_attempts())
@@ -206,7 +207,9 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
 	scope = boot_globalvar_scope_push();
 
 	ret = be->boot(be, verbose, dryrun);
-	if (ret && ret != -ENOMEDIUM)
+	if (ret > 0)
+		pr_err("Booting entry '%s' failed: exit status %d\n", be->title, ret);
+	else if (ret && ret != -ENOMEDIUM)
 		pr_err("Booting entry '%s' failed: %pe\n", be->title, ERR_PTR(ret));
 
 	globalvar_scope_pop(scope);
include/boot.h +1 -0
index 1ae689732d..dad45592a6 100644
@@ -20,6 +20,7 @@ struct bootentry {
 	const char *title;
 	char *description;
 	const char *path;
+	/* 0 on success, else negative errno or a boot script's exit status */
 	int (*boot)(struct bootentry *entry, int verbose, int dryrun);
 	void (*release)(struct bootentry *entry);
 	struct bootm_overrides overrides;
test/py/test_boot_script.py new file +13 -0
new file mode 100644
index 0000000000..be08e964d9
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+
+def test_boot_script_exit_status(barebox):
+    barebox.run_check("echo -o /env/boot/exit3 '#!/bin/sh'")
+    barebox.run_check("echo -a /env/boot/exit3 'exit 3'")
+
+    stdout, _, ret = barebox.run("boot exit3")
+    assert ret != 0
+    assert "ERROR: Booting entry 'exit3' failed: exit status 3" in stdout
+    assert not any("Running script" in line for line in stdout)
+
+    barebox.run_check("rm /env/boot/exit3")
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/6 hush: export source_script()

In reply to Sascha Hauer

C code that wants to source a shell script has to go through run_command("source ..."), which parses the command line and looks the script up in the PATH.

Export source_script() instead. As the simple parser can't source scripts, it gets a stub returning -ENOSYS. Unlike its callers in hush, source_script() can now be called directly, so check the security policy in it, like run_command() and execute_script() do.

---
 common/hush.c   | 17 +++++++++++++++--
 include/shell.h |  8 ++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
common/hush.c +15 -2
index ac885fbfe7..c5809b32cd 100644
@@ -329,7 +329,6 @@ static char **make_list_in(char **inp, char *name);
 static char *insert_var_value(char *inp);
 static int set_local_var(const char *s, int flg_export);
 static int execute_script(const char *path, int argc, char *argv[]);
-static int source_script(const char *path, int argc, char *argv[]);
 
 static int b_check_space(o_string *o, int len)
 {
@@ -1975,12 +1974,26 @@ static int execute_script(const char *path, int argc, char *argv[])
 	return ret;
 }
 
-static int source_script(const char *path, int argc, char *argv[])
+/**
+ * source_script - execute a shell script in the current environment
+ * @path: path of the script
+ * @argc: number of positional parameters, including $0
+ * @argv: positional parameters, starting with $0
+ *
+ * Unlike executing a script, variables set by it remain set in the current
+ * environment context after it returns.
+ *
+ * Return: exit status of the last command executed, or a negative error code
+ */
+int source_script(const char *path, int argc, char *argv[])
 {
 	struct p_context ctx = {};
 	char *script;
 	int ret;
 
+	if (!IS_ALLOWED(SCONFIG_SHELL))
+		return -EPERM;
+
 	initialize_context(&ctx, true);
 
 	ctx.global_argc = argc;
include/shell.h +8 -0
index b399564ff3..a0c3414fa6 100644
@@ -6,17 +6,25 @@
 #ifndef __SHELL_H__
 #define __SHELL_H__
 
+#include <linux/errno.h>
+
 int shell_get_last_return_code(void);
 
 int run_shell(void);
 
 #ifdef CONFIG_SHELL_HUSH
 char *shell_expand(char *str);
+int source_script(const char *path, int argc, char *argv[]);
 #else
 static inline char *shell_expand(char *str)
 {
 	return strdup(str);
 }
+
+static inline int source_script(const char *path, int argc, char *argv[])
+{
+	return -ENOSYS;
+}
 #endif
 
 #ifdef CONFIG_BAREBOX_CMDLINE
Signature · 1 line
2.47.3
#3 lore raw

PATCH v2 3/6 boot: hand overrides on to nested boots and the bootm command

In reply to Sascha Hauer

Overrides are stored in the boot entry they are given for and only applied by bootm_entry(). They get lost when a boot entry boots something else, like a boot script calling boot, or calling the bootm command.

Keep track of the overrides of the boot entry being booted. Hand them on to boot entries booted from there, with the ones of the outer entry taking precedence, and apply them in the bootm command. bootchooser no longer needs to merge the overrides into its targets itself.

This is done in do_bootm() and not in bootm_boot(), which the Android image handler calls while a bootm is already running, so it would apply the overrides a second time.

---
 Documentation/user/devboot.rst |  4 ++
 commands/bootm.c               |  3 +-
 common/boot.c                  | 44 ++++++++++++--------
 common/bootchooser.c           | 13 ++----
 common/bootm.c                 | 22 +++++++++-
 include/boot.h                 |  8 ++++
 include/bootchooser.h          |  2 +-
 include/bootm.h                |  3 ++
 test/py/test_boot_overrides.py | 92 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 163 insertions(+), 28 deletions(-)
Documentation/user/devboot.rst +4 -0
index 227048be97..efcfde918c 100644
@@ -38,6 +38,10 @@ Overrides are applied after the boot entry has been loaded, so the original
 entry still selects the boot handler, kernel arguments, etc. Only the
 specified components are replaced.
 
+Overrides also apply to whatever a boot entry boots itself, like a boot script
+calling ``boot`` or ``bootm``, even if that is passed an image explicitly. If
+a nested ``boot`` has overrides of its own, the outer ones take precedence.
+
 Override rules
 ^^^^^^^^^^^^^^
 
commands/bootm.c +2 -1
index 44abb953f6..0d6a95edae 100644
@@ -16,6 +16,7 @@
 #include <fcntl.h>
 #include <fs.h>
 #include <errno.h>
+#include <boot.h>
 #include <bootm.h>
 #include <rtc.h>
 #include <init.h>
@@ -94,7 +95,7 @@ static int do_bootm(int argc, char *argv[])
 		goto err_out;
 	}
 
-	ret = bootm_boot(&data);
+	ret = bootm_boot_overrides(&data, boot_get_active_overrides());
 	if (ret) {
 		printf("handler failed with: %pe\n", ERR_PTR(ret));
 		goto err_out;
common/boot.c +28 -16

63 lines not on this page · raw message

common/bootchooser.c +4 -9
index 2049425ab3..c8f72871f3 100644
@@ -840,8 +840,7 @@ void bootchooser_lock_attempts(bool locked)
 	attempts_locked = locked;
 }
 
-static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain,
-				struct bootentry *parent_entry)
+static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
 {
 	char *system;
 	struct bootentries *entries;
@@ -878,10 +877,6 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain,
 	ret = -ENOENT;
 
 	bootentries_for_each_entry(entries, entry) {
-		if (parent_entry)
-			bootm_merge_overrides(&entry->overrides,
-					      &parent_entry->overrides);
-
 		ret = boot_entry(entry, bc->verbose, bc->dryrun);
 		if (!ret) {
 			*tryagain = 0;
@@ -898,12 +893,12 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain,
 	return ret;
 }
 
-int bootchooser_boot(struct bootchooser *bc, struct bootentry *entry)
+int bootchooser_boot(struct bootchooser *bc)
 {
 	int ret, tryagain;
 
 	do {
-		ret = bootchooser_boot_one(bc, &tryagain, entry);
+		ret = bootchooser_boot_one(bc, &tryagain);
 
 		if (!retry)
 			break;
@@ -924,7 +919,7 @@ int bootchooser_entry_boot(struct bootentry *entry, int verbose, int dryrun)
 	bc->verbose = verbose;
 	bc->dryrun = dryrun;
 
-	ret = bootchooser_boot(bc, entry);
+	ret = bootchooser_boot(bc);
 
 	bootchooser_put(bc);
 
common/bootm.c +21 -1
index 4e0b688910..a65aa64ddf 100644
@@ -794,7 +794,15 @@ void bootm_boot_cleanup(struct image_data *data)
 /*
  * bootm_boot - Boot an application image described by bootm_data
  */
-int bootm_boot(const struct bootm_data *bootm_data)
+/**
+ * bootm_boot_overrides - boot with overrides applied
+ * @bootm_data: bootm data
+ * @overrides: overrides to apply, may be NULL
+ *
+ * Return: 0 on success, or negative error code otherwise
+ */
+int bootm_boot_overrides(const struct bootm_data *bootm_data,
+			 const struct bootm_overrides *overrides)
 {
 	struct image_data *data;
 	int ret;
@@ -803,12 +811,24 @@ int bootm_boot(const struct bootm_data *bootm_data)
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	if (overrides) {
+		ret = bootm_apply_overrides(data, overrides);
+		if (ret)
+			goto out;
+	}
+
 	ret = bootm_boot_handler(data);
 
+out:
 	bootm_boot_cleanup(data);
 	return ret;
 }
 
+int bootm_boot(const struct bootm_data *bootm_data)
+{
+	return bootm_boot_overrides(bootm_data, NULL);
+}
+
 bool bootm_efi_check_image(struct image_handler *handler,
 			   struct image_data *data,
 			   enum filetype detected_filetype)
include/boot.h +8 -0
index dad45592a6..a55adc3c38 100644
@@ -56,6 +56,14 @@ int bootentry_create_from_name(struct bootentries *bootentries,
 void bootsources_menu(struct bootentries *bootentries, unsigned default_entry, int timeout);
 void bootsources_list(struct bootentries *bootentries);
 int boot_entry(struct bootentry *be, int verbose, int dryrun);
+#ifdef CONFIG_BOOT
+const struct bootm_overrides *boot_get_active_overrides(void);
+#else
+static inline const struct bootm_overrides *boot_get_active_overrides(void)
+{
+	return NULL;
+}
+#endif
 
 struct bootm_data;
 int bootm_entry(struct bootentry *be, const struct bootm_data *data);
include/bootchooser.h +1 -1
index da3b974ef6..36cbd0dd0a 100644
@@ -14,7 +14,7 @@ int bootchooser_put(struct bootchooser *bootchooser);
 
 void bootchooser_info(struct bootchooser *bootchooser);
 
-int bootchooser_boot(struct bootchooser *bc, struct bootentry *entry);
+int bootchooser_boot(struct bootchooser *bc);
 
 struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bootchooser);
 void bootchooser_lock_attempts(bool locked);
include/bootm.h +3 -0
index 06eb90c5ed..d63e9fc4f6 100644
@@ -75,6 +75,9 @@ struct bootm_data {
 int bootm_image_name_and_part(const char *name, char **filename, char **part);
 
 int bootm_boot(const struct bootm_data *data);
+struct bootm_overrides;
+int bootm_boot_overrides(const struct bootm_data *data,
+			 const struct bootm_overrides *overrides);
 
 struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data);
 int bootm_open_os_compressed(struct image_data *data);
test/py/test_boot_overrides.py new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.47.3
#4 lore raw

PATCH v2 4/6 commands: boot: apply -o overrides to boot entries in the menu

In reply to Sascha Hauer

boot -m collects the boot entries and shows them in a menu, but merges the overrides given with -o only into the entries it boots directly. An entry selected from the menu is booted without them, so
boot -m -o bootm.image=... silently boots the entry's own image.

Merge the overrides into all entries before showing the menu.

---
 commands/boot.c | 3 +++
 1 file changed, 3 insertions(+)
commands/boot.c +3 -0
index 81f392075d..8e8afdff9b 100644
@@ -204,6 +204,9 @@ static int do_boot(int argc, char *argv[])
 			goto out;
 		}
 
+		bootentries_for_each_entry(entries, entry)
+			bootm_merge_overrides(&entry->overrides, &overrides);
+
 		bootsources_menu(entries, idx, timeout);
 	}
 
Signature · 1 line
2.47.3
#5 lore raw

PATCH v2 5/6 boot: implement devboot in C

In reply to Sascha Hauer

devboot is a shell script that brings up the network, sources a per-user, per-board script from global.net.fetchdir and translates the variables it sets into boot -o options. To boot with it by default, the devboot boot target wraps it, so booting with devboot means a boot command running a boot entry that runs another boot command: two levels of boot entries, with the overrides passed on as a command line assembled by the script and failures reported by both levels. It also has to be applied to each boot target separately, as devboot@<target>, rather than to whatever targets are booted.

All devboot really is, is an option to the boot command. Implement it in C as such: boot -D, or global.boot.devboot=1 to enable it by default, does what the devboot script did before booting the boot targets. The script's changes to the boot related globalvars are reverted after the boot command returns, as is the working directory. A boot command started while devboot is active doesn't source the script again, it inherits the overrides from the boot entry it is started from. Overrides given with -o still take precedence. With the boot menu, the script is sourced before the menu is shown and applies to all entries booted from it.

This makes devboot independent of the boot targets: nv boot.devboot=1 works with any global.boot.default, and doing it in C allows for proper error handling instead of passing exit statuses through nested boots.

The devboot command remains as a shorthand for boot -D. The devboot boot target is removed, nv boot.devboot=1 replaces nv boot.default=devboot@...

---
 .../migration-master/devboot-boot-option.rst       |  22 +++
 Documentation/user/devboot.rst                     |  77 ++++----
 commands/boot.c                                    |  27 ++-
 common/Kconfig                                     |  12 +-
 common/Makefile                                    |   1 +
 common/boot.c                                      |   8 +-
 common/devboot.c                                   | 206 +++++++++++++++++++++
 defaultenv/defaultenv-2-base/bin/devboot           |  52 +-----
 defaultenv/defaultenv-2-base/boot/devboot          |   8 -
 include/devboot.h                                  |  31 ++++
 test/py/test_devboot.py                            | 131 +++++++++++++
 11 files changed, 479 insertions(+), 96 deletions(-)
Documentation/migration-guides/migration-master/devboot-boot-option.rst new file +22 -0
new file mode 100644
index 0000000000..b416f98176
@@ -0,0 +1,22 @@
+devboot is now an option of the boot command
+---------------------------------------------
+
+devboot is implemented in C as the ``-D`` option of the ``boot`` command,
+which needs ``CONFIG_BOOT_DEVBOOT``. The ``devboot`` command remains as a
+shorthand for ``boot -D``, so ``devboot mmc`` keeps working as before.
+
+The ``devboot`` boot target has been removed. Configurations booting with
+devboot by default through it, like::
+
+  nv boot.default=devboot@system0
+
+now fail with ``Nothing bootable found on 'devboot@system0'``. Set the
+boot target directly and enable devboot separately instead::
+
+  nv boot.default=system0
+  nv boot.devboot=1
+
+Kernel command line fragments set by the devboot script no longer need the
+``global.linux.bootargs.devboot.`` namespace: all changes the script makes
+to the boot related globalvars are reverted once the ``boot`` command
+returns.
Documentation/user/devboot.rst +46 -31

134 lines not on this page · raw message

commands/boot.c +25 -2
index 8e8afdff9b..d4f7998b96 100644
@@ -7,6 +7,7 @@
 #include <malloc.h>
 #include <boot.h>
 #include <bootm.h>
+#include <devboot.h>
 #include <fnmatch.h>
 #include <complete.h>
 
@@ -111,11 +112,13 @@ static int do_boot(int argc, char *argv[])
 	struct bootentries *entries;
 	struct bootentry *entry;
 	struct bootm_overrides overrides = {};
+	struct devboot *devboot = NULL;
+	bool do_devboot = devboot_enabled();
 	void *handle;
 	const char *name;
 	char *(*next)(void *);
 
-	while ((opt = getopt(argc, argv, "vldmM:t:w:o:")) > 0) {
+	while ((opt = getopt(argc, argv, "vldmM:t:w:o:D")) > 0) {
 		switch (opt) {
 		case 'v':
 			verbose++;
@@ -138,6 +141,13 @@ static int do_boot(int argc, char *argv[])
 		case 'w':
 			boot_set_watchdog_timeout(simple_strtoul(optarg, NULL, 0));
 			break;
+		case 'D':
+			if (!IS_ENABLED(CONFIG_BOOT_DEVBOOT)) {
+				ret = -ENOSYS;
+				goto out_overrides;
+			}
+			do_devboot = true;
+			break;
 		case 'o':
 			ret = boot_add_override(&overrides, optarg);
 			if (ret)
@@ -163,6 +173,15 @@ static int do_boot(int argc, char *argv[])
 		next = next_word;
 	}
 
+	if (do_devboot && !do_list) {
+		devboot = devboot_start(&overrides);
+		if (IS_ERR(devboot)) {
+			ret = PTR_ERR(devboot);
+			free(freep);
+			goto out_overrides;
+		}
+	}
+
 	entries = bootentries_alloc();
 
 	while ((name = next(&handle)) != NULL) {
@@ -214,6 +233,7 @@ static int do_boot(int argc, char *argv[])
 out:
 	bootentries_free(entries);
 	free(freep);
+	devboot_finish(devboot);
 out_overrides:
 	boot_free_overrides(&overrides);
 
@@ -269,13 +289,16 @@ BAREBOX_CMD_HELP_OPT ("-w SECS","Start watchdog with timeout SECS before booting
 BAREBOX_CMD_HELP_OPT ("-o VAR[=VAL]","override VAR (bootm.{image,oftree,initrd}) with VAL")
 BAREBOX_CMD_HELP_OPT ("            ","if VAL is not specified, the value of VAR is taken")
 #endif
+#ifdef CONFIG_BOOT_DEVBOOT
+BAREBOX_CMD_HELP_OPT ("-D","devboot: take overrides from a script in global.net.fetchdir")
+#endif
 BAREBOX_CMD_HELP_OPT ("-t SECS","specify timeout in SECS")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(boot)
 	.cmd	= do_boot,
 	BAREBOX_CMD_DESC("boot from script, device, ...")
-	BAREBOX_CMD_OPTS("[-vdlmMwto] [BOOTSRC...]")
+	BAREBOX_CMD_OPTS("[-vdlmMwtoD] [BOOTSRC...]")
 	BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
 	BAREBOX_CMD_HELP(cmd_boot_help)
 BAREBOX_CMD_END
common/Kconfig +11 -1
index da4cc8a5c9..9ce43df88d 100644
@@ -677,6 +677,16 @@ config BOOT_OVERRIDE
 	  Allow overriding of bootm image, oftree and initrd by passing
 	  -o as an argument to the boot command.
 
+config BOOT_DEVBOOT
+	bool "Support devboot"
+	depends on BOOT_OVERRIDE && SHELL_HUSH && BOOTM_OPTIONAL_SIGNED_IMAGES
+	default y
+	help
+	  Add a -D option to the boot command and a global.boot.devboot
+	  variable, which take boot overrides and kernel command line
+	  fragments from a per-user, per-board script in the network
+	  fetch directory. See Documentation/user/devboot.rst.
+
 config BOOTM_SHOW_TYPE
 	bool
 	depends on BOOTM && UIMAGE
@@ -1243,7 +1253,7 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW_SECURITY_POLICY
 config DEFAULT_ENVIRONMENT_GENERIC_NEW_DEVBOOT
 	bool "Reusable devboot snippets under /env/devboot/"
 	depends on DEFAULT_ENVIRONMENT_GENERIC_NEW
-	depends on BOOT_OVERRIDE
+	depends on BOOT_DEVBOOT
 	help
 	  Extend the defaultenv template with snippets under /env/devboot/
 	  that a devboot script can source: defaults for the image, oftree
common/Makefile +1 -0
index b1045c3acb..054a30a04b 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_BLSPEC)		+= blspec.o
 obj-$(CONFIG_BOOTM)		+= bootm.o booti.o
 obj-$(CONFIG_BOOTM_AIMAGE)	+= bootm-android-image.o
 obj-$(CONFIG_BOOT_OVERRIDE)	+= bootm-overrides.o
+obj-$(CONFIG_BOOT_DEVBOOT)	+= devboot.o
 obj-$(CONFIG_CMD_LOADS)		+= s_record.o
 obj-$(CONFIG_MEMTEST)		+= memtest.o
 obj-$(CONFIG_COMMAND_SUPPORT)	+= command.o
common/boot.c +4 -4
index 271cfd3a29..9919a9a8bc 100644
@@ -353,7 +353,7 @@ static int bootscript_scan_path(struct bootentries *bootentries, const char *pat
 /*
  * Only the first character of a boot script argument is restricted, so
  * that other forms can be added later without changing the meaning of
- * existing targets, e.g. devboot@@mmc0@mmc1 or devboot@[some-condition].
+ * existing targets, e.g. SCRIPT@@ARG1@ARG2 or SCRIPT@[some-condition].
  * Paths and URLs are fine as arguments.
  */
 static bool is_valid_bootarg(const char *s)
@@ -366,8 +366,8 @@ static bool is_valid_bootarg(const char *s)
  *
  * name is either an absolute path or a name relative to /env/boot. A name
  * of the form SCRIPT@ARGUMENT refers to the boot script SCRIPT and has
- * ARGUMENT passed to it as first argument, e.g. devboot@system0 runs
- * /env/boot/devboot with argument system0. A name that exists as-is takes
+ * ARGUMENT passed to it as first argument, e.g. mmc@1 runs /env/boot/mmc
+ * with argument 1. A name that exists as-is takes
  * precedence, so scripts and directories with an @ in their name keep
  * working. An empty SCRIPT is rejected, so that @ARGUMENT doesn't expand
  * to every script in /env/boot.
@@ -552,7 +552,7 @@ static char *parse_nfs_url(const char *url)
  * name can be:
  * - a name of a boot script under /env/boot
  * - a name of a boot script under /env/boot followed by an @ and an
- *   argument to pass to the script, e.g. devboot@system0
+ *   argument to pass to the script, e.g. mmc@1
  * - a full path of a boot script
  * - a full path of a bootloader spec entry
  * - a device name
common/devboot.c new file +206 -0

206 lines not on this page · raw message

defaultenv/defaultenv-2-base/bin/devboot +2 -50

54 lines not on this page · raw message

defaultenv/defaultenv-2-base/boot/devboot deleted +0 -8
deleted file mode 100644
index 4dd0626774..0000000000
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-if [ $# = 0 ]; then
-	echo "usage: boot devboot@<target>, e.g. boot devboot@mmc"
-	exit 1
-fi
-
-devboot $*
include/devboot.h new file +31 -0
new file mode 100644
index 0000000000..c33638d83b
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __DEVBOOT_H
+#define __DEVBOOT_H
+
+#include <linux/stddef.h>
+#include <linux/types.h>
+
+struct bootm_overrides;
+struct devboot;
+
+#ifdef CONFIG_BOOT_DEVBOOT
+bool devboot_enabled(void);
+struct devboot *devboot_start(struct bootm_overrides *overrides);
+void devboot_finish(struct devboot *db);
+#else
+static inline bool devboot_enabled(void)
+{
+	return false;
+}
+
+static inline struct devboot *devboot_start(struct bootm_overrides *overrides)
+{
+	return NULL;
+}
+
+static inline void devboot_finish(struct devboot *db)
+{
+}
+#endif
+
+#endif
test/py/test_devboot.py new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.47.3
#6 lore raw

PATCH v2 6/6 sandbox: defconfig: enable boot overrides and devboot

In reply to Sascha Hauer

Enable boot overrides and with it devboot along with the devboot snippets, so that the devboot tests run on sandbox as well.

---
 arch/sandbox/configs/sandbox_defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/sandbox/configs/sandbox_defconfig +2 -0
index 5b2cfdd515..46f1270178 100644
@@ -4,12 +4,14 @@ CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
+CONFIG_BOOT_OVERRIDE=y
 CONFIG_CONSOLE_ACTIVATE_ALL=y
 CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_COMPRESSION_GZIP=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE=y
+CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DEVBOOT=y
 CONFIG_DEFAULT_ENVIRONMENT_PATH=""
 CONFIG_STATE=y
 CONFIG_STATE_CRYPTO=y
Signature · 1 line
2.47.3
author Applied
#7 lore raw
In reply to Sascha Hauer
Quoted 8 lines · Sascha Hauer

devboot is a script on top of the boot command, and the devboot boot target needed to boot with it by default is another one on top of that. Booting with devboot thus means nested boot commands, and booting with it by default means rewriting global.boot.default as devboot@<target>. Also, boot overrides get lost when a boot script calls boot or bootm itself, and the boot menu ignores them altogether.

[...]

Applied, thanks!

[1/6] boot: report the exit status of failing boot scripts
https://git.pengutronix.de/cgit/barebox/commit/?id=acdc54ad128b (link may not be stable)
[2/6] hush: export source_script()
https://git.pengutronix.de/cgit/barebox/commit/?id=4c2de96f88f8 (link may not be stable)
[3/6] boot: hand overrides on to nested boots and the bootm command
https://git.pengutronix.de/cgit/barebox/commit/?id=44a0d8228ae0 (link may not be stable)
[4/6] commands: boot: apply -o overrides to boot entries in the menu
https://git.pengutronix.de/cgit/barebox/commit/?id=f7a31e905b4c (link may not be stable)
[5/6] boot: implement devboot in C
https://git.pengutronix.de/cgit/barebox/commit/?id=04b0a80c059a (link may not be stable)
[6/6] sandbox: defconfig: enable boot overrides and devboot
https://git.pengutronix.de/cgit/barebox/commit/?id=fe7895c5da1a (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>