fix(guid-partition): fix MBR header load
In the case of GPT, the UEFI specification requires that the PMBR
(Protective MBR) partition table contain one partition record, which
starts at LBA 1, containing the GPT Header. Hence, the field 'first_lba'
of the first partition table entry of the PMBR should always be set to 1
when GPT is used. However, this is not the case for plain MBR.
The function load_mbr_header() should also work for plain MBR
partitioning, so the check 'if (tmp.first_lba != 1)' has been relocated.
Change-Id: Iad990e61b2186c21f942537dfd140ed0e023ac4c
Signed-off-by: Bogdan Roman <bogdan-gabriel.roman@nxp.com>
Signed-off-by: Ghennadi Procopciuc <ghennadi.procopciuc@nxp.com>
diff --git a/drivers/partition/partition.c b/drivers/partition/partition.c
index 387469c..564d29d 100644
--- a/drivers/partition/partition.c
+++ b/drivers/partition/partition.c
@@ -75,11 +75,6 @@
memcpy(&tmp, mbr_sector + MBR_PRIMARY_ENTRY_OFFSET, sizeof(tmp));
- if (tmp.first_lba != 1) {
- VERBOSE("MBR header may have an invalid first LBA\n");
- return -EINVAL;
- }
-
if ((tmp.sector_nums == 0) || (tmp.sector_nums == UINT32_MAX)) {
VERBOSE("MBR header entry has an invalid number of sectors\n");
return -EINVAL;
@@ -421,6 +416,11 @@
goto out;
}
if (mbr_entry.type == PARTITION_TYPE_GPT) {
+ if (mbr_entry.first_lba != 1U) {
+ VERBOSE("MBR header may have an invalid first LBA\n");
+ return -EINVAL;
+ }
+
result = load_primary_gpt(image_handle, mbr_entry.first_lba);
if (result != 0) {
io_close(image_handle);