Add capsule and FWU support for Versal and Versal Gen 2
Subsystems (3)
cover Add capsule and FWU support for Versal and Versal Gen 2
This patch series adds EFI capsule update and FWU (Firmware Update) multi-bank update support for AMD Xilinx Versal and Versal Gen 2 platforms.
Padmarao Begari (7):
arm64: xilinx: Add PMC PGGS3 and PGGS4 registers
firmware: zynqmp: Add PMC PGGS register read API
board: xilinx: Add capsule and FWU support
board: amd: Add capsule and FWU support
board: xilinx: Add FWU boot index support
configs: xilinx: Enable DFU MTD support
configs: amd: Enable capsule update and DFU support
arch/arm/mach-versal/include/mach/hardware.h | 3 + arch/arm/mach-versal2/include/mach/hardware.h | 3 + board/amd/versal2/board.c | 131 +++++++++++++++++- board/xilinx/common/board.c | 73 ++++++++++ board/xilinx/versal/board.c | 42 +++++- configs/amd_versal2_virt_defconfig | 15 +- configs/xilinx_versal_virt_defconfig | 2 + drivers/firmware/firmware-zynqmp.c | 54 +++++++- include/configs/amd_versal2.h | 5 + include/zynqmp_firmware.h | 4 + 10 files changed, 327 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/7 arm64: xilinx: Add PMC PGGS3 and PGGS4 registers
Add PMC Global PGGS3 and PGGS4 register defines to Versal and Versal Gen 2 hardware headers. These registers hold boot index and boot metadata required for FWU multi-bank update support.
--- arch/arm/mach-versal/include/mach/hardware.h | 3 +++ arch/arm/mach-versal2/include/mach/hardware.h | 3 +++ 2 files changed, 6 insertions(+)
arch/arm/mach-versal/include/mach/hardware.h +3 -0
@@ -100,3 +100,6 @@ struct crp_regs {#define MIO_PIN_12 0xF1060030#define BANK0_OUTPUT 0xF1020040#define BANK0_TRI 0xF1060200 + +#define PMC_GLOBAL_PGGS3_REG 0xF111005C +#define PMC_GLOBAL_PGGS4_REG 0xF1110060
arch/arm/mach-versal2/include/mach/hardware.h +3 -0
@@ -105,3 +105,6 @@ enum versal2_platform {#define PMXC_UFS_CAL_1_OFFSET 0xBE8#define PMXC_SRAM_CSR 0x4C#define PMXC_TX_RX_CFG_RDY 0x54 + +#define PMC_GLOBAL_PGGS3_REG 0xF111005C +#define PMC_GLOBAL_PGGS4_REG 0xF1110060
Signature · 1 line
2.34.1
PATCH 2/7 firmware: zynqmp: Add PMC PGGS register read API
In reply to Padmarao BegariAdd zynqmp_pm_get_pmc_global_pggs_reg() to read PMC Global PGGS3 and PGGS4 registers via firmware IOCTL. Supports IOCTL_READ_PGGS as the preferred path and falls back to IOCTL_READ_REG for older PLM firmware versions that do not support IOCTL_READ_PGGS.
--- drivers/firmware/firmware-zynqmp.c | 54 +++++++++++++++++++++++++++++- include/zynqmp_firmware.h | 4 +++ 2 files changed, 57 insertions(+), 1 deletion(-)
drivers/firmware/firmware-zynqmp.c +53 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware driver * * Copyright (C) 2018-2019 Xilinx, Inc. -* Copyright (C) 2022 - 2025, Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026, Advanced Micro Devices, Inc. */ #include <asm/arch/hardware.h>
@@ -197,6 +197,58 @@ int zynqmp_pm_ufs_cal_reg(u32 *value) *value =readl (PMXC_EFUSE_CACHE_BASE_ADDRESS +PMXC_UFS_CAL_1_OFFSET );return 0 ; } +#endif /* CONFIG_ARCH_VERSAL2 */ + +#if defined(CONFIG_ARCH_VERSAL ) || defined(CONFIG_ARCH_VERSAL2 ) +u32 zynqmp_pm_get_pmc_global_pggs_reg (u32 reg_addr) +{ +int ret; +u32 value =0 ; +u32 ret_payload[PAYLOAD_ARG_CNT ]; + +if (reg_addr ==PMC_GLOBAL_PGGS3_REG ) { + value =0 ; + }else if (reg_addr ==PMC_GLOBAL_PGGS4_REG ) { + value =1 ; + }else { +printf ("%s: not supported pggs register 0x%x\n" , + __func__, reg_addr); +return 0 ; + } + + ret =zynqmp_pm_is_function_supported (PM_IOCTL ,IOCTL_READ_PGGS ); +if (ret) { + ret =zynqmp_pm_is_function_supported (PM_IOCTL ,IOCTL_READ_REG ); +if (ret) { +printf ("%s: IOCTL_READ_REG is not supported : %d\n" + , __func__, ret); +return 0 ; + } + +/* find node ID from the pggs3 offset */ + value =PM_REG_PGGS3 + value; + + ret =xilinx_pm_request (PM_IOCTL , value, +IOCTL_READ_REG ,0 ,0 ,0 ,0 , + ret_payload); +if (ret) { +printf ("%s: node 0x%x get pggs register failed\n" , + __func__, value); +return 0 ; + } + }else { + ret =xilinx_pm_request (PM_IOCTL ,PMC_GLOBAL_PGGS3_REG_NODE , +IOCTL_READ_PGGS , value,0 ,0 ,0 , + ret_payload); +if (ret) { +printf ("%s: node 0x%x get pggs register failed\n" , + __func__,PMC_GLOBAL_PGGS3_REG_NODE ); +return 0 ; + } + } + +return ret_payload[1 ]; +}#endif int zynqmp_pm_set_gem_config (u32 node,enum pm_gem_config_type config,u32 value)
include/zynqmp_firmware.h +4 -0
@@ -470,6 +470,7 @@ int zynqmp_pm_ufs_sram_csr_read(u32 *value);int zynqmp_pm_ufs_sram_csr_write (u32 *value);int zynqmp_pm_ufs_cal_reg (u32 *value);u32 zynqmp_pm_get_pmc_multi_boot_reg (void ); +u32 zynqmp_pm_get_pmc_global_pggs_reg (u32 reg_addr);/* Type of Config Object */ #define PM_CONFIG_OBJECT_TYPE_BASE 0x1U
@@ -534,4 +535,7 @@ extern smc_call_handler_t __data smc_call_handler;#define PM_DEV_OSPI (0x1822402aU) +#define PM_REG_PGGS3 0x30004003 +#define PMC_GLOBAL_PGGS3_REG_NODE 0x1824C005 +#endif /* _ZYNQMP_FIRMWARE_H_ */
Signature · 1 line
2.34.1
PATCH 3/7 board: xilinx: Add capsule and FWU support
In reply to Padmarao BegariGuard configure_capsule_updates() so it is skipped when FWU multi-bank update is enabled. Add set_dfu_alt_info() for FWU multi-bank mode to generate DFU alt info dynamically from NOR flash MTD partitions using fwu_gen_alt_info_from_mtd().
--- board/xilinx/versal/board.c | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
board/xilinx/versal/board.c +41 -1
@@ -10,6 +10,7 @@#include <env.h> #include <efi_loader.h> #include <fdtdec.h> +#include <fwu.h> #include <init.h> #include <env_internal.h> #include <log.h>
@@ -293,7 +294,8 @@ int board_late_init(void) {int ret; -if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT )) +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT ) && + !IS_ENABLED (CONFIG_FWU_MULTI_BANK_UPDATE ))configure_capsule_updates ();if (!(gd->flags &GD_FLG_ENV_DEFAULT )) {
@@ -374,6 +376,8 @@ 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;
@@ -450,3 +454,39 @@ 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
Signature · 1 line
2.34.1
PATCH 4/7 board: amd: Add capsule and FWU support
In reply to Padmarao BegariAdd configure_capsule_updates() supporting MMC, SD and QSPI/OSPI boot modes for DFU string generation. Add set_dfu_alt_info() for FWU multi-bank mode to generate DFU alt info from NOR flash MTD partitions. Add XILINX_BOOT_IMAGE_GUID for the capsule updatable firmware image.
--- board/amd/versal2/board.c | 131 +++++++++++++++++++++++++++++++++- include/configs/amd_versal2.h | 5 ++ 2 files changed, 135 insertions(+), 1 deletion(-)
board/amd/versal2/board.c +130 -1
@@ -1,17 +1,24 @@// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2021 - 2022, Xilinx, Inc. -* Copyright (C) 2022 - 2025, Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026, Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> */ #include <cpu_func.h> +#include <dfu.h> +#include <env.h> +#include <efi_loader.h> #include <fdtdec.h> +#include <fwu.h> #include <init.h> #include <env_internal.h> #include <log.h> #include <malloc.h> +#include <memalign.h> +#include <mmc.h> +#include <mtd.h> #include <time.h> #include <asm/cache.h> #include <asm/global_data.h>
@@ -26,6 +33,7 @@#include "../../xilinx/common/board.h" #include <linux/bitfield.h> +#include <linux/sizes.h> #include <debug_uart.h> #include <generated/dt.h> #include <linux/ioport.h>
@@ -347,6 +355,10 @@ int board_late_init(void)int ret;u32 multiboot; +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT ) && + !IS_ENABLED (CONFIG_FWU_MULTI_BANK_UPDATE )) +configure_capsule_updates (); +if (!(gd->flags &GD_FLG_ENV_DEFAULT )) {debug ("Saved variables - Skipping\n" );return 0 ;
@@ -475,3 +487,120 @@ enum env_location env_get_location(enum env_operation op, int prio) } }#endif + +#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; + +mtd_probe_devices (); + + mtd =get_mtd_device_nm ("nor0" ); +if (!IS_ERR_OR_NULL (mtd)) { +list_for_each_entry (part, &mtd->partitions, node) { +debug ("0x%012llx-0x%012llx : \"%s\"\n" , + part->offset, part->offset + part->size, + part->name); + +if (*base >= part->offset && + *base < part->offset + part->size) { +debug ("Found my partition: %d/%s\n" , + part->index, part->name); + *base = part->offset; + *size = part->size; +break ; + } + } + } +} + +void configure_capsule_updates (void ) +{ +int bootseq =0 , len =0 ; +u32 multiboot =versal2_multi_boot (); +u32 bootmode =versal2_get_bootmode (); + +ALLOC_CACHE_ALIGN_BUFFER (char, buf,DFU_ALT_BUF_LEN ); + +memset (buf,0 ,DFU_ALT_BUF_LEN ); + + multiboot =env_get_hex ("multiboot" , multiboot); + +switch (bootmode) { +case EMMC_MODE : +case SD_MODE : +case SD1_LSHFT_MODE : +case SD_MODE1 : + bootseq =mmc_get_env_dev (); + + len +=snprintf (buf + len,DFU_ALT_BUF_LEN ,"mmc %d=boot" , + bootseq); + +if (multiboot) + len +=snprintf (buf + len,DFU_ALT_BUF_LEN , +"%04d" , multiboot); + + len +=snprintf (buf + len,DFU_ALT_BUF_LEN ,".bin fat %d 1" , + bootseq); +break ; +case QSPI_MODE_24BIT : +case QSPI_MODE_32BIT : +case OSPI_MODE : + { +u32 base = multiboot *SZ_32K ; +u32 size =0x1500000 ; +u32 limit = size; + +mtd_found_part (&base, &limit); + + len +=snprintf (buf + len,DFU_ALT_BUF_LEN , +"sf 0:0=boot.bin raw 0x%x 0x%x" , + base, limit); + } +break ; +default : +return ; + } + + 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
include/configs/amd_versal2.h +5 -0
@@ -23,6 +23,11 @@#define CFG_SYS_BAUDRATE_TABLE \ { 4800, 9600, 19200, 38400, 57600, 115200 } +/* GUID for capsule updatable firmware image */ +#define XILINX_BOOT_IMAGE_GUID \ + EFI_GUID(0xed9e7fcf, 0x47b3, 0x40cd, 0xb6, 0xe3, \ + 0x56, 0x5f, 0x14, 0x67, 0x6d, 0x82) +#if defined(CONFIG_CMD_DFU )#define DFU_DEFAULT_POLL_TIMEOUT 300#define DFU_ALT_INFO_RAM \
Signature · 1 line
2.34.1
PATCH 5/7 board: xilinx: Add FWU boot index support
In reply to Padmarao BegariAdd fwu_plat_get_alt_num() and fwu_plat_get_bootidx() platform callbacks required for FWU multi-bank update on Versal and Versal Gen 2. The boot index is read from the PMC Global PGGS4 register which is populated by PLM with a magic number and boot partition index. Uses firmware IOCTL when CONFIG_ZYNQMP_FIRMWARE is enabled, otherwise falls back to direct MMIO read.
--- board/xilinx/common/board.c | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
board/xilinx/common/board.c +73 -0
@@ -14,8 +14,12 @@#include <init.h> #include <jffs2/load_kernel.h> #include <log.h> +#include <asm/io.h> #include <asm/global_data.h> #include <asm/sections.h> +#if defined(CONFIG_ARCH_VERSAL ) || defined(CONFIG_ARCH_VERSAL2 ) +#include <asm/arch/hardware.h> +#endif #include <dm/uclass.h> #include <i2c.h> #include <linux/sizes.h>
@@ -30,6 +34,8 @@#include <rng.h> #include <slre.h> #include <soc.h> +#include <zynqmp_firmware.h> +#include <linux/bitfield.h> #include <linux/ctype.h> #include <linux/kernel.h> #include <u-boot/uuid.h>
@@ -718,7 +724,74 @@ phys_addr_t board_get_usable_ram_top(phys_size_t total_size)return reg + size; } +#endif + +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE ) + +#if defined(CONFIG_ARCH_VERSAL ) || defined(CONFIG_ARCH_VERSAL2 ) +/* +* The Versal and Versal Gen 2 PMC Global pggs4 register contains below +* information in each byte as: +* +* Byte[3]: Magic number +* Byte[2]: Boot counter value +* Byte[1]: Boot partition value - boot index +* Byte[0]: Rollback counter value +*/ + +#define MAGIC_NUM 0x1D +#define MAGIC_MASK GENMASK(31, 24) +#define BOOTINDEX_MASK GENMASK(15, 8) + +static int plat_get_boot_index (void ) +{ +u32 val; + +if (IS_ENABLED (CONFIG_ZYNQMP_FIRMWARE )) + val =zynqmp_pm_get_pmc_global_pggs_reg (PMC_GLOBAL_PGGS4_REG ); +else + val =readl (PMC_GLOBAL_PGGS4_REG ); + +if (FIELD_GET (MAGIC_MASK , val) !=MAGIC_NUM ) { +log_err ("FWU requires PMC magic number 0x%x\n" ,MAGIC_NUM ); +return -EINVAL ; + } + +return FIELD_GET (BOOTINDEX_MASK , val); +} +#endif + +int fwu_plat_get_alt_num (struct udevice __always_unused *dev, +efi_guid_t *image_id,u8 *alt_num) +{ +int ret; + + ret =fwu_mtd_get_alt_num (image_id, alt_num,"nor0" ); +debug ("%s: return %d\n" , __func__, ret); + +return ret; +} +void fwu_plat_get_bootidx (uint *boot_idx) +{ +int ret; +u32 active_idx; + + ret =fwu_get_active_index (&active_idx); +if (ret <0 ) +printf ("%s: failed to read active index\n" , __func__); + + ret =plat_get_boot_index (); +if (ret <0 ) { + *boot_idx =0 ; +printf ("%s: failed and setup boot index to 0\n" , __func__); + }else { + *boot_idx = ret; + } + +debug ("%s: boot_idx: %d, active_idx: %d\n" , + __func__, *boot_idx, active_idx); +}#endif #if IS_ENABLED (CONFIG_BOARD_RNG_SEED )
Signature · 1 line
2.34.1
PATCH 6/7 configs: xilinx: Enable DFU MTD support
In reply to Padmarao BegariEnable CONFIG_DFU_MTD and CONFIG_DM_MTD to support DFU transfers over MTD partitions, required for FWU multi-bank update using NOR flash.
--- configs/xilinx_versal_virt_defconfig | 2 ++ 1 file changed, 2 insertions(+)
configs/xilinx_versal_virt_defconfig +2 -0
@@ -80,6 +80,7 @@ CONFIG_SIMPLE_PM_BUS=y CONFIG_CLK_VERSAL=y CONFIG_DFU_TIMEOUT=y CONFIG_DFU_MMC=y +CONFIG_DFU_MTD=y CONFIG_DFU_RAM=y CONFIG_DFU_SF=y CONFIG_SYS_DFU_DATA_BUF_SIZE=0x1800000
@@ -106,6 +107,7 @@ CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_ZYNQ=y CONFIG_ZYNQ_SDHCI_MIN_FREQ=100000 CONFIG_MTD=y +CONFIG_DM_MTD=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_SOFT_RESET=y CONFIG_SPI_FLASH_SOFT_RESET_ON_BOOT=y
Signature · 1 line
2.34.1
Quoted 13 lines · Padmarao Begari
This patch series adds EFI capsule update and FWU (Firmware Update) multi-bank update support for AMD Xilinx Versal and Versal Gen 2 platforms.
Padmarao Begari (7):
arm64: xilinx: Add PMC PGGS3 and PGGS4 registers
firmware: zynqmp: Add PMC PGGS register read API
board: xilinx: Add capsule and FWU support
board: amd: Add capsule and FWU support
board: xilinx: Add FWU boot index support
configs: xilinx: Enable DFU MTD support
configs: amd: Enable capsule update and DFU support
Quoted 12 lines
arch/arm/mach-versal/include/mach/hardware.h | 3 + arch/arm/mach-versal2/include/mach/hardware.h | 3 + board/amd/versal2/board.c | 131 +++++++++++++++++- board/xilinx/common/board.c | 73 ++++++++++ board/xilinx/versal/board.c | 42 +++++- configs/amd_versal2_virt_defconfig | 15 +- configs/xilinx_versal_virt_defconfig | 2 + drivers/firmware/firmware-zynqmp.c | 54 +++++++- include/configs/amd_versal2.h | 5 + include/zynqmp_firmware.h | 4 + 10 files changed, 327 insertions(+), 5 deletions(-)
Applied.
M