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(+)
@@ -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.
@@ -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)