aboutsummaryrefslogtreecommitdiffstats
path: root/disk
diff options
context:
space:
mode:
authorPeter Jones2017-09-13 17:05:25 -0500
committerAlexander Graf2017-09-20 03:20:19 -0500
commitff98cb90514d9b787ddc097c203ac8db2941efe1 (patch)
tree18c1894c6eb53cd60889d6044a87f9b1f81a8afe /disk
parent0d6ab32e3712fe7bc2e3aaf3d93e0d5910264df3 (diff)
downloadu-boot-ff98cb90514d9b787ddc097c203ac8db2941efe1.tar.gz
u-boot-ff98cb90514d9b787ddc097c203ac8db2941efe1.tar.xz
u-boot-ff98cb90514d9b787ddc097c203ac8db2941efe1.zip
part: extract MBR signature from partitions
EFI client programs need the signature information from the partition table to determine the disk a partition is on, so we need to fill that in here. Signed-off-by: Peter Jones <pjones@redhat.com> [separated from efi_loader part, and fixed build-errors for non- CONFIG_EFI_PARTITION case] Signed-off-by: Rob Clark <robdclark@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'disk')
-rw-r--r--disk/part_dos.c12
-rw-r--r--disk/part_efi.c20
2 files changed, 29 insertions, 3 deletions
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 7aff73d6f8..1a36be0446 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -89,14 +89,20 @@ static int test_block_type(unsigned char *buffer)
89 89
90static int part_test_dos(struct blk_desc *dev_desc) 90static int part_test_dos(struct blk_desc *dev_desc)
91{ 91{
92 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); 92 ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
93 93
94 if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1) 94 if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1)
95 return -1; 95 return -1;
96 96
97 if (test_block_type(buffer) != DOS_MBR) 97 if (test_block_type((unsigned char *)mbr) != DOS_MBR)
98 return -1; 98 return -1;
99 99
100 if (dev_desc->sig_type == SIG_TYPE_NONE &&
101 mbr->unique_mbr_signature != 0) {
102 dev_desc->sig_type = SIG_TYPE_MBR;
103 dev_desc->mbr_sig = mbr->unique_mbr_signature;
104 }
105
100 return 0; 106 return 0;
101} 107}
102 108
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 2973d52f6a..208bb14ee8 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -923,11 +923,19 @@ static int is_pmbr_valid(legacy_mbr * mbr)
923static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, 923static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
924 gpt_header *pgpt_head, gpt_entry **pgpt_pte) 924 gpt_header *pgpt_head, gpt_entry **pgpt_pte)
925{ 925{
926 ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
927
926 if (!dev_desc || !pgpt_head) { 928 if (!dev_desc || !pgpt_head) {
927 printf("%s: Invalid Argument(s)\n", __func__); 929 printf("%s: Invalid Argument(s)\n", __func__);
928 return 0; 930 return 0;
929 } 931 }
930 932
933 /* Read MBR Header from device */
934 if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) {
935 printf("*** ERROR: Can't read MBR header ***\n");
936 return 0;
937 }
938
931 /* Read GPT Header from device */ 939 /* Read GPT Header from device */
932 if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) { 940 if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) {
933 printf("*** ERROR: Can't read GPT header ***\n"); 941 printf("*** ERROR: Can't read GPT header ***\n");
@@ -937,6 +945,18 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
937 if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) 945 if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba))
938 return 0; 946 return 0;
939 947
948 if (dev_desc->sig_type == SIG_TYPE_NONE) {
949 efi_guid_t empty = {};
950 if (memcmp(&pgpt_head->disk_guid, &empty, sizeof(empty))) {
951 dev_desc->sig_type = SIG_TYPE_GUID;
952 memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid,
953 sizeof(empty));
954 } else if (mbr->unique_mbr_signature != 0) {
955 dev_desc->sig_type = SIG_TYPE_MBR;
956 dev_desc->mbr_sig = mbr->unique_mbr_signature;
957 }
958 }
959
940 /* Read and allocate Partition Table Entries */ 960 /* Read and allocate Partition Table Entries */
941 *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head); 961 *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head);
942 if (*pgpt_pte == NULL) { 962 if (*pgpt_pte == NULL) {