[PATCH v2 05/14] qemu: arm64: Set dfu_alt_info variable for the platform

Sughosh Ganu sughosh.ganu at linaro.org
Mon Dec 21 12:43:05 CET 2020


The dfu framework uses the dfu_alt_info environment variable to get
information that is needed for performing the firmware update. Set the
dfu_alt_info for the platform to reflect the two mtd partitions
created for the u-boot env and the firmware image.

Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
---

Changes since V1:
* Build set_dfu_alt_info and board_get_alt_info functions only if
  CONFIG_SET_DFU_ALT_INFO is defined
* Enable CONFIG_SET_DFU_ALT_INFO with
  CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT

 board/emulation/qemu-arm/qemu-arm.c | 57 +++++++++++++++++++++++++++++
 lib/efi_loader/Kconfig              |  1 +
 2 files changed, 58 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
index 68f70cb9be..a7be3c7c1c 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -195,8 +195,65 @@ void flash_write32(u32 value, void *addr)
 
 #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
 
+#include <memalign.h>
 #include <mtd.h>
 
+#define MTDPARTS_LEN		256
+#define MTDIDS_LEN		128
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+static void board_get_alt_info(struct mtd_info *mtd, char *buf)
+{
+	struct mtd_info *part;
+	bool first = true;
+	const char *name;
+	int len, partnum = 0;
+
+	name = mtd->name;
+	len = strlen(buf);
+
+	if (buf[0] != '\0')
+		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
+	len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
+			"mtd %s=", name);
+
+	list_for_each_entry(part, &mtd->partitions, node) {
+		partnum++;
+		if (!first)
+			len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";");
+		first = false;
+
+		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
+				"%s part %d",
+				part->name, partnum);
+	}
+}
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	struct mtd_info *mtd;
+
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, sizeof(buf));
+
+	/* probe all MTD devices */
+	mtd_probe_devices();
+
+	mtd = get_mtd_device_nm("nor0");
+	if (!IS_ERR_OR_NULL(mtd))
+		board_get_alt_info(mtd, buf);
+
+	env_set("dfu_alt_info", buf);
+	printf("dfu_alt_info set\n");
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
+
 static void board_get_mtdparts(const char *dev, const char *partition,
 			       char *mtdids, char *mtdparts)
 {
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 2cb0a6e399..bc47e7fe76 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -136,6 +136,7 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT
 	depends on EFI_HAVE_CAPSULE_SUPPORT
 	default y
 	select SYS_MTDPARTS_RUNTIME
+	select SET_DFU_ALT_INFO
 	help
 	  Select this option if you want to enable capsule-based
 	  firmware update using Firmware Management Protocol.
-- 
2.17.1



More information about the U-Boot mailing list