[Concept,10/24] boot: Provide a bootflow option to fake a boot

Message ID 20250922180116.3088502-11-sjg@u-boot.org
State New
Headers
Series boot: efi: Various improvements to booting with the EFI app |

Commit Message

Simon Glass Sept. 22, 2025, 6 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Allow using 'bootflow boot -f' to fake a boot.

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

 cmd/bootflow.c             | 16 ++++++++++++++--
 doc/usage/cmd/bootflow.rst |  3 +++
 include/bootflow.h         |  3 +++
 3 files changed, 20 insertions(+), 2 deletions(-)
  

Patch

diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 43335fecb34..33ed9a1cd73 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -523,8 +523,12 @@  static int do_bootflow_boot(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	struct bootstd_priv *std;
 	struct bootflow *bflow;
+	bool fake = false;
 	int ret;
 
+	if (IS_ENABLED(CONFIG_BOOTM_FAKE_GO) && argc > 1 && *argv[1] == '-')
+		fake = strchr(argv[1], 'f');
+
 	ret = bootstd_get_priv(&std);
 	if (ret)
 		return CMD_RET_FAILURE;
@@ -538,6 +542,14 @@  static int do_bootflow_boot(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 	bflow = std->cur_bootflow;
+
+	if (IS_ENABLED(CONFIG_BOOTM_FAKE_GO)) {
+		if (fake)
+			bflow->flags |= BOOTFLOWF_FAKE_GO;
+		else
+			bflow->flags &= ~BOOTFLOWF_FAKE_GO;
+	}
+	log_debug("cmd bflow flags %x\n", bflow->flags);
 	ret = bootflow_run_boot(NULL, bflow);
 	if (ret)
 		return CMD_RET_FAILURE;
@@ -649,7 +661,7 @@  U_BOOT_LONGHELP(bootflow,
 	"bootflow select [<num>|<name>] - select a bootflow\n"
 	"bootflow info [-ds]            - show info on current bootflow (-d dump bootflow)\n"
 	"bootflow read                  - read all current-bootflow files\n"
-	"bootflow boot                  - boot current bootflow\n"
+	"bootflow boot [-f]             - boot current bootflow (-f fake)\n"
 	"bootflow menu [-t]             - show a menu of available bootflows\n"
 	"bootflow cmdline [set|get|clear|delete|auto] <param> [<value>] - update cmdline"
 #else
@@ -664,7 +676,7 @@  U_BOOT_CMD_WITH_SUBCMDS(bootflow, "Boot flows", bootflow_help_text,
 	U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootflow_select),
 	U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootflow_info),
 	U_BOOT_SUBCMD_MKENT(read, 1, 1, do_bootflow_read),
-	U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot),
+	U_BOOT_SUBCMD_MKENT(boot, 2, 1, do_bootflow_boot),
 	U_BOOT_SUBCMD_MKENT(menu, 2, 1, do_bootflow_menu),
 	U_BOOT_SUBCMD_MKENT(cmdline, 4, 1, do_bootflow_cmdline),
 #endif
diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst
index d57a6e36c3b..938e5c79903 100644
--- a/doc/usage/cmd/bootflow.rst
+++ b/doc/usage/cmd/bootflow.rst
@@ -231,6 +231,9 @@  bootflow boot
 
 This boots the current bootflow, reading any required files first.
 
+For debugging only, the `-f` flag can be provided to cause a fake boot. This
+runs the boot through to the point of handing off to the OS, then returns, to
+allow the state to be examined.
 
 bootflow cmdline
 ~~~~~~~~~~~~~~~~
diff --git a/include/bootflow.h b/include/bootflow.h
index c8f5d6e0859..284c23c59dd 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -52,11 +52,14 @@  enum bootflow_state_t {
  * @BOOTFLOWF_STATIC_BUF: Indicates that @bflow->buf is statically set, rather
  *	than being allocated by malloc().
  * @BOOTFLOWF_USE_BUILTIN_FDT: Indicates that current bootflow uses built-in FDT
+ * @BOOTFLOWF_FAKE_GO: Do a 'fake' boot, up to the last possible point, then
+ * return
  */
 enum bootflow_flags_t {
 	BOOTFLOWF_USE_PRIOR_FDT		= BIT(0),
 	BOOTFLOWF_STATIC_BUF		= BIT(1),
 	BOOTFLOWF_USE_BUILTIN_FDT	= BIT(2),
+	BOOTFLOWF_FAKE_GO		= BIT(3),
 };
 
 /**