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