diff mbox series

[v3,31/32] bootstd: Introduce programmatic boot

Message ID 20231118210547.577026-32-sjg@chromium.org
State Accepted
Commit 1047b5340c1203f825c0a68b33997b787be0123e
Delegated to: Tom Rini
Headers show
Series bootm: Refactoring to reduce reliance on CMDLINE (part A) | expand

Commit Message

Simon Glass Nov. 18, 2023, 9:05 p.m. UTC
At present bootstd requires CONFIG_CMDLINE to operate. Add a new
'programmatic' boot which can be used when no command line is available.
For now it does almost nothing, since most bootmeths require the
command line.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Add a panic if programmatic boot fails

 boot/Kconfig      | 12 +++++++++++
 boot/Makefile     |  2 ++
 boot/prog_boot.c  | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 common/main.c     | 11 ++++++++++
 include/bootstd.h |  9 +++++++++
 5 files changed, 85 insertions(+)
 create mode 100644 boot/prog_boot.c

Comments

Tom Rini Nov. 28, 2023, 6:21 p.m. UTC | #1
On Sat, Nov 18, 2023 at 02:05:19PM -0700, Simon Glass wrote:

> At present bootstd requires CONFIG_CMDLINE to operate. Add a new
> 'programmatic' boot which can be used when no command line is available.
> For now it does almost nothing, since most bootmeths require the
> command line.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Overall, this seems fine. The only ask I have really is, can we think
about how to handle both this case and the case handled by
cmd/bootmenu.c in a common fashion? To me, one is "show a menu of boot
options, based on env variables" and one is "show a menu of boot
options, based on C code" and the "show a menu of boot options" should
have a lot in common.
Simon Glass Nov. 28, 2023, 9:14 p.m. UTC | #2
Hi Tom,


On Tue, Nov 28, 2023, 12:21 Tom Rini <trini@konsulko.com> wrote:

> On Sat, Nov 18, 2023 at 02:05:19PM -0700, Simon Glass wrote:
>
> > At present bootstd requires CONFIG_CMDLINE to operate. Add a new
> > 'programmatic' boot which can be used when no command line is available.
> > For now it does almost nothing, since most bootmeths require the
> > command line.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
>
> Overall, this seems fine. The only ask I have really is, can we think
> about how to handle both this case and the case handled by
> cmd/bootmenu.c in a common fashion? To me, one is "show a menu of boot
> options, based on env variables" and one is "show a menu of boot
> options, based on C code" and the "show a menu of boot options" should
> have a lot in common.
>

I had not thought about providing a menu with prog boot.

Could we drop this patch from the series for now and apply the others? I
would like to finish and send the follow-on

Regards,
Simon

>
> --
> Tom
>
Tom Rini Nov. 28, 2023, 9:18 p.m. UTC | #3
On Tue, Nov 28, 2023 at 03:14:30PM -0600, Simon Glass wrote:
> Hi Tom,
> 
> 
> On Tue, Nov 28, 2023, 12:21 Tom Rini <trini@konsulko.com> wrote:
> 
> > On Sat, Nov 18, 2023 at 02:05:19PM -0700, Simon Glass wrote:
> >
> > > At present bootstd requires CONFIG_CMDLINE to operate. Add a new
> > > 'programmatic' boot which can be used when no command line is available.
> > > For now it does almost nothing, since most bootmeths require the
> > > command line.
> > >
> > > Signed-off-by: Simon Glass <sjg@chromium.org>
> >
> > Overall, this seems fine. The only ask I have really is, can we think
> > about how to handle both this case and the case handled by
> > cmd/bootmenu.c in a common fashion? To me, one is "show a menu of boot
> > options, based on env variables" and one is "show a menu of boot
> > options, based on C code" and the "show a menu of boot options" should
> > have a lot in common.
> 
> I had not thought about providing a menu with prog boot.

I guess I missed how there wasn't a menu with this series and conflated
that with one of your other series.

> Could we drop this patch from the series for now and apply the others? I
> would like to finish and send the follow-on

I didn't see any other feedback so yes, I'll be applying this soon'ish.
diff mbox series

Patch

