]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/FfsInfStatement.py
BaseTools: FILE DATA to support relative path under Multiple workspace
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsInfStatement.py
... / ...
CommitLineData
1## @file\r
2# process FFS generation from INF statement\r
3#\r
4# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
5# Copyright (c) 2014-2016 Hewlett-Packard Development Company, L.P.<BR>\r
6#\r
7# This program and the accompanying materials\r
8# are licensed and made available under the terms and conditions of the BSD License\r
9# which accompanies this distribution. The full text of the license may be found at\r
10# http://opensource.org/licenses/bsd-license.php\r
11#\r
12# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14#\r
15\r
16##\r
17# Import Modules\r
18#\r
19import Rule\r
20import Common.LongFilePathOs as os\r
21import StringIO\r
22from struct import *\r
23from GenFdsGlobalVariable import GenFdsGlobalVariable\r
24import Ffs\r
25import subprocess\r
26import sys\r
27import Section\r
28import RuleSimpleFile\r
29import RuleComplexFile\r
30from CommonDataClass.FdfClass import FfsInfStatementClassObject\r
31from Common.MultipleWorkspace import MultipleWorkspace as mws\r
32from Common.String import *\r
33from Common.Misc import PathClass\r
34from Common.Misc import GuidStructureByteArrayToGuidString\r
35from Common.Misc import ProcessDuplicatedInf\r
36from Common.Misc import GetVariableOffset\r
37from Common import EdkLogger\r
38from Common.BuildToolError import *\r
39from GuidSection import GuidSection\r
40from FvImageSection import FvImageSection\r
41from Common.Misc import PeImageClass\r
42from AutoGen.GenDepex import DependencyExpression\r
43from PatchPcdValue.PatchPcdValue import PatchBinaryFile\r
44from Common.LongFilePathSupport import CopyLongFilePath\r
45from Common.LongFilePathSupport import OpenLongFilePath as open\r
46import Common.GlobalData as GlobalData\r
47\r
48## generate FFS from INF\r
49#\r
50#\r
51class FfsInfStatement(FfsInfStatementClassObject):\r
52 ## The mapping dictionary from datum type to its maximum number.\r
53 _MAX_SIZE_TYPE = {"BOOLEAN":0x01, "UINT8":0xFF, "UINT16":0xFFFF, "UINT32":0xFFFFFFFF, "UINT64":0xFFFFFFFFFFFFFFFF}\r
54 ## The constructor\r
55 #\r
56 # @param self The object pointer\r
57 #\r
58 def __init__(self):\r
59 FfsInfStatementClassObject.__init__(self)\r
60 self.TargetOverrideList = []\r
61 self.ShadowFromInfFile = None\r
62 self.KeepRelocFromRule = None\r
63 self.InDsc = True\r
64 self.OptRomDefs = {}\r
65 self.PiSpecVersion = '0x00000000'\r
66 self.InfModule = None\r
67 self.FinalTargetSuffixMap = {}\r
68 self.CurrentLineNum = None\r
69 self.CurrentLineContent = None\r
70 self.FileName = None\r
71 self.InfFileName = None\r
72 self.OverrideGuid = None\r
73 self.PatchedBinFile = ''\r
74 self.MacroDict = {}\r
75\r
76 ## GetFinalTargetSuffixMap() method\r
77 #\r
78 # Get final build target list\r
79 def GetFinalTargetSuffixMap(self):\r
80 if not self.InfModule or not self.CurrentArch:\r
81 return []\r
82 if not self.FinalTargetSuffixMap:\r
83 FinalBuildTargetList = GenFdsGlobalVariable.GetModuleCodaTargetList(self.InfModule, self.CurrentArch)\r
84 for File in FinalBuildTargetList:\r
85 self.FinalTargetSuffixMap.setdefault(os.path.splitext(File)[1], []).append(File)\r
86\r
87 # Check if current INF module has DEPEX\r
88 if '.depex' not in self.FinalTargetSuffixMap and self.InfModule.ModuleType != "USER_DEFINED" \\r
89 and not self.InfModule.DxsFile and not self.InfModule.LibraryClass:\r
90 ModuleType = self.InfModule.ModuleType\r
91 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
92\r
93 if ModuleType != DataType.SUP_MODULE_USER_DEFINED:\r
94 for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys():\r
95 if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:\r
96 self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]\r
97\r
98 StrModule = str(self.InfModule)\r
99 PlatformModule = None\r
100 if StrModule in PlatformDataBase.Modules:\r
101 PlatformModule = PlatformDataBase.Modules[StrModule]\r
102 for LibraryClass in PlatformModule.LibraryClasses:\r
103 if LibraryClass.startswith("NULL"):\r
104 self.InfModule.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
105\r
106 DependencyList = [self.InfModule]\r
107 LibraryInstance = {}\r
108 DepexList = []\r
109 while len(DependencyList) > 0:\r
110 Module = DependencyList.pop(0)\r
111 if not Module:\r
112 continue\r
113 for Dep in Module.Depex[self.CurrentArch, ModuleType]:\r
114 if DepexList != []:\r
115 DepexList.append('AND')\r
116 DepexList.append('(')\r
117 DepexList.extend(Dep)\r
118 if DepexList[-1] == 'END': # no need of a END at this time\r
119 DepexList.pop()\r
120 DepexList.append(')')\r
121 if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
122 break\r
123 for LibName in Module.LibraryClasses:\r
124 if LibName in LibraryInstance:\r
125 continue\r
126 if PlatformModule and LibName in PlatformModule.LibraryClasses:\r
127 LibraryPath = PlatformModule.LibraryClasses[LibName]\r
128 else:\r
129 LibraryPath = PlatformDataBase.LibraryClasses[LibName, ModuleType]\r
130 if not LibraryPath:\r
131 LibraryPath = Module.LibraryClasses[LibName]\r
132 if not LibraryPath:\r
133 continue\r
134 LibraryModule = GenFdsGlobalVariable.WorkSpace.BuildObject[LibraryPath, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
135 LibraryInstance[LibName] = LibraryModule\r
136 DependencyList.append(LibraryModule)\r
137 if DepexList:\r
138 Dpx = DependencyExpression(DepexList, ModuleType, True)\r
139 if len(Dpx.PostfixNotation) != 0:\r
140 # It means this module has DEPEX\r
141 self.FinalTargetSuffixMap['.depex'] = [os.path.join(self.EfiOutputPath, self.BaseName) + '.depex']\r
142 return self.FinalTargetSuffixMap\r
143\r
144 ## __InfParse() method\r
145 #\r
146 # Parse inf file to get module information\r
147 #\r
148 # @param self The object pointer\r
149 # @param Dict dictionary contains macro and value pair\r
150 #\r
151 def __InfParse__(self, Dict = {}):\r
152\r
153 GenFdsGlobalVariable.VerboseLogger( " Begine parsing INf file : %s" %self.InfFileName)\r
154\r
155 self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '')\r
156 if len(self.InfFileName) > 1 and self.InfFileName[0] == '\\' and self.InfFileName[1] == '\\':\r
157 pass\r
158 elif self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :\r
159 self.InfFileName = self.InfFileName[1:]\r
160\r
161 if self.InfFileName.find('$') == -1:\r
162 InfPath = NormPath(self.InfFileName)\r
163 if not os.path.exists(InfPath):\r
164 InfPath = GenFdsGlobalVariable.ReplaceWorkspaceMacro(InfPath)\r
165 if not os.path.exists(InfPath):\r
166 EdkLogger.error("GenFds", GENFDS_ERROR, "Non-existant Module %s !" % (self.InfFileName))\r
167\r
168 self.CurrentArch = self.GetCurrentArch()\r
169 #\r
170 # Get the InfClass object\r
171 #\r
172\r
173 PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
174 ErrorCode, ErrorInfo = PathClassObj.Validate(".inf")\r
175 if ErrorCode != 0:\r
176 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
177\r
178 #\r
179 # Cache lower case version of INF path before processing FILE_GUID override\r
180 #\r
181 InfLowerPath = str(PathClassObj).lower()\r
182 if self.OverrideGuid:\r
183 PathClassObj = ProcessDuplicatedInf(PathClassObj, self.OverrideGuid, GenFdsGlobalVariable.WorkSpaceDir)\r
184 if self.CurrentArch != None:\r
185\r
186 Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
187 #\r
188 # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath\r
189 #\r
190 self.BaseName = Inf.BaseName\r
191 self.ModuleGuid = Inf.Guid\r
192 self.ModuleType = Inf.ModuleType\r
193 if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:\r
194 self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']\r
195 if Inf.AutoGenVersion < 0x00010005:\r
196 self.ModuleType = Inf.ComponentType\r
197 self.VersionString = Inf.Version\r
198 self.BinFileList = Inf.Binaries\r
199 self.SourceFileList = Inf.Sources\r
200 if self.KeepReloc == None and Inf.Shadow:\r
201 self.ShadowFromInfFile = Inf.Shadow\r
202\r
203 else:\r
204 Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
205 self.BaseName = Inf.BaseName\r
206 self.ModuleGuid = Inf.Guid\r
207 self.ModuleType = Inf.ModuleType\r
208 if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:\r
209 self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']\r
210 self.VersionString = Inf.Version\r
211 self.BinFileList = Inf.Binaries\r
212 self.SourceFileList = Inf.Sources\r
213 if self.BinFileList == []:\r
214 EdkLogger.error("GenFds", GENFDS_ERROR,\r
215 "INF %s specified in FDF could not be found in build ARCH %s!" \\r
216 % (self.InfFileName, GenFdsGlobalVariable.ArchList))\r
217\r
218 if self.OverrideGuid:\r
219 self.ModuleGuid = self.OverrideGuid\r
220\r
221 if len(self.SourceFileList) != 0 and not self.InDsc:\r
222 EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (self.InfFileName))\r
223\r
224 if self.ModuleType == 'SMM_CORE' and int(self.PiSpecVersion, 16) < 0x0001000A:\r
225 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.InfFileName) \r
226\r
227 if Inf._Defs != None and len(Inf._Defs) > 0:\r
228 self.OptRomDefs.update(Inf._Defs)\r
229\r
230 self.PatchPcds = []\r
231 InfPcds = Inf.Pcds\r
232 Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
233 FdfPcdDict = GenFdsGlobalVariable.FdfParser.Profile.PcdDict\r
234\r
235 # Workaround here: both build and GenFds tool convert the workspace path to lower case\r
236 # But INF file path in FDF and DSC file may have real case characters.\r
237 # Try to convert the path to lower case to see if PCDs value are override by DSC.\r
238 DscModules = {}\r
239 for DscModule in Platform.Modules:\r
240 DscModules[str(DscModule).lower()] = Platform.Modules[DscModule]\r
241 for PcdKey in InfPcds:\r
242 Pcd = InfPcds[PcdKey]\r
243 if not hasattr(Pcd, 'Offset'):\r
244 continue\r
245 if Pcd.Type != 'PatchableInModule':\r
246 continue\r
247 # Override Patchable PCD value by the value from DSC\r
248 PatchPcd = None\r
249 if InfLowerPath in DscModules and PcdKey in DscModules[InfLowerPath].Pcds:\r
250 PatchPcd = DscModules[InfLowerPath].Pcds[PcdKey]\r
251 elif PcdKey in Platform.Pcds:\r
252 PatchPcd = Platform.Pcds[PcdKey]\r
253 DscOverride = False\r
254 if PatchPcd and Pcd.Type == PatchPcd.Type:\r
255 DefaultValue = PatchPcd.DefaultValue\r
256 DscOverride = True\r
257\r
258 # Override Patchable PCD value by the value from FDF\r
259 FdfOverride = False\r
260 if PcdKey in FdfPcdDict:\r
261 DefaultValue = FdfPcdDict[PcdKey]\r
262 FdfOverride = True\r
263\r
264 # Override Patchable PCD value by the value from Build Option\r
265 BuildOptionOverride = False\r
266 if GlobalData.BuildOptionPcd:\r
267 for pcd in GlobalData.BuildOptionPcd:\r
268 if PcdKey == (pcd[1], pcd[0]):\r
269 DefaultValue = pcd[2]\r
270 BuildOptionOverride = True\r
271 break\r
272\r
273 if not DscOverride and not FdfOverride and not BuildOptionOverride:\r
274 continue\r
275 # Check value, if value are equal, no need to patch\r
276 if Pcd.DatumType == "VOID*":\r
277 if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']:\r
278 continue\r
279 # Get the string size from FDF or DSC\r
280 if DefaultValue[0] == 'L':\r
281 # Remove L"", but the '\0' must be appended\r
282 MaxDatumSize = str((len(DefaultValue) - 2) * 2)\r
283 elif DefaultValue[0] == '{':\r
284 MaxDatumSize = str(len(DefaultValue.split(',')))\r
285 else:\r
286 MaxDatumSize = str(len(DefaultValue) - 1)\r
287 if DscOverride:\r
288 Pcd.MaxDatumSize = PatchPcd.MaxDatumSize\r
289 # If no defined the maximum size in DSC, try to get current size from INF\r
290 if Pcd.MaxDatumSize in ['', None]:\r
291 Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(',')))\r
292 else:\r
293 Base1 = Base2 = 10\r
294 if Pcd.DefaultValue.upper().startswith('0X'):\r
295 Base1 = 16\r
296 if DefaultValue.upper().startswith('0X'):\r
297 Base2 = 16\r
298 try:\r
299 PcdValueInImg = int(Pcd.DefaultValue, Base1)\r
300 PcdValueInDscOrFdf = int(DefaultValue, Base2)\r
301 if PcdValueInImg == PcdValueInDscOrFdf:\r
302 continue\r
303 except:\r
304 continue\r
305 # Check the Pcd size and data type\r
306 if Pcd.DatumType == "VOID*":\r
307 if int(MaxDatumSize) > int(Pcd.MaxDatumSize):\r
308 EdkLogger.error("GenFds", GENFDS_ERROR, "The size of VOID* type PCD '%s.%s' exceeds its maximum size %d bytes." \\r
309 % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, int(MaxDatumSize) - int(Pcd.MaxDatumSize)))\r
310 else:\r
311 if PcdValueInDscOrFdf > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType] \\r
312 or PcdValueInImg > FfsInfStatement._MAX_SIZE_TYPE[Pcd.DatumType]:\r
313 EdkLogger.error("GenFds", GENFDS_ERROR, "The size of %s type PCD '%s.%s' doesn't match its data type." \\r
314 % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
315 self.PatchPcds.append((Pcd, DefaultValue))\r
316\r
317 self.InfModule = Inf\r
318 self.PcdIsDriver = Inf.PcdIsDriver\r
319 self.IsBinaryModule = Inf.IsBinaryModule\r
320 GenFdsGlobalVariable.VerboseLogger("BaseName : %s" % self.BaseName)\r
321 GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" % self.ModuleGuid)\r
322 GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" % self.ModuleType)\r
323 GenFdsGlobalVariable.VerboseLogger("VersionString : %s" % self.VersionString)\r
324 GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" % self.InfFileName)\r
325\r
326 #\r
327 # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\\r
328 #\r
329\r
330 self.OutputPath = os.path.join(GenFdsGlobalVariable.FfsDir, \\r
331 self.ModuleGuid + self.BaseName)\r
332 if not os.path.exists(self.OutputPath) :\r
333 os.makedirs(self.OutputPath)\r
334\r
335 self.EfiOutputPath = self.__GetEFIOutPutPath__()\r
336 GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)\r
337\r
338 ## PatchEfiFile\r
339 #\r
340 # Patch EFI file with patch PCD\r
341 #\r
342 # @param EfiFile: EFI file needs to be patched.\r
343 # @retval: Full path of patched EFI file: self.OutputPath + EfiFile base name\r
344 # If passed in file does not end with efi, return as is\r
345 #\r
346 def PatchEfiFile(self, EfiFile, FileType):\r
347 #\r
348 # If the module does not have any patches, then return path to input file\r
349 # \r
350 if not self.PatchPcds:\r
351 return EfiFile\r
352\r
353 #\r
354 # Only patch file if FileType is PE32 or ModuleType is USER_DEFINED\r
355 # \r
356 if FileType != 'PE32' and self.ModuleType != "USER_DEFINED":\r
357 return EfiFile\r
358\r
359 #\r
360 # Generate path to patched output file\r
361 #\r
362 Basename = os.path.basename(EfiFile)\r
363 Output = os.path.normpath (os.path.join(self.OutputPath, Basename))\r
364\r
365 #\r
366 # If this file has already been patched, then return the path to the patched file\r
367 #\r
368 if self.PatchedBinFile == Output:\r
369 return Output\r
370\r
371 #\r
372 # If a different file from the same module has already been patched, then generate an error\r
373 # \r
374 if self.PatchedBinFile:\r
375 EdkLogger.error("GenFds", GENFDS_ERROR,\r
376 'Only one binary file can be patched:\n'\r
377 ' a binary file has been patched: %s\n'\r
378 ' current file: %s' % (self.PatchedBinFile, EfiFile),\r
379 File=self.InfFileName)\r
380\r
381 #\r
382 # Copy unpatched file contents to output file location to perform patching\r
383 # \r
384 CopyLongFilePath(EfiFile, Output)\r
385\r
386 #\r
387 # Apply patches to patched output file\r
388 # \r
389 for Pcd, Value in self.PatchPcds:\r
390 RetVal, RetStr = PatchBinaryFile(Output, int(Pcd.Offset, 0), Pcd.DatumType, Value, Pcd.MaxDatumSize)\r
391 if RetVal:\r
392 EdkLogger.error("GenFds", GENFDS_ERROR, RetStr, File=self.InfFileName)\r
393\r
394 #\r
395 # Save the path of the patched output file\r
396 # \r
397 self.PatchedBinFile = Output\r
398\r
399 #\r
400 # Return path to patched output file\r
401 # \r
402 return Output\r
403\r
404 ## GenFfs() method\r
405 #\r
406 # Generate FFS\r
407 #\r
408 # @param self The object pointer\r
409 # @param Dict dictionary contains macro and value pair\r
410 # @param FvChildAddr Array of the inside FvImage base address\r
411 # @param FvParentAddr Parent Fv base address\r
412 # @retval string Generated FFS file name\r
413 #\r
414 def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None):\r
415 #\r
416 # Parse Inf file get Module related information\r
417 #\r
418\r
419 self.__InfParse__(Dict)\r
420 SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir , self.InfFileName);\r
421 DestFile = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
422 \r
423 SrcFileDir = "."\r
424 SrcPath = os.path.dirname(SrcFile)\r
425 SrcFileName = os.path.basename(SrcFile)\r
426 SrcFileBase, SrcFileExt = os.path.splitext(SrcFileName) \r
427 DestPath = os.path.dirname(DestFile)\r
428 DestFileName = os.path.basename(DestFile)\r
429 DestFileBase, DestFileExt = os.path.splitext(DestFileName) \r
430 self.MacroDict = {\r
431 # source file\r
432 "${src}" : SrcFile,\r
433 "${s_path}" : SrcPath,\r
434 "${s_dir}" : SrcFileDir,\r
435 "${s_name}" : SrcFileName,\r
436 "${s_base}" : SrcFileBase,\r
437 "${s_ext}" : SrcFileExt,\r
438 # destination file\r
439 "${dst}" : DestFile,\r
440 "${d_path}" : DestPath,\r
441 "${d_name}" : DestFileName,\r
442 "${d_base}" : DestFileBase,\r
443 "${d_ext}" : DestFileExt\r
444 }\r
445 #\r
446 # Allow binary type module not specify override rule in FDF file.\r
447 # \r
448 if len(self.BinFileList) > 0:\r
449 if self.Rule == None or self.Rule == "":\r
450 self.Rule = "BINARY"\r
451 \r
452 #\r
453 # Get the rule of how to generate Ffs file\r
454 #\r
455 Rule = self.__GetRule__()\r
456 GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName)\r
457 #\r
458 # Convert Fv File Type for PI1.1 SMM driver.\r
459 #\r
460 if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A:\r
461 if Rule.FvFileType == 'DRIVER':\r
462 Rule.FvFileType = 'SMM'\r
463 #\r
464 # Framework SMM Driver has no SMM FV file type\r
465 #\r
466 if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A:\r
467 if Rule.FvFileType == 'SMM' or Rule.FvFileType == 'SMM_CORE':\r
468 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM or SMM_CORE FV file type", File=self.InfFileName)\r
469 #\r
470 # For the rule only has simpleFile\r
471 #\r
472 if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :\r
473 SectionOutputList = self.__GenSimpleFileSection__(Rule)\r
474 FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutputList)\r
475 return FfsOutput\r
476 #\r
477 # For Rule has ComplexFile\r
478 #\r
479 elif isinstance(Rule, RuleComplexFile.RuleComplexFile):\r
480 InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr)\r
481 FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)\r
482\r
483 return FfsOutput\r
484\r
485 ## __ExtendMacro__() method\r
486 #\r
487 # Replace macro with its value\r
488 #\r
489 # @param self The object pointer\r
490 # @param String The string to be replaced\r
491 # @retval string Macro replaced string\r
492 #\r
493 def __ExtendMacro__ (self, String):\r
494 MacroDict = {\r
495 '$(INF_OUTPUT)' : self.EfiOutputPath,\r
496 '$(MODULE_NAME)' : self.BaseName,\r
497 '$(BUILD_NUMBER)': self.BuildNum,\r
498 '$(INF_VERSION)' : self.VersionString,\r
499 '$(NAMED_GUID)' : self.ModuleGuid\r
500 }\r
501 String = GenFdsGlobalVariable.MacroExtend(String, MacroDict)\r
502 String = GenFdsGlobalVariable.MacroExtend(String, self.MacroDict) \r
503 return String\r
504\r
505 ## __GetRule__() method\r
506 #\r
507 # Get correct rule for generating FFS for this INF\r
508 #\r
509 # @param self The object pointer\r
510 # @retval Rule Rule object\r
511 #\r
512 def __GetRule__ (self) :\r
513 CurrentArchList = []\r
514 if self.CurrentArch == None:\r
515 CurrentArchList = ['common']\r
516 else:\r
517 CurrentArchList.append(self.CurrentArch)\r
518\r
519 for CurrentArch in CurrentArchList:\r
520 RuleName = 'RULE' + \\r
521 '.' + \\r
522 CurrentArch.upper() + \\r
523 '.' + \\r
524 self.ModuleType.upper()\r
525 if self.Rule != None:\r
526 RuleName = RuleName + \\r
527 '.' + \\r
528 self.Rule.upper()\r
529\r
530 Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)\r
531 if Rule != None:\r
532 GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)\r
533 return Rule\r
534\r
535 RuleName = 'RULE' + \\r
536 '.' + \\r
537 'COMMON' + \\r
538 '.' + \\r
539 self.ModuleType.upper()\r
540\r
541 if self.Rule != None:\r
542 RuleName = RuleName + \\r
543 '.' + \\r
544 self.Rule.upper()\r
545\r
546 GenFdsGlobalVariable.VerboseLogger ('Trying to apply common rule %s for INF %s' % (RuleName, self.InfFileName))\r
547\r
548 Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)\r
549 if Rule != None:\r
550 GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)\r
551 return Rule\r
552\r
553 if Rule == None :\r
554 EdkLogger.error("GenFds", GENFDS_ERROR, 'Don\'t Find common rule %s for INF %s' \\r
555 % (RuleName, self.InfFileName))\r
556\r
557 ## __GetPlatformArchList__() method\r
558 #\r
559 # Get Arch list this INF built under\r
560 #\r
561 # @param self The object pointer\r
562 # @retval list Arch list\r
563 #\r
564 def __GetPlatformArchList__(self):\r
565\r
566 InfFileKey = os.path.normpath(mws.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName))\r
567 DscArchList = []\r
568 for Arch in GenFdsGlobalVariable.ArchList :\r
569 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
570 if PlatformDataBase != None:\r
571 if InfFileKey in PlatformDataBase.Modules:\r
572 DscArchList.append (Arch)\r
573 else:\r
574 #\r
575 # BaseTools support build same module more than once, the module path with FILE_GUID overridden has\r
576 # the file name FILE_GUIDmodule.inf, then PlatformDataBase.Modules use FILE_GUIDmodule.inf as key,\r
577 # but the path (self.MetaFile.Path) is the real path\r
578 #\r
579 for key in PlatformDataBase.Modules.keys():\r
580 if InfFileKey == str((PlatformDataBase.Modules[key]).MetaFile.Path):\r
581 DscArchList.append (Arch)\r
582 break\r
583\r
584 return DscArchList\r
585\r
586 ## GetCurrentArch() method\r
587 #\r
588 # Get Arch list of the module from this INF is to be placed into flash\r
589 #\r
590 # @param self The object pointer\r
591 # @retval list Arch list\r
592 #\r
593 def GetCurrentArch(self) :\r
594\r
595 TargetArchList = GenFdsGlobalVariable.ArchList\r
596\r
597 PlatformArchList = self.__GetPlatformArchList__()\r
598\r
599 CurArchList = TargetArchList\r
600 if PlatformArchList != []:\r
601 CurArchList = list(set (TargetArchList) & set (PlatformArchList))\r
602 GenFdsGlobalVariable.VerboseLogger ("Valid target architecture(s) is : " + " ".join(CurArchList))\r
603\r
604 ArchList = []\r
605 if self.KeyStringList != []:\r
606 for Key in self.KeyStringList:\r
607 Key = GenFdsGlobalVariable.MacroExtend(Key)\r
608 Target, Tag, Arch = Key.split('_')\r
609 if Arch in CurArchList:\r
610 ArchList.append(Arch)\r
611 if Target not in self.TargetOverrideList:\r
612 self.TargetOverrideList.append(Target)\r
613 else:\r
614 ArchList = CurArchList\r
615\r
616 UseArchList = TargetArchList\r
617 if self.UseArch != None:\r
618 UseArchList = []\r
619 UseArchList.append(self.UseArch)\r
620 ArchList = list(set (UseArchList) & set (ArchList))\r
621\r
622 self.InfFileName = NormPath(self.InfFileName)\r
623 if len(PlatformArchList) == 0:\r
624 self.InDsc = False\r
625 PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
626 ErrorCode, ErrorInfo = PathClassObj.Validate(".inf")\r
627 if ErrorCode != 0:\r
628 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
629 if len(ArchList) == 1:\r
630 Arch = ArchList[0]\r
631 return Arch\r
632 elif len(ArchList) > 1:\r
633 if len(PlatformArchList) == 0:\r
634 EdkLogger.error("GenFds", GENFDS_ERROR, "GenFds command line option has multiple ARCHs %s. Not able to determine which ARCH is valid for Module %s !" % (str(ArchList), self.InfFileName))\r
635 else:\r
636 EdkLogger.error("GenFds", GENFDS_ERROR, "Module built under multiple ARCHs %s. Not able to determine which output to put into flash for Module %s !" % (str(ArchList), self.InfFileName))\r
637 else:\r
638 EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s appears under ARCH %s in platform %s, but current deduced ARCH is %s, so NO build output could be put into flash." \\r
639 % (self.InfFileName, str(PlatformArchList), GenFdsGlobalVariable.ActivePlatform, str(set (UseArchList) & set (TargetArchList))))\r
640\r
641 ## __GetEFIOutPutPath__() method\r
642 #\r
643 # Get the output path for generated files\r
644 #\r
645 # @param self The object pointer\r
646 # @retval string Path that output files from this INF go to\r
647 #\r
648 def __GetEFIOutPutPath__(self):\r
649 Arch = ''\r
650 OutputPath = ''\r
651 (ModulePath, FileName) = os.path.split(self.InfFileName)\r
652 Index = FileName.rfind('.')\r
653 FileName = FileName[0:Index]\r
654 if self.OverrideGuid:\r
655 FileName = self.OverrideGuid\r
656 Arch = "NoneArch"\r
657 if self.CurrentArch != None:\r
658 Arch = self.CurrentArch\r
659\r
660 OutputPath = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch],\r
661 Arch ,\r
662 ModulePath,\r
663 FileName,\r
664 'OUTPUT'\r
665 )\r
666 OutputPath = os.path.realpath(OutputPath)\r
667 return OutputPath\r
668\r
669 ## __GenSimpleFileSection__() method\r
670 #\r
671 # Generate section by specified file name or a list of files with file extension\r
672 #\r
673 # @param self The object pointer\r
674 # @param Rule The rule object used to generate section\r
675 # @retval string File name of the generated section file\r
676 #\r
677 def __GenSimpleFileSection__(self, Rule):\r
678 #\r
679 # Prepare the parameter of GenSection\r
680 #\r
681 FileList = []\r
682 OutputFileList = []\r
683 GenSecInputFile = None\r
684 if Rule.FileName != None:\r
685 GenSecInputFile = self.__ExtendMacro__(Rule.FileName)\r
686 if os.path.isabs(GenSecInputFile):\r
687 GenSecInputFile = os.path.normpath(GenSecInputFile)\r
688 else:\r
689 GenSecInputFile = os.path.normpath(os.path.join(self.EfiOutputPath, GenSecInputFile))\r
690 else:\r
691 FileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)\r
692\r
693 Index = 1\r
694 SectionType = Rule.SectionType\r
695 #\r
696 # Convert Fv Section Type for PI1.1 SMM driver.\r
697 #\r
698 if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A:\r
699 if SectionType == 'DXE_DEPEX':\r
700 SectionType = 'SMM_DEPEX'\r
701 #\r
702 # Framework SMM Driver has no SMM_DEPEX section type\r
703 #\r
704 if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A:\r
705 if SectionType == 'SMM_DEPEX':\r
706 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
707 NoStrip = True\r
708 if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
709 if self.KeepReloc != None:\r
710 NoStrip = self.KeepReloc\r
711 elif Rule.KeepReloc != None:\r
712 NoStrip = Rule.KeepReloc\r
713 elif self.ShadowFromInfFile != None:\r
714 NoStrip = self.ShadowFromInfFile\r
715\r
716 if FileList != [] :\r
717 for File in FileList:\r
718\r
719 SecNum = '%d' %Index\r
720 GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
721 Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
722 Index = Index + 1\r
723 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
724 File = GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)\r
725\r
726 #Get PE Section alignment when align is set to AUTO\r
727 if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
728 ImageObj = PeImageClass (File)\r
729 if ImageObj.SectionAlignment < 0x400:\r
730 self.Alignment = str (ImageObj.SectionAlignment)\r
731 else:\r
732 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
733\r
734 if not NoStrip:\r
735 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
736 if not os.path.exists(FileBeforeStrip) or \\r
737 (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
738 CopyLongFilePath(File, FileBeforeStrip)\r
739 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
740 GenFdsGlobalVariable.GenerateFirmwareImage(\r
741 StrippedFile,\r
742 [File],\r
743 Strip=True\r
744 )\r
745 File = StrippedFile\r
746\r
747 if SectionType == 'TE':\r
748 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
749 GenFdsGlobalVariable.GenerateFirmwareImage(\r
750 TeFile,\r
751 [File],\r
752 Type='te'\r
753 )\r
754 File = TeFile\r
755\r
756 GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType])\r
757 OutputFileList.append(OutputFile)\r
758 else:\r
759 SecNum = '%d' %Index\r
760 GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
761 Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
762 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
763 GenSecInputFile = GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)\r
764\r
765 #Get PE Section alignment when align is set to AUTO\r
766 if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r
767 ImageObj = PeImageClass (GenSecInputFile)\r
768 if ImageObj.SectionAlignment < 0x400:\r
769 self.Alignment = str (ImageObj.SectionAlignment)\r
770 else:\r
771 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
772\r
773 if not NoStrip:\r
774 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
775 if not os.path.exists(FileBeforeStrip) or \\r
776 (os.path.getmtime(GenSecInputFile) > os.path.getmtime(FileBeforeStrip)):\r
777 CopyLongFilePath(GenSecInputFile, FileBeforeStrip)\r
778\r
779 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
780 GenFdsGlobalVariable.GenerateFirmwareImage(\r
781 StrippedFile,\r
782 [GenSecInputFile],\r
783 Strip=True\r
784 )\r
785 GenSecInputFile = StrippedFile\r
786\r
787 if SectionType == 'TE':\r
788 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
789 GenFdsGlobalVariable.GenerateFirmwareImage(\r
790 TeFile,\r
791 [GenSecInputFile],\r
792 Type='te'\r
793 )\r
794 GenSecInputFile = TeFile\r
795\r
796 GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType])\r
797 OutputFileList.append(OutputFile)\r
798\r
799 return OutputFileList\r
800\r
801 ## __GenSimpleFileFfs__() method\r
802 #\r
803 # Generate FFS\r
804 #\r
805 # @param self The object pointer\r
806 # @param Rule The rule object used to generate section\r
807 # @param InputFileList The output file list from GenSection\r
808 # @retval string Generated FFS file name\r
809 #\r
810 def __GenSimpleFileFfs__(self, Rule, InputFileList):\r
811 FfsOutput = self.OutputPath + \\r
812 os.sep + \\r
813 self.__ExtendMacro__(Rule.NameGuid) + \\r
814 '.ffs'\r
815\r
816 GenFdsGlobalVariable.VerboseLogger(self.__ExtendMacro__(Rule.NameGuid))\r
817 InputSection = []\r
818 SectionAlignments = []\r
819 for InputFile in InputFileList:\r
820 InputSection.append(InputFile)\r
821 SectionAlignments.append(Rule.SectAlignment)\r
822\r
823 if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):\r
824 PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)\r
825 if len(PcdValue) == 0:\r
826 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
827 % (Rule.NameGuid))\r
828 if PcdValue.startswith('{'):\r
829 PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r
830 RegistryGuidStr = PcdValue\r
831 if len(RegistryGuidStr) == 0:\r
832 EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r
833 % (Rule.NameGuid))\r
834 self.ModuleGuid = RegistryGuidStr\r
835\r
836 GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputSection,\r
837 Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
838 self.ModuleGuid, Fixed=Rule.Fixed,\r
839 CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
840 SectionAlign=SectionAlignments\r
841 )\r
842 return FfsOutput\r
843\r
844 ## __GenComplexFileSection__() method\r
845 #\r
846 # Generate section by sections in Rule\r
847 #\r
848 # @param self The object pointer\r
849 # @param Rule The rule object used to generate section\r
850 # @param FvChildAddr Array of the inside FvImage base address\r
851 # @param FvParentAddr Parent Fv base address\r
852 # @retval string File name of the generated section file\r
853 #\r
854 def __GenComplexFileSection__(self, Rule, FvChildAddr, FvParentAddr):\r
855 if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
856 if Rule.KeepReloc != None:\r
857 self.KeepRelocFromRule = Rule.KeepReloc\r
858 SectFiles = []\r
859 SectAlignments = []\r
860 Index = 1\r
861 HasGneratedFlag = False\r
862 if self.PcdIsDriver == 'PEI_PCD_DRIVER':\r
863 if self.IsBinaryModule:\r
864 PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "PEIPcdDataBase.raw")\r
865 else:\r
866 PcdExDbFileName = os.path.join(self.EfiOutputPath, "PEIPcdDataBase.raw")\r
867 PcdExDbSecName = os.path.join(self.OutputPath, "PEIPcdDataBaseSec.raw")\r
868 GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
869 [PcdExDbFileName],\r
870 "EFI_SECTION_RAW",\r
871 )\r
872 SectFiles.append(PcdExDbSecName)\r
873 SectAlignments.append(None)\r
874 elif self.PcdIsDriver == 'DXE_PCD_DRIVER':\r
875 if self.IsBinaryModule:\r
876 PcdExDbFileName = os.path.join(GenFdsGlobalVariable.FvDir, "DXEPcdDataBase.raw")\r
877 else:\r
878 PcdExDbFileName = os.path.join(self.EfiOutputPath, "DXEPcdDataBase.raw")\r
879 PcdExDbSecName = os.path.join(self.OutputPath, "DXEPcdDataBaseSec.raw")\r
880 GenFdsGlobalVariable.GenerateSection(PcdExDbSecName,\r
881 [PcdExDbFileName],\r
882 "EFI_SECTION_RAW",\r
883 )\r
884 SectFiles.append(PcdExDbSecName)\r
885 SectAlignments.append(None)\r
886 for Sect in Rule.SectionList:\r
887 SecIndex = '%d' %Index\r
888 SectList = []\r
889 #\r
890 # Convert Fv Section Type for PI1.1 SMM driver.\r
891 #\r
892 if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) >= 0x0001000A:\r
893 if Sect.SectionType == 'DXE_DEPEX':\r
894 Sect.SectionType = 'SMM_DEPEX'\r
895 #\r
896 # Framework SMM Driver has no SMM_DEPEX section type\r
897 #\r
898 if self.ModuleType == 'DXE_SMM_DRIVER' and int(self.PiSpecVersion, 16) < 0x0001000A:\r
899 if Sect.SectionType == 'SMM_DEPEX':\r
900 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
901 #\r
902 # process the inside FvImage from FvSection or GuidSection\r
903 #\r
904 if FvChildAddr != []:\r
905 if isinstance(Sect, FvImageSection):\r
906 Sect.FvAddr = FvChildAddr.pop(0)\r
907 elif isinstance(Sect, GuidSection):\r
908 Sect.FvAddr = FvChildAddr\r
909 if FvParentAddr != None and isinstance(Sect, GuidSection):\r
910 Sect.FvParentAddr = FvParentAddr\r
911 \r
912 if Rule.KeyStringList != []:\r
913 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
914 else :\r
915 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)\r
916 \r
917 if not HasGneratedFlag:\r
918 UniVfrOffsetFileSection = "" \r
919 ModuleFileName = mws.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName)\r
920 InfData = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(ModuleFileName), self.CurrentArch]\r
921 #\r
922 # Search the source list in InfData to find if there are .vfr file exist.\r
923 #\r
924 VfrUniBaseName = {}\r
925 VfrUniOffsetList = []\r
926 for SourceFile in InfData.Sources:\r
927 if SourceFile.Type.upper() == ".VFR" :\r
928 #\r
929 # search the .map file to find the offset of vfr binary in the PE32+/TE file. \r
930 #\r
931 VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
932 if SourceFile.Type.upper() == ".UNI" :\r
933 #\r
934 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file. \r
935 #\r
936 VfrUniBaseName["UniOffsetName"] = (self.BaseName + "Strings")\r
937 \r
938 \r
939 if len(VfrUniBaseName) > 0:\r
940 VfrUniOffsetList = self.__GetBuildOutputMapFileVfrUniInfo(VfrUniBaseName)\r
941 #\r
942 # Generate the Raw data of raw section\r
943 #\r
944 if VfrUniOffsetList:\r
945 os.path.join( self.OutputPath, self.BaseName + '.offset')\r
946 UniVfrOffsetFileName = os.path.join( self.OutputPath, self.BaseName + '.offset')\r
947 UniVfrOffsetFileSection = os.path.join( self.OutputPath, self.BaseName + 'Offset' + '.raw')\r
948\r
949 self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)\r
950\r
951 UniVfrOffsetFileNameList = []\r
952 UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)\r
953 """Call GenSection"""\r
954 GenFdsGlobalVariable.GenerateSection(UniVfrOffsetFileSection,\r
955 UniVfrOffsetFileNameList,\r
956 "EFI_SECTION_RAW"\r
957 )\r
958 os.remove(UniVfrOffsetFileName)\r
959 SectList.append(UniVfrOffsetFileSection)\r
960 HasGneratedFlag = True\r
961 \r
962 for SecName in SectList :\r
963 SectFiles.append(SecName)\r
964 SectAlignments.append(Align)\r
965 Index = Index + 1\r
966 return SectFiles, SectAlignments\r
967\r
968 ## __GenComplexFileFfs__() method\r
969 #\r
970 # Generate FFS\r
971 #\r
972 # @param self The object pointer\r
973 # @param Rule The rule object used to generate section\r
974 # @param InputFileList The output file list from GenSection\r
975 # @retval string Generated FFS file name\r
976 #\r
977 def __GenComplexFileFfs__(self, Rule, InputFile, Alignments):\r
978\r
979 if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):\r
980 PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)\r
981 if len(PcdValue) == 0:\r
982 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
983 % (Rule.NameGuid))\r
984 if PcdValue.startswith('{'):\r
985 PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r
986 RegistryGuidStr = PcdValue\r
987 if len(RegistryGuidStr) == 0:\r
988 EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r
989 % (Rule.NameGuid))\r
990 self.ModuleGuid = RegistryGuidStr\r
991\r
992 FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
993 GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputFile,\r
994 Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
995 self.ModuleGuid, Fixed=Rule.Fixed,\r
996 CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
997 SectionAlign=Alignments\r
998 )\r
999 return FfsOutput\r
1000\r
1001 ## __GetGenFfsCmdParameter__() method\r
1002 #\r
1003 # Create parameter string for GenFfs\r
1004 #\r
1005 # @param self The object pointer\r
1006 # @param Rule The rule object used to generate section\r
1007 # @retval tuple (FileType, Fixed, CheckSum, Alignment)\r
1008 #\r
1009 def __GetGenFfsCmdParameter__(self, Rule):\r
1010 result = tuple()\r
1011 result += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType])\r
1012 if Rule.Fixed != False:\r
1013 result += ('-x',)\r
1014 if Rule.CheckSum != False:\r
1015 result += ('-s',)\r
1016\r
1017 if Rule.Alignment != None and Rule.Alignment != '':\r
1018 result += ('-a', Rule.Alignment)\r
1019\r
1020 return result\r
1021 \r
1022 ## __GetBuildOutputMapFileVfrUniInfo() method\r
1023 #\r
1024 # Find the offset of UNI/INF object offset in the EFI image file.\r
1025 #\r
1026 # @param self The object pointer\r
1027 # @param VfrUniBaseName A name list contain the UNI/INF object name.\r
1028 # @retval RetValue A list contain offset of UNI/INF object.\r
1029 # \r
1030 def __GetBuildOutputMapFileVfrUniInfo(self, VfrUniBaseName):\r
1031 MapFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".map")\r
1032 EfiFileName = os.path.join(self.EfiOutputPath, self.BaseName + ".efi")\r
1033 return GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())\r
1034 \r
1035 ## __GenUniVfrOffsetFile() method\r
1036 #\r
1037 # Generate the offset file for the module which contain VFR or UNI file.\r
1038 #\r
1039 # @param self The object pointer\r
1040 # @param VfrUniOffsetList A list contain the VFR/UNI offsets in the EFI image file.\r
1041 # @param UniVfrOffsetFileName The output offset file name.\r
1042 #\r
1043 def __GenUniVfrOffsetFile(self, VfrUniOffsetList, UniVfrOffsetFileName):\r
1044 \r
1045 try:\r
1046 fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
1047 except:\r
1048 EdkLogger.error("GenFds", FILE_OPEN_FAILURE, "File open failed for %s" %UniVfrOffsetFileName,None)\r
1049 \r
1050 # Use a instance of StringIO to cache data\r
1051 fStringIO = StringIO.StringIO('') \r
1052 \r
1053 for Item in VfrUniOffsetList:\r
1054 if (Item[0].find("Strings") != -1):\r
1055 #\r
1056 # UNI offset in image.\r
1057 # GUID + Offset\r
1058 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
1059 #\r
1060 UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
1061 UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
1062 fStringIO.write(''.join(UniGuid)) \r
1063 UniValue = pack ('Q', int (Item[1], 16))\r
1064 fStringIO.write (UniValue)\r
1065 else:\r
1066 #\r
1067 # VFR binary offset in image.\r
1068 # GUID + Offset\r
1069 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
1070 #\r
1071 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
1072 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
1073 fStringIO.write(''.join(VfrGuid)) \r
1074 type (Item[1]) \r
1075 VfrValue = pack ('Q', int (Item[1], 16))\r
1076 fStringIO.write (VfrValue)\r
1077 \r
1078 #\r
1079 # write data into file.\r
1080 #\r
1081 try : \r
1082 fInputfile.write (fStringIO.getvalue())\r
1083 except:\r
1084 EdkLogger.error("GenFds", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %UniVfrOffsetFileName,None)\r
1085 \r
1086 fStringIO.close ()\r
1087 fInputfile.close ()\r
1088 \r
1089 \r
1090 \r
1091 \r
1092 \r
1093 \r
1094 \r
1095 \r