summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
Diffstat (limited to 'disk')
-rw-r--r--disk/part.c15
-rw-r--r--disk/part_dos.c18
-rw-r--r--disk/part_efi.c31
-rw-r--r--disk/part_iso.c4
4 files changed, 58 insertions, 10 deletions
diff --git a/disk/part.c b/disk/part.c
index aa9183d696..66b8101f98 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -21,6 +21,9 @@
#define PRINTF(fmt,args...)
#endif
+/* Check all partition types */
+#define PART_TYPE_ALL -1
+
DECLARE_GLOBAL_DATA_PTR;
#ifdef HAVE_BLOCK_DEVICE
@@ -626,8 +629,8 @@ cleanup:
return ret;
}
-int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
- disk_partition_t *info)
+int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
+ disk_partition_t *info, int part_type)
{
struct part_driver *first_drv =
ll_entry_start(struct part_driver, part_driver);
@@ -638,6 +641,8 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
int ret;
int i;
for (i = 1; i < part_drv->max_entries; i++) {
+ if (part_type >= 0 && part_type != part_drv->part_type)
+ break;
ret = part_drv->get_info(dev_desc, i, info);
if (ret != 0) {
/* no more entries in table */
@@ -652,6 +657,12 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
return -1;
}
+int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
+ disk_partition_t *info)
+{
+ return part_get_info_by_name_type(dev_desc, name, info, PART_TYPE_ALL);
+}
+
void part_set_generic_name(const struct blk_desc *dev_desc,
int part_num, char *name)
{
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 7ede15ec26..6dd2c2d147 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -44,7 +44,7 @@ static inline int is_extended(int part_type)
static inline int is_bootable(dos_partition_t *p)
{
- return p->boot_ind == 0x80;
+ return (p->sys_ind == 0xef) || (p->boot_ind == 0x80);
}
static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
@@ -89,6 +89,21 @@ static int test_block_type(unsigned char *buffer)
static int part_test_dos(struct blk_desc *dev_desc)
{
+#ifndef CONFIG_SPL_BUILD
+ ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
+
+ if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1)
+ return -1;
+
+ if (test_block_type((unsigned char *)mbr) != DOS_MBR)
+ return -1;
+
+ if (dev_desc->sig_type == SIG_TYPE_NONE &&
+ mbr->unique_mbr_signature != 0) {
+ dev_desc->sig_type = SIG_TYPE_MBR;
+ dev_desc->mbr_sig = mbr->unique_mbr_signature;
+ }
+#else
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
@@ -96,6 +111,7 @@ static int part_test_dos(struct blk_desc *dev_desc)
if (test_block_type(buffer) != DOS_MBR)
return -1;
+#endif
return 0;
}
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 2973d52f6a..782f8be502 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -360,7 +360,7 @@ static int set_protective_mbr(struct blk_desc *dev_desc)
/* Read MBR to backup boot code if it exists */
if (blk_dread(dev_desc, 0, 1, p_mbr) != 1) {
- error("** Can't read from device %d **\n", dev_desc->devnum);
+ pr_err("** Can't read from device %d **\n", dev_desc->devnum);
return -1;
}
@@ -716,7 +716,7 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,
for (i = 0; i < parts; i++) {
if (i == gpt_head->num_partition_entries) {
- error("More partitions than allowed!\n");
+ pr_err("More partitions than allowed!\n");
return -1;
}
@@ -729,7 +729,7 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,
if (strncmp(efi_str, (char *)partitions[i].name,
sizeof(partitions->name))) {
- error("Partition name: %s does not match %s!\n",
+ pr_err("Partition name: %s does not match %s!\n",
efi_str, (char *)partitions[i].name);
return -1;
}
@@ -746,7 +746,7 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,
if ((i == parts - 1) && (partitions[i].size == 0))
continue;
- error("Partition %s size: %llu does not match %llu!\n",
+ pr_err("Partition %s size: %llu does not match %llu!\n",
efi_str, (unsigned long long)gpt_part_size,
(unsigned long long)partitions[i].size);
return -1;
@@ -767,7 +767,7 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,
(unsigned long long)partitions[i].start);
if (le64_to_cpu(gpt_e[i].starting_lba) != partitions[i].start) {
- error("Partition %s start: %llu does not match %llu!\n",
+ pr_err("Partition %s start: %llu does not match %llu!\n",
efi_str, le64_to_cpu(gpt_e[i].starting_lba),
(unsigned long long)partitions[i].start);
return -1;
@@ -923,11 +923,20 @@ static int is_pmbr_valid(legacy_mbr * mbr)
static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
gpt_header *pgpt_head, gpt_entry **pgpt_pte)
{
+ /* Confirm valid arguments prior to allocation. */
if (!dev_desc || !pgpt_head) {
printf("%s: Invalid Argument(s)\n", __func__);
return 0;
}
+ ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
+
+ /* Read MBR Header from device */
+ if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) {
+ printf("*** ERROR: Can't read MBR header ***\n");
+ return 0;
+ }
+
/* Read GPT Header from device */
if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) {
printf("*** ERROR: Can't read GPT header ***\n");
@@ -937,6 +946,18 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba))
return 0;
+ if (dev_desc->sig_type == SIG_TYPE_NONE) {
+ efi_guid_t empty = {};
+ if (memcmp(&pgpt_head->disk_guid, &empty, sizeof(empty))) {
+ dev_desc->sig_type = SIG_TYPE_GUID;
+ memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid,
+ sizeof(empty));
+ } else if (mbr->unique_mbr_signature != 0) {
+ dev_desc->sig_type = SIG_TYPE_MBR;
+ dev_desc->mbr_sig = mbr->unique_mbr_signature;
+ }
+ }
+
/* Read and allocate Partition Table Entries */
*pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head);
if (*pgpt_pte == NULL) {
diff --git a/disk/part_iso.c b/disk/part_iso.c
index 8aef251f4e..4036b00b25 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -202,7 +202,7 @@ found:
static int part_get_info_iso(struct blk_desc *dev_desc, int part_num,
disk_partition_t *info)
{
- return part_get_info_iso_verb(dev_desc, part_num, info, 1);
+ return part_get_info_iso_verb(dev_desc, part_num, info, 0);
}
static void part_print_iso(struct blk_desc *dev_desc)
@@ -228,7 +228,7 @@ static int part_test_iso(struct blk_desc *dev_desc)
{
disk_partition_t info;
- return part_get_info_iso_verb(dev_desc, 1, &info, 1);
+ return part_get_info_iso_verb(dev_desc, 1, &info, 0);
}
U_BOOT_PART_TYPE(iso) = {