[PATCH v4 4/8] board: Define set_dfu_alt_info() for boards with UEFI capsule update enabled

Sughosh Ganu sughosh.ganu at linaro.org
Thu Mar 31 15:27:46 CEST 2022


Currently, there are a bunch of boards which enable the UEFI capsule
update feature. The actual update of the firmware images is done
through the dfu framework which uses the dfu_alt_info environment
variable for getting information on the update, like device, partition
number/address etc. Currently, these boards define the dfu_alt_info
variable in the board config header, as an environment variable. With
this, the variable can be modified from the u-boot command line and
this can cause an incorrect update.

To prevent this from happening, define the set_dfu_alt_info function
in the board file, and select SET_DFU_ALT_INFO for all platforms which
enable the capsule update feature. With the function defined, the dfu
framework populates the dfu_alt_info variable through the board file,
instead of fetching the variable from the environment, thus making the
update more robust.

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

Changes since V3:
* Do not remove the existing dfu_alt_info definitions made by
  platforms in the config files, as discussed with Masami.
* Squash the selection of the SET_DFU_ALT_INFO config symbol for
  capsule update feature as part of this patch.


 .../imx8mp_rsb3720a1/imx8mp_rsb3720a1.c       | 24 +++++++++++++++++
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 24 +++++++++++++++++
 board/emulation/common/qemu_dfu.c             |  6 ++---
 board/kontron/pitx_imx8m/pitx_imx8m.c         | 24 +++++++++++++++++
 board/kontron/sl-mx8mm/sl-mx8mm.c             | 24 +++++++++++++++++
 board/kontron/sl28/sl28.c                     | 25 ++++++++++++++++++
 board/sandbox/sandbox.c                       | 26 +++++++++++++++++++
 board/socionext/developerbox/developerbox.c   | 26 +++++++++++++++++++
 board/xilinx/zynq/board.c                     |  5 ++--
 board/xilinx/zynqmp/zynqmp.c                  |  5 ++--
 lib/efi_loader/Kconfig                        |  2 ++
 11 files changed, 184 insertions(+), 7 deletions(-)

diff --git a/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c b/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c
index 1c953ba195..41154ca9f3 100644
--- a/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c
+++ b/board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c
@@ -5,10 +5,12 @@
  */
 
 #include <common.h>
+#include <dfu.h>
 #include <dwc3-uboot.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <errno.h>
+#include <memalign.h>
 #include <miiphy.h>
 #include <netdev.h>
 #include <spl.h>
@@ -24,6 +26,7 @@
 #include <asm/mach-imx/dma.h>
 #include <linux/delay.h>
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 #include <power/pmic.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -231,3 +234,24 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
 	}
 }
 #endif /* CONFIG_SPL_MMC_SUPPORT */
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		 "mmc 2=flash-bin raw 0 0x1B00 mmcpart 1");
+
+	env_set("dfu_alt_info", buf);
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
diff --git a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
index f5b89a5ddc..1880dd9c55 100644
--- a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
+++ b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <dfu.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <env.h>
@@ -12,6 +13,7 @@
 #include <hang.h>
 #include <i2c.h>
 #include <init.h>
+#include <memalign.h>
 #include <miiphy.h>
 #include <netdev.h>
 
@@ -24,6 +26,7 @@
 #include <asm/mach-imx/mxc_i2c.h>
 #include <asm/sections.h>
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 
 #include "ddr/ddr.h"
 
@@ -446,3 +449,24 @@ int board_late_init(void)
 
 	return 0;
 }
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		 "mmc 2=flash-bin raw 0x42 0x1D00 mmcpart 1");
+
+	env_set("dfu_alt_info", buf);
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
diff --git a/board/emulation/common/qemu_dfu.c b/board/emulation/common/qemu_dfu.c
index 62234a7647..85dff4373b 100644
--- a/board/emulation/common/qemu_dfu.c
+++ b/board/emulation/common/qemu_dfu.c
@@ -44,10 +44,11 @@ void set_dfu_alt_info(char *interface, char *devstr)
 
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
 
-	if (env_get("dfu_alt_info"))
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
 		return;
 