diff --git a/boot/Kconfig b/boot/Kconfig
index ef71883a5026..b438002059c3 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -459,6 +459,18 @@  config BOOTSTD_BOOTCOMMAND
 	  standard boot does not support all of the features of distro boot
 	  yet.
 
+config BOOTSTD_PROG
+	bool "Use programmatic boot"
+	depends on !CMDLINE
+	default y
+	help
+	  Enable this to provide a board_run_command() function which can boot
+	  a systen without using commands. If the boot fails, then U-Boot will
+	  panic.
+
+	  Note: This currently has many limitations and is not a useful booting
+	  solution. Future work will eventually make this a viable option.
+
 config BOOTMETH_GLOBAL
 	bool
 	help
diff --git a/boot/Makefile b/boot/Makefile
index 3fd048bb41ab..de0eafed14b1 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -25,6 +25,8 @@  obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootmeth-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD_PROG) += prog_boot.o
+
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EXTLINUX) += bootmeth_extlinux.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EXTLINUX_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
diff --git a/boot/prog_boot.c b/boot/prog_boot.c
new file mode 100644
index 000000000000..045554b93db0
--- /dev/null
+++ b/boot/prog_boot.c
@@ -0,0 +1,51 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include <bootflow.h>
+#include <bootstd.h>
+#include <command.h>
+#include <dm.h>
+
+/*
+ * show_bootmeths() - List available bootmeths
+ *
+ * We could refactor this to use do_bootmeth_list() if more detail (or ordering)
+ * are needed
+ */
+static void show_bootmeths(void)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+
+	printf("Bootmeths: ");
+	uclass_id_foreach_dev(UCLASS_BOOTMETH, dev, uc)
+		printf(" %s", dev->name);
+	printf("\n");
+}
+
+int bootstd_prog_boot(void)
+{
+	struct bootflow_iter iter;
+	struct bootflow bflow;
+	int ret, flags, i;
+
+	printf("Programmatic boot starting\n");
+	show_bootmeths();
+	flags = BOOTFLOWIF_HUNT | BOOTFLOWIF_SHOW | BOOTFLOWIF_SKIP_GLOBAL;
+
+	bootstd_clear_glob();
+	for (i = 0, ret = bootflow_scan_first(NULL, NULL, &iter, flags, &bflow);
+	     i < 1000 && ret != -ENODEV;
+	     i++, ret = bootflow_scan_next(&iter, &bflow)) {
+		if (!bflow.err)
+			bootflow_run_boot(&iter, &bflow);
+		bootflow_free(&bflow);
+	}
+
+	return -EFAULT;
+}
diff --git a/common/main.c b/common/main.c
index 7c70de2e59a8..6dba6cba144b 100644
--- a/common/main.c
+++ b/common/main.c
@@ -9,6 +9,7 @@ 
 #include <common.h>
 #include <autoboot.h>
 #include <bootstage.h>
+#include <bootstd.h>
 #include <cli.h>
 #include <command.h>
 #include <console.h>
@@ -67,6 +68,16 @@  void main_loop(void)
 
 	autoboot_command(s);
 
+	/* if standard boot if enabled, assume that it will be able to boot */
+	if (IS_ENABLED(CONFIG_BOOTSTD_PROG)) {
+		int ret;
+
+		ret = bootstd_prog_boot();
+		printf("Standard boot failed (err=%dE)\n", ret);
+		panic("Failed to boot");
+	}
+
 	cli_loop();
+
 	panic("No CLI available");
 }
diff --git a/include/bootstd.h b/include/bootstd.h
index 7802564bcc63..99ce7b64e7c5 100644
--- a/include/bootstd.h
+++ b/include/bootstd.h
@@ -94,4 +94,13 @@  int bootstd_get_priv(struct bootstd_priv **stdp);
  */
 void bootstd_clear_glob(void);
 
+/**
+ * bootstd_prog_boot() - Run standard boot in a fully programmatic mode
+ *
+ * Attempts to boot without making any use of U-Boot commands
+ *
+ * Returns: -ve error value (does not return except on failure to boot)
+ */
+int bootstd_prog_boot(void);
+
 #endif