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
70 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.
71 # At the beginning of each generation of FV, false flag is appended to the list,
72 # after the call to GenerateSection returns, check the size of the output file,
73 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,
74 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.
75 # At the end of generation of FV, pop the flag.
76 # List is used as a stack to handle nested FV generation.
78 LargeFileInFvFlags
= []
79 EFI_FIRMWARE_FILE_SYSTEM3_GUID
= '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'
80 LARGE_FILE_SIZE
= 0x1000000
82 SectionHeader
= struct
.Struct("3B 1B")
87 def __LoadBuildRule():
88 if GenFdsGlobalVariable
.__BuildRuleDatabase
:
89 return GenFdsGlobalVariable
.__BuildRuleDatabase
90 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, "Conf/target.txt"))
91 TargetTxt
= TargetTxtClassObject()
92 if os
.path
.isfile(BuildConfigurationFile
) == True:
93 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
94 if DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
in TargetTxt
.TargetTxtDictionary
:
95 BuildRuleFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]
96 if BuildRuleFile
in [None, '']:
97 BuildRuleFile
= 'Conf/build_rule.txt'
98 GenFdsGlobalVariable
.__BuildRuleDatabase
= BuildRule(BuildRuleFile
)
99 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
100 if ToolDefinitionFile
== '':
101 ToolDefinitionFile
= "Conf/tools_def.txt"
102 if os
.path
.isfile(ToolDefinitionFile
):
103 ToolDef
= ToolDefClassObject()
104 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
105 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
106 if DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
in ToolDefinition \
107 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
108 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
109 GenFdsGlobalVariable
.BuildRuleFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
111 if DataType
.TAB_TOD_DEFINES_FAMILY
in ToolDefinition \
112 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
] \
113 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
114 GenFdsGlobalVariable
.ToolChainFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
115 return GenFdsGlobalVariable
.__BuildRuleDatabase
118 # @param Inf: object of InfBuildData
119 # @param Arch: current arch
122 def GetBuildRules(Inf
, Arch
):
126 if not Arch
in GenFdsGlobalVariable
.OutputDirDict
:
129 BuildRuleDatabase
= GenFdsGlobalVariable
.__LoadBuildRule
()
130 if not BuildRuleDatabase
:
133 PathClassObj
= PathClass(Inf
.MetaFile
.File
,
134 GenFdsGlobalVariable
.WorkSpaceDir
)
136 Macro
["WORKSPACE" ] = GenFdsGlobalVariable
.WorkSpaceDir
137 Macro
["MODULE_NAME" ] = Inf
.BaseName
138 Macro
["MODULE_GUID" ] = Inf
.Guid
139 Macro
["MODULE_VERSION" ] = Inf
.Version
140 Macro
["MODULE_TYPE" ] = Inf
.ModuleType
141 Macro
["MODULE_FILE" ] = str(PathClassObj
)
142 Macro
["MODULE_FILE_BASE_NAME" ] = PathClassObj
.BaseName
143 Macro
["MODULE_RELATIVE_DIR" ] = PathClassObj
.SubDir
144 Macro
["MODULE_DIR" ] = PathClassObj
.SubDir
146 Macro
["BASE_NAME" ] = Inf
.BaseName
148 Macro
["ARCH" ] = Arch
149 Macro
["TOOLCHAIN" ] = GenFdsGlobalVariable
.ToolChainTag
150 Macro
["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
151 Macro
["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
152 Macro
["TARGET" ] = GenFdsGlobalVariable
.TargetName
154 Macro
["BUILD_DIR" ] = GenFdsGlobalVariable
.OutputDirDict
[Arch
]
155 Macro
["BIN_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
156 Macro
["LIB_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
157 BuildDir
= os
.path
.join(
158 GenFdsGlobalVariable
.OutputDirDict
[Arch
],
161 PathClassObj
.BaseName
163 Macro
["MODULE_BUILD_DIR" ] = BuildDir
164 Macro
["OUTPUT_DIR" ] = os
.path
.join(BuildDir
, "OUTPUT")
165 Macro
["DEBUG_DIR" ] = os
.path
.join(BuildDir
, "DEBUG")
168 for Type
in BuildRuleDatabase
.FileTypeList
:
169 #first try getting build rule by BuildRuleFamily
170 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
172 # build type is always module type, but ...
173 if Inf
.ModuleType
!= Inf
.BuildType
:
174 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
175 #second try getting build rule by ToolChainFamily
177 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
179 # build type is always module type, but ...
180 if Inf
.ModuleType
!= Inf
.BuildType
:
181 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
184 RuleObject
= RuleObject
.Instantiate(Macro
)
185 BuildRules
[Type
] = RuleObject
186 for Ext
in RuleObject
.SourceFileExtList
:
187 BuildRules
[Ext
] = RuleObject
190 ## GetModuleCodaTargetList
192 # @param Inf: object of InfBuildData
193 # @param Arch: current arch
196 def GetModuleCodaTargetList(Inf
, Arch
):
197 BuildRules
= GenFdsGlobalVariable
.GetBuildRules(Inf
, Arch
)
203 for File
in Inf
.Sources
:
204 if File
.TagName
in ("", "*", GenFdsGlobalVariable
.ToolChainTag
) and \
205 File
.ToolChainFamily
in ("", "*", GenFdsGlobalVariable
.ToolChainFamily
):
206 FileList
.append((File
, DataType
.TAB_UNKNOWN_FILE
))
208 for File
in Inf
.Binaries
:
209 if File
.Target
in ['COMMON', '*', GenFdsGlobalVariable
.TargetName
]:
210 FileList
.append((File
, File
.Type
))
212 for File
, FileType
in FileList
:
217 while Index
< len(SourceList
):
218 Source
= SourceList
[Index
]
221 if File
.IsBinary
and File
== Source
and Inf
.Binaries
!= None and File
in Inf
.Binaries
:
222 # Skip all files that are not binary libraries
223 if not Inf
.LibraryClass
:
225 RuleObject
= BuildRules
[DataType
.TAB_DEFAULT_BINARY_FILE
]
226 elif FileType
in BuildRules
:
227 RuleObject
= BuildRules
[FileType
]
228 elif Source
.Ext
in BuildRules
:
229 RuleObject
= BuildRules
[Source
.Ext
]
231 # stop at no more rules
233 TargetList
.add(str(LastTarget
))
236 FileType
= RuleObject
.SourceFileType
238 # stop at STATIC_LIBRARY for library
239 if Inf
.LibraryClass
and FileType
== DataType
.TAB_STATIC_LIBRARY
:
241 TargetList
.add(str(LastTarget
))
244 Target
= RuleObject
.Apply(Source
)
247 TargetList
.add(str(LastTarget
))
249 elif not Target
.Outputs
:
250 # Only do build for target with outputs
251 TargetList
.add(str(Target
))
253 # to avoid cyclic rule
254 if FileType
in RuleChain
:
257 RuleChain
.append(FileType
)
258 SourceList
.extend(Target
.Outputs
)
260 FileType
= DataType
.TAB_UNKNOWN_FILE
262 return list(TargetList
)
266 # @param OutputDir Output directory
267 # @param FdfParser FDF contents parser
268 # @param Workspace The directory of workspace
269 # @param ArchList The Arch list of platform
271 def SetDir (OutputDir
, FdfParser
, WorkSpace
, ArchList
):
272 GenFdsGlobalVariable
.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir
)
273 # GenFdsGlobalVariable.OutputDirDict = OutputDir
274 GenFdsGlobalVariable
.FdfParser
= FdfParser
275 GenFdsGlobalVariable
.WorkSpace
= WorkSpace
276 GenFdsGlobalVariable
.FvDir
= os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[ArchList
[0]], 'FV')
277 if not os
.path
.exists(GenFdsGlobalVariable
.FvDir
) :
278 os
.makedirs(GenFdsGlobalVariable
.FvDir
)
279 GenFdsGlobalVariable
.FfsDir
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, 'Ffs')
280 if not os
.path
.exists(GenFdsGlobalVariable
.FfsDir
) :
281 os
.makedirs(GenFdsGlobalVariable
.FfsDir
)
283 GenFdsGlobalVariable
.ArchList
= ArchList
287 # Create FV Address inf file
289 GenFdsGlobalVariable
.FvAddressFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, 'FvAddress.inf')
290 FvAddressFile
= open (GenFdsGlobalVariable
.FvAddressFileName
, 'w')
294 FvAddressFile
.writelines("[options]" + T_CHAR_LF
)
296 for Arch
in ArchList
:
297 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
:
298 BsAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
301 FvAddressFile
.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
306 for Arch
in ArchList
:
307 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
:
308 RtAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
310 FvAddressFile
.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
314 FvAddressFile
.close()
316 ## ReplaceWorkspaceMacro()
318 # @param String String that may contain macro
320 def ReplaceWorkspaceMacro(String
):
321 Str
= String
.replace('$(WORKSPACE)', GenFdsGlobalVariable
.WorkSpaceDir
)
322 if os
.path
.exists(Str
):
323 if not os
.path
.isabs(Str
):
324 Str
= os
.path
.abspath(Str
)
326 Str
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, String
)
327 return os
.path
.normpath(Str
)
329 ## Check if the input files are newer than output files
331 # @param Output Path of output file
332 # @param Input Path list of input files
334 # @retval True if Output doesn't exist, or any Input is newer
335 # @retval False if all Input is older than Output
338 def NeedsUpdate(Output
, Input
):
339 if not os
.path
.exists(Output
):
341 # always update "Output" if no "Input" given
342 if Input
== None or len(Input
) == 0:
345 # if fdf file is changed after the 'Output" is generated, update the 'Output'
346 OutputTime
= os
.path
.getmtime(Output
)
347 if GenFdsGlobalVariable
.FdfFileTimeStamp
> OutputTime
:
351 # always update "Output" if any "Input" doesn't exist
352 if not os
.path
.exists(F
):
354 # always update "Output" if any "Input" is newer than "Output"
355 if os
.path
.getmtime(F
) > OutputTime
:
360 def GenerateSection(Output
, Input
, Type
=None, CompressionType
=None, Guid
=None,
361 GuidHdrLen
=None, GuidAttr
=[], Ui
=None, Ver
=None, InputAlign
=None, BuildNumber
=None):
363 if Type
not in [None, '']:
365 if CompressionType
not in [None, '']:
366 Cmd
+= ["-c", CompressionType
]
369 if GuidHdrLen
not in [None, '']:
370 Cmd
+= ["-l", GuidHdrLen
]
371 if len(GuidAttr
) != 0:
372 #Add each guided attribute
373 for Attr
in GuidAttr
:
375 if InputAlign
!= None:
376 #Section Align is only for dummy section without section type
377 for SecAlign
in InputAlign
:
378 Cmd
+= ["--sectionalign", SecAlign
]
380 CommandFile
= Output
+ '.txt'
381 if Ui
not in [None, '']:
382 #Cmd += ["-n", '"' + Ui + '"']
383 SectionData
= array
.array('B', [0,0,0,0])
384 SectionData
.fromstring(Ui
.encode("utf_16_le"))
385 SectionData
.append(0)
386 SectionData
.append(0)
387 Len
= len(SectionData
)
388 GenFdsGlobalVariable
.SectionHeader
.pack_into(SectionData
, 0, Len
& 0xff, (Len
>> 8) & 0xff, (Len
>> 16) & 0xff, 0x15)
389 SaveFileOnChange(Output
, SectionData
.tostring())
390 elif Ver
not in [None, '']:
393 Cmd
+= ["-j", BuildNumber
]
394 Cmd
+= ["-o", Output
]
396 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
397 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
400 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
402 Cmd
+= ["-o", Output
]
405 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
406 if GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
407 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
408 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
410 if (os
.path
.getsize(Output
) >= GenFdsGlobalVariable
.LARGE_FILE_SIZE
and
411 GenFdsGlobalVariable
.LargeFileInFvFlags
):
412 GenFdsGlobalVariable
.LargeFileInFvFlags
[-1] = True
415 def GetAlignment (AlignString
):
416 if AlignString
== None:
418 if AlignString
in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):
419 return int (AlignString
.rstrip('K')) * 1024
421 return int (AlignString
)
424 def GenerateFfs(Output
, Input
, Type
, Guid
, Fixed
=False, CheckSum
=False, Align
=None,
426 Cmd
= ["GenFfs", "-t", Type
, "-g", Guid
]
431 if Align
not in [None, '']:
434 Cmd
+= ["-o", Output
]
435 for I
in range(0, len(Input
)):
436 Cmd
+= ("-i", Input
[I
])
437 if SectionAlign
not in [None, '', []] and SectionAlign
[I
] not in [None, '']:
438 Cmd
+= ("-n", SectionAlign
[I
])
440 CommandFile
= Output
+ '.txt'
441 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
442 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
444 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
446 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FFS")
449 def GenerateFirmwareVolume(Output
, Input
, BaseAddress
=None, ForceRebase
=None, Capsule
=False, Dump
=False,
450 AddressFile
=None, MapFile
=None, FfsList
=[], FileSystemGuid
=None):
451 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
+FfsList
):
453 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
456 if BaseAddress
not in [None, '']:
457 Cmd
+= ["-r", BaseAddress
]
459 if ForceRebase
== False:
460 Cmd
+=["-F", "FALSE"]
461 elif ForceRebase
== True:
468 if AddressFile
not in [None, '']:
469 Cmd
+= ["-a", AddressFile
]
470 if MapFile
not in [None, '']:
471 Cmd
+= ["-m", MapFile
]
473 Cmd
+= ["-g", FileSystemGuid
]
474 Cmd
+= ["-o", Output
]
478 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FV")
481 def GenerateVtf(Output
, Input
, BaseAddress
=None, FvSize
=None):
482 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
484 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
487 if BaseAddress
not in [None, ''] and FvSize
not in [None, ''] \
488 and len(BaseAddress
) == len(FvSize
):
489 for I
in range(0, len(BaseAddress
)):
490 Cmd
+= ["-r", BaseAddress
[I
], "-s", FvSize
[I
]]
491 Cmd
+= ["-o", Output
]
495 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate VTF")
498 def GenerateFirmwareImage(Output
, Input
, Type
="efi", SubType
=None, Zero
=False,
499 Strip
=False, Replace
=False, TimeStamp
=None, Join
=False,
500 Align
=None, Padding
=None, Convert
=False):
501 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
503 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
506 if Type
.lower() == "te":
508 if SubType
not in [None, '']:
509 Cmd
+= ["-e", SubType
]
510 if TimeStamp
not in [None, '']:
511 Cmd
+= ["-s", TimeStamp
]
512 if Align
not in [None, '']:
514 if Padding
not in [None, '']:
515 Cmd
+= ["-p", Padding
]
526 Cmd
+= ["-o", Output
]
529 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate firmware image")
532 def GenerateOptionRom(Output
, EfiInput
, BinaryInput
, Compress
=False, ClassCode
=None,
533 Revision
=None, DeviceId
=None, VendorId
=None):
536 if len(EfiInput
) > 0:
543 for EfiFile
in EfiInput
:
545 InputList
.append (EfiFile
)
547 if len(BinaryInput
) > 0:
549 for BinFile
in BinaryInput
:
551 InputList
.append (BinFile
)
554 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, InputList
):
556 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, InputList
))
558 if ClassCode
!= None:
559 Cmd
+= ["-l", ClassCode
]
561 Cmd
+= ["-r", Revision
]
563 Cmd
+= ["-i", DeviceId
]
565 Cmd
+= ["-f", VendorId
]
567 Cmd
+= ["-o", Output
]
568 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate option rom")
571 def GuidTool(Output
, Input
, ToolPath
, Options
='', returnValue
=[]):
572 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
574 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
577 Cmd
+= Options
.split(' ')
578 Cmd
+= ["-o", Output
]
581 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to call " + ToolPath
, returnValue
)
583 def CallExternalTool (cmd
, errorMess
, returnValue
=[]):
585 if type(cmd
) not in (tuple, list):
586 GenFdsGlobalVariable
.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")
588 if GenFdsGlobalVariable
.DebugLevel
!= -1:
589 cmd
+= ('--debug', str(GenFdsGlobalVariable
.DebugLevel
))
590 GenFdsGlobalVariable
.InfLogger (cmd
)
592 if GenFdsGlobalVariable
.VerboseMode
:
594 GenFdsGlobalVariable
.InfLogger (cmd
)
596 sys
.stdout
.write ('#')
598 GenFdsGlobalVariable
.SharpCounter
= GenFdsGlobalVariable
.SharpCounter
+ 1
599 if GenFdsGlobalVariable
.SharpCounter
% GenFdsGlobalVariable
.SharpNumberPerLine
== 0:
600 sys
.stdout
.write('\n')
603 PopenObject
= subprocess
.Popen(' '.join(cmd
), stdout
=subprocess
.PIPE
, stderr
= subprocess
.PIPE
, shell
=True)
605 EdkLogger
.error("GenFds", COMMAND_FAILURE
, ExtraData
="%s: %s" % (str(X
), cmd
[0]))
606 (out
, error
) = PopenObject
.communicate()
608 while PopenObject
.returncode
== None :
610 if returnValue
!= [] and returnValue
[0] != 0:
611 #get command return value
612 returnValue
[0] = PopenObject
.returncode
614 if PopenObject
.returncode
!= 0 or GenFdsGlobalVariable
.VerboseMode
or GenFdsGlobalVariable
.DebugLevel
!= -1:
615 GenFdsGlobalVariable
.InfLogger ("Return Value = %d" %PopenObject
.returncode
)
616 GenFdsGlobalVariable
.InfLogger (out
)
617 GenFdsGlobalVariable
.InfLogger (error
)
618 if PopenObject
.returncode
!= 0:
620 EdkLogger
.error("GenFds", COMMAND_FAILURE
, errorMess
)
622 def VerboseLogger (msg
):
623 EdkLogger
.verbose(msg
)
628 def ErrorLogger (msg
, File
= None, Line
= None, ExtraData
= None):
629 EdkLogger
.error('GenFds', GENFDS_ERROR
, msg
, File
, Line
, ExtraData
)
631 def DebugLogger (Level
, msg
):
632 EdkLogger
.debug(Level
, msg
)
634 ## ReplaceWorkspaceMacro()
636 # @param Str String that may contain macro
637 # @param MacroDict Dictionary that contains macro value pair
639 def MacroExtend (Str
, MacroDict
= {}, Arch
= 'COMMON'):
643 Dict
= {'$(WORKSPACE)' : GenFdsGlobalVariable
.WorkSpaceDir
,
644 '$(EDK_SOURCE)' : GenFdsGlobalVariable
.EdkSourceDir
,
645 # '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,
646 '$(TARGET)' : GenFdsGlobalVariable
.TargetName
,
647 '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable
.ToolChainTag
649 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[GenFdsGlobalVariable
.ArchList
[0]]
650 if Arch
!= 'COMMON' and Arch
in GenFdsGlobalVariable
.ArchList
:
651 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
]
653 Dict
['$(OUTPUT_DIRECTORY)'] = OutputDir
655 if MacroDict
!= None and len (MacroDict
) != 0:
656 Dict
.update(MacroDict
)
658 for key
in Dict
.keys():
659 if Str
.find(key
) >= 0 :
660 Str
= Str
.replace (key
, Dict
[key
])
662 if Str
.find('$(ARCH)') >= 0:
663 if len(GenFdsGlobalVariable
.ArchList
) == 1:
664 Str
= Str
.replace('$(ARCH)', GenFdsGlobalVariable
.ArchList
[0])
666 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No way to determine $(ARCH) for %s" % Str
)
672 # @param PcdPattern pattern that labels a PCD.
674 def GetPcdValue (PcdPattern
):
675 if PcdPattern
== None :
677 PcdPair
= PcdPattern
.lstrip('PCD(').rstrip(')').strip().split('.')
678 TokenSpace
= PcdPair
[0]
679 TokenCName
= PcdPair
[1]
682 for Arch
in GenFdsGlobalVariable
.ArchList
:
683 Platform
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
684 PcdDict
= Platform
.Pcds
686 PcdObj
= PcdDict
[Key
]
687 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
688 if PcdObj
.Type
!= 'FixedAtBuild':
689 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
690 if PcdObj
.DatumType
!= 'VOID*':
691 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
693 PcdValue
= PcdObj
.DefaultValue
696 for Package
in GenFdsGlobalVariable
.WorkSpace
.GetPackageList(GenFdsGlobalVariable
.ActivePlatform
,
698 GenFdsGlobalVariable
.TargetName
,
699 GenFdsGlobalVariable
.ToolChainTag
):
700 PcdDict
= Package
.Pcds
702 PcdObj
= PcdDict
[Key
]
703 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
704 if PcdObj
.Type
!= 'FixedAtBuild':
705 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
706 if PcdObj
.DatumType
!= 'VOID*':
707 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
709 PcdValue
= PcdObj
.DefaultValue
714 SetDir
= staticmethod(SetDir
)
715 ReplaceWorkspaceMacro
= staticmethod(ReplaceWorkspaceMacro
)
716 CallExternalTool
= staticmethod(CallExternalTool
)
717 VerboseLogger
= staticmethod(VerboseLogger
)
718 InfLogger
= staticmethod(InfLogger
)
719 ErrorLogger
= staticmethod(ErrorLogger
)
720 DebugLogger
= staticmethod(DebugLogger
)
721 MacroExtend
= staticmethod (MacroExtend
)
722 GetPcdValue
= staticmethod(GetPcdValue
)