From 35760a325dc18af30f010c62b5c076f81c694998 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:31 -0600 Subject: [PATCH 01/10] part: Add accessors for struct disk_partition uuid This field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it. Note that the accessor is optional. It can be omitted if it is known that the option is enabled. Signed-off-by: Simon Glass --- cmd/gpt.c | 10 ++++------ disk/part.c | 8 ++------ disk/part_dos.c | 17 ++++++++--------- disk/part_efi.c | 31 ++++++++++++++++--------------- fs/fat/fat.c | 4 +--- include/part.h | 27 +++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 39 deletions(-) diff --git a/cmd/gpt.c b/cmd/gpt.c index fe9e06681ce2..3cc6436b28b0 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -211,12 +211,10 @@ static struct disk_part *allocate_disk_part(struct disk_partition *info, PART_TYPE_LEN); newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0'; newpart->gpt_part_info.bootable = info->bootable; -#ifdef CONFIG_PARTITION_UUIDS - strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid, - UUID_STR_LEN); - /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars */ - newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0'; -#endif + if (IS_ENABLED(CONFIG_PARTITION_UUIDS)) { + strlcpy(newpart->gpt_part_info.uuid, disk_partition_uuid(info), + UUID_STR_LEN + 1); + } newpart->partnum = partnum; return newpart; diff --git a/disk/part.c b/disk/part.c index eec02f58988d..43f1d83bc7f8 100644 --- a/disk/part.c +++ b/disk/part.c @@ -341,10 +341,8 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, struct part_driver *drv; if (blk_enabled()) { -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) /* The common case is no UUID support */ - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif @@ -389,9 +387,7 @@ int part_get_info_whole_disk(struct blk_desc *dev_desc, info->bootable = 0; strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Whole Disk"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif diff --git a/disk/part_dos.c b/disk/part_dos.c index 56e61884deff..2fa0fbe0fd05 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -231,10 +231,8 @@ static int part_get_info_extended(struct blk_desc *dev_desc, return -1; } -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - if (!ext_part_sector) + if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector) disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]); -#endif /* Print all primary/logical partitions */ pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); @@ -256,9 +254,12 @@ static int part_get_info_extended(struct blk_desc *dev_desc, /* sprintf(info->type, "%d, pt->sys_ind); */ strcpy((char *)info->type, "U-Boot"); info->bootable = get_bootable(pt); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - sprintf(info->uuid, "%08x-%02x", disksig, part_num); -#endif + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + char str[12]; + + sprintf(str, "%08x-%02x", disksig, part_num); + disk_partition_set_uuid(info, str); + } info->sys_ind = pt->sys_ind; return 0; } @@ -292,9 +293,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc, info->blksz = DOS_PART_DEFAULT_SECTOR; info->bootable = 0; strcpy((char *)info->type, "U-Boot"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); return 0; } diff --git a/disk/part_efi.c b/disk/part_efi.c index 80a44dc9f072..cec8399d4f75 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -289,10 +289,11 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, print_efiname(&gpt_pte[part - 1])); strcpy((char *)info->type, "U-Boot"); info->bootable = get_bootable(&gpt_pte[part - 1]); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, - UUID_STR_FORMAT_GUID); -#endif + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, + (char *)disk_partition_uuid(info), + UUID_STR_FORMAT_GUID); + } #ifdef CONFIG_PARTITION_TYPE_GUID uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, info->type_guid, UUID_STR_FORMAT_GUID); @@ -416,10 +417,7 @@ int gpt_fill_pte(struct blk_desc *dev_desc, le64_to_cpu(gpt_h->last_usable_lba); int i, k; size_t efiname_len, dosname_len; -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - char *str_uuid; unsigned char *bin_uuid; -#endif #ifdef CONFIG_PARTITION_TYPE_GUID char *str_type_guid; unsigned char *bin_type_guid; @@ -488,16 +486,19 @@ int gpt_fill_pte(struct blk_desc *dev_desc, &partition_basic_data_guid, 16); #endif -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - str_uuid = partitions[i].uuid; - bin_uuid = gpt_e[i].unique_partition_guid.b; + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + const char *str_uuid; + + str_uuid = disk_partition_uuid(&partitions[i]); + bin_uuid = gpt_e[i].unique_partition_guid.b; - if (uuid_str_to_bin(str_uuid, bin_uuid, UUID_STR_FORMAT_GUID)) { - log_debug("Partition no. %d: invalid guid: %s\n", - i, str_uuid); - return -EINVAL; + if (uuid_str_to_bin(str_uuid, bin_uuid, + UUID_STR_FORMAT_GUID)) { + log_debug("Partition no. %d: invalid guid: %s\n", + i, str_uuid); + return -EINVAL; + } } -#endif /* partition attributes */ memset(&gpt_e[i].attributes, 0, diff --git a/fs/fat/fat.c b/fs/fat/fat.c index d1476aa433d6..8ff1fd0ec835 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -110,9 +110,7 @@ int fat_register_device(struct blk_desc *dev_desc, int part_no) info.name[0] = 0; info.type[0] = 0; info.bootable = 0; -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info.uuid[0] = 0; -#endif + disk_partition_clr_uuid(&info); } return fat_set_blk_dev(dev_desc, &info); diff --git a/include/part.h b/include/part.h index 8e451bbdff94..9c7ec4d90fa2 100644 --- a/include/part.h +++ b/include/part.h @@ -80,6 +80,33 @@ struct disk_partition { #endif }; +/* Accessors for struct disk_partition field ->uuid */ +extern char *__invalid_use_of_disk_partition_uuid; + +static inline const char *disk_partition_uuid(const struct disk_partition *info) +{ +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + return info->uuid; +#else + return __invalid_use_of_disk_partition_uuid; +#endif +} + +static inline void disk_partition_set_uuid(struct disk_partition *info, + const char *val) +{ +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + strlcpy(info->uuid, val, UUID_STR_LEN + 1); +#endif +} + +static inline void disk_partition_clr_uuid(struct disk_partition *info) +{ +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + *info->uuid = '\0'; +#endif +} + struct disk_part { int partnum; struct disk_partition gpt_part_info; From 9827fa7ca3bceaf1aa7fa416b0c1d5a1b9541547 Mon Sep 17 00:00:00 2001 From: Pascal Zimmermann Date: Thu, 27 Mar 2025 15:38:42 +0100 Subject: [PATCH 02/10] config_distro_bootcmd: make possible to substitute 'part list' in distro_bootcmd Make it possible to substitute the 'part list' command inside 'scan_dev_for_boot_part' with a custom board specific implementation. For this the new define 'SCAN_DEV_FOR_BOOT_PARTS' is introduced. Signed-off-by: Pascal Zimmermann Reviewed-by: Patrice Chotard Signed-off-by: Dario Binacchi --- include/config_distro_bootcmd.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index 2a136b96a6d9..f396df4f3c10 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -194,6 +194,11 @@ #define SCAN_DEV_FOR_EFI #endif +#ifndef SCAN_DEV_FOR_BOOT_PARTS +#define SCAN_DEV_FOR_BOOT_PARTS \ + "part list ${devtype} ${devnum} -bootable devplist; " +#endif + #ifdef CONFIG_SATA #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata) #define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV @@ -538,7 +543,7 @@ "\0" \ \ "scan_dev_for_boot_part=" \ - "part list ${devtype} ${devnum} -bootable devplist; " \ + SCAN_DEV_FOR_BOOT_PARTS \ "env exists devplist || setenv devplist 1; " \ "for distro_bootpart in ${devplist}; do " \ "if fstype ${devtype} " \ From 76ae90009cf76b1bfe172a37a7574417c3de4507 Mon Sep 17 00:00:00 2001 From: Varadarajan Narayanan Date: Tue, 13 May 2025 14:47:06 +0530 Subject: [PATCH 03/10] disk: part: implement generic function part_get_info_by_uuid() Add function to search for a partition by UUID as partition names may not be unique. Signed-off-by: Varadarajan Narayanan Acked-by: Casey Connolly Signed-off-by: Dario Binacchi --- disk/part.c | 39 +++++++++++++++++++++++++++++++++++++++ include/part.h | 20 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/disk/part.c b/disk/part.c index 43f1d83bc7f8..950a342602b3 100644 --- a/disk/part.c +++ b/disk/part.c @@ -700,6 +700,45 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, return -ENOENT; } +int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, + struct disk_partition *info) +{ + struct part_driver *part_drv; + int ret; + int i; + + if (!CONFIG_IS_ENABLED(PARTITION_UUIDS)) + return -ENOENT; + + part_drv = part_driver_lookup_type(desc); + if (!part_drv) + return -1; + + if (!part_drv->get_info) { + log_debug("## Driver %s does not have the get_info() method\n", + part_drv->name); + return -ENOSYS; + } + + for (i = 1; i < part_drv->max_entries; i++) { + ret = part_drv->get_info(desc, i, info); + if (ret != 0) { + /* + * Partition with this index can't be obtained, but + * further partitions might be, so keep checking. + */ + continue; + } + + if (!strncasecmp(uuid, disk_partition_uuid(info), UUID_STR_LEN)) { + /* matched */ + return i; + } + } + + return -ENOENT; +} + /** * Get partition info from device number and partition name. * diff --git a/include/part.h b/include/part.h index 9c7ec4d90fa2..7ad5b3048c3a 100644 --- a/include/part.h +++ b/include/part.h @@ -249,6 +249,20 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, struct disk_partition *info); +/** + * part_get_info_by_uuid() - Search for a partition by uuid + * among all available registered partitions + * + * @desc: block device descriptor + * @uuid: the specified table entry uuid + * @info: the disk partition info + * + * Return: the partition number on match (starting on 1), -ENOENT on no match, + * otherwise error + */ +int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, + struct disk_partition *info); + /** * part_get_info_by_dev_and_name_or_num() - Get partition info from dev number * and part name, or dev number and @@ -321,6 +335,12 @@ static inline int part_get_info_by_name(struct blk_desc *dev_desc, return -ENOENT; } +static inline int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, + struct disk_partition *info) +{ + return -ENOENT; +} + static inline int part_get_info_by_dev_and_name_or_num(const char *dev_iface, const char *dev_part_str, From c5341b5c4de36b781484dab6f6c345f41f42ba75 Mon Sep 17 00:00:00 2001 From: Padmarao Begari Date: Fri, 12 Sep 2025 15:35:38 +0530 Subject: [PATCH 04/10] FWU: Add platform hook support for fwu metata FWU metadata information is unavailable for platform-specific operations since FWU initialization has not yet occurred. The initialization function is invoked as part of the main loop event. To address this, the FWU platform hook function is introduced during FWU initialization, allowing metadata processing with platform-specific operations. Signed-off-by: Padmarao Begari Link: https://lore.kernel.org/r/20250912100539.4127378-2-padmarao.begari@amd.com Signed-off-by: Michal Simek Signed-off-by: Dario Binacchi --- include/fwu.h | 11 +++++++++++ lib/fwu_updates/fwu.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/fwu.h b/include/fwu.h index 77ec65e61807..865c239b66a4 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -129,6 +129,17 @@ int fwu_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary, uint32_t size); +/** + * fwu_platform_hook() - Platform specific processing with FWU metadata + * @dev: FWU metadata device + * @data: FWU metadata + * + * Provide a platform specific function for processing with the FWU metadata. + * + * Return: 0 if OK, -ve on error + */ +int fwu_platform_hook(struct udevice *dev, struct fwu_data *data); + /** * fwu_get_mdata() - Read, verify and return the FWU metadata * diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index f5e0315b796f..50793a7784c9 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -629,6 +629,16 @@ __weak void fwu_plat_get_bootidx(uint *boot_idx) *boot_idx = 0; /* Dummy value */ } +/** + * fwu_platform_hook() - Platform specific processing with FWU metadata + * + * Return: 0 if OK, -ve on error + */ +__weak int fwu_platform_hook(struct udevice *dev, struct fwu_data *data) +{ + return 0; +} + /** * fwu_update_checks_pass() - Check if FWU update can be done * @@ -686,6 +696,7 @@ static int fwu_boottime_checks(void *ctx, struct event *event) { int ret; u32 boot_idx, active_idx; + struct fwu_data *data; ret = uclass_first_device_err(UCLASS_FWU_MDATA, &g_dev); if (ret) { @@ -744,6 +755,13 @@ static int fwu_boottime_checks(void *ctx, struct event *event) if (!ret) boottime_check = 1; + data = fwu_get_data(); + ret = fwu_platform_hook(g_dev, data); + if (ret) { + log_err("fwu_platform_hook() failed\n"); + return ret; + } + return 0; } EVENT_SPY(EVT_MAIN_LOOP, fwu_boottime_checks); From 1793613e77d04f0324c618a659b70c153ac15d37 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Fri, 30 Jan 2026 09:51:37 +0100 Subject: [PATCH 05/10] lib: uuid: add partition type GUID for extended bootloader The Extended Boot Loader Partition (XBOOTLDR) is a standard defined by the Discoverable Partitions Specification (DPS) to host boot loader resources outside of the EFI System Partition. Defining this GUID (bc13c2ff-59e6-4262-a352-b275fd6f7172) allows U-Boot to correctly identify and label these partitions using the "xbootldr" shorthand. Signed-off-by: Dario Binacchi --- doc/README.gpt | 2 ++ include/part_efi.h | 3 +++ lib/uuid.c | 1 + 3 files changed, 6 insertions(+) diff --git a/doc/README.gpt b/doc/README.gpt index 386ac2e0fc8f..a6e1fd7ce8d4 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -286,6 +286,8 @@ Some strings can be also used at the place of known GUID : (E6D6D379-F507-44C2-A23C-238F2A3DF928) "u-boot-env" = PARTITION_U_BOOT_ENVIRONMENT (3DE21764-95BD-54BD-A5C3-4ABE786F38A8) + "xbootldr" = PARTITION_XBOOTLDR + (BC13C2FF-59E6-4262-A352-B275FD6F7172) "uuid_disk=...;name=u-boot,size=60MiB,uuid=...; name=kernel,size=60MiB,uuid=...,type=linux;" diff --git a/include/part_efi.h b/include/part_efi.h index c68529b4dafe..d9573cf685e2 100644 --- a/include/part_efi.h +++ b/include/part_efi.h @@ -59,6 +59,9 @@ #define PARTITION_U_BOOT_ENVIRONMENT \ EFI_GUID( 0x3de21764, 0x95bd, 0x54bd, \ 0xa5, 0xc3, 0x4a, 0xbe, 0x78, 0x6f, 0x38, 0xa8) +#define PARTITION_XBOOTLDR \ + EFI_GUID( 0xbc13c2ff, 0x59e6, 0x4262, \ + 0xa3, 0x52, 0xb2, 0x75, 0xfd, 0x6f, 0x71, 0x72) /* linux/include/efi.h */ typedef u16 efi_char16_t; diff --git a/lib/uuid.c b/lib/uuid.c index d0187007d0e8..3678fd4084a8 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -105,6 +105,7 @@ static const struct { {"swap", PARTITION_LINUX_SWAP_GUID}, {"lvm", PARTITION_LINUX_LVM_GUID}, {"u-boot-env", PARTITION_U_BOOT_ENVIRONMENT}, + {"xbootldr", PARTITION_XBOOTLDR}, #endif #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI) { From 96d0d8142ecddb80dc149d2c7b948af55a01a22b Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 8 Mar 2026 18:11:41 +0100 Subject: [PATCH 06/10] cmd: part: support lookup by UUID in 'part number' The 'part number' command currently allows looking up a partition index only by its name. Extend the command to support looking up the partition index via its partition UUID. Unlike names, UUIDs guarantee unique partition identification, avoiding ambiguity. The logic is updated to check if the provided string is a valid UUID before falling back to a name-based search. Signed-off-by: Dario Binacchi --- cmd/part.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/part.c b/cmd/part.c index 0ce190005d32..e23299094b86 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -138,6 +138,10 @@ static int do_part_info(int argc, char *const argv[], enum cmd_part_info param) err = part_get_info(desc, part, &info); if (err) return 1; + } else if (uuid_str_valid(argv[2])) { + part = part_get_info_by_uuid(desc, argv[2], &info); + if (part < 0) + return 1; } else { part = part_get_info_by_name(desc, argv[2], &info); if (part < 0) @@ -303,8 +307,8 @@ U_BOOT_CMD( " - set environment variable to the size of the partition (in blocks)\n" " part can be either partition number or partition name\n" "part number \n" - " - set environment variable to the partition number using the partition name\n" - " part must be specified as partition name\n" + " - set environment variable to the partition number using the partition UUID or name\n" + " part must be specified as partition UUID or name\n" #ifdef CONFIG_PARTITION_TYPE_GUID "part type :\n" " - print partition type\n" From 686ea981ba1c92897a5ac687081cc88ac68217b6 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 8 Mar 2026 18:22:42 +0100 Subject: [PATCH 07/10] fwu: add helper to get image GUID by type and bank index Introduce fwu_mdata_get_image_guid() to retrieve a specific image GUID from the FWU metadata based on the bank index and image type GUID. This allows identifying the correct partition in multi-bank (A/B) scenarios, ensuring the correct image is targeted depending on the current bank. Signed-off-by: Dario Binacchi --- include/fwu.h | 3 +++ lib/fwu_updates/fwu.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/fwu.h b/include/fwu.h index 865c239b66a4..1f6a814906d3 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -395,6 +395,9 @@ void fwu_populate_mdata_image_info(struct fwu_data *data); */ int fwu_get_mdata_size(uint32_t *mdata_size); +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, efi_guid_t image_type_guid, + u32 bank_index); + /** * fwu_state_machine_updates() - Update FWU state of the platform * @trial_state: Is platform transitioning into Trial State diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 50793a7784c9..104d76bf35be 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -216,6 +216,30 @@ int fwu_sync_mdata(struct fwu_mdata *mdata, int part) return 0; } +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, efi_guid_t image_type_guid, + u32 bank_index) +{ + struct fwu_data *data = &g_fwu_data; + struct fwu_image_entry *image; + int i; + + if (bank_index >= data->num_banks) + return -EINVAL; + + for (i = 0; i < data->num_images; i++) { + image = &data->fwu_images[i]; + + if (!guidcmp(&image_type_guid, &image->image_type_guid)) { + struct fwu_image_bank_info *bank; + + bank = &image->img_bank_info[bank_index]; + guidcpy(image_guid, &bank->image_guid); + return 0; + } + } + + return -ENOENT; +} /** * fwu_mdata_copies_allocate() - Allocate memory for metadata * @mdata_size: Size of the metadata structure From a44eed49ead535da6971d3b74b052f190a521a3c Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 8 Mar 2026 18:45:00 +0100 Subject: [PATCH 08/10] board: st: stm32mp2: support dynamic A/B bank bootup Enable automatic detection of the active A/B bank by retrieving partition GUIDs from FWU metadata. This ensures the system correctly identifies the bootable partitions even in multi-bank scenarios, falling back to a standard bootable flag scan if the UUIDs are missing. Signed-off-by: Dario Binacchi --- board/st/stm32mp2/stm32mp2.c | 27 +++++++++++++++++++++++++++ include/configs/stm32mp25_st_common.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index 60ab005e0e38..15dafc3a735c 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -926,5 +926,32 @@ void fwu_plat_get_bootidx(uint *boot_idx) *boot_idx = (readl(TAMP_FWU_BOOT_INFO_REG) >> TAMP_FWU_BOOT_IDX_OFFSET) & TAMP_FWU_BOOT_IDX_MASK; } + +int fwu_platform_hook(struct udevice *dev, struct fwu_data *data) +{ + uint boot_idx; + efi_guid_t boot_uuid, root_uuid; + const efi_guid_t boot_type_guid = PARTITION_XBOOTLDR; + const efi_guid_t root_type_guid = + PARTITION_LINUX_FILE_SYSTEM_DATA_GUID; + char uuidbuf[UUID_STR_LEN + 1]; + + fwu_plat_get_bootidx(&boot_idx); + + if (!fwu_mdata_get_image_guid(&boot_uuid, boot_type_guid, + boot_idx) && + !fwu_mdata_get_image_guid(&root_uuid, root_type_guid, + boot_idx)) { + + uuid_bin_to_str(boot_uuid.b, uuidbuf, UUID_STR_FORMAT_GUID); + env_set("boot_partuuid", uuidbuf); + + uuid_bin_to_str(root_uuid.b, uuidbuf, UUID_STR_FORMAT_GUID); + env_set("root_partuuid", uuidbuf); + } + + return 0; +} + #endif /* CONFIG_FWU_MULTI_BANK_UPDATE */ diff --git a/include/configs/stm32mp25_st_common.h b/include/configs/stm32mp25_st_common.h index 579145fcc494..48de4091cbbf 100644 --- a/include/configs/stm32mp25_st_common.h +++ b/include/configs/stm32mp25_st_common.h @@ -8,7 +8,22 @@ #ifndef __CONFIG_STM32MP25_ST_COMMON_H__ #define __CONFIG_STM32MP25_ST_COMMON_H__ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define SCAN_DEV_FOR_BOOT_PARTS \ + "setenv devplist; " \ + "env exists boot_partuuid && " \ + "part number ${devtype} ${devnum} ${boot_partuuid} devplist; " \ + "env exists devplist || " \ + "part list ${devtype} ${devnum} -bootable devplist; " + +#define ST_STM32MP25_FWU_ENV \ + "altbootcmd=${bootcmd}\0" +#else +#define ST_STM32MP25_FWU_ENV +#endif + #define STM32MP_BOARD_EXTRA_ENV \ + ST_STM32MP25_FWU_ENV \ "usb_pgood_delay=2000\0" \ "console=ttySTM0\0" From 8e9d3052019c0a709a8fba0e6e9136d8605720f9 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 10 May 2026 10:36:55 +0200 Subject: [PATCH 09/10] ARM: dts: stm32: add FWU metadata node for stm32mp157f-dk2 The FWU metadata structure is accessed through the driver model interface. While commit a402adc664d4 ("stm32mp1: Add a node for the FWU metadata device") added this support for the stm32mp157c variants, it was missing for the stm32mp157f-dk2 board. Since the FWU metadata is also stored on the uSD card for the stm32mp157f-dk2 board, add the fwu-mdata node in its u-boot specific dtsi file to allow accessing the metadata structure properly. Signed-off-by: Dario Binacchi --- arch/arm/dts/stm32mp157f-dk2-u-boot.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm/dts/stm32mp157f-dk2-u-boot.dtsi b/arch/arm/dts/stm32mp157f-dk2-u-boot.dtsi index 53133e98ba82..329c48723a97 100644 --- a/arch/arm/dts/stm32mp157f-dk2-u-boot.dtsi +++ b/arch/arm/dts/stm32mp157f-dk2-u-boot.dtsi @@ -5,6 +5,13 @@ #include "stm32mp157a-dk1-u-boot.dtsi" +/ { + fwu-mdata { + compatible = "u-boot,fwu-mdata-gpt"; + fwu-mdata-store = <&sdmmc1>; + }; +}; + &sdmmc2 { status = "disabled"; }; From 31cbae64fa7f8c319c9f09e28ad21231d9f3dcc3 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 10 May 2026 10:41:25 +0200 Subject: [PATCH 10/10] board: st: stm32mp1: support dynamic A/B bank bootup Enable automatic detection of the active A/B bank by retrieving partition GUIDs from FWU metadata. This ensures the system correctly identifies the bootable partitions even in multi-bank scenarios, falling back to a standard bootable flag scan if the UUIDs are missing. Signed-off-by: Dario Binacchi --- board/st/stm32mp1/stm32mp1.c | 27 +++++++++++++++++++++++++++ include/configs/stm32mp15_st_common.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 76c431197b6b..b669402b6775 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -1356,4 +1356,31 @@ void fwu_plat_get_bootidx(uint *boot_idx) *boot_idx = (readl(TAMP_FWU_BOOT_INFO_REG) >> TAMP_FWU_BOOT_IDX_OFFSET) & TAMP_FWU_BOOT_IDX_MASK; } + +int fwu_platform_hook(struct udevice *dev, struct fwu_data *data) +{ + uint boot_idx; + efi_guid_t boot_uuid, root_uuid; + const efi_guid_t boot_type_guid = PARTITION_XBOOTLDR; + const efi_guid_t root_type_guid = + PARTITION_LINUX_FILE_SYSTEM_DATA_GUID; + char uuidbuf[UUID_STR_LEN + 1]; + + fwu_plat_get_bootidx(&boot_idx); + + if (!fwu_mdata_get_image_guid(&boot_uuid, boot_type_guid, + boot_idx) && + !fwu_mdata_get_image_guid(&root_uuid, root_type_guid, + boot_idx)) { + + uuid_bin_to_str(boot_uuid.b, uuidbuf, UUID_STR_FORMAT_GUID); + env_set("boot_partuuid", uuidbuf); + + uuid_bin_to_str(root_uuid.b, uuidbuf, UUID_STR_FORMAT_GUID); + env_set("root_partuuid", uuidbuf); + } + + return 0; +} #endif /* CONFIG_FWU_MULTI_BANK_UPDATE */ + diff --git a/include/configs/stm32mp15_st_common.h b/include/configs/stm32mp15_st_common.h index 7b3b887a2f2d..30467ca68bae 100644 --- a/include/configs/stm32mp15_st_common.h +++ b/include/configs/stm32mp15_st_common.h @@ -8,7 +8,22 @@ #ifndef __CONFIG_STM32MP15_ST_COMMON_H__ #define __CONFIG_STM32MP15_ST_COMMON_H__ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define SCAN_DEV_FOR_BOOT_PARTS \ + "setenv devplist; " \ + "env exists boot_partuuid && " \ + "part number ${devtype} ${devnum} ${boot_partuuid} devplist; " \ + "env exists devplist || " \ + "part list ${devtype} ${devnum} -bootable devplist; " + +#define ST_STM32MP15_FWU_ENV \ + "altbootcmd=${bootcmd}\0" +#else +#define ST_STM32MP15_FWU_ENV +#endif + #define STM32MP_BOARD_EXTRA_ENV \ + ST_STM32MP15_FWU_ENV \ "usb_pgood_delay=2000\0" \ "console=ttySTM0\0" \ "splashimage=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \