]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/FfsInfStatement.py
Fix build break caused by adding DebugAgentLib to the DXE Core.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsInfStatement.py
CommitLineData
30fdf114
LG
1## @file\r
2# process FFS generation from INF statement\r
3#\r
4# Copyright (c) 2007, Intel Corporation\r
5#\r
6# All rights reserved. This program and the accompanying materials\r
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
18import Rule\r
19import os\r
20import shutil\r
21from GenFdsGlobalVariable import GenFdsGlobalVariable\r
22import Ffs\r
23import subprocess\r
24import sys\r
25import Section\r
26import RuleSimpleFile\r
27import RuleComplexFile\r
28from CommonDataClass.FdfClass import FfsInfStatementClassObject\r
29from Common.String import *\r
30from Common.Misc import PathClass\r
31from Common.Misc import GuidStructureByteArrayToGuidString\r
32from Common import EdkLogger\r
33from Common.BuildToolError import *\r
34\r
35## generate FFS from INF\r
36#\r
37#\r
38class FfsInfStatement(FfsInfStatementClassObject):\r
39 ## The constructor\r
40 #\r
41 # @param self The object pointer\r
42 #\r
43 def __init__(self):\r
44 FfsInfStatementClassObject.__init__(self)\r
45 self.TargetOverrideList = []\r
46 self.ShadowFromInfFile = None\r
47 self.KeepRelocFromRule = None\r
48 self.InDsc = True\r
49 self.OptRomDefs = {}\r
b303ea72 50 self.PiSpecVersion = 0\r
30fdf114
LG
51 \r
52 ## __InfParse() method\r
53 #\r
54 # Parse inf file to get module information\r
55 #\r
56 # @param self The object pointer\r
57 # @param Dict dictionary contains macro and value pair\r
58 #\r
59 def __InfParse__(self, Dict = {}):\r
60\r
61 GenFdsGlobalVariable.VerboseLogger( " Begine parsing INf file : %s" %self.InfFileName)\r
62\r
63 self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '')\r
64 if self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :\r
65 self.InfFileName = self.InfFileName[1:]\r
66\r
67 if self.InfFileName.find('$') == -1:\r
68 InfPath = NormPath(self.InfFileName)\r
69 if not os.path.exists(InfPath):\r
70 InfPath = GenFdsGlobalVariable.ReplaceWorkspaceMacro(InfPath)\r
71 if not os.path.exists(InfPath):\r
72 EdkLogger.error("GenFds", GENFDS_ERROR, "Non-existant Module %s !" % (self.InfFileName))\r
73\r
74 self.CurrentArch = self.GetCurrentArch()\r
75 #\r
76 # Get the InfClass object\r
77 #\r
78\r
79 PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
80 ErrorCode, ErrorInfo = PathClassObj.Validate()\r
81 if ErrorCode != 0:\r
82 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
83 \r
84 if self.CurrentArch != None:\r
85\r
86 Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch]\r
87 #\r
88 # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath\r
89 #\r
90 self.BaseName = Inf.BaseName\r
91 self.ModuleGuid = Inf.Guid\r
92 self.ModuleType = Inf.ModuleType\r
b303ea72
LG
93 if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:
94 self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']\r
30fdf114
LG
95 if Inf.AutoGenVersion < 0x00010005:\r
96 self.ModuleType = Inf.ComponentType\r
97 self.VersionString = Inf.Version\r
98 self.BinFileList = Inf.Binaries\r
99 self.SourceFileList = Inf.Sources\r
100 if self.KeepReloc == None and Inf.Shadow:\r
101 self.ShadowFromInfFile = Inf.Shadow\r
102\r
103 else:\r
104 Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON']\r
105 self.BaseName = Inf.BaseName\r
106 self.ModuleGuid = Inf.Guid\r
107 self.ModuleType = Inf.ModuleType\r
b303ea72
LG
108 if Inf.Specification != None and 'PI_SPECIFICATION_VERSION' in Inf.Specification:
109 self.PiSpecVersion = Inf.Specification['PI_SPECIFICATION_VERSION']\r
30fdf114
LG
110 self.VersionString = Inf.Version\r
111 self.BinFileList = Inf.Binaries\r
112 self.SourceFileList = Inf.Sources\r
113 if self.BinFileList == []:\r
114 EdkLogger.error("GenFds", GENFDS_ERROR,\r
115 "INF %s specified in FDF could not be found in build ARCH %s!" \\r
116 % (self.InfFileName, GenFdsGlobalVariable.ArchList))\r
117\r
118 if len(self.SourceFileList) != 0 and not self.InDsc:\r
119 EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (self.InfFileName))\r
120\r
b303ea72
LG
121 if self.ModuleType == 'SMM_CORE' and self.PiSpecVersion < 0x0001000A:
122 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
123\r
30fdf114
LG
124 if Inf._Defs != None and len(Inf._Defs) > 0:\r
125 self.OptRomDefs.update(Inf._Defs)\r
126 \r
127 GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName)\r
128 GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid)\r
129 GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" %self.ModuleType)\r
130 GenFdsGlobalVariable.VerboseLogger("VersionString : %s" %self.VersionString)\r
131 GenFdsGlobalVariable.VerboseLogger("InfFileName :%s" %self.InfFileName)\r
132\r
133 #\r
134 # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\\r
135 #\r
136\r
137 self.OutputPath = os.path.join(GenFdsGlobalVariable.FfsDir, \\r
138 self.ModuleGuid + self.BaseName)\r
139 if not os.path.exists(self.OutputPath) :\r
140 os.makedirs(self.OutputPath)\r
141\r
142 self.EfiOutputPath = self.__GetEFIOutPutPath__()\r
143 GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)\r
144\r
145 ## GenFfs() method\r
146 #\r
147 # Generate FFS\r
148 #\r
149 # @param self The object pointer\r
150 # @param Dict dictionary contains macro and value pair\r
151 # @retval string Generated FFS file name\r
152 #\r
153 def GenFfs(self, Dict = {}):\r
154 #\r
155 # Parse Inf file get Module related information\r
156 #\r
157\r
158 self.__InfParse__(Dict)\r
159 #\r
160 # Get the rule of how to generate Ffs file\r
161 #\r
162 Rule = self.__GetRule__()\r
163 GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName)\r
b303ea72
LG
164 #\r
165 # Convert Fv File Type for PI1.1 SMM driver.\r
166 #\r
167 if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
168 if Rule.FvFileType == 'DRIVER':\r
169 Rule.FvFileType = 'SMM'\r
170 #\r
171 # Framework SMM Driver has no SMM FV file type\r
172 #\r
173 if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
174 if Rule.FvFileType == 'SMM' or Rule.FvFileType == 'SMM_CORE':\r
175 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM or SMM_CORE FV file type", File=self.InfFileName)\r
30fdf114
LG
176 #\r
177 # For the rule only has simpleFile\r
178 #\r
179 if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :\r
180 SectionOutputList = self.__GenSimpleFileSection__(Rule)\r
181 FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutputList)\r
182 return FfsOutput\r
183 #\r
184 # For Rule has ComplexFile\r
185 #\r
186 elif isinstance(Rule, RuleComplexFile.RuleComplexFile):\r
187 InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule)\r
188 FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList, InputSectAlignments)\r
189\r
190 return FfsOutput\r
191\r
192 ## __ExtendMacro__() method\r
193 #\r
194 # Replace macro with its value\r
195 #\r
196 # @param self The object pointer\r
197 # @param String The string to be replaced\r
198 # @retval string Macro replaced string\r
199 #\r
200 def __ExtendMacro__ (self, String):\r
201 MacroDict = {\r
202 '$(INF_OUTPUT)' : self.EfiOutputPath,\r
203 '$(MODULE_NAME)' : self.BaseName,\r
204 '$(BUILD_NUMBER)': self.BuildNum,\r
205 '$(INF_VERSION)' : self.VersionString,\r
206 '$(NAMED_GUID)' : self.ModuleGuid\r
207 }\r
208 String = GenFdsGlobalVariable.MacroExtend(String, MacroDict)\r
209 return String\r
210\r
211 ## __GetRule__() method\r
212 #\r
213 # Get correct rule for generating FFS for this INF\r
214 #\r
215 # @param self The object pointer\r
216 # @retval Rule Rule object\r
217 #\r
218 def __GetRule__ (self) :\r
219 CurrentArchList = []\r
220 if self.CurrentArch == None:\r
221 CurrentArchList = ['common']\r
222 else:\r
223 CurrentArchList.append(self.CurrentArch)\r
224\r
225 for CurrentArch in CurrentArchList:\r
226 RuleName = 'RULE' + \\r
227 '.' + \\r
228 CurrentArch.upper() + \\r
229 '.' + \\r
230 self.ModuleType.upper()\r
231 if self.Rule != None:\r
232 RuleName = RuleName + \\r
233 '.' + \\r
234 self.Rule.upper()\r
235\r
236 Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)\r
237 if Rule != None:\r
238 GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)\r
239 return Rule\r
240\r
241 RuleName = 'RULE' + \\r
242 '.' + \\r
243 'COMMON' + \\r
244 '.' + \\r
245 self.ModuleType.upper()\r
246\r
247 if self.Rule != None:\r
248 RuleName = RuleName + \\r
249 '.' + \\r
250 self.Rule.upper()\r
251\r
252 GenFdsGlobalVariable.VerboseLogger ('Trying to apply common rule %s for INF %s' % (RuleName, self.InfFileName))\r
253\r
254 Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)\r
255 if Rule != None:\r
256 GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)\r
257 return Rule\r
258\r
259 if Rule == None :\r
260 EdkLogger.error("GenFds", GENFDS_ERROR, 'Don\'t Find common rule %s for INF %s' \\r
261 % (RuleName, self.InfFileName))\r
262\r
263 ## __GetPlatformArchList__() method\r
264 #\r
265 # Get Arch list this INF built under\r
266 #\r
267 # @param self The object pointer\r
268 # @retval list Arch list\r
269 #\r
270 def __GetPlatformArchList__(self):\r
271\r
272 InfFileKey = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName))\r
273 DscArchList = []\r
274 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32']\r
275 if PlatformDataBase != None:\r
276 if InfFileKey in PlatformDataBase.Modules:\r
277 DscArchList.append ('IA32')\r
278\r
279 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64']\r
280 if PlatformDataBase != None:\r
281 if InfFileKey in PlatformDataBase.Modules:\r
282 DscArchList.append ('X64')\r
283\r
284 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF']\r
285 if PlatformDataBase != None:\r
286 if InfFileKey in (PlatformDataBase.Modules):\r
287 DscArchList.append ('IPF')\r
288\r
289 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM']\r
290 if PlatformDataBase != None:\r
291 if InfFileKey in (PlatformDataBase.Modules):\r
292 DscArchList.append ('ARM')\r
293\r
294 PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC']\r
295 if PlatformDataBase != None:\r
296 if InfFileKey in (PlatformDataBase.Modules):\r
297 DscArchList.append ('EBC')\r
298\r
299 return DscArchList\r
300\r
301 ## GetCurrentArch() method\r
302 #\r
303 # Get Arch list of the module from this INF is to be placed into flash\r
304 #\r
305 # @param self The object pointer\r
306 # @retval list Arch list\r
307 #\r
308 def GetCurrentArch(self) :\r
309\r
310 TargetArchList = GenFdsGlobalVariable.ArchList\r
311\r
312 PlatformArchList = self.__GetPlatformArchList__()\r
313\r
314 CurArchList = TargetArchList\r
315 if PlatformArchList != []:\r
316 CurArchList = list(set (TargetArchList) & set (PlatformArchList))\r
317 GenFdsGlobalVariable.VerboseLogger ("Valid target architecture(s) is : " + " ".join(CurArchList))\r
318\r
319 ArchList = []\r
320 if self.KeyStringList != []:\r
321 for Key in self.KeyStringList:\r
322 Key = GenFdsGlobalVariable.MacroExtend(Key)\r
323 Target, Tag, Arch = Key.split('_')\r
324 if Arch in CurArchList:\r
325 ArchList.append(Arch)\r
326 if Target not in self.TargetOverrideList:\r
327 self.TargetOverrideList.append(Target)\r
328 else:\r
329 ArchList = CurArchList\r
330\r
331 UseArchList = TargetArchList\r
332 if self.UseArch != None:\r
333 UseArchList = []\r
334 UseArchList.append(self.UseArch)\r
335 ArchList = list(set (UseArchList) & set (ArchList))\r
336\r
337 self.InfFileName = NormPath(self.InfFileName)\r
338 if len(PlatformArchList) == 0:\r
339 self.InDsc = False\r
340 PathClassObj = PathClass(self.InfFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
341 ErrorCode, ErrorInfo = PathClassObj.Validate()\r
342 if ErrorCode != 0:\r
343 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
344 if len(ArchList) == 1:\r
345 Arch = ArchList[0]\r
346 return Arch\r
347 elif len(ArchList) > 1:\r
348 if len(PlatformArchList) == 0:\r
349 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
350 else:\r
351 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
352 else:\r
353 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
354 % (self.InfFileName, str(PlatformArchList), GenFdsGlobalVariable.ActivePlatform, str(set (UseArchList) & set (TargetArchList))))\r
355\r
356 ## __GetEFIOutPutPath__() method\r
357 #\r
358 # Get the output path for generated files\r
359 #\r
360 # @param self The object pointer\r
361 # @retval string Path that output files from this INF go to\r
362 #\r
363 def __GetEFIOutPutPath__(self):\r
364 Arch = ''\r
365 OutputPath = ''\r
366 (ModulePath, FileName) = os.path.split(self.InfFileName)\r
367 Index = FileName.find('.')\r
368 FileName = FileName[0:Index]\r
369 Arch = "NoneArch"\r
370 if self.CurrentArch != None:\r
371 Arch = self.CurrentArch\r
372\r
373 OutputPath = os.path.join(GenFdsGlobalVariable.OutputDirDict[Arch],\r
374 Arch ,\r
375 ModulePath,\r
376 FileName,\r
377 'OUTPUT'\r
378 )\r
379 OutputPath = os.path.realpath(OutputPath)\r
380 return OutputPath\r
381\r
382 ## __GenSimpleFileSection__() method\r
383 #\r
384 # Generate section by specified file name or a list of files with file extension\r
385 #\r
386 # @param self The object pointer\r
387 # @param Rule The rule object used to generate section\r
388 # @retval string File name of the generated section file\r
389 #\r
390 def __GenSimpleFileSection__(self, Rule):\r
391 #\r
392 # Prepare the parameter of GenSection\r
393 #\r
394 FileList = []\r
395 OutputFileList = []\r
396 if Rule.FileName != None:\r
397 GenSecInputFile = self.__ExtendMacro__(Rule.FileName)\r
398 else:\r
399 FileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)\r
400\r
401 Index = 1\r
b303ea72
LG
402 SectionType = Rule.SectionType\r
403 #\r
404 # Convert Fv Section Type for PI1.1 SMM driver.\r
405 #\r
406 if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
407 if SectionType == 'DXE_DEPEX':\r
408 SectionType = 'SMM_DEPEX'\r
409 #\r
410 # Framework SMM Driver has no SMM_DEPEX section type\r
411 #\r
412 if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
413 if SectionType == 'SMM_DEPEX':\r
414 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
30fdf114
LG
415 NoStrip = True\r
416 if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
417 if self.KeepReloc != None:\r
418 NoStrip = self.KeepReloc\r
419 elif Rule.KeepReloc != None:\r
420 NoStrip = Rule.KeepReloc\r
421 elif self.ShadowFromInfFile != None:\r
422 NoStrip = self.ShadowFromInfFile\r
423\r
424 if FileList != [] :\r
425 for File in FileList:\r
426\r
427 SecNum = '%d' %Index\r
428 GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
429 Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
430 Index = Index + 1\r
431 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
432\r
433 if not NoStrip:\r
434 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
435 if not os.path.exists(FileBeforeStrip) or \\r
436 (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
437 shutil.copyfile(File, FileBeforeStrip)\r
438 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
439 GenFdsGlobalVariable.GenerateFirmwareImage(\r
440 StrippedFile,\r
441 [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
442 Strip=True\r
443 )\r
444 File = StrippedFile\r
445\r
446 if SectionType == 'TE':\r
447 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
448 GenFdsGlobalVariable.GenerateFirmwareImage(\r
449 TeFile,\r
450 [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
451 Type='te'\r
452 )\r
453 File = TeFile\r
454\r
455 GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType])\r
456 OutputFileList.append(OutputFile)\r
457 else:\r
458 SecNum = '%d' %Index\r
459 GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \\r
460 Ffs.Ffs.SectionSuffix[SectionType] + 'SEC' + SecNum\r
461 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)\r
462\r
463 if not NoStrip:\r
464 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + '.reloc')\r
465 if not os.path.exists(FileBeforeStrip) or \\r
466 (os.path.getmtime(GenSecInputFile) > os.path.getmtime(FileBeforeStrip)):\r
467 shutil.copyfile(GenSecInputFile, FileBeforeStrip)\r
468 StrippedFile = os.path.join(self.OutputPath, ModuleName + '.stipped')\r
469 GenFdsGlobalVariable.GenerateFirmwareImage(\r
470 StrippedFile,\r
471 [GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch)],\r
472 Strip=True\r
473 )\r
474 GenSecInputFile = StrippedFile\r
475\r
476 if SectionType == 'TE':\r
477 TeFile = os.path.join( self.OutputPath, self.ModuleGuid + 'Te.raw')\r
478 GenFdsGlobalVariable.GenerateFirmwareImage(\r
479 TeFile,\r
480 [GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch)],\r
481 Type='te'\r
482 )\r
483 GenSecInputFile = TeFile\r
484\r
485 GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType])\r
486 OutputFileList.append(OutputFile)\r
487\r
488 return OutputFileList\r
489\r
490 ## __GenSimpleFileFfs__() method\r
491 #\r
492 # Generate FFS\r
493 #\r
494 # @param self The object pointer\r
495 # @param Rule The rule object used to generate section\r
496 # @param InputFileList The output file list from GenSection\r
497 # @retval string Generated FFS file name\r
498 #\r
499 def __GenSimpleFileFfs__(self, Rule, InputFileList):\r
500 FfsOutput = self.OutputPath + \\r
501 os.sep + \\r
502 self.__ExtendMacro__(Rule.NameGuid) + \\r
503 '.ffs'\r
504\r
505 GenFdsGlobalVariable.VerboseLogger(self.__ExtendMacro__(Rule.NameGuid))\r
506 InputSection = []\r
507 SectionAlignments = []\r
508 for InputFile in InputFileList:\r
509 InputSection.append(InputFile)\r
510 SectionAlignments.append(Rule.Alignment)\r
511\r
512 if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):\r
513 PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)\r
514 if len(PcdValue) == 0:\r
515 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
516 % (Rule.NameGuid))\r
517 if PcdValue.startswith('{'):\r
518 PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r
519 RegistryGuidStr = PcdValue\r
520 if len(RegistryGuidStr) == 0:\r
521 EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r
522 % (Rule.NameGuid))\r
523 self.ModuleGuid = RegistryGuidStr\r
524\r
525 GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputSection,\r
526 Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
527 self.ModuleGuid, Fixed=Rule.Fixed,\r
528 CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
529 SectionAlign=SectionAlignments\r
530 )\r
531 return FfsOutput\r
532\r
533 ## __GenComplexFileSection__() method\r
534 #\r
535 # Generate section by sections in Rule\r
536 #\r
537 # @param self The object pointer\r
538 # @param Rule The rule object used to generate section\r
539 # @retval string File name of the generated section file\r
540 #\r
541 def __GenComplexFileSection__(self, Rule):\r
542 if self.ModuleType in ('SEC', 'PEI_CORE', 'PEIM'):\r
543 if Rule.KeepReloc != None:\r
544 self.KeepRelocFromRule = Rule.KeepReloc\r
545 SectFiles = []\r
546 SectAlignments = []\r
547 Index = 1\r
548 for Sect in Rule.SectionList:\r
549 SecIndex = '%d' %Index\r
550 SectList = []\r
b303ea72
LG
551 #\r
552 # Convert Fv Section Type for PI1.1 SMM driver.\r
553 #\r
554 if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion >= 0x0001000A:\r
555 if Sect.SectionType == 'DXE_DEPEX':\r
556 Sect.SectionType = 'SMM_DEPEX'\r
557 #\r
558 # Framework SMM Driver has no SMM_DEPEX section type\r
559 #\r
560 if self.ModuleType == 'DXE_SMM_DRIVER' and self.PiSpecVersion < 0x0001000A:\r
561 if Sect.SectionType == 'SMM_DEPEX':\r
562 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)\r
30fdf114
LG
563 if Rule.KeyStringList != []:\r
564 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)\r
565 else :\r
566 SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)\r
567 for SecName in SectList :\r
568 SectFiles.append(SecName)\r
569 SectAlignments.append(Align)\r
570 Index = Index + 1\r
571 return SectFiles, SectAlignments\r
572\r
573 ## __GenComplexFileFfs__() method\r
574 #\r
575 # Generate FFS\r
576 #\r
577 # @param self The object pointer\r
578 # @param Rule The rule object used to generate section\r
579 # @param InputFileList The output file list from GenSection\r
580 # @retval string Generated FFS file name\r
581 #\r
582 def __GenComplexFileFfs__(self, Rule, InputFile, Alignments):\r
583\r
584 if Rule.NameGuid != None and Rule.NameGuid.startswith('PCD('):\r
585 PcdValue = GenFdsGlobalVariable.GetPcdValue(Rule.NameGuid)\r
586 if len(PcdValue) == 0:\r
587 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
588 % (Rule.NameGuid))\r
589 if PcdValue.startswith('{'):\r
590 PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r
591 RegistryGuidStr = PcdValue\r
592 if len(RegistryGuidStr) == 0:\r
593 EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r
594 % (Rule.NameGuid))\r
595 self.ModuleGuid = RegistryGuidStr\r
596\r
597 FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')\r
598 GenFdsGlobalVariable.GenerateFfs(FfsOutput, InputFile,\r
599 Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType],\r
600 self.ModuleGuid, Fixed=Rule.Fixed,\r
601 CheckSum=Rule.CheckSum, Align=Rule.Alignment,\r
602 SectionAlign=Alignments\r
603 )\r
604 return FfsOutput\r
605\r
606 ## __GetGenFfsCmdParameter__() method\r
607 #\r
608 # Create parameter string for GenFfs\r
609 #\r
610 # @param self The object pointer\r
611 # @param Rule The rule object used to generate section\r
612 # @retval tuple (FileType, Fixed, CheckSum, Alignment)\r
613 #\r
614 def __GetGenFfsCmdParameter__(self, Rule):\r
615 result = tuple()\r
616 result += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType])\r
617 if Rule.Fixed != False:\r
618 result += ('-x',)\r
619 if Rule.CheckSum != False:\r
620 result += ('-s',)\r
621\r
622 if Rule.Alignment != None and Rule.Alignment != '':\r
623 result += ('-a', Rule.Alignment)\r
624\r
625 return result\r