diff options
Diffstat (limited to 'disk')
-rw-r--r-- | disk/part.c | 40 | ||||
-rw-r--r-- | disk/part_amiga.c | 1 | ||||
-rw-r--r-- | disk/part_dos.c | 3 | ||||
-rw-r--r-- | disk/part_efi.c | 68 | ||||
-rw-r--r-- | disk/part_mac.c | 1 |
5 files changed, 80 insertions, 33 deletions
diff --git a/disk/part.c b/disk/part.c index 303178161c0..66e2b3a7219 100644 --- a/disk/part.c +++ b/disk/part.c @@ -8,7 +8,6 @@ #include <command.h> #include <env.h> #include <errno.h> -#include <ide.h> #include <log.h> #include <malloc.h> #include <part.h> @@ -698,6 +697,45 @@ int part_get_info_by_name(struct blk_desc *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_amiga.c b/disk/part_amiga.c index 5b8ae5762d3..22bf99f1b88 100644 --- a/disk/part_amiga.c +++ b/disk/part_amiga.c @@ -6,7 +6,6 @@ */ #include <command.h> #include <env.h> -#include <ide.h> #include "part_amiga.h" #include <part.h> #include <vsprintf.h> diff --git a/disk/part_dos.c b/disk/part_dos.c index 96f748702fd..18dd35c9b98 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -15,7 +15,6 @@ #include <blk.h> #include <command.h> -#include <ide.h> #include <memalign.h> #include <vsprintf.h> #include <asm/unaligned.h> @@ -422,7 +421,7 @@ int write_mbr_partitions(struct blk_desc *dev, /* write EBR */ if (blk_dwrite(dev, ext_part_sect, 1, buffer) != 1) { - printf("%s: failed writing 'EBR' (1 blks at 0x%lx)\n", + printf("%s: failed writing 'EBR' (1 blks at 0x" LBAF ")\n", __func__, ext_part_sect); return -1; } diff --git a/disk/part_efi.c b/disk/part_efi.c index 932d058c184..fb1ed534f86 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -21,7 +21,6 @@ #include <asm/unaligned.h> #include <command.h> #include <fdtdec.h> -#include <ide.h> #include <malloc.h> #include <memalign.h> #include <part_efi.h> @@ -216,6 +215,34 @@ int get_disk_guid(struct blk_desc *desc, char *guid) return 0; } +int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e) +{ + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); + gpt_entry *gpt_pte = NULL; + + /* "part" argument must be at least 1 */ + if (part < 1) { + log_debug("Invalid Argument(s)\n"); + return -EINVAL; + } + + /* This function validates AND fills in the GPT header and PTE */ + if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) + return -EINVAL; + + if (part > le32_to_cpu(gpt_head->num_partition_entries) || + !is_pte_valid(&gpt_pte[part - 1])) { + log_debug("Invalid partition number %d\n", part); + free(gpt_pte); + return -EPERM; + } + + memcpy(gpt_e, &gpt_pte[part - 1], sizeof(*gpt_e)); + + free(gpt_pte); + return 0; +} + static void __maybe_unused part_print_efi(struct blk_desc *desc) { ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); @@ -261,45 +288,32 @@ static void __maybe_unused part_print_efi(struct blk_desc *desc) static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, struct disk_partition *info) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); - gpt_entry *gpt_pte = NULL; - - /* "part" argument must be at least 1 */ - if (part < 1) { - log_debug("Invalid Argument(s)\n"); - return -EINVAL; - } - - /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) - return -EINVAL; + gpt_entry gpt_pte = {}; + int ret; - if (part > le32_to_cpu(gpt_head->num_partition_entries) || - !is_pte_valid(&gpt_pte[part - 1])) { - log_debug("Invalid partition number %d\n", part); - free(gpt_pte); - return -EPERM; - } + ret = part_get_gpt_pte(desc, part, &gpt_pte); + if (ret) + return ret; /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */ - info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba); + info->start = (lbaint_t)le64_to_cpu(gpt_pte.starting_lba); /* The ending LBA is inclusive, to calculate size, add 1 to it */ - info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1 + info->size = (lbaint_t)le64_to_cpu(gpt_pte.ending_lba) + 1 - info->start; info->blksz = desc->blksz; snprintf((char *)info->name, sizeof(info->name), "%s", - print_efiname(&gpt_pte[part - 1])); + print_efiname(&gpt_pte)); strcpy((char *)info->type, "U-Boot"); - info->bootable = get_bootable(&gpt_pte[part - 1]); - info->type_flags = gpt_pte[part - 1].attributes.fields.type_guid_specific; + info->bootable = get_bootable(&gpt_pte); + info->type_flags = gpt_pte.attributes.fields.type_guid_specific; if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { - uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, + uuid_bin_to_str(gpt_pte.unique_partition_guid.b, (char *)disk_partition_uuid(info), UUID_STR_FORMAT_GUID); } if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { - uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, + uuid_bin_to_str(gpt_pte.partition_type_guid.b, (char *)disk_partition_type_guid(info), UUID_STR_FORMAT_GUID); } @@ -307,8 +321,6 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start, info->size, info->name); - /* Remember to free pte */ - free(gpt_pte); return 0; } diff --git a/disk/part_mac.c b/disk/part_mac.c index 21c85942fd8..dd3ce0be832 100644 --- a/disk/part_mac.c +++ b/disk/part_mac.c @@ -15,7 +15,6 @@ #include <command.h> #include <log.h> #include <memalign.h> -#include <ide.h> #include "part_mac.h" #include <part.h> |