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 use the function for populating the
variable. 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.g...@linaro.org>
---

Changes since V2: New 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 ++--
 include/configs/imx8mm-cl-iot-gate.h          |  1 -
 include/configs/imx8mp_rsb3720.h              |  1 -
 include/configs/kontron-sl-mx8mm.h            |  1 -
 include/configs/kontron_pitx_imx8m.h          |  1 -
 include/configs/kontron_sl28.h                |  2 --
 include/configs/synquacer.h                   |  6 -----
 16 files changed, 182 insertions(+), 19 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/include/configs/imx8mm-cl-iot-gate.h 
b/include/configs/imx8mm-cl-iot-gate.h
index 35df2e755e..b37efab753 100644
--- a/include/configs/imx8mm-cl-iot-gate.h
+++ b/include/configs/imx8mm-cl-iot-gate.h
@@ -82,7 +82,6 @@
        "fdt_addr=0x43000000\0"                 \
        "fdt_addr_r=0x43000000\0" \
        "boot_fit=no\0" \
-       "dfu_alt_info=mmc 2=flash-bin raw 0x42 0x1D00 mmcpart 1\0" \
        "fdt_file=sb-iotgimx8.dtb\0" \
        "fdtfile=sb-iotgimx8.dtb\0" \
        "initrd_addr=0x43800000\0"              \
diff --git a/include/configs/imx8mp_rsb3720.h b/include/configs/imx8mp_rsb3720.h
index a5a845c2da..8c39009dff 100644
--- a/include/configs/imx8mp_rsb3720.h
+++ b/include/configs/imx8mp_rsb3720.h
@@ -120,7 +120,6 @@
        "fdt_addr=0x43000000\0"                 \
        "fdt_addr_r=0x43000000\0"                       \
        "boot_fit=no\0" \
-       "dfu_alt_info=mmc 2=flash-bin raw 0 0x1B00 mmcpart 1\0" \
        "fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
        "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
        "initrd_addr=0x43800000\0"              \
diff --git a/include/configs/kontron-sl-mx8mm.h 
b/include/configs/kontron-sl-mx8mm.h
index aff1b90010..7c4e55a519 100644
--- a/include/configs/kontron-sl-mx8mm.h
+++ b/include/configs/kontron-sl-mx8mm.h
@@ -83,7 +83,6 @@
        "pxefile_addr_r=0x40100000\0"
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
-       "dfu_alt_info=sf 0:0=flash-bin raw 0x400 0x1f0000\0" \
        "bootdelay=3\0" \
        "hostname=" CONFIG_HOSTNAME "\0" \
        ENV_MEM_LAYOUT_SETTINGS \
diff --git a/include/configs/kontron_pitx_imx8m.h 
b/include/configs/kontron_pitx_imx8m.h
index 678364e367..060a26920b 100644
--- a/include/configs/kontron_pitx_imx8m.h
+++ b/include/configs/kontron_pitx_imx8m.h
@@ -77,7 +77,6 @@
        "console=ttymxc2,115200\0" \
        "boot_fdt=try\0" \
        "fdtfile=freescale/imx8mq-kontron-pitx-imx8m.dtb\0" \
-       "dfu_alt_info=mmc 0=flash-bin raw 0x42 0x1000 mmcpart 1\0"\
        ENV_MEM_LAYOUT_SETTINGS \
        BOOTENV
 
diff --git a/include/configs/kontron_sl28.h b/include/configs/kontron_sl28.h
index 97d0d365f6..5275686058 100644
--- a/include/configs/kontron_sl28.h
+++ b/include/configs/kontron_sl28.h
@@ -89,8 +89,6 @@
        "envload=env import -d -b ${env_addr}\0" \
        "install_rcw=source 20200000\0" \
        "fdtfile=freescale/fsl-ls1028a-kontron-sl28.dtb\0" \
-       "dfu_alt_info=sf 0:0=u-boot-bin raw 0x210000 0x1d0000;" \
-                           "u-boot-env raw 0x3e0000 0x20000\0" \
        ENV_MEM_LAYOUT_SETTINGS \
        BOOTENV
 
diff --git a/include/configs/synquacer.h b/include/configs/synquacer.h
index 07e1f56e3d..a68ff4ee00 100644
--- a/include/configs/synquacer.h
+++ b/include/configs/synquacer.h
@@ -46,11 +46,6 @@
 
 /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */
 
-#define DEFAULT_DFU_ALT_INFO "dfu_alt_info="                           \
-                       "mtd nor1=u-boot.bin raw 200000 100000;"        \
-                       "fip.bin raw 180000 78000;"                     \
-                       "optee.bin raw 500000 100000\0"
-
 #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
 #define DEVELOPERBOX_UBOOT_IMAGE_GUID \
        EFI_GUID(0x53a92e83, 0x4ef4, 0x473a, 0x8b, 0x0d, \
@@ -108,7 +103,6 @@
        "ramdisk_addr_r=0xa0000000\0"           \
        "scriptaddr=0x88000000\0"               \
        "pxefile_addr_r=0x88100000\0"           \
-       DEFAULT_DFU_ALT_INFO                    \
        BOOTENV
 
 #endif /* __CONFIG_H */
-- 
2.25.1

Reply via email to