2 # Global variables for GenFds
4 # Copyright (c) 2007 - 2014, 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.
18 import Common
.LongFilePathOs
as os
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
33 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
34 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
39 class GenFdsGlobalVariable
:
43 # will be FvDir + os.sep + 'Ffs'
51 OutputDirFromDscDict
= {}
58 FvAddressFileName
= ''
62 SharpNumberPerLine
= 40
65 FixedLoadAddress
= False
68 BuildRuleFamily
= "MSFT"
69 ToolChainFamily
= "MSFT"
70 __BuildRuleDatabase
= None
73 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.
74 # At the beginning of each generation of FV, false flag is appended to the list,
75 # after the call to GenerateSection returns, check the size of the output file,
76 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,
77 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.
78 # At the end of generation of FV, pop the flag.
79 # List is used as a stack to handle nested FV generation.
81 LargeFileInFvFlags
= []
82 EFI_FIRMWARE_FILE_SYSTEM3_GUID
= '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'
83 LARGE_FILE_SIZE
= 0x1000000
85 SectionHeader
= struct
.Struct("3B 1B")
90 def __LoadBuildRule():
91 if GenFdsGlobalVariable
.__BuildRuleDatabase
:
92 return GenFdsGlobalVariable
.__BuildRuleDatabase
93 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GenFdsGlobalVariable
.ConfDir
, "target.txt"))
94 TargetTxt
= TargetTxtClassObject()
95 if os
.path
.isfile(BuildConfigurationFile
) == True:
96 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
97 if DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
in TargetTxt
.TargetTxtDictionary
:
98 BuildRuleFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]
99 if BuildRuleFile
in [None, '']:
100 BuildRuleFile
= 'Conf/build_rule.txt'
101 GenFdsGlobalVariable
.__BuildRuleDatabase
= BuildRule(BuildRuleFile
)
102 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
103 if ToolDefinitionFile
== '':
104 ToolDefinitionFile
= "Conf/tools_def.txt"
105 if os
.path
.isfile(ToolDefinitionFile
):
106 ToolDef
= ToolDefClassObject()
107 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
108 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
109 if DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
in ToolDefinition \
110 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
111 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
112 GenFdsGlobalVariable
.BuildRuleFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
114 if DataType
.TAB_TOD_DEFINES_FAMILY
in ToolDefinition \
115 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
] \
116 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
117 GenFdsGlobalVariable
.ToolChainFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
118 return GenFdsGlobalVariable
.__BuildRuleDatabase
121 # @param Inf: object of InfBuildData
122 # @param Arch: current arch
125 def GetBuildRules(Inf
, Arch
):
129 if not Arch
in GenFdsGlobalVariable
.OutputDirDict
:
132 BuildRuleDatabase
= GenFdsGlobalVariable
.__LoadBuildRule
()
133 if not BuildRuleDatabase
:
136 PathClassObj
= PathClass(Inf
.MetaFile
.File
,
137 GenFdsGlobalVariable
.WorkSpaceDir
)
139 Macro
["WORKSPACE" ] = GenFdsGlobalVariable
.WorkSpaceDir
140 Macro
["MODULE_NAME" ] = Inf
.BaseName
141 Macro
["MODULE_GUID" ] = Inf
.Guid
142 Macro
["MODULE_VERSION" ] = Inf
.Version
143 Macro
["MODULE_TYPE" ] = Inf
.ModuleType
144 Macro
["MODULE_FILE" ] = str(PathClassObj
)
145 Macro
["MODULE_FILE_BASE_NAME" ] = PathClassObj
.BaseName
146 Macro
["MODULE_RELATIVE_DIR" ] = PathClassObj
.SubDir
147 Macro
["MODULE_DIR" ] = PathClassObj
.SubDir
149 Macro
["BASE_NAME" ] = Inf
.BaseName
151 Macro
["ARCH" ] = Arch
152 Macro
["TOOLCHAIN" ] = GenFdsGlobalVariable
.ToolChainTag
153 Macro
["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
154 Macro
["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
155 Macro
["TARGET" ] = GenFdsGlobalVariable
.TargetName
157 Macro
["BUILD_DIR" ] = GenFdsGlobalVariable
.OutputDirDict
[Arch
]
158 Macro
["BIN_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
159 Macro
["LIB_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
160 BuildDir
= os
.path
.join(
161 GenFdsGlobalVariable
.OutputDirDict
[Arch
],
164 PathClassObj
.BaseName
166 Macro
["MODULE_BUILD_DIR" ] = BuildDir
167 Macro
["OUTPUT_DIR" ] = os
.path
.join(BuildDir
, "OUTPUT")
168 Macro
["DEBUG_DIR" ] = os
.path
.join(BuildDir
, "DEBUG")
171 for Type
in BuildRuleDatabase
.FileTypeList
:
172 #first try getting build rule by BuildRuleFamily
173 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
175 # build type is always module type, but ...
176 if Inf
.ModuleType
!= Inf
.BuildType
:
177 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
178 #second try getting build rule by ToolChainFamily
180 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
182 # build type is always module type, but ...
183 if Inf
.ModuleType
!= Inf
.BuildType
:
184 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
187 RuleObject
= RuleObject
.Instantiate(Macro
)
188 BuildRules
[Type
] = RuleObject
189 for Ext
in RuleObject
.SourceFileExtList
:
190 BuildRules
[Ext
] = RuleObject
193 ## GetModuleCodaTargetList
195 # @param Inf: object of InfBuildData
196 # @param Arch: current arch
199 def GetModuleCodaTargetList(Inf
, Arch
):
200 BuildRules
= GenFdsGlobalVariable
.GetBuildRules(Inf
, Arch
)
207 if not Inf
.IsBinaryModule
:
208 for File
in Inf
.Sources
:
209 if File
.TagName
in ("", "*", GenFdsGlobalVariable
.ToolChainTag
) and \
210 File
.ToolChainFamily
in ("", "*", GenFdsGlobalVariable
.ToolChainFamily
):
211 FileList
.append((File
, DataType
.TAB_UNKNOWN_FILE
))
213 for File
in Inf
.Binaries
:
214 if File
.Target
in ['COMMON', '*', GenFdsGlobalVariable
.TargetName
]:
215 FileList
.append((File
, File
.Type
))
217 for File
, FileType
in FileList
:
222 while Index
< len(SourceList
):
223 Source
= SourceList
[Index
]
226 if File
.IsBinary
and File
== Source
and Inf
.Binaries
!= None and File
in Inf
.Binaries
:
227 # Skip all files that are not binary libraries
228 if not Inf
.LibraryClass
:
230 RuleObject
= BuildRules
[DataType
.TAB_DEFAULT_BINARY_FILE
]
231 elif FileType
in BuildRules
:
232 RuleObject
= BuildRules
[FileType
]
233 elif Source
.Ext
in BuildRules
:
234 RuleObject
= BuildRules
[Source
.Ext
]
236 # stop at no more rules
238 TargetList
.add(str(LastTarget
))
241 FileType
= RuleObject
.SourceFileType
243 # stop at STATIC_LIBRARY for library
244 if Inf
.LibraryClass
and FileType
== DataType
.TAB_STATIC_LIBRARY
:
246 TargetList
.add(str(LastTarget
))
249 Target
= RuleObject
.Apply(Source
)
252 TargetList
.add(str(LastTarget
))
254 elif not Target
.Outputs
:
255 # Only do build for target with outputs
256 TargetList
.add(str(Target
))
258 # to avoid cyclic rule
259 if FileType
in RuleChain
:
262 RuleChain
.append(FileType
)
263 SourceList
.extend(Target
.Outputs
)
265 FileType
= DataType
.TAB_UNKNOWN_FILE
267 return list(TargetList
)
271 # @param OutputDir Output directory
272 # @param FdfParser FDF contents parser
273 # @param Workspace The directory of workspace
274 # @param ArchList The Arch list of platform
276 def SetDir (OutputDir
, FdfParser
, WorkSpace
, ArchList
):
277 GenFdsGlobalVariable
.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir
)
278 # GenFdsGlobalVariable.OutputDirDict = OutputDir
279 GenFdsGlobalVariable
.FdfParser
= FdfParser
280 GenFdsGlobalVariable
.WorkSpace
= WorkSpace
281 GenFdsGlobalVariable
.FvDir
= os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[ArchList
[0]], 'FV')
282 if not os
.path
.exists(GenFdsGlobalVariable
.FvDir
) :
283 os
.makedirs(GenFdsGlobalVariable
.FvDir
)
284 GenFdsGlobalVariable
.FfsDir
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, 'Ffs')
285 if not os
.path
.exists(GenFdsGlobalVariable
.FfsDir
) :
286 os
.makedirs(GenFdsGlobalVariable
.FfsDir
)
288 GenFdsGlobalVariable
.ArchList
= ArchList
292 # Create FV Address inf file
294 GenFdsGlobalVariable
.FvAddressFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, 'FvAddress.inf')
295 FvAddressFile
= open (GenFdsGlobalVariable
.FvAddressFileName
, 'w')
299 FvAddressFile
.writelines("[options]" + T_CHAR_LF
)
301 for Arch
in ArchList
:
302 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
:
303 BsAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
306 FvAddressFile
.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
311 for Arch
in ArchList
:
312 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
:
313 RtAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
315 FvAddressFile
.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
319 FvAddressFile
.close()
321 ## ReplaceWorkspaceMacro()
323 # @param String String that may contain macro
325 def ReplaceWorkspaceMacro(String
):
326 String
= mws
.handleWsMacro(String
)
327 Str
= String
.replace('$(WORKSPACE)', GenFdsGlobalVariable
.WorkSpaceDir
)
328 if os
.path
.exists(Str
):
329 if not os
.path
.isabs(Str
):
330 Str
= os
.path
.abspath(Str
)
332 Str
= mws
.join(GenFdsGlobalVariable
.WorkSpaceDir
, String
)
333 return os
.path
.normpath(Str
)
335 ## Check if the input files are newer than output files
337 # @param Output Path of output file
338 # @param Input Path list of input files
340 # @retval True if Output doesn't exist, or any Input is newer
341 # @retval False if all Input is older than Output
344 def NeedsUpdate(Output
, Input
):
345 if not os
.path
.exists(Output
):
347 # always update "Output" if no "Input" given
348 if Input
== None or len(Input
) == 0:
351 # if fdf file is changed after the 'Output" is generated, update the 'Output'
352 OutputTime
= os
.path
.getmtime(Output
)
353 if GenFdsGlobalVariable
.FdfFileTimeStamp
> OutputTime
:
357 # always update "Output" if any "Input" doesn't exist
358 if not os
.path
.exists(F
):
360 # always update "Output" if any "Input" is newer than "Output"
361 if os
.path
.getmtime(F
) > OutputTime
:
366 def GenerateSection(Output
, Input
, Type
=None, CompressionType
=None, Guid
=None,
367 GuidHdrLen
=None, GuidAttr
=[], Ui
=None, Ver
=None, InputAlign
=None, BuildNumber
=None):
369 if Type
not in [None, '']:
371 if CompressionType
not in [None, '']:
372 Cmd
+= ["-c", CompressionType
]
375 if GuidHdrLen
not in [None, '']:
376 Cmd
+= ["-l", GuidHdrLen
]
377 if len(GuidAttr
) != 0:
378 #Add each guided attribute
379 for Attr
in GuidAttr
:
381 if InputAlign
!= None:
382 #Section Align is only for dummy section without section type
383 for SecAlign
in InputAlign
:
384 Cmd
+= ["--sectionalign", SecAlign
]
386 CommandFile
= Output
+ '.txt'
387 if Ui
not in [None, '']:
388 #Cmd += ["-n", '"' + Ui + '"']
389 SectionData
= array
.array('B', [0,0,0,0])
390 SectionData
.fromstring(Ui
.encode("utf_16_le"))
391 SectionData
.append(0)
392 SectionData
.append(0)
393 Len
= len(SectionData
)
394 GenFdsGlobalVariable
.SectionHeader
.pack_into(SectionData
, 0, Len
& 0xff, (Len
>> 8) & 0xff, (Len
>> 16) & 0xff, 0x15)
395 SaveFileOnChange(Output
, SectionData
.tostring())
396 elif Ver
not in [None, '']:
399 Cmd
+= ["-j", BuildNumber
]
400 Cmd
+= ["-o", Output
]
402 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
403 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
406 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
408 Cmd
+= ["-o", Output
]
411 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
412 if GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
413 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
414 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
416 if (os
.path
.getsize(Output
) >= GenFdsGlobalVariable
.LARGE_FILE_SIZE
and
417 GenFdsGlobalVariable
.LargeFileInFvFlags
):
418 GenFdsGlobalVariable
.LargeFileInFvFlags
[-1] = True
421 def GetAlignment (AlignString
):
422 if AlignString
== None:
424 if AlignString
in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):
425 return int (AlignString
.rstrip('K')) * 1024
427 return int (AlignString
)
430 def GenerateFfs(Output
, Input
, Type
, Guid
, Fixed
=False, CheckSum
=False, Align
=None,
432 Cmd
= ["GenFfs", "-t", Type
, "-g", Guid
]
437 if Align
not in [None, '']:
440 Cmd
+= ["-o", Output
]
441 for I
in range(0, len(Input
)):
442 Cmd
+= ("-i", Input
[I
])
443 if SectionAlign
not in [None, '', []] and SectionAlign
[I
] not in [None, '']:
444 Cmd
+= ("-n", SectionAlign
[I
])
446 CommandFile
= Output
+ '.txt'
447 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
448 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
450 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
452 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FFS")
455 def GenerateFirmwareVolume(Output
, Input
, BaseAddress
=None, ForceRebase
=None, Capsule
=False, Dump
=False,
456 AddressFile
=None, MapFile
=None, FfsList
=[], FileSystemGuid
=None):
457 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
+FfsList
):
459 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
462 if BaseAddress
not in [None, '']:
463 Cmd
+= ["-r", BaseAddress
]
465 if ForceRebase
== False:
466 Cmd
+=["-F", "FALSE"]
467 elif ForceRebase
== True:
474 if AddressFile
not in [None, '']:
475 Cmd
+= ["-a", AddressFile
]
476 if MapFile
not in [None, '']:
477 Cmd
+= ["-m", MapFile
]
479 Cmd
+= ["-g", FileSystemGuid
]
480 Cmd
+= ["-o", Output
]
484 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FV")
487 def GenerateVtf(Output
, Input
, BaseAddress
=None, FvSize
=None):
488 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
490 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
493 if BaseAddress
not in [None, ''] and FvSize
not in [None, ''] \
494 and len(BaseAddress
) == len(FvSize
):
495 for I
in range(0, len(BaseAddress
)):
496 Cmd
+= ["-r", BaseAddress
[I
], "-s", FvSize
[I
]]
497 Cmd
+= ["-o", Output
]
501 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate VTF")
504 def GenerateFirmwareImage(Output
, Input
, Type
="efi", SubType
=None, Zero
=False,
505 Strip
=False, Replace
=False, TimeStamp
=None, Join
=False,
506 Align
=None, Padding
=None, Convert
=False):
507 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
509 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
512 if Type
.lower() == "te":
514 if SubType
not in [None, '']:
515 Cmd
+= ["-e", SubType
]
516 if TimeStamp
not in [None, '']:
517 Cmd
+= ["-s", TimeStamp
]
518 if Align
not in [None, '']:
520 if Padding
not in [None, '']:
521 Cmd
+= ["-p", Padding
]
532 Cmd
+= ["-o", Output
]
535 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate firmware image")
538 def GenerateOptionRom(Output
, EfiInput
, BinaryInput
, Compress
=False, ClassCode
=None,
539 Revision
=None, DeviceId
=None, VendorId
=None):
542 if len(EfiInput
) > 0:
549 for EfiFile
in EfiInput
:
551 InputList
.append (EfiFile
)
553 if len(BinaryInput
) > 0:
555 for BinFile
in BinaryInput
:
557 InputList
.append (BinFile
)
560 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, InputList
):
562 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, InputList
))
564 if ClassCode
!= None:
565 Cmd
+= ["-l", ClassCode
]
567 Cmd
+= ["-r", Revision
]
569 Cmd
+= ["-i", DeviceId
]
571 Cmd
+= ["-f", VendorId
]
573 Cmd
+= ["-o", Output
]
574 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate option rom")
577 def GuidTool(Output
, Input
, ToolPath
, Options
='', returnValue
=[]):
578 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
580 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
583 Cmd
+= Options
.split(' ')
584 Cmd
+= ["-o", Output
]
587 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to call " + ToolPath
, returnValue
)
589 def CallExternalTool (cmd
, errorMess
, returnValue
=[]):
591 if type(cmd
) not in (tuple, list):
592 GenFdsGlobalVariable
.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")
594 if GenFdsGlobalVariable
.DebugLevel
!= -1:
595 cmd
+= ('--debug', str(GenFdsGlobalVariable
.DebugLevel
))
596 GenFdsGlobalVariable
.InfLogger (cmd
)
598 if GenFdsGlobalVariable
.VerboseMode
:
600 GenFdsGlobalVariable
.InfLogger (cmd
)
602 sys
.stdout
.write ('#')
604 GenFdsGlobalVariable
.SharpCounter
= GenFdsGlobalVariable
.SharpCounter
+ 1
605 if GenFdsGlobalVariable
.SharpCounter
% GenFdsGlobalVariable
.SharpNumberPerLine
== 0:
606 sys
.stdout
.write('\n')
609 PopenObject
= subprocess
.Popen(' '.join(cmd
), stdout
=subprocess
.PIPE
, stderr
= subprocess
.PIPE
, shell
=True)
611 EdkLogger
.error("GenFds", COMMAND_FAILURE
, ExtraData
="%s: %s" % (str(X
), cmd
[0]))
612 (out
, error
) = PopenObject
.communicate()
614 while PopenObject
.returncode
== None :
616 if returnValue
!= [] and returnValue
[0] != 0:
617 #get command return value
618 returnValue
[0] = PopenObject
.returncode
620 if PopenObject
.returncode
!= 0 or GenFdsGlobalVariable
.VerboseMode
or GenFdsGlobalVariable
.DebugLevel
!= -1:
621 GenFdsGlobalVariable
.InfLogger ("Return Value = %d" %PopenObject
.returncode
)
622 GenFdsGlobalVariable
.InfLogger (out
)
623 GenFdsGlobalVariable
.InfLogger (error
)
624 if PopenObject
.returncode
!= 0:
626 EdkLogger
.error("GenFds", COMMAND_FAILURE
, errorMess
)
628 def VerboseLogger (msg
):
629 EdkLogger
.verbose(msg
)
634 def ErrorLogger (msg
, File
= None, Line
= None, ExtraData
= None):
635 EdkLogger
.error('GenFds', GENFDS_ERROR
, msg
, File
, Line
, ExtraData
)
637 def DebugLogger (Level
, msg
):
638 EdkLogger
.debug(Level
, msg
)
640 ## ReplaceWorkspaceMacro()
642 # @param Str String that may contain macro
643 # @param MacroDict Dictionary that contains macro value pair
645 def MacroExtend (Str
, MacroDict
= {}, Arch
= 'COMMON'):
649 Dict
= {'$(WORKSPACE)' : GenFdsGlobalVariable
.WorkSpaceDir
,
650 '$(EDK_SOURCE)' : GenFdsGlobalVariable
.EdkSourceDir
,
651 # '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,
652 '$(TARGET)' : GenFdsGlobalVariable
.TargetName
,
653 '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable
.ToolChainTag
,
656 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[GenFdsGlobalVariable
.ArchList
[0]]
657 if Arch
!= 'COMMON' and Arch
in GenFdsGlobalVariable
.ArchList
:
658 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
]
660 Dict
['$(OUTPUT_DIRECTORY)'] = OutputDir
662 if MacroDict
!= None and len (MacroDict
) != 0:
663 Dict
.update(MacroDict
)
665 for key
in Dict
.keys():
666 if Str
.find(key
) >= 0 :
667 Str
= Str
.replace (key
, Dict
[key
])
669 if Str
.find('$(ARCH)') >= 0:
670 if len(GenFdsGlobalVariable
.ArchList
) == 1:
671 Str
= Str
.replace('$(ARCH)', GenFdsGlobalVariable
.ArchList
[0])
673 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No way to determine $(ARCH) for %s" % Str
)
679 # @param PcdPattern pattern that labels a PCD.
681 def GetPcdValue (PcdPattern
):
682 if PcdPattern
== None :
684 PcdPair
= PcdPattern
.lstrip('PCD(').rstrip(')').strip().split('.')
685 TokenSpace
= PcdPair
[0]
686 TokenCName
= PcdPair
[1]
689 for Arch
in GenFdsGlobalVariable
.ArchList
:
690 Platform
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
691 PcdDict
= Platform
.Pcds
693 PcdObj
= PcdDict
[Key
]
694 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
695 if PcdObj
.Type
!= 'FixedAtBuild':
696 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
697 if PcdObj
.DatumType
!= 'VOID*':
698 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
700 PcdValue
= PcdObj
.DefaultValue
703 for Package
in GenFdsGlobalVariable
.WorkSpace
.GetPackageList(GenFdsGlobalVariable
.ActivePlatform
,
705 GenFdsGlobalVariable
.TargetName
,
706 GenFdsGlobalVariable
.ToolChainTag
):
707 PcdDict
= Package
.Pcds
709 PcdObj
= PcdDict
[Key
]
710 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
711 if PcdObj
.Type
!= 'FixedAtBuild':
712 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
713 if PcdObj
.DatumType
!= 'VOID*':
714 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
716 PcdValue
= PcdObj
.DefaultValue
721 SetDir
= staticmethod(SetDir
)
722 ReplaceWorkspaceMacro
= staticmethod(ReplaceWorkspaceMacro
)
723 CallExternalTool
= staticmethod(CallExternalTool
)
724 VerboseLogger
= staticmethod(VerboseLogger
)
725 InfLogger
= staticmethod(InfLogger
)
726 ErrorLogger
= staticmethod(ErrorLogger
)
727 DebugLogger
= staticmethod(DebugLogger
)
728 MacroExtend
= staticmethod (MacroExtend
)
729 GetPcdValue
= staticmethod(GetPcdValue
)