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