-	memset(buf, 0, sizeof(buf));
+	memset(buf, 0, DFU_ALT_BUF_LEN);
 
 	/*
 	 * Currently dfu_alt_info is needed on Qemu ARM64 for
@@ -64,5 +65,4 @@ void set_dfu_alt_info(char *interface, char *devstr)
 	}
 
 	env_set("dfu_alt_info", buf);
-	printf("dfu_alt_info set\n");
 }
diff --git a/board/kontron/pitx_imx8m/pitx_imx8m.c b/board/kontron/pitx_imx8m/pitx_imx8m.c
index 8dc04411cc..f3f6fbee9f 100644
--- a/board/kontron/pitx_imx8m/pitx_imx8m.c
+++ b/board/kontron/pitx_imx8m/pitx_imx8m.c
@@ -2,9 +2,11 @@
 
 #include "pitx_misc.h"
 #include <common.h>
+#include <dfu.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <init.h>
+#include <memalign.h>
 #include <mmc.h>
 #include <miiphy.h>
 #include <asm/arch/clock.h>
@@ -15,6 +17,7 @@
 #include <asm/mach-imx/iomux-v3.h>
 #include <linux/delay.h>
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -181,3 +184,24 @@ int board_late_init(void)
 {
 	return 0;
 }
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		 "mmc 0=flash-bin raw 0x42 0x1000 mmcpart 1");
+
+	env_set("dfu_alt_info", buf);
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
diff --git a/board/kontron/sl-mx8mm/sl-mx8mm.c b/board/kontron/sl-mx8mm/sl-mx8mm.c
index 834588af3a..a00eb19828 100644
--- a/board/kontron/sl-mx8mm/sl-mx8mm.c
+++ b/board/kontron/sl-mx8mm/sl-mx8mm.c
@@ -6,11 +6,14 @@
 #include <asm/arch/imx-regs.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
+#include <dfu.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <fdt_support.h>
+#include <memalign.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 #include <net.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -112,3 +115,24 @@ int board_init(void)
 {
 	return 0;
 }
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		 "sf 0:0=flash-bin raw 0x400 0x1f0000");
+
+	env_set("dfu_alt_info", buf);
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
diff --git a/board/kontron/sl28/sl28.c b/board/kontron/sl28/sl28.c
index 7d3635da45..db41e2885c 100644
--- a/board/kontron/sl28/sl28.c
+++ b/board/kontron/sl28/sl28.c
@@ -2,7 +2,9 @@
 
 #include <common.h>
 #include <dm.h>
+#include <dfu.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <errno.h>
@@ -11,6 +13,7 @@
 #include <asm/global_data.h>
 #include <linux/libfdt.h>
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 #include <env_internal.h>
 #include <asm/arch-fsl-layerscape/soc.h>
 #include <asm/arch-fsl-layerscape/fsl_icid.h>
@@ -150,3 +153,25 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
 	return 0;
 }
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		 "sf 0:0=u-boot-bin raw 0x210000 0x1d0000;"
+		 "u-boot-env raw 0x3e0000 0x20000");
+
+	env_set("dfu_alt_info", buf);
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c
index c5e6e3d2a0..6a0453281d 100644
--- a/board/sandbox/sandbox.c
+++ b/board/sandbox/sandbox.c
@@ -6,17 +6,20 @@
 #include <common.h>
 #include <cpu_func.h>
 #include <cros_ec.h>
+#include <dfu.h>
 #include <dm.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <env_internal.h>
 #include <init.h>
 #include <led.h>
+#include <memalign.h>
 #include <os.h>
 #include <asm/global_data.h>
 #include <asm/test.h>
 #include <asm/u-boot-sandbox.h>
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 #include <malloc.h>
 
 #include <extension_board.h>
@@ -152,3 +155,26 @@ int board_late_init(void)
 	return 0;
 }
 #endif
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		 "sf 0:0=u-boot-bin raw 0x100000 0x50000;"
+		 "u-boot-env raw 0x150000 0x200000"
+		);
+
+	env_set("dfu_alt_info", buf);
+}
+#endif
diff --git a/board/socionext/developerbox/developerbox.c b/board/socionext/developerbox/developerbox.c
index ae4b2d6ed8..6784a3db53 100644
--- a/board/socionext/developerbox/developerbox.c
+++ b/board/socionext/developerbox/developerbox.c
@@ -10,13 +10,16 @@
 #include <asm/global_data.h>
 #include <asm/io.h>
 #include <common.h>
+#include <dfu.h>
 #include <efi.h>
 #include <efi_loader.h>
 #include <env_internal.h>
 #include <fdt_support.h>
 #include <log.h>
+#include <memalign.h>
 
 #include <linux/kernel.h>
+#include <linux/sizes.h>
 
 #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
 struct efi_fw_images fw_images[] = {
@@ -185,3 +188,26 @@ int print_cpuinfo(void)
 	printf("CPU:   SC2A11:Cortex-A53 MPCore 24cores\n");
 	return 0;
 }
+
+#if defined(CONFIG_SET_DFU_ALT_INFO)
+
+#define DFU_ALT_BUF_LEN		SZ_1K
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
+		return;
+
+	memset(buf, 0, DFU_ALT_BUF_LEN);
+
+	snprintf(buf, DFU_ALT_BUF_LEN,
+		"mtd nor1=u-boot.bin raw 200000 100000;"
+		"fip.bin raw 180000 78000;"
+		"optee.bin raw 500000 100000");
+
+	env_set("dfu_alt_info", buf);
+}
+#endif /* CONFIG_SET_DFU_ALT_INFO */
diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
index 26ef048835..c70ad07269 100644
--- a/board/xilinx/zynq/board.c
+++ b/board/xilinx/zynq/board.c
@@ -168,10 +168,11 @@ void set_dfu_alt_info(char *interface, char *devstr)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
 
-	if (env_get("dfu_alt_info"))
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
 		return;
 
-	memset(buf, 0, sizeof(buf));
+	memset(buf, 0, DFU_ALT_BUF_LEN);
 
 	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
 	case ZYNQ_BM_SD:
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 70b3c81f12..d278ed21a1 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -890,10 +890,11 @@ void set_dfu_alt_info(char *interface, char *devstr)
 
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
 
-	if (env_get("dfu_alt_info"))
+	if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) &&
+	    env_get("dfu_alt_info"))
 		return;
 
-	memset(buf, 0, sizeof(buf));
+	memset(buf, 0, DFU_ALT_BUF_LEN);
 
 	multiboot = multi_boot();
 	if (multiboot < 0)
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index e5e35fe51f..09fb8cbe75 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -174,6 +174,7 @@ config EFI_CAPSULE_FIRMWARE_FIT
 	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
 	select UPDATE_FIT
 	select DFU
+	select SET_DFU_ALT_INFO
 	select EFI_CAPSULE_FIRMWARE
 	help
 	  Select this option if you want to enable firmware management protocol
@@ -185,6 +186,7 @@ config EFI_CAPSULE_FIRMWARE_RAW
 	depends on SANDBOX || (!SANDBOX && !EFI_CAPSULE_FIRMWARE_FIT)
 	select DFU_WRITE_ALT
 	select DFU
+	select SET_DFU_ALT_INFO
 	select EFI_CAPSULE_FIRMWARE
 	help
 	  Select this option if you want to enable firmware management protocol
-- 
2.25.1



More information about the U-Boot mailing list