]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process FV generation\r | |
3 | #\r | |
ff260aa7 | 4 | # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
30fdf114 | 5 | #\r |
40d841f6 | 6 | # This program and the accompanying materials\r |
30fdf114 LG |
7 | # are licensed and made available under the terms and conditions of the BSD License\r |
8 | # which accompanies this distribution. The full text of the license may be found at\r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | \r | |
15 | ##\r | |
16 | # Import Modules\r | |
17 | #\r | |
9e47e6f9 | 18 | from __future__ import absolute_import\r |
1be2ed90 | 19 | import Common.LongFilePathOs as os\r |
30fdf114 | 20 | import subprocess\r |
86379ac4 | 21 | from io import BytesIO\r |
b303ea72 | 22 | from struct import *\r |
bfa65b61 GL |
23 | from . import FfsFileStatement\r |
24 | from .GenFdsGlobalVariable import GenFdsGlobalVariable\r | |
d0a0c52c | 25 | from Common.Misc import SaveFileOnChange, PackGUID\r |
1be2ed90 HC |
26 | from Common.LongFilePathSupport import CopyLongFilePath\r |
27 | from Common.LongFilePathSupport import OpenLongFilePath as open\r | |
91fa33ee | 28 | from Common.DataType import *\r |
30fdf114 | 29 | \r |
0614d73b | 30 | FV_UI_EXT_ENTY_GUID = 'A67DF1FA-8DE8-4E98-AF09-4BDF2EFFBC7C'\r |
30fdf114 LG |
31 | \r |
32 | ## generate FV\r | |
33 | #\r | |
34 | #\r | |
9e47e6f9 | 35 | class FV (object):\r |
30fdf114 LG |
36 | ## The constructor\r |
37 | #\r | |
38 | # @param self The object pointer\r | |
39 | #\r | |
40 | def __init__(self):\r | |
9e47e6f9 CJ |
41 | self.UiFvName = None\r |
42 | self.CreateFileName = None\r | |
43 | self.BlockSizeList = []\r | |
44 | self.DefineVarDict = {}\r | |
45 | self.SetVarDict = {}\r | |
46 | self.FvAlignment = None\r | |
47 | self.FvAttributeDict = {}\r | |
48 | self.FvNameGuid = None\r | |
49 | self.FvNameString = None\r | |
50 | self.AprioriSectionList = []\r | |
51 | self.FfsList = []\r | |
52 | self.BsBaseAddress = None\r | |
53 | self.RtBaseAddress = None\r | |
30fdf114 LG |
54 | self.FvInfFile = None\r |
55 | self.FvAddressFile = None\r | |
56 | self.BaseAddress = None\r | |
57 | self.InfFileName = None\r | |
58 | self.FvAddressFileName = None\r | |
fd171542 | 59 | self.CapsuleName = None\r |
4234283c | 60 | self.FvBaseAddress = None\r |
79b74a03 | 61 | self.FvForceRebase = None\r |
135ae8c8 | 62 | self.FvRegionInFD = None\r |
9425b349 | 63 | self.UsedSizeEnable = False\r |
f7496d71 | 64 | \r |
30fdf114 LG |
65 | ## AddToBuffer()\r |
66 | #\r | |
67 | # Generate Fv and add it to the Buffer\r | |
68 | #\r | |
69 | # @param self The object pointer\r | |
70 | # @param Buffer The buffer generated FV data will be put\r | |
71 | # @param BaseAddress base address of FV\r | |
72 | # @param BlockSize block size of FV\r | |
73 | # @param BlockNum How many blocks in FV\r | |
74 | # @param ErasePolarity Flash erase polarity\r | |
75 | # @param VtfDict VTF objects\r | |
76 | # @param MacroDict macro value pair\r | |
77 | # @retval string Generated FV file path\r | |
78 | #\r | |
9e47e6f9 | 79 | def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}, Flag=False):\r |
30fdf114 | 80 | \r |
7de00838 GL |
81 | if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:\r |
82 | return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv']\r | |
f7496d71 | 83 | \r |
fd171542 | 84 | #\r |
85 | # Check whether FV in Capsule is in FD flash region.\r | |
86 | # If yes, return error. Doesn't support FV in Capsule image is also in FD flash region.\r | |
87 | #\r | |
4231a819 | 88 | if self.CapsuleName is not None:\r |
9eb87141 | 89 | for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r |
fd171542 | 90 | for RegionObj in FdObj.RegionList:\r |
91fa33ee | 91 | if RegionObj.RegionType == BINARY_FILE_TYPE_FV:\r |
fd171542 | 92 | for RegionData in RegionObj.RegionDataList:\r |
93 | if RegionData.endswith(".fv"):\r | |
94 | continue\r | |
7de00838 | 95 | elif RegionData.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:\r |
fd171542 | 96 | continue\r |
97 | elif self.UiFvName.upper() == RegionData.upper():\r | |
0d2711a6 | 98 | GenFdsGlobalVariable.ErrorLogger("Capsule %s in FD region can't contain a FV %s in FD region." % (self.CapsuleName, self.UiFvName.upper()))\r |
37de70b7 YZ |
99 | if not Flag:\r |
100 | GenFdsGlobalVariable.InfLogger( "\nGenerating %s FV" %self.UiFvName)\r | |
2bc3256c LG |
101 | GenFdsGlobalVariable.LargeFileInFvFlags.append(False)\r |
102 | FFSGuid = None\r | |
f7496d71 | 103 | \r |
4231a819 | 104 | if self.FvBaseAddress is not None:\r |
0d2711a6 | 105 | BaseAddress = self.FvBaseAddress\r |
37de70b7 | 106 | if not Flag:\r |
9e47e6f9 | 107 | self._InitializeInf(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)\r |
30fdf114 LG |
108 | #\r |
109 | # First Process the Apriori section\r | |
110 | #\r | |
111 | MacroDict.update(self.DefineVarDict)\r | |
112 | \r | |
113 | GenFdsGlobalVariable.VerboseLogger('First generate Apriori file !')\r | |
114 | FfsFileList = []\r | |
115 | for AprSection in self.AprioriSectionList:\r | |
37de70b7 | 116 | FileName = AprSection.GenFfs (self.UiFvName, MacroDict, IsMakefile=Flag)\r |
30fdf114 LG |
117 | FfsFileList.append(FileName)\r |
118 | # Add Apriori file name to Inf file\r | |
37de70b7 YZ |
119 | if not Flag:\r |
120 | self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r | |
121 | FileName + \\r | |
ef4f218b | 122 | TAB_LINE_BREAK)\r |
30fdf114 LG |
123 | \r |
124 | # Process Modules in FfsList\r | |
9e47e6f9 | 125 | for FfsFile in self.FfsList:\r |
37de70b7 YZ |
126 | if Flag:\r |
127 | if isinstance(FfsFile, FfsFileStatement.FileStatement):\r | |
128 | continue\r | |
129 | if GenFdsGlobalVariable.EnableGenfdsMultiThread and GenFdsGlobalVariable.ModuleFile and GenFdsGlobalVariable.ModuleFile.Path.find(os.path.normpath(FfsFile.InfFileName)) == -1:\r | |
130 | continue\r | |
a743986d | 131 | FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress, IsMakefile=Flag, FvName=self.UiFvName)\r |
30fdf114 | 132 | FfsFileList.append(FileName)\r |
37de70b7 YZ |
133 | if not Flag:\r |
134 | self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r | |
135 | FileName + \\r | |
ef4f218b | 136 | TAB_LINE_BREAK)\r |
37de70b7 YZ |
137 | if not Flag:\r |
138 | SaveFileOnChange(self.InfFileName, self.FvInfFile.getvalue(), False)\r | |
139 | self.FvInfFile.close()\r | |
30fdf114 LG |
140 | #\r |
141 | # Call GenFv tool\r | |
142 | #\r | |
143 | FvOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName)\r | |
144 | FvOutputFile = FvOutputFile + '.Fv'\r | |
145 | # BUGBUG: FvOutputFile could be specified from FDF file (FV section, CreateFile statement)\r | |
4231a819 | 146 | if self.CreateFileName is not None:\r |
30fdf114 LG |
147 | FvOutputFile = self.CreateFileName\r |
148 | \r | |
37de70b7 | 149 | if Flag:\r |
7de00838 | 150 | GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r |
37de70b7 | 151 | return FvOutputFile\r |
52302d4d | 152 | \r |
37de70b7 YZ |
153 | FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')\r |
154 | if not Flag:\r | |
155 | CopyLongFilePath(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)\r | |
156 | OrigFvInfo = None\r | |
157 | if os.path.exists (FvInfoFileName):\r | |
158 | OrigFvInfo = open(FvInfoFileName, 'r').read()\r | |
159 | if GenFdsGlobalVariable.LargeFileInFvFlags[-1]:\r | |
160 | FFSGuid = GenFdsGlobalVariable.EFI_FIRMWARE_FILE_SYSTEM3_GUID\r | |
161 | GenFdsGlobalVariable.GenerateFirmwareVolume(\r | |
162 | FvOutputFile,\r | |
163 | [self.InfFileName],\r | |
164 | AddressFile=FvInfoFileName,\r | |
165 | FfsList=FfsFileList,\r | |
166 | ForceRebase=self.FvForceRebase,\r | |
167 | FileSystemGuid=FFSGuid\r | |
168 | )\r | |
169 | \r | |
170 | NewFvInfo = None\r | |
171 | if os.path.exists (FvInfoFileName):\r | |
172 | NewFvInfo = open(FvInfoFileName, 'r').read()\r | |
4231a819 | 173 | if NewFvInfo is not None and NewFvInfo != OrigFvInfo:\r |
37de70b7 YZ |
174 | FvChildAddr = []\r |
175 | AddFileObj = open(FvInfoFileName, 'r')\r | |
176 | AddrStrings = AddFileObj.readlines()\r | |
177 | AddrKeyFound = False\r | |
178 | for AddrString in AddrStrings:\r | |
179 | if AddrKeyFound:\r | |
180 | #get base address for the inside FvImage\r | |
181 | FvChildAddr.append (AddrString)\r | |
182 | elif AddrString.find ("[FV_BASE_ADDRESS]") != -1:\r | |
183 | AddrKeyFound = True\r | |
184 | AddFileObj.close()\r | |
185 | \r | |
186 | if FvChildAddr != []:\r | |
187 | # Update Ffs again\r | |
9e47e6f9 | 188 | for FfsFile in self.FfsList:\r |
ff260aa7 | 189 | FileName = FfsFile.GenFfs(MacroDict, FvChildAddr, BaseAddress, IsMakefile=Flag, FvName=self.UiFvName)\r |
37de70b7 YZ |
190 | \r |
191 | if GenFdsGlobalVariable.LargeFileInFvFlags[-1]:\r | |
192 | FFSGuid = GenFdsGlobalVariable.EFI_FIRMWARE_FILE_SYSTEM3_GUID;\r | |
193 | #Update GenFv again\r | |
0385efa0 | 194 | GenFdsGlobalVariable.GenerateFirmwareVolume(\r |
37de70b7 YZ |
195 | FvOutputFile,\r |
196 | [self.InfFileName],\r | |
197 | AddressFile=FvInfoFileName,\r | |
198 | FfsList=FfsFileList,\r | |
199 | ForceRebase=self.FvForceRebase,\r | |
200 | FileSystemGuid=FFSGuid\r | |
201 | )\r | |
202 | \r | |
203 | #\r | |
204 | # Write the Fv contents to Buffer\r | |
205 | #\r | |
0e982cf0 | 206 | if os.path.isfile(FvOutputFile) and os.path.getsize(FvOutputFile) >= 0x48:\r |
37de70b7 | 207 | FvFileObj = open(FvOutputFile, 'rb')\r |
37de70b7 YZ |
208 | # PI FvHeader is 0x48 byte\r |
209 | FvHeaderBuffer = FvFileObj.read(0x48)\r | |
0e982cf0 | 210 | Signature = FvHeaderBuffer[0x28:0x32]\r |
211 | if Signature and Signature.startswith('_FVH'):\r | |
212 | GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV Successfully" % self.UiFvName)\r | |
213 | GenFdsGlobalVariable.SharpCounter = 0\r | |
214 | \r | |
0e982cf0 | 215 | FvFileObj.seek(0)\r |
272ecccd | 216 | Buffer.write(FvFileObj.read())\r |
0e982cf0 | 217 | # FV alignment position.\r |
218 | FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)\r | |
219 | if FvAlignmentValue >= 0x400:\r | |
220 | if FvAlignmentValue >= 0x100000:\r | |
221 | if FvAlignmentValue >= 0x1000000:\r | |
222 | #The max alignment supported by FFS is 16M.\r | |
223 | self.FvAlignment = "16M"\r | |
224 | else:\r | |
225 | self.FvAlignment = str(FvAlignmentValue / 0x100000) + "M"\r | |
37de70b7 | 226 | else:\r |
0e982cf0 | 227 | self.FvAlignment = str(FvAlignmentValue / 0x400) + "K"\r |
e921f58d | 228 | else:\r |
0e982cf0 | 229 | # FvAlignmentValue is less than 1K\r |
230 | self.FvAlignment = str (FvAlignmentValue)\r | |
231 | FvFileObj.close()\r | |
232 | GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r | |
233 | GenFdsGlobalVariable.LargeFileInFvFlags.pop()\r | |
2ff9e575 | 234 | else:\r |
0e982cf0 | 235 | GenFdsGlobalVariable.ErrorLogger("Invalid FV file %s." % self.UiFvName)\r |
52302d4d | 236 | else:\r |
37de70b7 | 237 | GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)\r |
30fdf114 LG |
238 | return FvOutputFile\r |
239 | \r | |
29d960f9 YL |
240 | ## _GetBlockSize()\r |
241 | #\r | |
242 | # Calculate FV's block size\r | |
243 | # Inherit block size from FD if no block size specified in FV\r | |
244 | #\r | |
245 | def _GetBlockSize(self):\r | |
246 | if self.BlockSizeList:\r | |
247 | return True\r | |
248 | \r | |
9eb87141 | 249 | for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r |
29d960f9 | 250 | for RegionObj in FdObj.RegionList:\r |
91fa33ee | 251 | if RegionObj.RegionType != BINARY_FILE_TYPE_FV:\r |
29d960f9 YL |
252 | continue\r |
253 | for RegionData in RegionObj.RegionDataList:\r | |
254 | #\r | |
255 | # Found the FD and region that contain this FV\r | |
256 | #\r | |
257 | if self.UiFvName.upper() == RegionData.upper():\r | |
258 | RegionObj.BlockInfoOfRegion(FdObj.BlockSizeList, self)\r | |
259 | if self.BlockSizeList:\r | |
260 | return True\r | |
261 | return False\r | |
262 | \r | |
9e47e6f9 | 263 | ## _InitializeInf()\r |
30fdf114 LG |
264 | #\r |
265 | # Initilize the inf file to create FV\r | |
266 | #\r | |
267 | # @param self The object pointer\r | |
268 | # @param BaseAddress base address of FV\r | |
269 | # @param BlockSize block size of FV\r | |
270 | # @param BlockNum How many blocks in FV\r | |
271 | # @param ErasePolarity Flash erase polarity\r | |
272 | # @param VtfDict VTF objects\r | |
273 | #\r | |
9e47e6f9 | 274 | def _InitializeInf (self, BaseAddress = None, BlockSize= None, BlockNum = None, ErasePloarity='1', VtfDict=None):\r |
30fdf114 LG |
275 | #\r |
276 | # Create FV inf file\r | |
277 | #\r | |
278 | self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r | |
279 | self.UiFvName + '.inf')\r | |
1ccc4d89 | 280 | self.FvInfFile = BytesIO()\r |
30fdf114 LG |
281 | \r |
282 | #\r | |
283 | # Add [Options]\r | |
284 | #\r | |
ef4f218b | 285 | self.FvInfFile.writelines("[options]" + TAB_LINE_BREAK)\r |
9e47e6f9 | 286 | if BaseAddress is not None:\r |
30fdf114 LG |
287 | self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \\r |
288 | BaseAddress + \\r | |
ef4f218b | 289 | TAB_LINE_BREAK)\r |
30fdf114 | 290 | \r |
4231a819 | 291 | if BlockSize is not None:\r |
30fdf114 LG |
292 | self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r |
293 | '0x%X' %BlockSize + \\r | |
ef4f218b | 294 | TAB_LINE_BREAK)\r |
4231a819 | 295 | if BlockNum is not None:\r |
30fdf114 LG |
296 | self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \\r |
297 | ' 0x%X' %BlockNum + \\r | |
ef4f218b | 298 | TAB_LINE_BREAK)\r |
30fdf114 | 299 | else:\r |
52302d4d | 300 | if self.BlockSizeList == []:\r |
29d960f9 YL |
301 | if not self._GetBlockSize():\r |
302 | #set default block size is 1\r | |
ef4f218b | 303 | self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1" + TAB_LINE_BREAK)\r |
f7496d71 | 304 | \r |
9e47e6f9 | 305 | for BlockSize in self.BlockSizeList:\r |
4231a819 | 306 | if BlockSize[0] is not None:\r |
30fdf114 LG |
307 | self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r |
308 | '0x%X' %BlockSize[0] + \\r | |
ef4f218b | 309 | TAB_LINE_BREAK)\r |
30fdf114 | 310 | \r |
4231a819 | 311 | if BlockSize[1] is not None:\r |
30fdf114 LG |
312 | self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \\r |
313 | ' 0x%X' %BlockSize[1] + \\r | |
ef4f218b | 314 | TAB_LINE_BREAK)\r |
30fdf114 | 315 | \r |
4231a819 | 316 | if self.BsBaseAddress is not None:\r |
30fdf114 LG |
317 | self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \\r |
318 | '0x%X' %self.BsBaseAddress)\r | |
4231a819 | 319 | if self.RtBaseAddress is not None:\r |
30fdf114 LG |
320 | self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \\r |
321 | '0x%X' %self.RtBaseAddress)\r | |
322 | #\r | |
323 | # Add attribute\r | |
324 | #\r | |
ef4f218b | 325 | self.FvInfFile.writelines("[attributes]" + TAB_LINE_BREAK)\r |
30fdf114 LG |
326 | \r |
327 | self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \\r | |
328 | ' %s' %ErasePloarity + \\r | |
ef4f218b | 329 | TAB_LINE_BREAK)\r |
4231a819 | 330 | if not (self.FvAttributeDict is None):\r |
9e47e6f9 | 331 | for FvAttribute in self.FvAttributeDict.keys():\r |
9425b349 | 332 | if FvAttribute == "FvUsedSizeEnable":\r |
9e47e6f9 | 333 | if self.FvAttributeDict[FvAttribute].upper() in ('TRUE', '1'):\r |
9425b349 YF |
334 | self.UsedSizeEnable = True\r |
335 | continue\r | |
30fdf114 LG |
336 | self.FvInfFile.writelines("EFI_" + \\r |
337 | FvAttribute + \\r | |
338 | ' = ' + \\r | |
339 | self.FvAttributeDict[FvAttribute] + \\r | |
ef4f218b | 340 | TAB_LINE_BREAK )\r |
4231a819 | 341 | if self.FvAlignment is not None:\r |
30fdf114 LG |
342 | self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \\r |
343 | self.FvAlignment.strip() + \\r | |
344 | " = TRUE" + \\r | |
ef4f218b | 345 | TAB_LINE_BREAK)\r |
f7496d71 | 346 | \r |
30fdf114 | 347 | #\r |
b303ea72 | 348 | # Generate FV extension header file\r |
30fdf114 | 349 | #\r |
128d435f | 350 | if not self.FvNameGuid:\r |
9425b349 | 351 | if len(self.FvExtEntryType) > 0 or self.UsedSizeEnable:\r |
b303ea72 | 352 | GenFdsGlobalVariable.ErrorLogger("FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName))\r |
128d435f | 353 | else:\r |
b303ea72 | 354 | TotalSize = 16 + 4\r |
1ccc4d89 | 355 | Buffer = ''\r |
9425b349 YF |
356 | if self.UsedSizeEnable:\r |
357 | TotalSize += (4 + 4)\r | |
358 | ## define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03\r | |
359 | #typedef struct\r | |
360 | # {\r | |
361 | # EFI_FIRMWARE_VOLUME_EXT_ENTRY Hdr;\r | |
362 | # UINT32 UsedSize;\r | |
363 | # } EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE;\r | |
364 | Buffer += pack('HHL', 8, 3, 0)\r | |
365 | \r | |
aaf8aa7b YL |
366 | if self.FvNameString == 'TRUE':\r |
367 | #\r | |
368 | # Create EXT entry for FV UI name\r | |
369 | # This GUID is used: A67DF1FA-8DE8-4E98-AF09-4BDF2EFFBC7C\r | |
370 | #\r | |
371 | FvUiLen = len(self.UiFvName)\r | |
372 | TotalSize += (FvUiLen + 16 + 4)\r | |
373 | Guid = FV_UI_EXT_ENTY_GUID.split('-')\r | |
374 | #\r | |
375 | # Layout:\r | |
9e47e6f9 CJ |
376 | # EFI_FIRMWARE_VOLUME_EXT_ENTRY: size 4\r |
377 | # GUID: size 16\r | |
aaf8aa7b YL |
378 | # FV UI name\r |
379 | #\r | |
380 | Buffer += (pack('HH', (FvUiLen + 16 + 4), 0x0002)\r | |
d0a0c52c | 381 | + PackGUID(Guid)\r |
1ccc4d89 | 382 | + self.UiFvName)\r |
0614d73b | 383 | \r |
b303ea72 LG |
384 | for Index in range (0, len(self.FvExtEntryType)):\r |
385 | if self.FvExtEntryType[Index] == 'FILE':\r | |
f51461c8 LG |
386 | # check if the path is absolute or relative\r |
387 | if os.path.isabs(self.FvExtEntryData[Index]):\r | |
388 | FileFullPath = os.path.normpath(self.FvExtEntryData[Index])\r | |
389 | else:\r | |
390 | FileFullPath = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.FvExtEntryData[Index]))\r | |
391 | # check if the file path exists or not\r | |
392 | if not os.path.isfile(FileFullPath):\r | |
b303ea72 | 393 | GenFdsGlobalVariable.ErrorLogger("Error opening FV Extension Header Entry file %s." % (self.FvExtEntryData[Index]))\r |
ccaa7754 GL |
394 | FvExtFile = open (FileFullPath, 'rb')\r |
395 | FvExtFile.seek(0, 2)\r | |
b303ea72 LG |
396 | Size = FvExtFile.tell()\r |
397 | if Size >= 0x10000:\r | |
398 | GenFdsGlobalVariable.ErrorLogger("The size of FV Extension Header Entry file %s exceeds 0x10000." % (self.FvExtEntryData[Index]))\r | |
399 | TotalSize += (Size + 4)\r | |
400 | FvExtFile.seek(0)\r | |
401 | Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16))\r | |
f7496d71 | 402 | Buffer += FvExtFile.read()\r |
b303ea72 LG |
403 | FvExtFile.close()\r |
404 | if self.FvExtEntryType[Index] == 'DATA':\r | |
405 | ByteList = self.FvExtEntryData[Index].split(',')\r | |
406 | Size = len (ByteList)\r | |
407 | if Size >= 0x10000:\r | |
408 | GenFdsGlobalVariable.ErrorLogger("The size of FV Extension Header Entry data %s exceeds 0x10000." % (self.FvExtEntryData[Index]))\r | |
409 | TotalSize += (Size + 4)\r | |
410 | Buffer += pack('HH', (Size + 4), int(self.FvExtEntryTypeValue[Index], 16))\r | |
411 | for Index1 in range (0, Size):\r | |
412 | Buffer += pack('B', int(ByteList[Index1], 16))\r | |
413 | \r | |
414 | Guid = self.FvNameGuid.split('-')\r | |
d0a0c52c | 415 | Buffer = PackGUID(Guid) + pack('=L', TotalSize) + Buffer\r |
b303ea72 LG |
416 | \r |
417 | #\r | |
418 | # Generate FV extension header file if the total size is not zero\r | |
419 | #\r | |
420 | if TotalSize > 0:\r | |
421 | FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext')\r | |
86379ac4 | 422 | FvExtHeaderFile = BytesIO()\r |
b303ea72 | 423 | FvExtHeaderFile.write(Buffer)\r |
a709adfa | 424 | Changed = SaveFileOnChange(FvExtHeaderFileName, FvExtHeaderFile.getvalue(), True)\r |
b303ea72 | 425 | FvExtHeaderFile.close()\r |
a709adfa LG |
426 | if Changed:\r |
427 | if os.path.exists (self.InfFileName):\r | |
428 | os.remove (self.InfFileName)\r | |
b303ea72 LG |
429 | self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = " + \\r |
430 | FvExtHeaderFileName + \\r | |
ef4f218b | 431 | TAB_LINE_BREAK)\r |
30fdf114 | 432 | \r |
b303ea72 LG |
433 | #\r |
434 | # Add [Files]\r | |
435 | #\r | |
ef4f218b | 436 | self.FvInfFile.writelines("[files]" + TAB_LINE_BREAK)\r |
b491aa95 | 437 | if VtfDict and self.UiFvName in VtfDict:\r |
30fdf114 | 438 | self.FvInfFile.writelines("EFI_FILE_NAME = " + \\r |
9eb87141 | 439 | VtfDict[self.UiFvName] + \\r |
ef4f218b | 440 | TAB_LINE_BREAK)\r |