From 467dc9a44b7b5654089ea1334a14ffd20c028916 Mon Sep 17 00:00:00 2001 From: Austin Shirley Date: Wed, 6 May 2026 16:37:58 -0600 Subject: configs: stm32mp13: add SPI-NAND UBI boot support The STM32MP13 default environment only handles MMC and serial/USB boot. When TF-A reports BOOT_FLASH_SPINAND the boot_device variable is set to 'spi-nand' but bootcmd_stm32mp never redirects boot_targets to ubifs0, so distro_bootcmd falls through to MMC/USB. This change mirrors the STM32MP15 logic: - Add a BOOT_TARGET_UBIFS entry to BOOT_TARGET_DEVICES so that bootcmd_ubifs0 is defined (ubi part UBI; ubifsmount ubi0:boot). - Add the 'spi-nand' / 'nand' clause to bootcmd_stm32mp so that boot_targets is set to 'ubifs0' when booting from NAND. Signed-off-by: Austin Shirley Cc: Patrick Delaunay Cc: Patrice Chotard Cc: Tom Rini Cc: uboot-stm32@st-md-mailman.stormreply.com --- include/configs/stm32mp13_common.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/configs/stm32mp13_common.h b/include/configs/stm32mp13_common.h index 3e3f49abae0..e707b146f90 100644 --- a/include/configs/stm32mp13_common.h +++ b/include/configs/stm32mp13_common.h @@ -33,6 +33,12 @@ #define BOOT_TARGET_MMC1(func) #endif +#ifdef CONFIG_CMD_UBIFS +#define BOOT_TARGET_UBIFS(func) func(UBIFS, ubifs, 0, UBI, boot) +#else +#define BOOT_TARGET_UBIFS(func) +#endif + #ifdef CONFIG_CMD_USB #define BOOT_TARGET_USB(func) func(USB, usb, 0) #else @@ -41,12 +47,14 @@ #define BOOT_TARGET_DEVICES(func) \ BOOT_TARGET_MMC1(func) \ + BOOT_TARGET_UBIFS(func) \ BOOT_TARGET_MMC0(func) \ BOOT_TARGET_USB(func) /* * default bootcmd for stm32mp13: * for serial/usb: execute the stm32prog command + * for nand or spi-nand boot, distro boot with ubifs on UBI partition * for mmc boot (eMMC, SD card), distro boot on the same mmc device */ #define STM32MP_BOOTCMD "bootcmd_stm32mp=" \ @@ -56,7 +64,10 @@ "else " \ "run env_check;" \ "if test ${boot_device} = mmc;" \ - "then env set boot_targets \"mmc${boot_instance}\"; fi;" \ + "then env set boot_targets \"mmc${boot_instance}\"; fi; " \ + "if test ${boot_device} = nand ||" \ + " test ${boot_device} = spi-nand ;" \ + "then env set boot_targets ubifs0; fi;" \ "run distro_bootcmd;" \ "fi;\0" -- cgit v1.2.3 From 2a55938b42b90eb656fe32384294318e37305830 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:02 +0200 Subject: 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 ([1], [2]). Defining this GUID (bc13c2ff-59e6-4262-a352-b275fd6f7172) allows U-Boot to correctly identify and label these partitions using the "xbootldr" shorthand. [1] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/#extended-boot-loader-partition:~:text=UEFI%20Specification.-,Extended%20Boot%20Loader%20Partition,-bc13c2ff%2D59e6%2D4262 [2] https://uapi-group.org/specifications/specs/boot_loader_specification/ Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- 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 386ac2e0fc8..a6e1fd7ce8d 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 2cea5088046..5713b3018f4 100644 --- a/include/part_efi.h +++ b/include/part_efi.h @@ -60,6 +60,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) /* Special ChromiumOS things */ #define PARTITION_CROS_KERNEL \ diff --git a/lib/uuid.c b/lib/uuid.c index 3a666d0430d..d7c164ea06b 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -86,6 +86,7 @@ static const struct { {"swap", NULL, PARTITION_LINUX_SWAP_GUID}, {"lvm", NULL, PARTITION_LINUX_LVM_GUID}, {"u-boot-env", NULL, PARTITION_U_BOOT_ENVIRONMENT}, + {"xbootldr", NULL, PARTITION_XBOOTLDR}, {"cros-kern", NULL, PARTITION_CROS_KERNEL}, {"cros-root", NULL, PARTITION_CROS_ROOT}, {"cros-fw", NULL, PARTITION_CROS_FIRMWARE}, -- cgit v1.2.3 From 27a928553a1327e48e7749cb7d5d65ddaeef3e9a Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:03 +0200 Subject: test: dm: part: add test for part_get_info_by_uuid Add a new unit test for the part_get_info_by_uuid() function. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- test/dm/part.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/dm/part.c b/test/dm/part.c index caae23bd4aa..ad37d7f406f 100644 --- a/test/dm/part.c +++ b/test/dm/part.c @@ -195,3 +195,56 @@ static int dm_test_part_get_info_by_type(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_part_get_info_by_type, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +static int dm_test_part_get_info_by_uuid(struct unit_test_state *uts) +{ + struct disk_partition parts[] = { + { + .start = 48, + .size = 1, + .name = "test1", + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", + }, + { + .start = 49, + .size = 1, + .name = "test2", + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", + }, + }; + char disk_guid[UUID_STR_LEN + 1] = + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; + struct blk_desc *mmc_dev_desc; + struct disk_partition info; + int part, i; + + ut_asserteq(2, blk_get_device_by_str("mmc", "2", &mmc_dev_desc)); + + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { + for (i = 0; i < ARRAY_SIZE(parts); i++) + gen_rand_uuid_str(parts[i].uuid, UUID_STR_FORMAT_STD); + + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); + } + + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, parts, + ARRAY_SIZE(parts))); + + for (i = 0; i < ARRAY_SIZE(parts); i++) { + part = part_get_info_by_uuid(mmc_dev_desc, parts[i].uuid, + &info); + + ut_asserteq(i + 1, part); + ut_asserteq_str(parts[i].name, info.name); + ut_asserteq(parts[i].start, info.start); + ut_asserteq(parts[i].size, info.size); + } + + part = part_get_info_by_uuid(mmc_dev_desc, + "00000000-0000-0000-0000-000000000000", + &info); + ut_assert(part < 0); + + return 0; +} +DM_TEST(dm_test_part_get_info_by_uuid, UTF_SCAN_PDATA | UTF_SCAN_FDT); -- cgit v1.2.3 From a392450189d2434be19c194df560c8bc9335e337 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:04 +0200 Subject: test: cmd: add unit tests for part command Add unit tests for the 'part' command, specifically for the 'number', 'start', and 'size' subcommands. These tests establish a baseline for the current partition lookup functionality by name. This foundation will be used by subsequent patches to extend the command, ensuring consistent behavior as new features are introduced. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- test/cmd/Makefile | 1 + test/cmd/part.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 test/cmd/part.c diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 5f2815b1bb6..8d6932f1176 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_LOADM) += loadm.o obj-$(CONFIG_CMD_MEMINFO) += meminfo.o obj-$(CONFIG_CMD_MEMORY) += mem_copy.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o +obj-$(CONFIG_CMD_PART) += part.o ifdef CONFIG_CMD_PCI obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o endif diff --git a/test/cmd/part.c b/test/cmd/part.c new file mode 100644 index 00000000000..cac57a1a0e3 --- /dev/null +++ b/test/cmd/part.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for part command + * + * Copyright (C) 2026 Amarula Solutions + * Written by Dario Binacchi + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct disk_partition gpt_parts[] = { + { + .start = 48, + .size = 1, + .name = "test1", + .uuid = "c5bce7a2-03f0-4d03-9048-01ff23b9d527", + }, + { + .start = 49, + .size = 2, + .name = "test2", + .uuid = "9df346e8-2c53-4cd8-b9ac-3af83f9a9b74", + }, +}; + +static char disk_guid[UUID_STR_LEN + 1] = + "8d60b397-1bb6-4d33-80ee-b1587d24c2f8"; + +static int setup_gpt_partitions(struct unit_test_state *uts, + unsigned int mmc_dev_num) +{ + struct blk_desc *mmc_dev_desc; + char dev_str[10]; + int i, ret; + + if (!CONFIG_IS_ENABLED(MMC)) + return -EAGAIN; + + snprintf(dev_str, sizeof(dev_str), "%u", mmc_dev_num); + + ret = blk_get_device_by_str("mmc", dev_str, &mmc_dev_desc); + if (ret == -ENODEV) + return -EAGAIN; + + ut_asserteq(mmc_dev_num, ret); + + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) + gen_rand_uuid_str(gpt_parts[i].uuid, + UUID_STR_FORMAT_STD); + + gen_rand_uuid_str(disk_guid, UUID_STR_FORMAT_STD); + } + + ut_assertok(gpt_restore(mmc_dev_desc, disk_guid, gpt_parts, + ARRAY_SIZE(gpt_parts))); + return 0; +} + +static int cmd_test_part_number(struct unit_test_state *uts) +{ + unsigned int mmc_dev_num = 2; + char expected[10]; + int i, ret; + + ret = setup_gpt_partitions(uts, mmc_dev_num); + if (ret == -EAGAIN) + return ret; + + ut_assertok(ret); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partnum", NULL); + ut_assertok(run_commandf("part number mmc %u %s partnum", + mmc_dev_num, gpt_parts[i].name)); + snprintf(expected, sizeof(expected), "0x%x", i + 1); + ut_asserteq_str(expected, env_get("partnum")); + } + + env_set("partnum", NULL); + ut_asserteq(1, run_commandf("part number mmc %u bogus partnum", + mmc_dev_num)); + ut_assertnull(env_get("partnum")); + + return 0; +} +CMD_TEST(cmd_test_part_number, UTF_CONSOLE); + +static int cmd_test_part_start(struct unit_test_state *uts) +{ + unsigned int mmc_dev_num = 2; + char expected[32]; + int i, ret; + + ret = setup_gpt_partitions(uts, mmc_dev_num); + if (ret == -EAGAIN) + return ret; + + ut_assertok(ret); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partstart", NULL); + ut_assertok(run_commandf("part start mmc %u %d partstart", + mmc_dev_num, i + 1)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].start); + ut_asserteq_str(expected, env_get("partstart")); + } + + env_set("partstart", NULL); + ut_asserteq(1, run_commandf("part start mmc %u 3 partstart", + mmc_dev_num)); + ut_assertnull(env_get("partstart")); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partstart", NULL); + ut_assertok(run_commandf("part start mmc %u %s partstart", + mmc_dev_num, gpt_parts[i].name)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].start); + ut_asserteq_str(expected, env_get("partstart")); + } + + env_set("partstart", NULL); + ut_asserteq(1, run_commandf("part start mmc %u bogus partstart", + mmc_dev_num)); + ut_assertnull(env_get("partstart")); + + return 0; +} +CMD_TEST(cmd_test_part_start, UTF_CONSOLE); + +static int cmd_test_part_size(struct unit_test_state *uts) +{ + unsigned int mmc_dev_num = 2; + char expected[32]; + int i, ret; + + ret = setup_gpt_partitions(uts, mmc_dev_num); + if (ret == -EAGAIN) + return ret; + + ut_assertok(ret); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partsize", NULL); + ut_assertok(run_commandf("part size mmc %u %d partsize", + mmc_dev_num, i + 1)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].size); + ut_asserteq_str(expected, env_get("partsize")); + } + + env_set("partsize", NULL); + ut_asserteq(1, run_commandf("part size mmc %u 3 partsize", + mmc_dev_num)); + ut_assertnull(env_get("partsize")); + + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partsize", NULL); + ut_assertok(run_commandf("part size mmc %u %s partsize", + mmc_dev_num, gpt_parts[i].name)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].size); + ut_asserteq_str(expected, env_get("partsize")); + } + + env_set("partsize", NULL); + ut_asserteq(1, run_commandf("part size mmc %u bogus partsize", + mmc_dev_num)); + ut_assertnull(env_get("partsize")); + + return 0; +} +CMD_TEST(cmd_test_part_size, UTF_CONSOLE); -- cgit v1.2.3 From 703f8c313dd948e28868d964f798bad34ecc1572 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:05 +0200 Subject: cmd: part: support lookup by UUID The 'part' command currently allows looking up a partition only by its number or name. Extend the 'number', 'start', and 'size' subcommands to support looking up the partition via its 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. The help strings for these subcommands are updated accordingly. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- cmd/part.c | 12 ++++++++---- doc/usage/cmd/part.rst | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/part.c b/cmd/part.c index 5e520d707f3..3191d5861fd 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -144,6 +144,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) @@ -517,13 +521,13 @@ U_BOOT_CMD( " flags can be -bootable (list only bootable partitions)\n" "part start \n" " - set environment variable to the start of the partition (in blocks)\n" - " part can be either partition number or partition name\n" + " part can be either partition number, UUID or name\n" "part size \n" " - set environment variable to the size of the partition (in blocks)\n" - " part can be either partition number or partition name\n" + " part can be either partition number, UUID or 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" "part name \n" " - set environment variable to the partition name using the partition number\n" " part must be specified as partition number\n" diff --git a/doc/usage/cmd/part.rst b/doc/usage/cmd/part.rst index b91f6541f7f..a0e7be08a9a 100644 --- a/doc/usage/cmd/part.rst +++ b/doc/usage/cmd/part.rst @@ -52,7 +52,7 @@ The 'part list' command prints or sets an environment variable to the list of pa an optional environment variable to store the list of partitions value into. The 'part start' command sets an environment variable to the start of the partition (in blocks), -part can be either partition number or partition name. +part can be either partition number, partition UUID or partition name. interface interface for accessing the block device (mmc, sata, scsi, usb, ....) @@ -64,7 +64,7 @@ part can be either partition number or partition name. a variable to store the current start of the partition value into. The 'part size' command sets an environment variable to the size of the partition (in blocks), -part can be either partition number or partition name. +part can be either partition number, partition UUID or partition name. interface interface for accessing the block device (mmc, sata, scsi, usb, ....) @@ -76,7 +76,7 @@ part can be either partition number or partition name. a variable to store the current size of the partition value into. The 'part number' command sets an environment variable to the partition number using the partition name, -part must be specified as partition name. +part must be specified as partition UUID or partition name. interface interface for accessing the block device (mmc, sata, scsi, usb, ....) -- cgit v1.2.3 From 2dc71c48bf14aa22f24824dcd94550cc5277f402 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:06 +0200 Subject: test: cmd: part: add UUID lookup tests Extend the 'part' command unit tests to include partition lookup via UUID. This ensures that the 'number', 'start', and 'size' subcommands consistently handle UUIDs as partition identifiers, maintaining parity with the name-based lookup functionality. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- test/cmd/part.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/cmd/part.c b/test/cmd/part.c index cac57a1a0e3..e0149011476 100644 --- a/test/cmd/part.c +++ b/test/cmd/part.c @@ -90,6 +90,20 @@ static int cmd_test_part_number(struct unit_test_state *uts) mmc_dev_num)); ut_assertnull(env_get("partnum")); + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partnum", NULL); + ut_assertok(run_commandf("part number mmc %u %s partnum", + mmc_dev_num, gpt_parts[i].uuid)); + snprintf(expected, sizeof(expected), "0x%x", i + 1); + ut_asserteq_str(expected, env_get("partnum")); + } + + env_set("partnum", NULL); + ut_asserteq(1, run_commandf("part number mmc %u %s partnum", + mmc_dev_num, + "00000000-0000-0000-0000-000000000000")); + ut_assertnull(env_get("partnum")); + return 0; } CMD_TEST(cmd_test_part_number, UTF_CONSOLE); @@ -134,6 +148,21 @@ static int cmd_test_part_start(struct unit_test_state *uts) mmc_dev_num)); ut_assertnull(env_get("partstart")); + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partstart", NULL); + ut_assertok(run_commandf("part start mmc %u %s partstart", + mmc_dev_num, gpt_parts[i].uuid)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].start); + ut_asserteq_str(expected, env_get("partstart")); + } + + env_set("partstart", NULL); + ut_asserteq(1, run_commandf("part start mmc %u %s partstart", + mmc_dev_num, + "00000000-0000-0000-0000-000000000000")); + ut_assertnull(env_get("partstart")); + return 0; } CMD_TEST(cmd_test_part_start, UTF_CONSOLE); @@ -178,6 +207,21 @@ static int cmd_test_part_size(struct unit_test_state *uts) mmc_dev_num)); ut_assertnull(env_get("partsize")); + for (i = 0; i < ARRAY_SIZE(gpt_parts); i++) { + env_set("partsize", NULL); + ut_assertok(run_commandf("part size mmc %u %s partsize", + mmc_dev_num, gpt_parts[i].uuid)); + snprintf(expected, sizeof(expected), "%lx", + (unsigned long)gpt_parts[i].size); + ut_asserteq_str(expected, env_get("partsize")); + } + + env_set("partsize", NULL); + ut_asserteq(1, run_commandf("part size mmc %u %s partsize", + mmc_dev_num, + "00000000-0000-0000-0000-000000000000")); + ut_assertnull(env_get("partsize")); + return 0; } CMD_TEST(cmd_test_part_size, UTF_CONSOLE); -- cgit v1.2.3 From 97cdde6dfad31341d5efc9a8030b90049577ab90 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:07 +0200 Subject: 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 Reviewed-by: Simon Glass Acked-by: Ilias Apalodimas --- include/fwu.h | 11 +++++++++++ lib/fwu_updates/fwu.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/fwu.h b/include/fwu.h index 9cee8fb085c..68a51fb4296 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -396,6 +396,17 @@ void fwu_populate_mdata_image_info(struct fwu_data *data); */ int fwu_get_mdata_size(uint32_t *mdata_size); +/** + * fwu_mdata_get_image_guid() - Get image GUID for a type and bank + * @image_guid: Pointer to be filled with the found image GUID + * @image_type_guid: Pointer to the image type GUID to search for + * @bank_index: Index of the bank + * + * Return: 0 if OK, -ve on error + */ +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, + const efi_guid_t *image_type_guid, u32 bank_index); + /** * fwu_state_machine_updates() - Update FWU state of the platform * @state: FWU bank state diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index e82600a29a4..2b11e5da061 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -243,6 +243,39 @@ int fwu_sync_mdata(struct fwu_mdata *mdata, int part) return 0; } +/** + * fwu_mdata_get_image_guid() - Get image GUID for a type and bank + * @image_guid: Pointer to be filled with the found image GUID + * @image_type_guid: Pointer to the image type GUID to search for + * @bank_index: Index of the bank + * + * Return: 0 if OK, -ve on error + */ +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, + const 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 -- cgit v1.2.3 From 63fc73ff31c47df8dd3cb708dc34053972d5f4a0 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:08 +0200 Subject: test: dm: fwu_mdata: add test for fwu_mdata_get_image_guid Add a new unit test for the fwu_mdata_get_image_guid() function. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- test/dm/fwu_mdata.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/dm/fwu_mdata.c b/test/dm/fwu_mdata.c index cfe543d8a23..8624ccf61f7 100644 --- a/test/dm/fwu_mdata.c +++ b/test/dm/fwu_mdata.c @@ -143,3 +143,51 @@ static int dm_test_fwu_mdata_write(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_fwu_mdata_write, UTF_SCAN_FDT); + +static int dm_test_fwu_mdata_get_image_guid(struct unit_test_state *uts) +{ + efi_guid_t image_type_guid = + EFI_GUID(0x09d7cf52, 0x0720, 0x4710, \ + 0x91, 0xd1, 0x08, 0x46, 0x9b, 0x7f, 0xe9, 0xc8); + efi_guid_t bank_0_image_guid = + EFI_GUID(0x10057a86, 0xdaf1, 0x4f93, \ + 0xba, 0x7f, 0xb1, 0x95, 0xf7, 0xfa, 0x41, 0x70); + efi_guid_t bank_1_image_guid = + EFI_GUID(0xdb62ed3e, 0x6237, 0x4fb4, \ + 0x80, 0xc4, 0x1b, 0x74, 0xd8, 0x46, 0xa8, 0xe7); + efi_guid_t wrong_image_type_guid = + EFI_GUID(0x12345678, 0x1302, 0x133f, \ + 0x18, 0x0a, 0x14, 0x05, 0x18, 0x05, 0x14, 0x0b); + struct udevice *dev; + efi_guid_t image_guid; + + ut_assertok(setup_blk_device(uts)); + ut_assertok(populate_mmc_disk_image(uts)); + ut_assertok(write_mmc_blk_device(uts)); + + /* + * Trigger lib/fwu_updates/fwu.c fwu_boottime_checks() + * to populate g_dev global pointer in that library. + */ + ut_assertok(event_notify_null(EVT_POST_PREBOOT)); + + ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev)); + + ut_assertok(fwu_init()); + + ut_assertok(fwu_mdata_get_image_guid(&image_guid, &image_type_guid, 0)); + ut_assertok(guidcmp(&image_guid, &bank_0_image_guid)); + + ut_assertok(fwu_mdata_get_image_guid(&image_guid, &image_type_guid, 1)); + ut_assertok(guidcmp(&image_guid, &bank_1_image_guid)); + + ut_asserteq(-EINVAL, fwu_mdata_get_image_guid(&image_guid, + &image_type_guid, 2)); + + ut_asserteq(-ENOENT, fwu_mdata_get_image_guid(&image_guid, + &wrong_image_type_guid, + 0)); + + return 0; +} +DM_TEST(dm_test_fwu_mdata_get_image_guid, UTF_SCAN_FDT); -- cgit v1.2.3 From 4300f9f4c5d709c86297c8a8702b92af604ed7c3 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Thu, 30 Apr 2026 10:06:09 +0200 Subject: board: st: stm32mp25: 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. To enable A/B bank bootup on stm32mp25 boards, add the following Kconfig options to the stm32mp25_defconfig: CONFIG_FWU_MULTI_BANK_UPDATE=y CONFIG_FWU_MDATA=y CONFIG_FWU_NUM_BANKS=2 CONFIG_FWU_NUM_IMAGES_PER_BANK=3 CONFIG_CMD_FWU_METADATA=y CONFIG_FWU_MDATA_V2=y Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass Reviewed-by: Patrice Chotard --- board/st/stm32mp2/stm32mp2.c | 32 ++++++++++++++++++++++++++++++++ include/configs/stm32mp25_st_common.h | 15 +++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index 43bc583378e..5cbbbc322a3 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -208,4 +208,36 @@ 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]; + int retb, retr; + + fwu_plat_get_bootidx(&boot_idx); + + retb = fwu_mdata_get_image_guid(&boot_uuid, &boot_type_guid, boot_idx); + retr = fwu_mdata_get_image_guid(&root_uuid, &root_type_guid, boot_idx); + + if (!retb && !retr) { + 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); + } else if (!retb && retr) { + log_warning("%s: found boot GUID but missing root GUID (%d)\n", + __func__, retr); + } else if (!retr && retb) { + log_warning("%s: found root GUID but missing boot GUID (%d)\n", + __func__, retb); + } + + 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 cb679eb1be2..0b0267ae99b 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" -- cgit v1.2.3 From 43ba37376b9f6bc2142ce2a9d69f8d96c45812df Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Apr 2026 09:14:20 +0200 Subject: arm/mach-stm32: Remove remaining non-existent STM32_RESET Symbol CONFIG_STM32_RESET does not exist. Don't select it. Signed-off-by: Patrice Chotard Reviewed-by: Quentin Schulz --- arch/arm/mach-stm32mp/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig index b64965d204e..39f25869c1d 100644 --- a/arch/arm/mach-stm32mp/Kconfig +++ b/arch/arm/mach-stm32mp/Kconfig @@ -114,7 +114,6 @@ config STM32MP23X select OF_BOARD select PINCTRL_STM32 select STM32_RCC - select STM32_RESET select STM32_SERIAL select STM32MP_TAMP_NVMEM select SYS_ARCH_TIMER -- cgit v1.2.3 From 612256838acec75407b1a268459c3a9dbb63c7f9 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Tue, 28 Apr 2026 18:10:59 +0200 Subject: reset: stm32: Fix compilation error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following compilation error occurs when environment variable KBUILD_OUTPUT is not set : drivers/reset/stm32/stm32-reset-mp21.c:8:10: fatal error: stm32-reset-core.h: No such file or directory 8 | #include | ^~~~~~~~~~~~~~~~~~~~ As stm32-reset-core.h is located in same directory than stm32-reset-mp21.c, we should use #include "stm32-reset-core.h". Signed-off-by: Patrice Chotard Reviewed-by: Raphaƫl Gallais-Pou --- drivers/reset/stm32/stm32-reset-mp21.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/reset/stm32/stm32-reset-mp21.c b/drivers/reset/stm32/stm32-reset-mp21.c index 7d169d7582f..0e92b0f5d5d 100644 --- a/drivers/reset/stm32/stm32-reset-mp21.c +++ b/drivers/reset/stm32/stm32-reset-mp21.c @@ -5,7 +5,7 @@ */ #include -#include +#include "stm32-reset-core.h" #include #include -- cgit v1.2.3