2 # Global variables for GenFds
4 # Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
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
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.
24 from Common
.BuildToolError
import *
25 from Common
import EdkLogger
26 from Common
.Misc
import SaveFileOnChange
28 from Common
.TargetTxtClassObject
import TargetTxtClassObject
29 from Common
.ToolDefClassObject
import ToolDefClassObject
30 from AutoGen
.BuildEngine
import BuildRule
31 import Common
.DataType
as DataType
32 from Common
.Misc
import PathClass
37 class GenFdsGlobalVariable
:
41 # will be FvDir + os.sep + 'Ffs'
48 OutputDirFromDscDict
= {}
55 FvAddressFileName
= ''
59 SharpNumberPerLine
= 40
62 FixedLoadAddress
= False
65 BuildRuleFamily
= "MSFT"
66 ToolChainFamily
= "MSFT"
67 __BuildRuleDatabase
= None
69 SectionHeader
= struct
.Struct("3B 1B")
74 def __LoadBuildRule():
75 if GenFdsGlobalVariable
.__BuildRuleDatabase
:
76 return GenFdsGlobalVariable
.__BuildRuleDatabase
77 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, "Conf/target.txt"))
78 TargetTxt
= TargetTxtClassObject()
79 if os
.path
.isfile(BuildConfigurationFile
) == True:
80 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
81 if DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
in TargetTxt
.TargetTxtDictionary
:
82 BuildRuleFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]
83 if BuildRuleFile
in [None, '']:
84 BuildRuleFile
= 'Conf/build_rule.txt'
85 GenFdsGlobalVariable
.__BuildRuleDatabase
= BuildRule(BuildRuleFile
)
86 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
87 if ToolDefinitionFile
== '':
88 ToolDefinitionFile
= "Conf/tools_def.txt"
89 if os
.path
.isfile(ToolDefinitionFile
):
90 ToolDef
= ToolDefClassObject()
91 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
92 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
93 if DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
in ToolDefinition \
94 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
95 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
96 GenFdsGlobalVariable
.BuildRuleFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
98 if DataType
.TAB_TOD_DEFINES_FAMILY
in ToolDefinition \
99 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
] \
100 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
101 GenFdsGlobalVariable
.ToolChainFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
102 return GenFdsGlobalVariable
.__BuildRuleDatabase
105 # @param Inf: object of InfBuildData
106 # @param Arch: current arch
109 def GetBuildRules(Inf
, Arch
):
113 if not Arch
in GenFdsGlobalVariable
.OutputDirDict
:
116 BuildRuleDatabase
= GenFdsGlobalVariable
.__LoadBuildRule
()
117 if not BuildRuleDatabase
:
120 PathClassObj
= PathClass(Inf
.MetaFile
.File
,
121 GenFdsGlobalVariable
.WorkSpaceDir
)
123 Macro
["WORKSPACE" ] = GenFdsGlobalVariable
.WorkSpaceDir
124 Macro
["MODULE_NAME" ] = Inf
.BaseName
125 Macro
["MODULE_GUID" ] = Inf
.Guid
126 Macro
["MODULE_VERSION" ] = Inf
.Version
127 Macro
["MODULE_TYPE" ] = Inf
.ModuleType
128 Macro
["MODULE_FILE" ] = str(PathClassObj
)
129 Macro
["MODULE_FILE_BASE_NAME" ] = PathClassObj
.BaseName
130 Macro
["MODULE_RELATIVE_DIR" ] = PathClassObj
.SubDir
131 Macro
["MODULE_DIR" ] = PathClassObj
.SubDir
133 Macro
["BASE_NAME" ] = Inf
.BaseName
135 Macro
["ARCH" ] = Arch
136 Macro
["TOOLCHAIN" ] = GenFdsGlobalVariable
.ToolChainTag
137 Macro
["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
138 Macro
["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
139 Macro
["TARGET" ] = GenFdsGlobalVariable
.TargetName
141 Macro
["BUILD_DIR" ] = GenFdsGlobalVariable
.OutputDirDict
[Arch
]
142 Macro
["BIN_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
143 Macro
["LIB_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
144 BuildDir
= os
.path
.join(
145 GenFdsGlobalVariable
.OutputDirDict
[Arch
],
148 PathClassObj
.BaseName
150 Macro
["MODULE_BUILD_DIR" ] = BuildDir
151 Macro
["OUTPUT_DIR" ] = os
.path
.join(BuildDir
, "OUTPUT")
152 Macro
["DEBUG_DIR" ] = os
.path
.join(BuildDir
, "DEBUG")
155 for Type
in BuildRuleDatabase
.FileTypeList
:
156 #first try getting build rule by BuildRuleFamily
157 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
159 # build type is always module type, but ...
160 if Inf
.ModuleType
!= Inf
.BuildType
:
161 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
162 #second try getting build rule by ToolChainFamily
164 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
166 # build type is always module type, but ...
167 if Inf
.ModuleType
!= Inf
.BuildType
:
168 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
171 RuleObject
= RuleObject
.Instantiate(Macro
)
172 BuildRules
[Type
] = RuleObject
173 for Ext
in RuleObject
.SourceFileExtList
:
174 BuildRules
[Ext
] = RuleObject
177 ## GetModuleCodaTargetList
179 # @param Inf: object of InfBuildData
180 # @param Arch: current arch
183 def GetModuleCodaTargetList(Inf
, Arch
):
184 BuildRules
= GenFdsGlobalVariable
.GetBuildRules(Inf
, Arch
)
190 for File
in Inf
.Sources
:
191 if File
.TagName
in ("", "*", GenFdsGlobalVariable
.ToolChainTag
) and \
192 File
.ToolChainFamily
in ("", "*", GenFdsGlobalVariable
.ToolChainFamily
):
193 FileList
.append((File
, DataType
.TAB_UNKNOWN_FILE
))
195 for File
in Inf
.Binaries
:
196 if File
.Target
in ['COMMON', '*', GenFdsGlobalVariable
.TargetName
]:
197 FileList
.append((File
, File
.Type
))
199 for File
, FileType
in FileList
:
204 while Index
< len(SourceList
):
205 Source
= SourceList
[Index
]
208 if File
.IsBinary
and File
== Source
and Inf
.Binaries
!= None and File
in Inf
.Binaries
:
209 # Skip all files that are not binary libraries
210 if not Inf
.LibraryClass
:
212 RuleObject
= BuildRules
[DataType
.TAB_DEFAULT_BINARY_FILE
]
213 elif FileType
in BuildRules
:
214 RuleObject
= BuildRules
[FileType
]
215 elif Source
.Ext
in BuildRules
:
216 RuleObject
= BuildRules
[Source
.Ext
]
218 # stop at no more rules
220 TargetList
.add(str(LastTarget
))
223 FileType
= RuleObject
.SourceFileType
225 # stop at STATIC_LIBRARY for library
226 if Inf
.LibraryClass
and FileType
== DataType
.TAB_STATIC_LIBRARY
:
228 TargetList
.add(str(LastTarget
))
231 Target
= RuleObject
.Apply(Source
)
234 TargetList
.add(str(LastTarget
))
236 elif not Target
.Outputs
:
237 # Only do build for target with outputs
238 TargetList
.add(str(Target
))
240 # to avoid cyclic rule
241 if FileType
in RuleChain
:
244 RuleChain
.append(FileType
)
245 SourceList
.extend(Target
.Outputs
)
247 FileType
= DataType
.TAB_UNKNOWN_FILE
249 return list(TargetList
)
253 # @param OutputDir Output directory
254 # @param FdfParser FDF contents parser
255 # @param Workspace The directory of workspace
256 # @param ArchList The Arch list of platform
258 def SetDir (OutputDir
, FdfParser
, WorkSpace
, ArchList
):
259 GenFdsGlobalVariable
.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir
)
260 # GenFdsGlobalVariable.OutputDirDict = OutputDir
261 GenFdsGlobalVariable
.FdfParser
= FdfParser
262 GenFdsGlobalVariable
.WorkSpace
= WorkSpace
263 GenFdsGlobalVariable
.FvDir
= os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[ArchList
[0]], 'FV')
264 if not os
.path
.exists(GenFdsGlobalVariable
.FvDir
) :
265 os
.makedirs(GenFdsGlobalVariable
.FvDir
)
266 GenFdsGlobalVariable
.FfsDir
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, 'Ffs')
267 if not os
.path
.exists(GenFdsGlobalVariable
.FfsDir
) :
268 os
.makedirs(GenFdsGlobalVariable
.FfsDir
)
270 GenFdsGlobalVariable
.ArchList
= ArchList
274 # Create FV Address inf file
276 GenFdsGlobalVariable
.FvAddressFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, 'FvAddress.inf')
277 FvAddressFile
= open (GenFdsGlobalVariable
.FvAddressFileName
, 'w')
281 FvAddressFile
.writelines("[options]" + T_CHAR_LF
)
283 for Arch
in ArchList
:
284 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
:
285 BsAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
288 FvAddressFile
.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
293 for Arch
in ArchList
:
294 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
:
295 RtAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
297 FvAddressFile
.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
301 FvAddressFile
.close()
303 ## ReplaceWorkspaceMacro()
305 # @param String String that may contain macro
307 def ReplaceWorkspaceMacro(String
):
308 Str
= String
.replace('$(WORKSPACE)', GenFdsGlobalVariable
.WorkSpaceDir
)
309 if os
.path
.exists(Str
):
310 if not os
.path
.isabs(Str
):
311 Str
= os
.path
.abspath(Str
)
313 Str
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, String
)
314 return os
.path
.normpath(Str
)
316 ## Check if the input files are newer than output files
318 # @param Output Path of output file
319 # @param Input Path list of input files
321 # @retval True if Output doesn't exist, or any Input is newer
322 # @retval False if all Input is older than Output
325 def NeedsUpdate(Output
, Input
):
326 if not os
.path
.exists(Output
):
328 # always update "Output" if no "Input" given
329 if Input
== None or len(Input
) == 0:
332 # if fdf file is changed after the 'Output" is generated, update the 'Output'
333 OutputTime
= os
.path
.getmtime(Output
)
334 if GenFdsGlobalVariable
.FdfFileTimeStamp
> OutputTime
:
338 # always update "Output" if any "Input" doesn't exist
339 if not os
.path
.exists(F
):
341 # always update "Output" if any "Input" is newer than "Output"
342 if os
.path
.getmtime(F
) > OutputTime
:
347 def GenerateSection(Output
, Input
, Type
=None, CompressionType
=None, Guid
=None,
348 GuidHdrLen
=None, GuidAttr
=[], Ui
=None, Ver
=None, InputAlign
=None):
350 if Type
not in [None, '']:
352 if CompressionType
not in [None, '']:
353 Cmd
+= ["-c", CompressionType
]
356 if GuidHdrLen
not in [None, '']:
357 Cmd
+= ["-l", GuidHdrLen
]
358 if len(GuidAttr
) != 0:
359 #Add each guided attribute
360 for Attr
in GuidAttr
:
362 if InputAlign
!= None:
363 #Section Align is only for dummy section without section type
364 for SecAlign
in InputAlign
:
365 Cmd
+= ["--sectionalign", SecAlign
]
367 if Ui
not in [None, '']:
368 #Cmd += ["-n", '"' + Ui + '"']
369 SectionData
= array
.array('B', [0,0,0,0])
370 SectionData
.fromstring(Ui
.encode("utf_16_le"))
371 SectionData
.append(0)
372 SectionData
.append(0)
373 Len
= len(SectionData
)
374 GenFdsGlobalVariable
.SectionHeader
.pack_into(SectionData
, 0, Len
& 0xff, (Len
>> 8) & 0xff, (Len
>> 16) & 0xff, 0x15)
375 SaveFileOnChange(Output
, SectionData
.tostring())
376 elif Ver
not in [None, '']:
378 SectionData
= array
.array('B', [0,0,0,0])
379 SectionData
.fromstring(Ver
.encode("utf_16_le"))
380 SectionData
.append(0)
381 SectionData
.append(0)
382 Len
= len(SectionData
)
383 GenFdsGlobalVariable
.SectionHeader
.pack_into(SectionData
, 0, Len
& 0xff, (Len
>> 8) & 0xff, (Len
>> 16) & 0xff, 0x14)
384 SaveFileOnChange(Output
, SectionData
.tostring())
386 Cmd
+= ["-o", Output
]
389 CommandFile
= Output
+ '.txt'
390 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
391 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
393 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
395 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
398 def GetAlignment (AlignString
):
399 if AlignString
== None:
401 if AlignString
in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):
402 return int (AlignString
.rstrip('K')) * 1024
404 return int (AlignString
)
407 def GenerateFfs(Output
, Input
, Type
, Guid
, Fixed
=False, CheckSum
=False, Align
=None,
409 Cmd
= ["GenFfs", "-t", Type
, "-g", Guid
]
414 if Align
not in [None, '']:
417 Cmd
+= ["-o", Output
]
418 for I
in range(0, len(Input
)):
419 Cmd
+= ("-i", Input
[I
])
420 if SectionAlign
not in [None, '', []] and SectionAlign
[I
] not in [None, '']:
421 Cmd
+= ("-n", SectionAlign
[I
])
423 CommandFile
= Output
+ '.txt'
424 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
425 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
427 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
429 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FFS")
432 def GenerateFirmwareVolume(Output
, Input
, BaseAddress
=None, ForceRebase
=None, Capsule
=False, Dump
=False,
433 AddressFile
=None, MapFile
=None, FfsList
=[]):
434 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
+FfsList
):
436 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
439 if BaseAddress
not in [None, '']:
440 Cmd
+= ["-r", BaseAddress
]
442 if ForceRebase
== False:
443 Cmd
+=["-F", "FALSE"]
444 elif ForceRebase
== True:
451 if AddressFile
not in [None, '']:
452 Cmd
+= ["-a", AddressFile
]
453 if MapFile
not in [None, '']:
454 Cmd
+= ["-m", MapFile
]
455 Cmd
+= ["-o", Output
]
459 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FV")
462 def GenerateVtf(Output
, Input
, BaseAddress
=None, FvSize
=None):
463 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
465 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
468 if BaseAddress
not in [None, ''] and FvSize
not in [None, ''] \
469 and len(BaseAddress
) == len(FvSize
):
470 for I
in range(0, len(BaseAddress
)):
471 Cmd
+= ["-r", BaseAddress
[I
], "-s", FvSize
[I
]]
472 Cmd
+= ["-o", Output
]
476 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate VTF")
479 def GenerateFirmwareImage(Output
, Input
, Type
="efi", SubType
=None, Zero
=False,
480 Strip
=False, Replace
=False, TimeStamp
=None, Join
=False,
481 Align
=None, Padding
=None, Convert
=False):
482 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
484 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
487 if Type
.lower() == "te":
489 if SubType
not in [None, '']:
490 Cmd
+= ["-e", SubType
]
491 if TimeStamp
not in [None, '']:
492 Cmd
+= ["-s", TimeStamp
]
493 if Align
not in [None, '']:
495 if Padding
not in [None, '']:
496 Cmd
+= ["-p", Padding
]
507 Cmd
+= ["-o", Output
]
510 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate firmware image")
513 def GenerateOptionRom(Output
, EfiInput
, BinaryInput
, Compress
=False, ClassCode
=None,
514 Revision
=None, DeviceId
=None, VendorId
=None):
517 if len(EfiInput
) > 0:
524 for EfiFile
in EfiInput
:
526 InputList
.append (EfiFile
)
528 if len(BinaryInput
) > 0:
530 for BinFile
in BinaryInput
:
532 InputList
.append (BinFile
)
535 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, InputList
):
537 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, InputList
))
539 if ClassCode
!= None:
540 Cmd
+= ["-l", ClassCode
]
542 Cmd
+= ["-r", Revision
]
544 Cmd
+= ["-i", DeviceId
]
546 Cmd
+= ["-f", VendorId
]
548 Cmd
+= ["-o", Output
]
549 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate option rom")
552 def GuidTool(Output
, Input
, ToolPath
, Options
='', returnValue
=[]):
553 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
555 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
558 Cmd
+= Options
.split(' ')
559 Cmd
+= ["-o", Output
]
562 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to call " + ToolPath
, returnValue
)
564 def CallExternalTool (cmd
, errorMess
, returnValue
=[]):
566 if type(cmd
) not in (tuple, list):
567 GenFdsGlobalVariable
.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")
569 if GenFdsGlobalVariable
.DebugLevel
!= -1:
570 cmd
+= ('--debug', str(GenFdsGlobalVariable
.DebugLevel
))
571 GenFdsGlobalVariable
.InfLogger (cmd
)
573 if GenFdsGlobalVariable
.VerboseMode
:
575 GenFdsGlobalVariable
.InfLogger (cmd
)
577 sys
.stdout
.write ('#')
579 GenFdsGlobalVariable
.SharpCounter
= GenFdsGlobalVariable
.SharpCounter
+ 1
580 if GenFdsGlobalVariable
.SharpCounter
% GenFdsGlobalVariable
.SharpNumberPerLine
== 0:
581 sys
.stdout
.write('\n')
584 PopenObject
= subprocess
.Popen(' '.join(cmd
), stdout
=subprocess
.PIPE
, stderr
= subprocess
.PIPE
, shell
=True)
586 EdkLogger
.error("GenFds", COMMAND_FAILURE
, ExtraData
="%s: %s" % (str(X
), cmd
[0]))
587 (out
, error
) = PopenObject
.communicate()
589 while PopenObject
.returncode
== None :
591 if returnValue
!= [] and returnValue
[0] != 0:
592 #get command return value
593 returnValue
[0] = PopenObject
.returncode
595 if PopenObject
.returncode
!= 0 or GenFdsGlobalVariable
.VerboseMode
or GenFdsGlobalVariable
.DebugLevel
!= -1:
596 GenFdsGlobalVariable
.InfLogger ("Return Value = %d" %PopenObject
.returncode
)
597 GenFdsGlobalVariable
.InfLogger (out
)
598 GenFdsGlobalVariable
.InfLogger (error
)
599 if PopenObject
.returncode
!= 0:
601 EdkLogger
.error("GenFds", COMMAND_FAILURE
, errorMess
)
603 def VerboseLogger (msg
):
604 EdkLogger
.verbose(msg
)
609 def ErrorLogger (msg
, File
= None, Line
= None, ExtraData
= None):
610 EdkLogger
.error('GenFds', GENFDS_ERROR
, msg
, File
, Line
, ExtraData
)
612 def DebugLogger (Level
, msg
):
613 EdkLogger
.debug(Level
, msg
)
615 ## ReplaceWorkspaceMacro()
617 # @param Str String that may contain macro
618 # @param MacroDict Dictionary that contains macro value pair
620 def MacroExtend (Str
, MacroDict
= {}, Arch
= 'COMMON'):
624 Dict
= {'$(WORKSPACE)' : GenFdsGlobalVariable
.WorkSpaceDir
,
625 '$(EDK_SOURCE)' : GenFdsGlobalVariable
.EdkSourceDir
,
626 # '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,
627 '$(TARGET)' : GenFdsGlobalVariable
.TargetName
,
628 '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable
.ToolChainTag
630 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[GenFdsGlobalVariable
.ArchList
[0]]
631 if Arch
!= 'COMMON' and Arch
in GenFdsGlobalVariable
.ArchList
:
632 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
]
634 Dict
['$(OUTPUT_DIRECTORY)'] = OutputDir
636 if MacroDict
!= None and len (MacroDict
) != 0:
637 Dict
.update(MacroDict
)
639 for key
in Dict
.keys():
640 if Str
.find(key
) >= 0 :
641 Str
= Str
.replace (key
, Dict
[key
])
643 if Str
.find('$(ARCH)') >= 0:
644 if len(GenFdsGlobalVariable
.ArchList
) == 1:
645 Str
= Str
.replace('$(ARCH)', GenFdsGlobalVariable
.ArchList
[0])
647 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No way to determine $(ARCH) for %s" % Str
)
653 # @param PcdPattern pattern that labels a PCD.
655 def GetPcdValue (PcdPattern
):
656 if PcdPattern
== None :
658 PcdPair
= PcdPattern
.lstrip('PCD(').rstrip(')').strip().split('.')
659 TokenSpace
= PcdPair
[0]
660 TokenCName
= PcdPair
[1]
663 for Arch
in GenFdsGlobalVariable
.ArchList
:
664 Platform
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
665 PcdDict
= Platform
.Pcds
667 PcdObj
= PcdDict
[Key
]
668 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
669 if PcdObj
.Type
!= 'FixedAtBuild':
670 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
671 if PcdObj
.DatumType
!= 'VOID*':
672 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
674 PcdValue
= PcdObj
.DefaultValue
677 for Package
in GenFdsGlobalVariable
.WorkSpace
.GetPackageList(GenFdsGlobalVariable
.ActivePlatform
,
679 GenFdsGlobalVariable
.TargetName
,
680 GenFdsGlobalVariable
.ToolChainTag
):
681 PcdDict
= Package
.Pcds
683 PcdObj
= PcdDict
[Key
]
684 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
685 if PcdObj
.Type
!= 'FixedAtBuild':
686 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
687 if PcdObj
.DatumType
!= 'VOID*':
688 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
690 PcdValue
= PcdObj
.DefaultValue
695 SetDir
= staticmethod(SetDir
)
696 ReplaceWorkspaceMacro
= staticmethod(ReplaceWorkspaceMacro
)
697 CallExternalTool
= staticmethod(CallExternalTool
)
698 VerboseLogger
= staticmethod(VerboseLogger
)
699 InfLogger
= staticmethod(InfLogger
)
700 ErrorLogger
= staticmethod(ErrorLogger
)
701 DebugLogger
= staticmethod(DebugLogger
)
702 MacroExtend
= staticmethod (MacroExtend
)
703 GetPcdValue
= staticmethod(GetPcdValue
)