diff options
Diffstat (limited to 'disk/part_efi.c')
-rw-r--r-- | disk/part_efi.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/disk/part_efi.c b/disk/part_efi.c index 0ac9ea6d9b..4f403d2e0e 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -333,6 +333,62 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, return 0; } +#if defined(CONFIG_DUAL_BOOTLOADER) && defined(CONFIG_SPL_BUILD) +int part_get_info_efi_by_name(struct blk_desc *dev_desc, const char *name, + disk_partition_t *info) +{ + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); + /* We don't free gpt_pte because the memory is allocated at + * CONFIG_SYS_SPL_PTE_RAM_BASE due to the limited memory at + * SPL stage. + */ + gpt_entry *gpt_pte = NULL; + int i = 0; + + if (name == NULL) { + printf("%s: Invalid Argument(s)\n", __func__); + return -1; + } + + /* This function validates AND fills in the GPT header and PTE */ + if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + return -1; + + /* Search PTE to find matched partition. */ + for (i = 0; i < le32_to_cpu(gpt_head->num_partition_entries); i++) { + if (is_pte_valid(&gpt_pte[i]) && + strcmp(name, print_efiname(&gpt_pte[i])) == 0) { + /* Matched partition found, copy it. */ + /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */ + info->start = (lbaint_t)le64_to_cpu(gpt_pte[i].starting_lba); + /* The ending LBA is inclusive, to calculate size, add 1 to it */ + info->size = (lbaint_t)le64_to_cpu(gpt_pte[i].ending_lba) + 1 + - info->start; + info->blksz = dev_desc->blksz; + + snprintf((char *)info->name, sizeof(info->name), "%s", name); + strcpy((char *)info->type, "U-Boot"); + info->bootable = is_bootable(&gpt_pte[i]); +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + uuid_bin_to_str(gpt_pte[i].unique_partition_guid.b, info->uuid, + UUID_STR_FORMAT_GUID); +#endif +#ifdef CONFIG_PARTITION_TYPE_GUID + uuid_bin_to_str(gpt_pte[i].partition_type_guid.b, + info->type_guid, UUID_STR_FORMAT_GUID); +#endif + + debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s\n", __func__, + info->start, info->size, info->name); + + return i; + } + } + + return -1; +} +#endif /* CONFIG_DUAL_BOOTLOADER && CONFIG_SPL_BUILD */ + static int part_test_efi(struct blk_desc *dev_desc) { ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); |