mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-30 17:14:07 +02:00
MdeModulePkg DxeCore: Check FvImage alignment
No need to allocate aligned buffer if FvImage has been at required alignment. Then the code logic will be aligned with ProcessFvFile() in MdeModulePkg/Core/Pei/FwVol/FwVol.c. Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
56c909f3b3
commit
5d0b4eb453
@ -1023,32 +1023,38 @@ CoreProcessFvImageFile (
|
|||||||
// can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
|
// can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
|
||||||
// its initial linked location and maintain its alignment.
|
// its initial linked location and maintain its alignment.
|
||||||
//
|
//
|
||||||
if ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
|
if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
|
||||||
//
|
//
|
||||||
// Get FvHeader alignment
|
// Get FvHeader alignment
|
||||||
//
|
//
|
||||||
FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
|
FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);
|
||||||
//
|
//
|
||||||
// FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
|
// FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
|
||||||
//
|
//
|
||||||
if (FvAlignment < 8) {
|
if (FvAlignment < 8) {
|
||||||
FvAlignment = 8;
|
FvAlignment = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate the aligned buffer for the FvImage.
|
// Check FvImage alignment.
|
||||||
//
|
//
|
||||||
AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);
|
if ((UINTN) FvHeader % FvAlignment != 0) {
|
||||||
if (AlignedBuffer == NULL) {
|
|
||||||
FreePool (Buffer);
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
} else {
|
|
||||||
//
|
//
|
||||||
// Move FvImage into the aligned buffer and release the original buffer.
|
// Allocate the aligned buffer for the FvImage.
|
||||||
//
|
//
|
||||||
CopyMem (AlignedBuffer, Buffer, BufferSize);
|
AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);
|
||||||
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;
|
if (AlignedBuffer == NULL) {
|
||||||
CoreFreePool (Buffer);
|
FreePool (Buffer);
|
||||||
Buffer = NULL;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
// Move FvImage into the aligned buffer and release the original buffer.
|
||||||
|
//
|
||||||
|
CopyMem (AlignedBuffer, Buffer, BufferSize);
|
||||||
|
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;
|
||||||
|
CoreFreePool (Buffer);
|
||||||
|
Buffer = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user