[PATCH 2/3] qemu-x86: Wire support for applying capsule updates to pflash

Elliot Berman <[email protected]> Thu, 30 Jul 2026 12:37:46 -0700
Newsgroups gmane.comp.boot-loaders.u-boot
Message-ID <[email protected]>
Following the flow used for qemu-arm64, probe the pflash MTD device
and set dfu_alt_info/mtdparts for qemu-x86 and qemu-x86_64 so EFI
capsule updates can target the u-boot pflash partition.

Signed-off-by: Elliot Berman <[email protected]>
---
 board/emulation/common/Kconfig         |  2 ++
 board/emulation/common/qemu_dfu.c      |  6 ++++--
 board/emulation/common/qemu_mtdparts.c |  6 ++++--
 board/emulation/qemu-x86/Kconfig       |  3 +++
 board/emulation/qemu-x86/Makefile      |  3 +++
 board/emulation/qemu-x86/qemu-x86.c    | 38 ++++++++++++++++++++++++++++++++++
 6 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/board/emulation/common/Kconfig b/board/emulation/common/Kconfig
index 4c15c8bcb89..79e8a5cfb01 100644
--- a/board/emulation/common/Kconfig
+++ b/board/emulation/common/Kconfig
@@ -1,6 +1,8 @@
 config MTDPARTS_NOR0
 	string "mtd boot partition for nor0"
 	default "64m(u-boot)" if TARGET_QEMU_ARM_64BIT && !TFABOOT
+	default "2m(u-boot)" if TARGET_QEMU_X86_64
+	default "1m(u-boot)" if TARGET_QEMU_X86
 	depends on SYS_MTDPARTS_RUNTIME
 	help
 	  This define the partition of nor0 used to build mtparts dynamically
diff --git a/board/emulation/common/qemu_dfu.c b/board/emulation/common/qemu_dfu.c
index 8a59f5ade13..db7d8cbbb4e 100644
--- a/board/emulation/common/qemu_dfu.c
+++ b/board/emulation/common/qemu_dfu.c
@@ -51,11 +51,13 @@ void set_dfu_alt_info(char *interface, char *devstr)
 	memset(buf, 0, DFU_ALT_BUF_LEN);
 
 	/*
-	 * Currently dfu_alt_info is needed on Qemu ARM64 for
+	 * Currently dfu_alt_info is needed on Qemu ARM64/X86/X86_64 for
 	 * capsule updates
 	*/
 	if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) &&
-	    IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT)) {
+	    (IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT) ||
+	     IS_ENABLED(CONFIG_TARGET_QEMU_X86) ||
+	     IS_ENABLED(CONFIG_TARGET_QEMU_X86_64))) {
 		/* probe all MTD devices */
 		mtd_probe_devices();
 
diff --git a/board/emulation/common/qemu_mtdparts.c b/board/emulation/common/qemu_mtdparts.c
index c1501276789..3b9319ea986 100644
--- a/board/emulation/common/qemu_mtdparts.c
+++ b/board/emulation/common/qemu_mtdparts.c
@@ -50,9 +50,11 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts)
 	memset(parts, 0, sizeof(parts));
 	memset(ids, 0, sizeof(ids));
 
-	/* Currently mtdparts is needed on Qemu ARM64 for capsule updates */
+	/* Currently mtdparts is needed on Qemu ARM64/x86/x86_64 for capsule updates */
 	if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) &&
-	    IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT)) {
+	    (IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT) ||
+	     IS_ENABLED(CONFIG_TARGET_QEMU_X86) ||
+	     IS_ENABLED(CONFIG_TARGET_QEMU_X86_64))) {
 		/* probe all MTD devices */
 		for (uclass_first_device(UCLASS_MTD, &dev); dev;
 		     uclass_next_device(&dev)) {
diff --git a/board/emulation/qemu-x86/Kconfig b/board/emulation/qemu-x86/Kconfig
index c1564fba7cd..0c2ded1515c 100644
--- a/board/emulation/qemu-x86/Kconfig
+++ b/board/emulation/qemu-x86/Kconfig
@@ -24,5 +24,8 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply VIRTIO_NET
 	imply VIRTIO_BLK
 	imply CMD_SMBIOS
+	imply SET_DFU_ALT_INFO
+	imply SYS_MTDPARTS_RUNTIME
 
+source "board/emulation/common/Kconfig"
 endif
diff --git a/board/emulation/qemu-x86/Makefile b/board/emulation/qemu-x86/Makefile
new file mode 100644
index 00000000000..7859f91d0ee
--- /dev/null
+++ b/board/emulation/qemu-x86/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y	+= qemu-x86.o
diff --git a/board/emulation/qemu-x86/qemu-x86.c b/board/emulation/qemu-x86/qemu-x86.c
new file mode 100644
index 00000000000..f4ea6c24913
--- /dev/null
+++ b/board/emulation/qemu-x86/qemu-x86.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <config.h>
+#include <efi.h>
+#include <efi_loader.h>
+
+/* GUIDs for capsule updatable firmware images */
+#define QEMU_X86_UBOOT_IMAGE_GUID \
+	EFI_GUID(0x8dfcd6f5, 0x42fe, 0x44c6, 0xa8, 0xae, \
+		 0x63, 0x7d, 0xa6, 0x1b, 0x6b, 0x95)
+
+#define QEMU_X86_64_UBOOT_IMAGE_GUID \
+	EFI_GUID(0x5bb9ce0d, 0xa389, 0x456f, 0x83, 0xa8, \
+		 0x2b, 0xdf, 0xb8, 0xad, 0x01, 0xa1)
+
+#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
+struct efi_fw_image fw_images[] = {
+#if defined(CONFIG_TARGET_QEMU_X86)
+	{
+		.image_type_id = QEMU_X86_UBOOT_IMAGE_GUID,
+		.fw_name = u"Qemu-X86-UBOOT",
+		.image_index = 1,
+	},
+#elif defined(CONFIG_TARGET_QEMU_X86_64)
+	{
+		.image_type_id = QEMU_X86_64_UBOOT_IMAGE_GUID,
+		.fw_name = u"Qemu-X86_64-UBOOT",
+		.image_index = 1,
+	},
+#endif
+};
+
+struct efi_capsule_update_info update_info = {
+	.num_images = ARRAY_SIZE(fw_images),
+	.images = fw_images,
+};
+
+#endif /* EFI_HAVE_CAPSULE_SUPPORT */

-- 
2.54.0