mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-27 23:54:02 +02:00
Move sure FvImage buffer at its alignment when install FVB protocol on it.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4380 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
3d5c59747e
commit
38837959db
@ -859,14 +859,20 @@ Returns:
|
|||||||
EFI_SECTION_TYPE SectionType;
|
EFI_SECTION_TYPE SectionType;
|
||||||
UINT32 AuthenticationStatus;
|
UINT32 AuthenticationStatus;
|
||||||
VOID *Buffer;
|
VOID *Buffer;
|
||||||
|
VOID *AlignedBuffer;
|
||||||
UINTN BufferSize;
|
UINTN BufferSize;
|
||||||
|
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
|
||||||
|
UINT32 FvAlignment;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read the first (and only the first) firmware volume section
|
// Read the first (and only the first) firmware volume section
|
||||||
//
|
//
|
||||||
SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;
|
SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;
|
||||||
|
FvHeader = NULL;
|
||||||
|
FvAlignment = 0;
|
||||||
Buffer = NULL;
|
Buffer = NULL;
|
||||||
BufferSize = 0;
|
BufferSize = 0;
|
||||||
|
AlignedBuffer = NULL;
|
||||||
Status = Fv->ReadSection (
|
Status = Fv->ReadSection (
|
||||||
Fv,
|
Fv,
|
||||||
DriverName,
|
DriverName,
|
||||||
@ -878,22 +884,50 @@ Returns:
|
|||||||
);
|
);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
//
|
//
|
||||||
// Produce a FVB protocol for the file
|
// FvImage should be at its required alignment.
|
||||||
//
|
//
|
||||||
Status = ProduceFVBProtocolOnBuffer (
|
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;
|
||||||
(EFI_PHYSICAL_ADDRESS) (UINTN) Buffer,
|
FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
|
||||||
(UINT64)BufferSize,
|
//
|
||||||
FvHandle,
|
// FvAlignment must be more than 8 bytes required by FvHeader structure.
|
||||||
NULL
|
//
|
||||||
);
|
if (FvAlignment < 8) {
|
||||||
|
FvAlignment = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlignedBuffer = AllocateAlignedPool ((UINTN) BufferSize, (UINTN) FvAlignment);
|
||||||
|
if (AlignedBuffer == NULL) {
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
// Move FvImage into the aligned buffer and release the original buffer.
|
||||||
|
//
|
||||||
|
CopyMem (AlignedBuffer, Buffer, BufferSize);
|
||||||
|
CoreFreePool (Buffer);
|
||||||
|
Buffer = NULL;
|
||||||
|
//
|
||||||
|
// Produce a FVB protocol for the file
|
||||||
|
//
|
||||||
|
Status = ProduceFVBProtocolOnBuffer (
|
||||||
|
(EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,
|
||||||
|
(UINT64)BufferSize,
|
||||||
|
FvHandle,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status) && (Buffer != NULL)) {
|
if (EFI_ERROR (Status)) {
|
||||||
//
|
//
|
||||||
// ReadSection or Produce FVB failed, Free data buffer
|
// ReadSection or Produce FVB failed, Free data buffer
|
||||||
//
|
//
|
||||||
CoreFreePool (Buffer);
|
if (Buffer != NULL) {
|
||||||
|
CoreFreePool (Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AlignedBuffer != NULL) {
|
||||||
|
FreeAlignedPool (AlignedBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
|
@ -413,8 +413,10 @@ Returns:
|
|||||||
UINTN BlockIndex;
|
UINTN BlockIndex;
|
||||||
UINTN BlockIndex2;
|
UINTN BlockIndex2;
|
||||||
UINTN LinearOffset;
|
UINTN LinearOffset;
|
||||||
|
UINT32 FvAlignment;
|
||||||
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
|
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
|
||||||
|
|
||||||
|
FvAlignment = 0;
|
||||||
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress;
|
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress;
|
||||||
//
|
//
|
||||||
// Validate FV Header, if not as expected, return
|
// Validate FV Header, if not as expected, return
|
||||||
@ -423,6 +425,19 @@ Returns:
|
|||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
// Get FvHeader alignment
|
||||||
|
//
|
||||||
|
FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
|
||||||
|
if (FvAlignment < 8) {
|
||||||
|
FvAlignment = 8;
|
||||||
|
}
|
||||||
|
if ((UINTN)BaseAddress % FvAlignment != 0) {
|
||||||
|
//
|
||||||
|
// FvImage buffer is not at its required alignment.
|
||||||
|
//
|
||||||
|
return EFI_VOLUME_CORRUPTED;
|
||||||
|
}
|
||||||
|
//
|
||||||
// Allocate EFI_FW_VOL_BLOCK_DEVICE
|
// Allocate EFI_FW_VOL_BLOCK_DEVICE
|
||||||
//
|
//
|
||||||
FvbDev = CoreAllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);
|
FvbDev = CoreAllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user