[Concept,03/17] x86: qemu: Add EVT_BOOTCMD handler to get bootcmd from fw_cfg
Commit Message
From: Simon Glass <sjg@chromium.org>
Implement an EVT_BOOTCMD event handler that reads the bootcmd from
QEMU's fw_cfg interface using the "opt/u-boot/bootcmd" file. This
allows QEMU to provide a custom boot command to U-Boot at runtime.
Uses the newly exported qfw_locate_file() function to locate and
read the bootcmd file.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/x86/cpu/qemu/qemu.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
@@ -4,6 +4,9 @@
*/
#include <cpu_func.h>
+#include <env.h>
+#include <errno.h>
+#include <event.h>
#include <init.h>
#include <pci.h>
#include <qfw.h>
@@ -150,3 +153,31 @@ int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq)
return irq;
}
#endif
+
+#if CONFIG_IS_ENABLED(EVENT)
+static int qemu_get_bootcmd(void *ctx, struct event *event)
+{
+ struct event_bootcmd *bc = &event->data.bootcmd;
+ enum fw_cfg_selector select;
+ struct udevice *qfw_dev;
+ ulong size;
+
+ if (qfw_get_dev(&qfw_dev))
+ return 0;
+
+ if (qfw_locate_file(qfw_dev, "opt/u-boot/bootcmd", &select, &size))
+ return 0;
+ if (!size)
+ return 0;
+
+ /* Check if the command fits in the provided buffer with terminator */
+ if (size >= bc->size)
+ return -ENOSPC;
+
+ qfw_read_entry(qfw_dev, select, size, bc->bootcmd);
+ bc->bootcmd[size] = '\0';
+
+ return 0;
+}
+EVENT_SPY_FULL(EVT_BOOTCMD, qemu_get_bootcmd);
+#endif