[Concept,v2,04/20] scripts: build-qemu: Add --bootcmd option to pass bootcmd via fw_cfg

Message ID 20251007170549.541981-5-sjg@u-boot.org
State New
Headers
Series expo: Complete mouse operation in the EFI app |

Commit Message

Simon Glass Oct. 7, 2025, 5:05 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add a --bootcmd option to the build-qemu script that allows passing a
boot command to QEMU via fw_cfg. The bootcmd is written to the
"opt/u-boot/bootcmd" fw_cfg entry, which can be read by U-Boot's
EVT_BOOTCMD handler.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 doc/board/emulation/script.rst | 15 +++++++++++++++
 scripts/build-qemu             |  7 +++++++
 2 files changed, 22 insertions(+)
  

Patch

diff --git a/doc/board/emulation/script.rst b/doc/board/emulation/script.rst
index cf718ad41a7..239b1e1718d 100644
--- a/doc/board/emulation/script.rst
+++ b/doc/board/emulation/script.rst
@@ -64,6 +64,14 @@  Once configured, you can build and run QEMU for arm64 like this::
 
     scripts/build-qemu -rsw
 
+To pass a custom boot command to U-Boot via fw_cfg, use the `--bootcmd`
+option::
+
+    scripts/build-qemu -rsw --bootcmd "echo Hello from QEMU; bootflow scan -lb"
+
+This will cause U-Boot to execute the specified command instead of the default
+autoboot behavior.
+
 Options
 ~~~~~~~
 
@@ -107,3 +115,10 @@  Options are available to control the script:
 
 -w
     Use word version (32-bit). By default, 64-bit is used
+
+--bootcmd BOOTCMD
+    U-Boot bootcmd to pass via fw_cfg. This allows passing a custom boot
+    command to U-Boot at runtime through QEMU's firmware configuration
+    interface. The bootcmd is written to the 'opt/u-boot/bootcmd' fw_cfg
+    entry and is read by U-Boot's EVT_BOOTCMD handler before the default
+    autoboot process runs.
diff --git a/scripts/build-qemu b/scripts/build-qemu
index 522325a8d57..ddaafc7587f 100755
--- a/scripts/build-qemu
+++ b/scripts/build-qemu
@@ -41,6 +41,8 @@  def parse_args():
         description='Build and/or run U-Boot with QEMU',
         formatter_class=argparse.RawTextHelpFormatter)
     build_helper.add_common_args(parser)
+    parser.add_argument('--bootcmd', type=str,
+                        help='U-Boot bootcmd to pass via fw_cfg')
     parser.add_argument('-e', '--sct-run', action='store_true',
                         help='Run UEFI Self-Certification Test (SCT)')
     parser.add_argument('-E', '--use-tianocore', action='store_true',
@@ -290,6 +292,11 @@  class BuildQemu:
         # Add other parameters gathered from options
         qemu_cmd.extend(self.qemu_extra)
 
+        # Add bootcmd via fw_cfg if specified
+        if self.args.bootcmd:
+            qemu_cmd.extend(['-fw_cfg',
+                f'name=opt/u-boot/bootcmd,string={self.args.bootcmd}'])
+
         self.helper.setup_share(qemu_cmd)
 
         self.helper.run(qemu_cmd)