Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions arch/arm/dts/stm32mp157f-dk2-u-boot.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
27 changes: 27 additions & 0 deletions board/st/stm32mp1/stm32mp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

27 changes: 27 additions & 0 deletions board/st/stm32mp2/stm32mp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

10 changes: 4 additions & 6 deletions cmd/gpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions cmd/part.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <interface> <dev> <part> <varname>\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 <interface> <dev>:<part>\n"
" - print partition type\n"
Expand Down
47 changes: 41 additions & 6 deletions disk/part.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
17 changes: 8 additions & 9 deletions disk/part_dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
31 changes: 16 additions & 15 deletions disk/part_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions doc/README.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
4 changes: 1 addition & 3 deletions fs/fat/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion include/config_distro_bootcmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} " \
Expand Down
15 changes: 15 additions & 0 deletions include/configs/stm32mp15_st_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
15 changes: 15 additions & 0 deletions include/configs/stm32mp25_st_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
14 changes: 14 additions & 0 deletions include/fwu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
Loading