summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg/Documentation/patches/BaseTools-Pending-Patches.patch
blob: d82f564c012470daebb2de106ec33832e851644b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Index: BaseTools/Source/C/GenFv/GenFv.c
===================================================================
--- BaseTools/Source/C/GenFv/GenFv.c	(revision 12691)
+++ BaseTools/Source/C/GenFv/GenFv.c	(working copy)
@@ -623,12 +623,7 @@
               );
   } else {
     VerboseMsg ("Create Fv image and its map file");
-    //
-    // Will take rebase action at below situation:
-    // 1. ForceRebase Flag specified to TRUE;
-    // 2. ForceRebase Flag not specified, BaseAddress greater than zero.
-    //
-    if (((mFvDataInfo.BaseAddress > 0) && (mFvDataInfo.ForceRebase == -1)) || (mFvDataInfo.ForceRebase == 1)) {
+    if (mFvDataInfo.BaseAddressSet) {
       VerboseMsg ("FvImage Rebase Address is 0x%llX", (unsigned long long) mFvDataInfo.BaseAddress);
     }
     //
Index: BaseTools/Source/C/GenFv/GenFvInternalLib.c
===================================================================
--- BaseTools/Source/C/GenFv/GenFvInternalLib.c	(revision 12691)
+++ BaseTools/Source/C/GenFv/GenFvInternalLib.c	(working copy)
@@ -506,6 +506,7 @@
 
 EFI_STATUS
 AddPadFile (
+  IN FV_INFO          *FvInfo,
   IN OUT MEMORY_FILE  *FvImage,
   IN UINT32           DataAlignment,
   IN VOID             *FvEnd,
@@ -537,6 +538,8 @@
 {
   EFI_FFS_FILE_HEADER *PadFile;
   UINTN               PadFileSize;
+  UINTN               PadFileOffset;
+  UINTN               ExtHeaderSize;
 
   //
   // Verify input parameters.
@@ -559,32 +562,29 @@
   // 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) {
@@ -1115,7 +1115,7 @@
   //
   // 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);
@@ -2304,7 +2304,7 @@
     //
     // 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
@@ -2825,20 +2825,12 @@
   PeFileBuffer       = NULL;
 
   //
-  // Don't need to relocate image when BaseAddress is zero and no ForceRebase Flag specified.
+  // Don't need to relocate image when BaseAddress is not set.
   //
-  if ((FvInfo->BaseAddress == 0) && (FvInfo->ForceRebase == -1)) {
+  if (FvInfo->BaseAddressSet == FALSE) {
     return EFI_SUCCESS;
   }
-  
-  //
-  // If ForceRebase Flag specified to FALSE, will always not take rebase action.
-  //
-  if (FvInfo->ForceRebase == 0) {
-    return EFI_SUCCESS;
-  }
 
-
   XipBase = FvInfo->BaseAddress + XipOffset;
 
   //