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'
50 OutputDirFromDscDict
= {}
57 FvAddressFileName
= ''
61 SharpNumberPerLine
= 40
64 FixedLoadAddress
= False
67 BuildRuleFamily
= "MSFT"
68 ToolChainFamily
= "MSFT"
69 __BuildRuleDatabase
= None
72 # The list whose element are flags to indicate if large FFS or SECTION files exist in FV.
73 # At the beginning of each generation of FV, false flag is appended to the list,
74 # after the call to GenerateSection returns, check the size of the output file,
75 # if it is greater than 0xFFFFFF, the tail flag in list is set to true,
76 # and EFI_FIRMWARE_FILE_SYSTEM3_GUID is passed to C GenFv.
77 # At the end of generation of FV, pop the flag.
78 # List is used as a stack to handle nested FV generation.
80 LargeFileInFvFlags
= []
81 EFI_FIRMWARE_FILE_SYSTEM3_GUID
= '5473C07A-3DCB-4dca-BD6F-1E9689E7349A'
82 LARGE_FILE_SIZE
= 0x1000000
84 SectionHeader
= struct
.Struct("3B 1B")
89 def __LoadBuildRule():
90 if GenFdsGlobalVariable
.__BuildRuleDatabase
:
91 return GenFdsGlobalVariable
.__BuildRuleDatabase
92 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GenFdsGlobalVariable
.ConfDir
, "target.txt"))
93 TargetTxt
= TargetTxtClassObject()
94 if os
.path
.isfile(BuildConfigurationFile
) == True:
95 TargetTxt
.LoadTargetTxtFile(BuildConfigurationFile
)
96 if DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
in TargetTxt
.TargetTxtDictionary
:
97 BuildRuleFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]
98 if BuildRuleFile
in [None, '']:
99 BuildRuleFile
= 'Conf/build_rule.txt'
100 GenFdsGlobalVariable
.__BuildRuleDatabase
= BuildRule(BuildRuleFile
)
101 ToolDefinitionFile
= TargetTxt
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
]
102 if ToolDefinitionFile
== '':
103 ToolDefinitionFile
= "Conf/tools_def.txt"
104 if os
.path
.isfile(ToolDefinitionFile
):
105 ToolDef
= ToolDefClassObject()
106 ToolDef
.LoadToolDefFile(ToolDefinitionFile
)
107 ToolDefinition
= ToolDef
.ToolsDefTxtDatabase
108 if DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
in ToolDefinition \
109 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
110 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
111 GenFdsGlobalVariable
.BuildRuleFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_BUILDRULEFAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
113 if DataType
.TAB_TOD_DEFINES_FAMILY
in ToolDefinition \
114 and GenFdsGlobalVariable
.ToolChainTag
in ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
] \
115 and ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]:
116 GenFdsGlobalVariable
.ToolChainFamily
= ToolDefinition
[DataType
.TAB_TOD_DEFINES_FAMILY
][GenFdsGlobalVariable
.ToolChainTag
]
117 return GenFdsGlobalVariable
.__BuildRuleDatabase
120 # @param Inf: object of InfBuildData
121 # @param Arch: current arch
124 def GetBuildRules(Inf
, Arch
):
128 if not Arch
in GenFdsGlobalVariable
.OutputDirDict
:
131 BuildRuleDatabase
= GenFdsGlobalVariable
.__LoadBuildRule
()
132 if not BuildRuleDatabase
:
135 PathClassObj
= PathClass(Inf
.MetaFile
.File
,
136 GenFdsGlobalVariable
.WorkSpaceDir
)
138 Macro
["WORKSPACE" ] = GenFdsGlobalVariable
.WorkSpaceDir
139 Macro
["MODULE_NAME" ] = Inf
.BaseName
140 Macro
["MODULE_GUID" ] = Inf
.Guid
141 Macro
["MODULE_VERSION" ] = Inf
.Version
142 Macro
["MODULE_TYPE" ] = Inf
.ModuleType
143 Macro
["MODULE_FILE" ] = str(PathClassObj
)
144 Macro
["MODULE_FILE_BASE_NAME" ] = PathClassObj
.BaseName
145 Macro
["MODULE_RELATIVE_DIR" ] = PathClassObj
.SubDir
146 Macro
["MODULE_DIR" ] = PathClassObj
.SubDir
148 Macro
["BASE_NAME" ] = Inf
.BaseName
150 Macro
["ARCH" ] = Arch
151 Macro
["TOOLCHAIN" ] = GenFdsGlobalVariable
.ToolChainTag
152 Macro
["TOOLCHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
153 Macro
["TOOL_CHAIN_TAG" ] = GenFdsGlobalVariable
.ToolChainTag
154 Macro
["TARGET" ] = GenFdsGlobalVariable
.TargetName
156 Macro
["BUILD_DIR" ] = GenFdsGlobalVariable
.OutputDirDict
[Arch
]
157 Macro
["BIN_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
158 Macro
["LIB_DIR" ] = os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[Arch
], Arch
)
159 BuildDir
= os
.path
.join(
160 GenFdsGlobalVariable
.OutputDirDict
[Arch
],
163 PathClassObj
.BaseName
165 Macro
["MODULE_BUILD_DIR" ] = BuildDir
166 Macro
["OUTPUT_DIR" ] = os
.path
.join(BuildDir
, "OUTPUT")
167 Macro
["DEBUG_DIR" ] = os
.path
.join(BuildDir
, "DEBUG")
170 for Type
in BuildRuleDatabase
.FileTypeList
:
171 #first try getting build rule by BuildRuleFamily
172 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
174 # build type is always module type, but ...
175 if Inf
.ModuleType
!= Inf
.BuildType
:
176 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.BuildRuleFamily
]
177 #second try getting build rule by ToolChainFamily
179 RuleObject
= BuildRuleDatabase
[Type
, Inf
.BuildType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
181 # build type is always module type, but ...
182 if Inf
.ModuleType
!= Inf
.BuildType
:
183 RuleObject
= BuildRuleDatabase
[Type
, Inf
.ModuleType
, Arch
, GenFdsGlobalVariable
.ToolChainFamily
]
186 RuleObject
= RuleObject
.Instantiate(Macro
)
187 BuildRules
[Type
] = RuleObject
188 for Ext
in RuleObject
.SourceFileExtList
:
189 BuildRules
[Ext
] = RuleObject
192 ## GetModuleCodaTargetList
194 # @param Inf: object of InfBuildData
195 # @param Arch: current arch
198 def GetModuleCodaTargetList(Inf
, Arch
):
199 BuildRules
= GenFdsGlobalVariable
.GetBuildRules(Inf
, Arch
)
206 if not Inf
.IsBinaryModule
:
207 for File
in Inf
.Sources
:
208 if File
.TagName
in ("", "*", GenFdsGlobalVariable
.ToolChainTag
) and \
209 File
.ToolChainFamily
in ("", "*", GenFdsGlobalVariable
.ToolChainFamily
):
210 FileList
.append((File
, DataType
.TAB_UNKNOWN_FILE
))
212 for File
in Inf
.Binaries
:
213 if File
.Target
in ['COMMON', '*', GenFdsGlobalVariable
.TargetName
]:
214 FileList
.append((File
, File
.Type
))
216 for File
, FileType
in FileList
:
221 while Index
< len(SourceList
):
222 Source
= SourceList
[Index
]
225 if File
.IsBinary
and File
== Source
and Inf
.Binaries
!= None and File
in Inf
.Binaries
:
226 # Skip all files that are not binary libraries
227 if not Inf
.LibraryClass
:
229 RuleObject
= BuildRules
[DataType
.TAB_DEFAULT_BINARY_FILE
]
230 elif FileType
in BuildRules
:
231 RuleObject
= BuildRules
[FileType
]
232 elif Source
.Ext
in BuildRules
:
233 RuleObject
= BuildRules
[Source
.Ext
]
235 # stop at no more rules
237 TargetList
.add(str(LastTarget
))
240 FileType
= RuleObject
.SourceFileType
242 # stop at STATIC_LIBRARY for library
243 if Inf
.LibraryClass
and FileType
== DataType
.TAB_STATIC_LIBRARY
:
245 TargetList
.add(str(LastTarget
))
248 Target
= RuleObject
.Apply(Source
)
251 TargetList
.add(str(LastTarget
))
253 elif not Target
.Outputs
:
254 # Only do build for target with outputs
255 TargetList
.add(str(Target
))
257 # to avoid cyclic rule
258 if FileType
in RuleChain
:
261 RuleChain
.append(FileType
)
262 SourceList
.extend(Target
.Outputs
)
264 FileType
= DataType
.TAB_UNKNOWN_FILE
266 return list(TargetList
)
270 # @param OutputDir Output directory
271 # @param FdfParser FDF contents parser
272 # @param Workspace The directory of workspace
273 # @param ArchList The Arch list of platform
275 def SetDir (OutputDir
, FdfParser
, WorkSpace
, ArchList
):
276 GenFdsGlobalVariable
.VerboseLogger( "GenFdsGlobalVariable.OutputDir :%s" %OutputDir
)
277 # GenFdsGlobalVariable.OutputDirDict = OutputDir
278 GenFdsGlobalVariable
.FdfParser
= FdfParser
279 GenFdsGlobalVariable
.WorkSpace
= WorkSpace
280 GenFdsGlobalVariable
.FvDir
= os
.path
.join(GenFdsGlobalVariable
.OutputDirDict
[ArchList
[0]], 'FV')
281 if not os
.path
.exists(GenFdsGlobalVariable
.FvDir
) :
282 os
.makedirs(GenFdsGlobalVariable
.FvDir
)
283 GenFdsGlobalVariable
.FfsDir
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, 'Ffs')
284 if not os
.path
.exists(GenFdsGlobalVariable
.FfsDir
) :
285 os
.makedirs(GenFdsGlobalVariable
.FfsDir
)
287 GenFdsGlobalVariable
.ArchList
= ArchList
291 # Create FV Address inf file
293 GenFdsGlobalVariable
.FvAddressFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, 'FvAddress.inf')
294 FvAddressFile
= open (GenFdsGlobalVariable
.FvAddressFileName
, 'w')
298 FvAddressFile
.writelines("[options]" + T_CHAR_LF
)
300 for Arch
in ArchList
:
301 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
:
302 BsAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].BsBaseAddress
305 FvAddressFile
.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
310 for Arch
in ArchList
:
311 if GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
:
312 RtAddress
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].RtBaseAddress
314 FvAddressFile
.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
318 FvAddressFile
.close()
320 ## ReplaceWorkspaceMacro()
322 # @param String String that may contain macro
324 def ReplaceWorkspaceMacro(String
):
325 Str
= String
.replace('$(WORKSPACE)', GenFdsGlobalVariable
.WorkSpaceDir
)
326 if os
.path
.exists(Str
):
327 if not os
.path
.isabs(Str
):
328 Str
= os
.path
.abspath(Str
)
330 Str
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, String
)
331 return os
.path
.normpath(Str
)
333 ## Check if the input files are newer than output files
335 # @param Output Path of output file
336 # @param Input Path list of input files
338 # @retval True if Output doesn't exist, or any Input is newer
339 # @retval False if all Input is older than Output
342 def NeedsUpdate(Output
, Input
):
343 if not os
.path
.exists(Output
):
345 # always update "Output" if no "Input" given
346 if Input
== None or len(Input
) == 0:
349 # if fdf file is changed after the 'Output" is generated, update the 'Output'
350 OutputTime
= os
.path
.getmtime(Output
)
351 if GenFdsGlobalVariable
.FdfFileTimeStamp
> OutputTime
:
355 # always update "Output" if any "Input" doesn't exist
356 if not os
.path
.exists(F
):
358 # always update "Output" if any "Input" is newer than "Output"
359 if os
.path
.getmtime(F
) > OutputTime
:
364 def GenerateSection(Output
, Input
, Type
=None, CompressionType
=None, Guid
=None,
365 GuidHdrLen
=None, GuidAttr
=[], Ui
=None, Ver
=None, InputAlign
=None, BuildNumber
=None):
367 if Type
not in [None, '']:
369 if CompressionType
not in [None, '']:
370 Cmd
+= ["-c", CompressionType
]
373 if GuidHdrLen
not in [None, '']:
374 Cmd
+= ["-l", GuidHdrLen
]
375 if len(GuidAttr
) != 0:
376 #Add each guided attribute
377 for Attr
in GuidAttr
:
379 if InputAlign
!= None:
380 #Section Align is only for dummy section without section type
381 for SecAlign
in InputAlign
:
382 Cmd
+= ["--sectionalign", SecAlign
]
384 CommandFile
= Output
+ '.txt'
385 if Ui
not in [None, '']:
386 #Cmd += ["-n", '"' + Ui + '"']
387 SectionData
= array
.array('B', [0,0,0,0])
388 SectionData
.fromstring(Ui
.encode("utf_16_le"))
389 SectionData
.append(0)
390 SectionData
.append(0)
391 Len
= len(SectionData
)
392 GenFdsGlobalVariable
.SectionHeader
.pack_into(SectionData
, 0, Len
& 0xff, (Len
>> 8) & 0xff, (Len
>> 16) & 0xff, 0x15)
393 SaveFileOnChange(Output
, SectionData
.tostring())
394 elif Ver
not in [None, '']:
397 Cmd
+= ["-j", BuildNumber
]
398 Cmd
+= ["-o", Output
]
400 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
401 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
404 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
406 Cmd
+= ["-o", Output
]
409 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
410 if GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
411 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
412 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate section")
414 if (os
.path
.getsize(Output
) >= GenFdsGlobalVariable
.LARGE_FILE_SIZE
and
415 GenFdsGlobalVariable
.LargeFileInFvFlags
):
416 GenFdsGlobalVariable
.LargeFileInFvFlags
[-1] = True
419 def GetAlignment (AlignString
):
420 if AlignString
== None:
422 if AlignString
in ("1K", "2K", "4K", "8K", "16K", "32K", "64K"):
423 return int (AlignString
.rstrip('K')) * 1024
425 return int (AlignString
)
428 def GenerateFfs(Output
, Input
, Type
, Guid
, Fixed
=False, CheckSum
=False, Align
=None,
430 Cmd
= ["GenFfs", "-t", Type
, "-g", Guid
]
435 if Align
not in [None, '']:
438 Cmd
+= ["-o", Output
]
439 for I
in range(0, len(Input
)):
440 Cmd
+= ("-i", Input
[I
])
441 if SectionAlign
not in [None, '', []] and SectionAlign
[I
] not in [None, '']:
442 Cmd
+= ("-n", SectionAlign
[I
])
444 CommandFile
= Output
+ '.txt'
445 SaveFileOnChange(CommandFile
, ' '.join(Cmd
), False)
446 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, list(Input
) + [CommandFile
]):
448 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
450 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FFS")
453 def GenerateFirmwareVolume(Output
, Input
, BaseAddress
=None, ForceRebase
=None, Capsule
=False, Dump
=False,
454 AddressFile
=None, MapFile
=None, FfsList
=[], FileSystemGuid
=None):
455 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
+FfsList
):
457 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
460 if BaseAddress
not in [None, '']:
461 Cmd
+= ["-r", BaseAddress
]
463 if ForceRebase
== False:
464 Cmd
+=["-F", "FALSE"]
465 elif ForceRebase
== True:
472 if AddressFile
not in [None, '']:
473 Cmd
+= ["-a", AddressFile
]
474 if MapFile
not in [None, '']:
475 Cmd
+= ["-m", MapFile
]
477 Cmd
+= ["-g", FileSystemGuid
]
478 Cmd
+= ["-o", Output
]
482 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate FV")
485 def GenerateVtf(Output
, Input
, BaseAddress
=None, FvSize
=None):
486 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
488 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
491 if BaseAddress
not in [None, ''] and FvSize
not in [None, ''] \
492 and len(BaseAddress
) == len(FvSize
):
493 for I
in range(0, len(BaseAddress
)):
494 Cmd
+= ["-r", BaseAddress
[I
], "-s", FvSize
[I
]]
495 Cmd
+= ["-o", Output
]
499 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate VTF")
502 def GenerateFirmwareImage(Output
, Input
, Type
="efi", SubType
=None, Zero
=False,
503 Strip
=False, Replace
=False, TimeStamp
=None, Join
=False,
504 Align
=None, Padding
=None, Convert
=False):
505 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
507 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
510 if Type
.lower() == "te":
512 if SubType
not in [None, '']:
513 Cmd
+= ["-e", SubType
]
514 if TimeStamp
not in [None, '']:
515 Cmd
+= ["-s", TimeStamp
]
516 if Align
not in [None, '']:
518 if Padding
not in [None, '']:
519 Cmd
+= ["-p", Padding
]
530 Cmd
+= ["-o", Output
]
533 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate firmware image")
536 def GenerateOptionRom(Output
, EfiInput
, BinaryInput
, Compress
=False, ClassCode
=None,
537 Revision
=None, DeviceId
=None, VendorId
=None):
540 if len(EfiInput
) > 0:
547 for EfiFile
in EfiInput
:
549 InputList
.append (EfiFile
)
551 if len(BinaryInput
) > 0:
553 for BinFile
in BinaryInput
:
555 InputList
.append (BinFile
)
558 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, InputList
):
560 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, InputList
))
562 if ClassCode
!= None:
563 Cmd
+= ["-l", ClassCode
]
565 Cmd
+= ["-r", Revision
]
567 Cmd
+= ["-i", DeviceId
]
569 Cmd
+= ["-f", VendorId
]
571 Cmd
+= ["-o", Output
]
572 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to generate option rom")
575 def GuidTool(Output
, Input
, ToolPath
, Options
='', returnValue
=[]):
576 if not GenFdsGlobalVariable
.NeedsUpdate(Output
, Input
):
578 GenFdsGlobalVariable
.DebugLogger(EdkLogger
.DEBUG_5
, "%s needs update because of newer %s" % (Output
, Input
))
581 Cmd
+= Options
.split(' ')
582 Cmd
+= ["-o", Output
]
585 GenFdsGlobalVariable
.CallExternalTool(Cmd
, "Failed to call " + ToolPath
, returnValue
)
587 def CallExternalTool (cmd
, errorMess
, returnValue
=[]):
589 if type(cmd
) not in (tuple, list):
590 GenFdsGlobalVariable
.ErrorLogger("ToolError! Invalid parameter type in call to CallExternalTool")
592 if GenFdsGlobalVariable
.DebugLevel
!= -1:
593 cmd
+= ('--debug', str(GenFdsGlobalVariable
.DebugLevel
))
594 GenFdsGlobalVariable
.InfLogger (cmd
)
596 if GenFdsGlobalVariable
.VerboseMode
:
598 GenFdsGlobalVariable
.InfLogger (cmd
)
600 sys
.stdout
.write ('#')
602 GenFdsGlobalVariable
.SharpCounter
= GenFdsGlobalVariable
.SharpCounter
+ 1
603 if GenFdsGlobalVariable
.SharpCounter
% GenFdsGlobalVariable
.SharpNumberPerLine
== 0:
604 sys
.stdout
.write('\n')
607 PopenObject
= subprocess
.Popen(' '.join(cmd
), stdout
=subprocess
.PIPE
, stderr
= subprocess
.PIPE
, shell
=True)
609 EdkLogger
.error("GenFds", COMMAND_FAILURE
, ExtraData
="%s: %s" % (str(X
), cmd
[0]))
610 (out
, error
) = PopenObject
.communicate()
612 while PopenObject
.returncode
== None :
614 if returnValue
!= [] and returnValue
[0] != 0:
615 #get command return value
616 returnValue
[0] = PopenObject
.returncode
618 if PopenObject
.returncode
!= 0 or GenFdsGlobalVariable
.VerboseMode
or GenFdsGlobalVariable
.DebugLevel
!= -1:
619 GenFdsGlobalVariable
.InfLogger ("Return Value = %d" %PopenObject
.returncode
)
620 GenFdsGlobalVariable
.InfLogger (out
)
621 GenFdsGlobalVariable
.InfLogger (error
)
622 if PopenObject
.returncode
!= 0:
624 EdkLogger
.error("GenFds", COMMAND_FAILURE
, errorMess
)
626 def VerboseLogger (msg
):
627 EdkLogger
.verbose(msg
)
632 def ErrorLogger (msg
, File
= None, Line
= None, ExtraData
= None):
633 EdkLogger
.error('GenFds', GENFDS_ERROR
, msg
, File
, Line
, ExtraData
)
635 def DebugLogger (Level
, msg
):
636 EdkLogger
.debug(Level
, msg
)
638 ## ReplaceWorkspaceMacro()
640 # @param Str String that may contain macro
641 # @param MacroDict Dictionary that contains macro value pair
643 def MacroExtend (Str
, MacroDict
= {}, Arch
= 'COMMON'):
647 Dict
= {'$(WORKSPACE)' : GenFdsGlobalVariable
.WorkSpaceDir
,
648 '$(EDK_SOURCE)' : GenFdsGlobalVariable
.EdkSourceDir
,
649 # '$(OUTPUT_DIRECTORY)': GenFdsGlobalVariable.OutputDirFromDsc,
650 '$(TARGET)' : GenFdsGlobalVariable
.TargetName
,
651 '$(TOOL_CHAIN_TAG)' : GenFdsGlobalVariable
.ToolChainTag
,
654 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[GenFdsGlobalVariable
.ArchList
[0]]
655 if Arch
!= 'COMMON' and Arch
in GenFdsGlobalVariable
.ArchList
:
656 OutputDir
= GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
]
658 Dict
['$(OUTPUT_DIRECTORY)'] = OutputDir
660 if MacroDict
!= None and len (MacroDict
) != 0:
661 Dict
.update(MacroDict
)
663 for key
in Dict
.keys():
664 if Str
.find(key
) >= 0 :
665 Str
= Str
.replace (key
, Dict
[key
])
667 if Str
.find('$(ARCH)') >= 0:
668 if len(GenFdsGlobalVariable
.ArchList
) == 1:
669 Str
= Str
.replace('$(ARCH)', GenFdsGlobalVariable
.ArchList
[0])
671 EdkLogger
.error("GenFds", GENFDS_ERROR
, "No way to determine $(ARCH) for %s" % Str
)
677 # @param PcdPattern pattern that labels a PCD.
679 def GetPcdValue (PcdPattern
):
680 if PcdPattern
== None :
682 PcdPair
= PcdPattern
.lstrip('PCD(').rstrip(')').strip().split('.')
683 TokenSpace
= PcdPair
[0]
684 TokenCName
= PcdPair
[1]
687 for Arch
in GenFdsGlobalVariable
.ArchList
:
688 Platform
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
689 PcdDict
= Platform
.Pcds
691 PcdObj
= PcdDict
[Key
]
692 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
693 if PcdObj
.Type
!= 'FixedAtBuild':
694 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
695 if PcdObj
.DatumType
!= 'VOID*':
696 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
698 PcdValue
= PcdObj
.DefaultValue
701 for Package
in GenFdsGlobalVariable
.WorkSpace
.GetPackageList(GenFdsGlobalVariable
.ActivePlatform
,
703 GenFdsGlobalVariable
.TargetName
,
704 GenFdsGlobalVariable
.ToolChainTag
):
705 PcdDict
= Package
.Pcds
707 PcdObj
= PcdDict
[Key
]
708 if (PcdObj
.TokenCName
== TokenCName
) and (PcdObj
.TokenSpaceGuidCName
== TokenSpace
):
709 if PcdObj
.Type
!= 'FixedAtBuild':
710 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not FixedAtBuild type." % PcdPattern
)
711 if PcdObj
.DatumType
!= 'VOID*':
712 EdkLogger
.error("GenFds", GENFDS_ERROR
, "%s is not VOID* datum type." % PcdPattern
)
714 PcdValue
= PcdObj
.DefaultValue
719 SetDir
= staticmethod(SetDir
)
720 ReplaceWorkspaceMacro
= staticmethod(ReplaceWorkspaceMacro
)
721 CallExternalTool
= staticmethod(CallExternalTool
)
722 VerboseLogger
= staticmethod(VerboseLogger
)
723 InfLogger
= staticmethod(InfLogger
)
724 ErrorLogger
= staticmethod(ErrorLogger
)
725 DebugLogger
= staticmethod(DebugLogger
)
726 MacroExtend
= staticmethod (MacroExtend
)
727 GetPcdValue
= staticmethod(GetPcdValue
)