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