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