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"; }; 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/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/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/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" diff --git a/disk/part.c b/disk/part.c index eec02f58988d..950a342602b3 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 @@ -704,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/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/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/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/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} " \ 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" \ 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" diff --git a/include/fwu.h b/include/fwu.h index 77ec65e61807..1f6a814906d3 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 * @@ -384,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/include/part.h b/include/part.h index 8e451bbdff94..7ad5b3048c3a 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; @@ -222,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 @@ -294,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, 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/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index f5e0315b796f..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 @@ -629,6 +653,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 +720,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 +779,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); 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) {