Commit 371a6c1744f3 ("board: xilinx: Add capsule and FWU support") and
commit 818c06faa119 ("board: amd: Add capsule and FWU support")
introduced a separate set_dfu_alt_info() for the FWU multi-bank case
(Versal and Versal Gen 2 respectively) which set the dfu_alt_info
environment variable directly, while configure_capsule_updates() handled
the non-FWU case by filling update_info.dfu_string.Fold the FWU multi-bank generation (fwu_gen_alt_info_from_mtd() over the nor0 MTD partitions) into fwu_platform_hook() and drop the standalone set_dfu_alt_info(). Signed-off-by: Michal Simek <[email protected]> --- Changes in v2: - Do not setup dfu_string in board_late_init() which is too early because fwu is initialized after preboot. - Update commit message board/amd/versal2/board.c | 39 ------------------------------------- board/xilinx/common/board.c | 37 ++++++++++++++++++++++++++++++++++- board/xilinx/versal/board.c | 39 ------------------------------------- 3 files changed, 36 insertions(+), 79 deletions(-) diff --git a/board/amd/versal2/board.c b/board/amd/versal2/board.c index 489b1fa9dca2..1855226398a9 100644 --- a/board/amd/versal2/board.c +++ b/board/amd/versal2/board.c @@ -11,7 +11,6 @@ #include <env.h> #include <efi_loader.h> #include <fdtdec.h> -#include <fwu.h> #include <init.h> #include <env_internal.h> #include <log.h> @@ -506,8 +505,6 @@ enum env_location env_get_location(enum env_operation op, int prio) #define DFU_ALT_BUF_LEN SZ_1K -#if defined(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && \ - !defined(CONFIG_FWU_MULTI_BANK_UPDATE) static void mtd_found_part(u32 *base, u32 *size) { struct mtd_info *part, *mtd; @@ -584,42 +581,6 @@ void configure_capsule_updates(void) update_info.dfu_string = strdup(buf); debug("Capsule DFU: %s\n", update_info.dfu_string); } -#endif - -#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) - -/* Generate dfu_alt_info from partitions */ -void set_dfu_alt_info(char *interface, char *devstr) -{ - int ret; - struct mtd_info *mtd; - - /* - * It is called multiple times for every image - * per bank that's why enough to set it up once. - */ - if (env_get("dfu_alt_info")) - return; - - ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); - memset(buf, 0, DFU_ALT_BUF_LEN); - - mtd_probe_devices(); - - mtd = get_mtd_device_nm("nor0"); - if (IS_ERR_OR_NULL(mtd)) - return; - - ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd); - if (ret < 0) { - log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret); - return; - } - log_debug("Make dfu_alt_info: '%s'\n", buf); - - env_set("dfu_alt_info", buf); -} -#endif int spi_get_env_dev(void) { diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index aff28cdd9b64..6fd0369a675e 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2014 - 2022, Xilinx, Inc. - * (C) Copyright 2022 - 2025, Advanced Micro Devices, Inc. + * (C) Copyright 2022 - 2026, Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> */ @@ -14,6 +14,8 @@ #include <init.h> #include <jffs2/load_kernel.h> #include <log.h> +#include <memalign.h> +#include <mtd.h> #include <asm/io.h> #include <asm/global_data.h> #include <asm/sections.h> @@ -22,6 +24,7 @@ #endif #include <dm/uclass.h> #include <i2c.h> +#include <linux/err.h> #include <linux/sizes.h> #include <malloc.h> #include <memtop.h> @@ -65,6 +68,8 @@ struct efi_capsule_update_info update_info = { .images = fw_images, }; +#define DFU_ALT_BUF_LEN SZ_1K + #endif /* EFI_HAVE_CAPSULE_SUPPORT */ #define EEPROM_HEADER_MAGIC 0xdaaddeed @@ -847,6 +852,36 @@ int fwu_platform_hook(struct udevice *dev, struct fwu_data *data) /* Copy image type GUID */ memcpy(&fw_images[0].image_type_id, &img_entry->image_type_guid, 16); + /* + * Generate the capsule DFU string from the FWU metadata. This has to + * happen here, and not in configure_capsule_updates() called from + * board_late_init(), because the FWU data is only populated by + * fwu_boottime_checks() at EVT_POST_PREBOOT. + */ + { + ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); + struct mtd_info *mtd; + int ret; + + memset(buf, 0, DFU_ALT_BUF_LEN); + + mtd_probe_devices(); + + mtd = get_mtd_device_nm("nor0"); + if (IS_ERR_OR_NULL(mtd)) + return -ENODEV; + + ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd); + if (ret < 0) { + log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret); + return ret; + } + log_debug("Make dfu_alt_info: '%s'\n", buf); + + update_info.dfu_string = strdup(buf); + debug("Capsule DFU: %s\n", update_info.dfu_string); + } + if (IS_ENABLED(CONFIG_EFI_ESRT)) { efi_status_t ret; diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c index 1ba6f3feca45..2cd34544a329 100644 --- a/board/xilinx/versal/board.c +++ b/board/xilinx/versal/board.c @@ -10,7 +10,6 @@ #include <env.h> #include <efi_loader.h> #include <fdtdec.h> -#include <fwu.h> #include <init.h> #include <env_internal.h> #include <log.h> @@ -377,8 +376,6 @@ enum env_location env_get_location(enum env_operation op, int prio) #define DFU_ALT_BUF_LEN SZ_1K -#if defined(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && \ - !defined(CONFIG_FWU_MULTI_BANK_UPDATE) static void mtd_found_part(u32 *base, u32 *size) { struct mtd_info *part, *mtd; @@ -455,39 +452,3 @@ void configure_capsule_updates(void) update_info.dfu_string = strdup(buf); debug("Capsule DFU: %s\n", update_info.dfu_string); } -#endif - -#if defined(CONFIG_FWU_MULTI_BANK_UPDATE) - -/* Generate dfu_alt_info from partitions */ -void set_dfu_alt_info(char *interface, char *devstr) -{ - int ret; - struct mtd_info *mtd; - - /* - * It is called multiple times for every image - * per bank that's why enough to set it up once. - */ - if (env_get("dfu_alt_info")) - return; - - ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); - memset(buf, 0, sizeof(buf)); - - mtd_probe_devices(); - - mtd = get_mtd_device_nm("nor0"); - if (IS_ERR_OR_NULL(mtd)) - return; - - ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd); - if (ret < 0) { - log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret); - return; - } - log_debug("Make dfu_alt_info: '%s'\n", buf); - - env_set("dfu_alt_info", buf); -} -#endif --- base-commit: 2c1b572ff2a1e54b22f6d9de77fc8bdcca7f3e7b branch: master-next-test -- 2.43.0

