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
38 class GenFdsGlobalVariable
:
42 # will be FvDir + os.sep + 'Ffs'
49 OutputDirFromDscDict
= {}
56 FvAddressFileName
= ''
60 SharpNumberPerLine
= 40
63 FixedLoadAddress
= False
66 BuildRuleFamily
= "MSFT"
67 ToolChainFamily
= "MSFT"
68 __BuildRuleDatabase
= None
71 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.
72 # At the beginning of each generation of FV, false flag is appended to the list,
73 # after the call to GenerateSection returns, check the size of the output file,
74 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,
75 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.
76 # At the end of generation of FV, pop the flag.
77 # List is used as a stack to handle nested FV generation.
79 LargeFileInFvFlags
= []
80 EFI_FIRMWARE_FILE_SYSTEM3_GUID
= '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'
81 LARGE_FILE_SIZE
= 0x1000000
83 SectionHeader
= struct
.Struct("3B 1B")
88 def __LoadBuildRule():
89 if GenFdsGlobalVariable
.__BuildRuleDatabase
:
90 return GenFdsGlobalVariable
.__BuildRuleDatabase
91 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, "Conf/target.txt"))
92 TargetTxt
= TargetTxtClassObject()
93 if os
.path
.isfile(BuildConfigurationFile
) == True:
94 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
95 if DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
in TargetTxt
.TargetTxtDictionary
:
96 BuildRuleFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]
97 if BuildRuleFile
in [None, '']:
98 BuildRuleFile
= 'Conf/build_rule.txt'
99 GenFdsGlobalVariable
.__BuildRuleDatabase
= BuildRule(BuildRuleFile
)
100 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
101 if ToolDefinitionFile
== '':
102 ToolDefinitionFile
= "Conf/tools_def.txt"
103 if os
.path
.isfile(ToolDefinitionFile
):
104 ToolDef
= ToolDefClassObject()
105 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
106 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
107 if DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
in ToolDefinition \
108 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
109 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
110 GenFdsGlobalVariable
.BuildRuleFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
112 if DataType
.TAB_TOD_DEFINES_FAMILY
in ToolDefinition \
113 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
] \
114 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
115 GenFdsGlobalVariable
.ToolChainFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
116 return GenFdsGlobalVariable
.__BuildRuleDatabase
119 # @param Inf: object of InfBuildData
120 # @param Arch: current arch
123 def GetBuildRules(Inf
, Arch
):
127 if not Arch
in GenFdsGlobalVariable
.OutputDirDict
:
130 BuildRuleDatabase
= GenFdsGlobalVariable
.__LoadBuildRule
()
131 if not BuildRuleDatabase
:
134 PathClassObj
= PathClass(Inf
.MetaFile
.File
,
135 GenFdsGlobalVariable
.WorkSpaceDir
)
137 Macro
["WORKSPACE" ] = GenFdsGlobalVariable
.WorkSpaceDir
138 Macro
["MODULE_NAME" ] = Inf
.BaseName
139 Macro
["MODULE_GUID" ] = Inf
.Guid
140 Macro
["MODULE_VERSION" ] = Inf
.Version
141 Macro
["MODULE_TYPE" ] = Inf
.ModuleType
142 Macro
["MODULE_FILE" ] = str(PathClassObj
)
143 Macro
["MODULE_FILE_BASE_NAME" ] = PathClassObj
.BaseName
144 Macro
["MODULE_RELATIVE_DIR" ] = PathClassObj
.SubDir
145 Macro
["MODULE_DIR" ] = PathClassObj
.SubDir
147 Macro
["BASE_NAME" ] = Inf
.BaseName
149 Macro
["ARCH" ] = Arch
150 Macro
["TOOLCHAIN" ] = GenFdsGlobalVariable
.ToolChainTag
151 Macro
["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
152 Macro
["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
153 Macro
["TARGET" ] = GenFdsGlobalVariable
.TargetName
155 Macro
["BUILD_DIR" ] = GenFdsGlobalVariable
.OutputDirDict
[Arch
]
156 Macro
["BIN_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
157 Macro
["LIB_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
158 BuildDir
= os
.path
.join(
159 GenFdsGlobalVariable
.OutputDirDict
[Arch
],
162 PathClassObj
.BaseName
164 Macro
["MODULE_BUILD_DIR" ] = BuildDir
165 Macro
["OUTPUT_DIR" ] = os
.path
.join(BuildDir
, "OUTPUT")
166 Macro
["DEBUG_DIR" ] = os
.path
.join(BuildDir
, "DEBUG")
169 for Type
in BuildRuleDatabase
.FileTypeList
:
170 #first try getting build rule by BuildRuleFamily
171 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
173 # build type is always module type, but ...
174 if Inf
.ModuleType
!= Inf
.BuildType
:
175 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
176 #second try getting build rule by ToolChainFamily
178 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
180 # build type is always module type, but ...
181 if Inf
.ModuleType
!= Inf
.BuildType
:
182 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
185 RuleObject
= RuleObject
.Instantiate(Macro
)
186 BuildRules
[Type
] = RuleObject
187 for Ext
in RuleObject
.SourceFileExtList
:
188 BuildRules
[Ext
] = RuleObject
191 ## GetModuleCodaTargetList
193 # @param Inf: object of InfBuildData
194 # @param Arch: current arch
197 def GetModuleCodaTargetList(Inf
, Arch
):
198 BuildRules
= GenFdsGlobalVariable
.GetBuildRules(Inf
, Arch
)
204 for File
in Inf
.Sources
:
205 if File
.TagName
in ("", "*", GenFdsGlobalVariable
.ToolChainTag
) and \
206 File
.ToolChainFamily
in ("", "*", GenFdsGlobalVariable
.ToolChainFamily
):
207 FileList
.append((File
, DataType
.TAB_UNKNOWN_FILE
))
209 for File
in Inf
.Binaries
:
210 if File
.Target
in ['COMMON', '*', GenFdsGlobalVariable
.TargetName
]:
211 FileList
.append((File
, File
.Type
))
213 for File
, FileType
in FileList
:
218 while Index
< len(SourceList
):
219 Source
= SourceList
[Index
]
222 if File
.IsBinary
and File
== Source
and Inf
.Binaries
!= None and File
in Inf
.Binaries
:
223 # Skip all files that are not binary libraries
224 if not Inf
.LibraryClass
:
226 RuleObject
= BuildRules
[DataType
.TAB_DEFAULT_BINARY_FILE
]
227 elif FileType
in BuildRules
:
228 RuleObject
= BuildRules
[FileType
]
229 elif Source
.Ext
in BuildRules
:
230 RuleObject
= BuildRules
[Source
.Ext
]
232 # stop at no more rules
234 TargetList
.add(str(LastTarget
))
237 FileType
= RuleObject
.SourceFileType
239 # stop at STATIC_LIBRARY for library
240 if Inf
.LibraryClass
and FileType
== DataType
.TAB_STATIC_LIBRARY
:
242 TargetList
.add(str(LastTarget
))
245 Target
= RuleObject
.Apply(Source
)
248 TargetList
.add(str(LastTarget
))
250 elif not Target
.Outputs
:
251 # Only do build for target with outputs
252 TargetList
.add(str(Target
))
254 # to avoid cyclic rule
255 if FileType
in RuleChain
:
258 RuleChain
.append(FileType
)
259 SourceList
.extend(Target
.Outputs
)
261 FileType
= DataType
.TAB_UNKNOWN_FILE
263 return list(TargetList
)
267 # @param OutputDir Output directory
268 # @param FdfParser FDF contents parser
269 # @param Workspace The directory of workspace
270 # @param ArchList The Arch list of platform
272 def SetDir (OutputDir
, FdfParser
, WorkSpace
, ArchList
):
273 GenFdsGlobalVariable
.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir
)
274 # GenFdsGlobalVariable.OutputDirDict = OutputDir
275 GenFdsGlobalVariable
.FdfParser
= FdfParser
276 GenFdsGlobalVariable
.WorkSpace
= WorkSpace
277 GenFdsGlobalVariable
.FvDir
= os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[ArchList
[0]], 'FV')
278 if not os
.path
.exists(GenFdsGlobalVariable
.FvDir
) :
279 os
.makedirs(GenFdsGlobalVariable
.FvDir
)
280 GenFdsGlobalVariable
.FfsDir
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, 'Ffs')
281 if not os
.path
.exists(GenFdsGlobalVariable
.FfsDir
) :
282 os
.makedirs(GenFdsGlobalVariable
.FfsDir
)
284 GenFdsGlobalVariable
.ArchList
= ArchList
288 # Create FV Address inf file
290 GenFdsGlobalVariable
.FvAddressFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, 'FvAddress.inf')
291 FvAddressFile
= open (GenFdsGlobalVariable
.FvAddressFileName
, 'w')
295 FvAddressFile
.writelines("[options]" + T_CHAR_LF
)
297 for Arch
in ArchList
:
298 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
:
299 BsAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
302 FvAddressFile
.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
307 for Arch
in ArchList
:
308 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
:
309 RtAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
311 FvAddressFile
.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
315 FvAddressFile
.close()
317 ## ReplaceWorkspaceMacro()
319 # @param String String that may contain macro
321 def ReplaceWorkspaceMacro(String
):
322 Str
= String
.replace('$(WORKSPACE)', GenFdsGlobalVariable
.WorkSpaceDir
)
323 if os
.path
.exists(Str
):
324 if not os
.path
.isabs(Str
):
325 Str
= os
.path
.abspath(Str
)
327 Str
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, String
)
328 return os
.path
.normpath(Str
)
330 ## Check if the input files are newer than output files
332 # @param Output Path of output file
333 # @param Input Path list of input files
335 # @retval True if Output doesn't exist, or any Input is newer
336 # @retval False if all Input is older than Output
339 def NeedsUpdate(Output
, Input
):
340 if not os
.path
.exists(Output
):
342 # always update "Output" if no "Input" given
343 if Input
== None or len(Input
) == 0:
346 # if fdf file is changed after the 'Output" is generated, update the 'Output'
347 OutputTime
= os
.path
.getmtime(Output
)
348 if GenFdsGlobalVariable
.FdfFileTimeStamp
> OutputTime
:
352 # always update "Output" if any "Input" doesn't exist
353 if not os
.path
.exists(F
):
355 # always update "Output" if any "Input" is newer than "Output"
356 if os
.path
.getmtime(F
) > OutputTime
:
361 def GenerateSection(Output
, Input
, Type
=None, CompressionType
=None, Guid
=None,
362 GuidHdrLen
=None, GuidAttr
=[], Ui
=None, Ver
=None, InputAlign
=None, BuildNumber
=None):
364 if Type
not in [None, '']:
366 if CompressionType
not in [None, '']:
367 Cmd
+= ["-c", CompressionType
]
370 if GuidHdrLen
not in [None, '']:
371 Cmd
+= ["-l", GuidHdrLen
]
372 if len(GuidAttr
) != 0:
373 #Add each guided attribute
374 for Attr
in GuidAttr
:
376 if InputAlign
!= None:
377 #Section Align is only for dummy section without section type
378 for SecAlign
in InputAlign
:
379 Cmd
+= ["--sectionalign", SecAlign
]
381 CommandFile
= Output
+ '.txt'
382 if Ui
not in [None, '']:
383 #Cmd += ["-n", '"' + Ui + '"']
384 SectionData
= array
.array('B', [0,0,0,0])
385 SectionData
.fromstring(Ui
.encode("utf_16_le"))
386 SectionData
.append(0)
387 SectionData
.append(0)
388 Len
= len(SectionData
)
389 GenFdsGlobalVariable
.SectionHeader
.pack_into(SectionData
, 0, Len
& 0xff, (Len
>> 8) & 0xff, (Len
>> 16) & 0xff, 0x15)
390 SaveFileOnChange(Output
, SectionData
.tostring())
391 elif Ver
not in [None, '']:
394 Cmd
+= ["-j", BuildNumber
]
395 Cmd
+= ["-o", Output
]
397 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
398 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
401 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
403 Cmd
+= ["-o", Output
]
406 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
407 if GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
408 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
409 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
411 if (os
.path
.getsize(Output
) >= GenFdsGlobalVariable
.LARGE_FILE_SIZE
and
412 GenFdsGlobalVariable
.LargeFileInFvFlags
):
413 GenFdsGlobalVariable
.LargeFileInFvFlags
[-1] = True
416 def GetAlignment (AlignString
):
417 if AlignString
== None:
419 if AlignString
in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):
420 return int (AlignString
.rstrip('K')) * 1024
422 return int (AlignString
)
425 def GenerateFfs(Output
, Input
, Type
, Guid
, Fixed
=False, CheckSum
=False, Align
=None,
427 Cmd
= ["GenFfs", "-t", Type
, "-g", Guid
]
432 if Align
not in [None, '']:
435 Cmd
+= ["-o", Output
]
436 for I
in range(0, len(Input
)):
437 Cmd
+= ("-i", Input
[I
])
438 if SectionAlign
not in [None, '', []] and SectionAlign
[I
] not in [None, '']:
439 Cmd
+= ("-n", SectionAlign
[I
])
441 CommandFile
= Output
+ '.txt'
442 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
443 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
445 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
447 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FFS")
450 def GenerateFirmwareVolume(Output
, Input
, BaseAddress
=None, ForceRebase
=None, Capsule
=False, Dump
=False,
451 AddressFile
=None, MapFile
=None, FfsList
=[], FileSystemGuid
=None):
452 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
+FfsList
):
454 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
457 if BaseAddress
not in [None, '']:
458 Cmd
+= ["-r", BaseAddress
]
460 if ForceRebase
== False:
461 Cmd
+=["-F", "FALSE"]
462 elif ForceRebase
== True:
469 if AddressFile
not in [None, '']:
470 Cmd
+= ["-a", AddressFile
]
471 if MapFile
not in [None, '']:
472 Cmd
+= ["-m", MapFile
]
474 Cmd
+= ["-g", FileSystemGuid
]
475 Cmd
+= ["-o", Output
]
479 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FV")
482 def GenerateVtf(Output
, Input
, BaseAddress
=None, FvSize
=None):
483 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
485 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
488 if BaseAddress
not in [None, ''] and FvSize
not in [None, ''] \
489 and len(BaseAddress
) == len(FvSize
):
490 for I
in range(0, len(BaseAddress
)):
491 Cmd
+= ["-r", BaseAddress
[I
], "-s", FvSize
[I
]]
492 Cmd
+= ["-o", Output
]
496 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate VTF")
499 def GenerateFirmwareImage(Output
, Input
, Type
="efi", SubType
=None, Zero
=False,
500 Strip
=False, Replace
=False, TimeStamp
=None, Join
=False,
501 Align
=None, Padding
=None, Convert
=False):
502 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
504 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
507 if Type
.lower() == "te":
509 if SubType
not in [None, '']:
510 Cmd
+= ["-e", SubType
]
511 if TimeStamp
not in [None, '']:
512 Cmd
+= ["-s", TimeStamp
]
513 if Align
not in [None, '']:
515 if Padding
not in [None, '']:
516 Cmd
+= ["-p", Padding
]
527 Cmd
+= ["-o", Output
]
530 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate firmware image")
533 def GenerateOptionRom(Output
, EfiInput
, BinaryInput
, Compress
=False, ClassCode
=None,
534 Revision
=None, DeviceId
=None, VendorId
=None):
537 if len(EfiInput
) > 0:
544 for EfiFile
in EfiInput
:
546 InputList
.append (EfiFile
)
548 if len(BinaryInput
) > 0:
550 for BinFile
in BinaryInput
:
552 InputList
.append (BinFile
)
555 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, InputList
):
557 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, InputList
))
559 if ClassCode
!= None:
560 Cmd
+= ["-l", ClassCode
]
562 Cmd
+= ["-r", Revision
]
564 Cmd
+= ["-i", DeviceId
]
566 Cmd
+= ["-f", VendorId
]
568 Cmd
+= ["-o", Output
]
569 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate option rom")
572 def GuidTool(Output
, Input
, ToolPath
, Options
='', returnValue
=[]):
573 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
575 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
578 Cmd
+= Options
.split(' ')
579 Cmd
+= ["-o", Output
]
582 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to call " + ToolPath
, returnValue
)
584 def CallExternalTool (cmd
, errorMess
, returnValue
=[]):
586 if type(cmd
) not in (tuple, list):
587 GenFdsGlobalVariable
.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")
589 if GenFdsGlobalVariable
.DebugLevel
!= -1:
590 cmd
+= ('--debug', str(GenFdsGlobalVariable
.DebugLevel
))
591 GenFdsGlobalVariable
.InfLogger (cmd
)
593 if GenFdsGlobalVariable
.VerboseMode
:
595 GenFdsGlobalVariable
.InfLogger (cmd
)
597 sys
.stdout
.write ('#')
599 GenFdsGlobalVariable
.SharpCounter
= GenFdsGlobalVariable
.SharpCounter
+ 1
600 if GenFdsGlobalVariable
.SharpCounter
% GenFdsGlobalVariable
.SharpNumberPerLine
== 0:
601 sys
.stdout
.write('\n')
604 PopenObject
= subprocess
.Popen(' '.join(cmd
), stdout
=subprocess
.PIPE
, stderr
= subprocess
.PIPE
, shell
=True)
606 EdkLogger
.error("GenFds", COMMAND_FAILURE
, ExtraData
="%s: %s" % (str(X
), cmd
[0]))
607 (out
, error
) = PopenObject
.communicate()
609 while PopenObject
.returncode
== None :
611 if returnValue
!= [] and returnValue
[0] != 0:
612 #get command return value
613 returnValue
[0] = PopenObject
.returncode
615 if PopenObject
.returncode
!= 0 or GenFdsGlobalVariable
.VerboseMode
or GenFdsGlobalVariable
.DebugLevel
!= -1:
616 GenFdsGlobalVariable
.InfLogger ("Return Value = %d" %PopenObject
.returncode
)
617 GenFdsGlobalVariable
.InfLogger (out
)
618 GenFdsGlobalVariable
.InfLogger (error
)
619 if PopenObject
.returncode
!= 0:
621 EdkLogger
.error("GenFds", COMMAND_FAILURE
, errorMess
)
623 def VerboseLogger (msg
):
624 EdkLogger
.verbose(msg
)
629 def ErrorLogger (msg
, File
= None, Line
= None, ExtraData
= None):
630 EdkLogger
.error('GenFds', GENFDS_ERROR
, msg
, File
, Line
, ExtraData
)
632 def DebugLogger (Level
, msg
):
633 EdkLogger
.debug(Level
, msg
)
635 ## ReplaceWorkspaceMacro()
637 # @param Str String that may contain macro
638 # @param MacroDict Dictionary that contains macro value pair
640 def MacroExtend (Str
, MacroDict
= {}, Arch
= 'COMMON'):
644 Dict
= {'$(WORKSPACE)' : GenFdsGlobalVariable
.WorkSpaceDir
,
645 '$(EDK_SOURCE)' : GenFdsGlobalVariable
.EdkSourceDir
,
646 # '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,
647 '$(TARGET)' : GenFdsGlobalVariable
.TargetName
,
648 '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable
.ToolChainTag
650 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[GenFdsGlobalVariable
.ArchList
[0]]
651 if Arch
!= 'COMMON' and Arch
in GenFdsGlobalVariable
.ArchList
:
652 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
]
654 Dict
['$(OUTPUT_DIRECTORY)'] = OutputDir
656 if MacroDict
!= None and len (MacroDict
) != 0:
657 Dict
.update(MacroDict
)
659 for key
in Dict
.keys():
660 if Str
.find(key
) >= 0 :
661 Str
= Str
.replace (key
, Dict
[key
])
663 if Str
.find('$(ARCH)') >= 0:
664 if len(GenFdsGlobalVariable
.ArchList
) == 1:
665 Str
= Str
.replace('$(ARCH)', GenFdsGlobalVariable
.ArchList
[0])
667 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No way to determine $(ARCH) for %s" % Str
)
673 # @param PcdPattern pattern that labels a PCD.
675 def GetPcdValue (PcdPattern
):
676 if PcdPattern
== None :
678 PcdPair
= PcdPattern
.lstrip('PCD(').rstrip(')').strip().split('.')
679 TokenSpace
= PcdPair
[0]
680 TokenCName
= PcdPair
[1]
683 for Arch
in GenFdsGlobalVariable
.ArchList
:
684 Platform
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
685 PcdDict
= Platform
.Pcds
687 PcdObj
= PcdDict
[Key
]
688 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
689 if PcdObj
.Type
!= 'FixedAtBuild':
690 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
691 if PcdObj
.DatumType
!= 'VOID*':
692 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
694 PcdValue
= PcdObj
.DefaultValue
697 for Package
in GenFdsGlobalVariable
.WorkSpace
.GetPackageList(GenFdsGlobalVariable
.ActivePlatform
,
699 GenFdsGlobalVariable
.TargetName
,
700 GenFdsGlobalVariable
.ToolChainTag
):
701 PcdDict
= Package
.Pcds
703 PcdObj
= PcdDict
[Key
]
704 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
705 if PcdObj
.Type
!= 'FixedAtBuild':
706 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
707 if PcdObj
.DatumType
!= 'VOID*':
708 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
710 PcdValue
= PcdObj
.DefaultValue
715 SetDir
= staticmethod(SetDir
)
716 ReplaceWorkspaceMacro
= staticmethod(ReplaceWorkspaceMacro
)
717 CallExternalTool
= staticmethod(CallExternalTool
)
718 VerboseLogger
= staticmethod(VerboseLogger
)
719 InfLogger
= staticmethod(InfLogger
)
720 ErrorLogger
= staticmethod(ErrorLogger
)
721 DebugLogger
= staticmethod(DebugLogger
)
722 MacroExtend
= staticmethod (MacroExtend
)
723 GetPcdValue
= staticmethod(GetPcdValue
)