Skip to content

Commit e12a8d8

Browse files
linjaso1mergify[bot]
authored andcommitted
FatPkg/FatPei: Simplify the GPT Header Check
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4860 - The condition of GPT header checking is mismatched between PEI FatPei module in FatPkg and DXE PartitionDxe module in MdeModulePkg. - This patch is intended to simplify the checking condition within FatPei module to align with PartitionDxe module to reduce code flow gap between both of them. - Below of condition would be checked on GPT header, 1. GPT header signature value 2. GPT header CRC value 3. GPT header LBA value 4. GPT header size of partition entry Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
1 parent ef4f3aa commit e12a8d8

File tree

1 file changed

+4
-36
lines changed

1 file changed

+4
-36
lines changed

FatPkg/FatPei/Gpt.c

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ PartitionCheckGptHeader (
110110
{
111111
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
112112
EFI_PEI_LBA Lba;
113-
EFI_PEI_LBA AlternateLba;
114113
EFI_PEI_LBA EntryArrayLastLba;
115114

116115
UINT64 PartitionEntryArraySize;
@@ -120,46 +119,15 @@ PartitionCheckGptHeader (
120119
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
121120

122121
if (IsPrimaryHeader) {
123-
Lba = PRIMARY_PART_HEADER_LBA;
124-
AlternateLba = ParentBlockDev->LastBlock;
122+
Lba = PRIMARY_PART_HEADER_LBA;
125123
} else {
126-
Lba = ParentBlockDev->LastBlock;
127-
AlternateLba = PRIMARY_PART_HEADER_LBA;
124+
Lba = ParentBlockDev->LastBlock;
128125
}
129126

130127
if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
131-
(PartHdr->Header.Revision != 0x00010000) ||
132-
(PartHdr->Header.HeaderSize < 92) ||
133-
(PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
134128
(!PartitionCheckGptHeaderCRC (PartHdr)) ||
135-
(PartHdr->Header.Reserved != 0)
136-
)
137-
{
138-
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
139-
return FALSE;
140-
}
141-
142-
//
143-
// | Block0 | Block1 |Block2 ~ FirstUsableLBA - 1|FirstUsableLBA, ... ,LastUsableLBA|LastUsableLBA+1 ~ LastBlock-1| LastBlock |
144-
// |Protective MBR|Primary Header|Entry Array(At Least 16384)| Partition | Entry Array(At Least 16384) |BackUp Header|
145-
//
146-
// 1. Protective MBR is fixed at Block 0.
147-
// 2. Primary Header is fixed at Block 1.
148-
// 3. Backup Header is fixed at LastBlock.
149-
// 4. Must be remain 128*128 bytes for primary entry array.
150-
// 5. Must be remain 128*128 bytes for backup entry array.
151-
// 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
152-
//
153-
if ((PartHdr->MyLBA != Lba) ||
154-
(PartHdr->AlternateLBA != AlternateLba) ||
155-
(PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
156-
(PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
157-
(PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
158-
(PartHdr->PartitionEntryLBA < 2) ||
159-
(PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
160-
((PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA) && (PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA)) ||
161-
(PartHdr->SizeOfPartitionEntry%128 != 0) ||
162-
(PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
129+
(PartHdr->MyLBA != Lba) ||
130+
(PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY))
163131
)
164132
{
165133
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));

0 commit comments

Comments
 (0)