On 26/11/25 15:25, Gerd Hoffmann wrote:
Add pcapfile property to uevi-vars-* devices, allowing to write out a
capture of the communication traffic between uefi firmware and qemu.
Signed-off-by: Gerd Hoffmann <[email protected]>
---
include/hw/uefi/var-service.h | 10 ++++
hw/uefi/var-service-core.c | 7 +++
hw/uefi/var-service-pcap.c | 94 +++++++++++++++++++++++++++++++++++
hw/uefi/var-service-sysbus.c | 1 +
hw/uefi/meson.build | 1 +
roms/edk2 | 2 +-
6 files changed, 114 insertions(+), 1 deletion(-)
create mode 100644 hw/uefi/var-service-pcap.c
diff --git a/hw/uefi/var-service-pcap.c b/hw/uefi/var-service-pcap.c
new file mode 100644
index 000000000000..879eee4699a3
--- /dev/null
+++ b/hw/uefi/var-service-pcap.c
@@ -0,0 +1,94 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/pcap.h"
+#include "system/dma.h"
+
+#include "hw/uefi/var-service.h"
+
+#define LINKTYPE_EDK2_MM 302
+
+#define SNAPLEN (64 * 1024)
+#define TYPE_RESET 0x01
+#define TYPE_REQUEST 0x02
+#define TYPE_REPLY 0x03
+
+static void uefi_vars_pcap_header(FILE *fp)
+{
static const
+ struct pcap_hdr header = {
+ .magic_number = PCAP_MAGIC,
+ .version_major = PCAP_MAJOR,
+ .version_minor = PCAP_MINOR,
+ .snaplen = SNAPLEN,
+ .network = LINKTYPE_EDK2_MM,
+ };
+
+ fwrite(&header, sizeof(header), 1, fp);
+ fflush(fp);
+}
+void uefi_vars_pcap_init(uefi_vars_state *uv)
+{
+ int fd;
+
+ if (!uv->pcapfile) {
+ return;
+ }
+
+ fd = qemu_open_old(uv->pcapfile,
+ O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666);
Consider qemu_create() to help Markus' tree-wide cleanup.
+ if (fd < 0) {
+ warn_report("open %s: %s", uv->pcapfile, strerror(errno));
+ return;
+ }
+
+ uv->pcapfp = fdopen(fd, "wb");
+ uefi_vars_pcap_header(uv->pcapfp);
+}
diff --git a/roms/edk2 b/roms/edk2
index 4dfdca63a934..46548b1adac8 160000
--- a/roms/edk2
+++ b/roms/edk2
@@ -1 +1 @@
-Subproject commit 4dfdca63a93497203f197ec98ba20e2327e4afe4
+Subproject commit 46548b1adac82211d8d11da12dd914f41e7aa775
Unrelated change I presume.
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>