]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Documentation/patches/BaseTools-GenFv-Calculate-Alignment-From-Fv-Offset.patch
ArmPlatformPkg: Update the list of the BaseTools pending patches and the documentation
[mirror_edk2.git] / ArmPlatformPkg / Documentation / patches / BaseTools-GenFv-Calculate-Alignment-From-Fv-Offset.patch
1 diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
2 old mode 100644
3 new mode 100755
4 index 189dc43..af47709
5 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c
6 +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
7 @@ -505,6 +505,7 @@ Returns:
8
9 EFI_STATUS
10 AddPadFile (
11 + IN FV_INFO *FvInfo,
12 IN OUT MEMORY_FILE *FvImage,
13 IN UINT32 DataAlignment,
14 IN VOID *FvEnd,
15 @@ -536,6 +537,8 @@ Returns:
16 {
17 EFI_FFS_FILE_HEADER *PadFile;
18 UINTN PadFileSize;
19 + UINTN PadFileOffset;
20 + UINTN ExtHeaderSize;
21
22 //
23 // Verify input parameters.
24 @@ -558,32 +561,29 @@ Returns:
25 // This is the earliest possible valid offset (current plus pad file header
26 // plus the next file header)
27 //
28 - PadFileSize = (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage + (sizeof (EFI_FFS_FILE_HEADER) * 2);
29 + // The padding is added into its own FFS file (which requires a header) added before the aligned file:
30 + // | ... FV data before AlignedFile ... | Pad File FFS Header | Padding | AlignedFile FFS Header (+ ExtHeader) | AlignedData
31
32 //
33 - // Add whatever it takes to get to the next aligned address
34 + // Calculate the Offset of the Pad File from the beginning of the FV file
35 //
36 - while ((PadFileSize % DataAlignment) != 0) {
37 - PadFileSize++;
38 - }
39 - //
40 - // Subtract the next file header size
41 - //
42 - PadFileSize -= sizeof (EFI_FFS_FILE_HEADER);
43 -
44 - //
45 - // Subtract the starting offset to get size
46 - //
47 - PadFileSize -= (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage;
48 + PadFileOffset = (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage;
49
50 //
51 - // Append extension header size
52 + // Get the size of the extension header if exists
53 //
54 if (ExtHeader != NULL) {
55 - PadFileSize = PadFileSize + ExtHeader->ExtHeaderSize;
56 + ExtHeaderSize = ExtHeader->ExtHeaderSize;
57 + } else {
58 + ExtHeaderSize = 0;
59 }
60
61 //
62 + // Calculate the Size of the Padding to ensure the alignment of the data of the Next file
63 + //
64 + PadFileSize = DataAlignment - ((FvInfo->BaseAddress + PadFileOffset + sizeof (EFI_FFS_FILE_HEADER) + ExtHeaderSize) & (DataAlignment - 1));
65 +
66 + //
67 // Verify that we have enough space for the file header
68 //
69 if (((UINTN) FvImage->CurrentFilePointer + PadFileSize) > (UINTN) FvEnd) {
70 @@ -1110,7 +1110,7 @@ Returns:
71 //
72 // Add pad file if necessary
73 //
74 - Status = AddPadFile (FvImage, 1 << CurrentFileAlignment, *VtfFileImage, NULL);
75 + Status = AddPadFile (FvInfo, FvImage, 1 << CurrentFileAlignment, *VtfFileImage, NULL);
76 if (EFI_ERROR (Status)) {
77 Error (NULL, 0, 4002, "Resource", "FV space is full, could not add pad file for data alignment property.");
78 free (FileBuffer);
79 @@ -2295,7 +2295,7 @@ Returns:
80 //
81 // Add FV Extended Header contents to the FV as a PAD file
82 //
83 - AddPadFile (&FvImageMemoryFile, 4, VtfFileImage, FvExtHeader);
84 + AddPadFile (&mFvDataInfo, &FvImageMemoryFile, 4, VtfFileImage, FvExtHeader);
85
86 //
87 // Fv Extension header change update Fv Header Check sum