mirror of https://github.com/acidanthera/audk.git
88 lines
3.2 KiB
Diff
Executable File
88 lines
3.2 KiB
Diff
Executable File
diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
|
|
old mode 100644
|
|
new mode 100755
|
|
index 189dc43..af47709
|
|
--- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c
|
|
+++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
|
|
@@ -505,6 +505,7 @@ Returns:
|
|
|
|
EFI_STATUS
|
|
AddPadFile (
|
|
+ IN FV_INFO *FvInfo,
|
|
IN OUT MEMORY_FILE *FvImage,
|
|
IN UINT32 DataAlignment,
|
|
IN VOID *FvEnd,
|
|
@@ -536,6 +537,8 @@ Returns:
|
|
{
|
|
EFI_FFS_FILE_HEADER *PadFile;
|
|
UINTN PadFileSize;
|
|
+ UINTN PadFileOffset;
|
|
+ UINTN ExtHeaderSize;
|
|
|
|
//
|
|
// Verify input parameters.
|
|
@@ -558,32 +561,29 @@ Returns:
|
|
// This is the earliest possible valid offset (current plus pad file header
|
|
// plus the next file header)
|
|
//
|
|
- PadFileSize = (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage + (sizeof (EFI_FFS_FILE_HEADER) * 2);
|
|
+ // The padding is added into its own FFS file (which requires a header) added before the aligned file:
|
|
+ // | ... FV data before AlignedFile ... | Pad File FFS Header | Padding | AlignedFile FFS Header (+ ExtHeader) | AlignedData
|
|
|
|
//
|
|
- // Add whatever it takes to get to the next aligned address
|
|
+ // Calculate the Offset of the Pad File from the beginning of the FV file
|
|
//
|
|
- while ((PadFileSize % DataAlignment) != 0) {
|
|
- PadFileSize++;
|
|
- }
|
|
- //
|
|
- // Subtract the next file header size
|
|
- //
|
|
- PadFileSize -= sizeof (EFI_FFS_FILE_HEADER);
|
|
-
|
|
- //
|
|
- // Subtract the starting offset to get size
|
|
- //
|
|
- PadFileSize -= (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage;
|
|
+ PadFileOffset = (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage;
|
|
|
|
//
|
|
- // Append extension header size
|
|
+ // Get the size of the extension header if exists
|
|
//
|
|
if (ExtHeader != NULL) {
|
|
- PadFileSize = PadFileSize + ExtHeader->ExtHeaderSize;
|
|
+ ExtHeaderSize = ExtHeader->ExtHeaderSize;
|
|
+ } else {
|
|
+ ExtHeaderSize = 0;
|
|
}
|
|
|
|
//
|
|
+ // Calculate the Size of the Padding to ensure the alignment of the data of the Next file
|
|
+ //
|
|
+ PadFileSize = DataAlignment - ((FvInfo->BaseAddress + PadFileOffset + sizeof (EFI_FFS_FILE_HEADER) + ExtHeaderSize) & (DataAlignment - 1));
|
|
+
|
|
+ //
|
|
// Verify that we have enough space for the file header
|
|
//
|
|
if (((UINTN) FvImage->CurrentFilePointer + PadFileSize) > (UINTN) FvEnd) {
|
|
@@ -1110,7 +1110,7 @@ Returns:
|
|
//
|
|
// Add pad file if necessary
|
|
//
|
|
- Status = AddPadFile (FvImage, 1 << CurrentFileAlignment, *VtfFileImage, NULL);
|
|
+ Status = AddPadFile (FvInfo, FvImage, 1 << CurrentFileAlignment, *VtfFileImage, NULL);
|
|
if (EFI_ERROR (Status)) {
|
|
Error (NULL, 0, 4002, "Resource", "FV space is full, could not add pad file for data alignment property.");
|
|
free (FileBuffer);
|
|
@@ -2295,7 +2295,7 @@ Returns:
|
|
//
|
|
// Add FV Extended Header contents to the FV as a PAD file
|
|
//
|
|
- AddPadFile (&FvImageMemoryFile, 4, VtfFileImage, FvExtHeader);
|
|
+ AddPadFile (&mFvDataInfo, &FvImageMemoryFile, 4, VtfFileImage, FvExtHeader);
|
|
|
|
//
|
|
// Fv Extension header change update Fv Header Check sum
|