]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GenFds.py
cb82c717ddd92c656262b1a09b8dd51292332007
4 # Copyright (c) 2007 - 2010, 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 from optparse
import OptionParser
23 import Common
. BuildToolError
as BuildToolError
24 from GenFdsGlobalVariable
import GenFdsGlobalVariable
25 from Workspace
. WorkspaceDatabase
import WorkspaceDatabase
26 from Workspace
. BuildClassObject
import PcdClassObject
27 from Workspace
. BuildClassObject
import ModuleBuildClassObject
28 import RuleComplexFile
29 from EfiSection
import EfiSection
31 import Common
. TargetTxtClassObject
as TargetTxtClassObject
32 import Common
. ToolDefClassObject
as ToolDefClassObject
33 import Common
. DataType
34 import Common
. GlobalData
as GlobalData
35 from Common
import EdkLogger
36 from Common
. String
import *
37 from Common
. Misc
import DirCache
, PathClass
38 from Common
. Misc
import SaveFileOnChange
40 ## Version and Copyright
42 __version__
= "%prog Version " + versionNumber
43 __copyright__
= "Copyright (c) 2007 - 2010, Intel Corporation All rights reserved."
45 ## Tool entrance method
47 # This method mainly dispatch specific methods per the command line options.
48 # If no error found, return zero value so the caller of this tool can know
49 # if it's executed successfully or not.
51 # @retval 0 Tool was successful
52 # @retval 1 Tool failed
56 Options
= myOptionParser ()
63 EdkLogger
. Initialize ()
65 if Options
. verbose
!= None :
66 EdkLogger
. SetLevel ( EdkLogger
. VERBOSE
)
67 GenFdsGlobalVariable
. VerboseMode
= True
69 if Options
. FixedAddress
!= None :
70 GenFdsGlobalVariable
. FixedLoadAddress
= True
72 if Options
. quiet
!= None :
73 EdkLogger
. SetLevel ( EdkLogger
. QUIET
)
74 if Options
. debug
!= None :
75 EdkLogger
. SetLevel ( Options
. debug
+ 1 )
76 GenFdsGlobalVariable
. DebugLevel
= Options
. debug
78 EdkLogger
. SetLevel ( EdkLogger
. INFO
)
80 if ( Options
. Workspace
== None ):
81 EdkLogger
. error ( "GenFds" , OPTION_MISSING
, "WORKSPACE not defined" ,
82 ExtraData
= "Please use '-w' switch to pass it or set the WORKSPACE environment variable." )
83 elif not os
. path
. exists ( Options
. Workspace
):
84 EdkLogger
. error ( "GenFds" , PARAMETER_INVALID
, "WORKSPACE is invalid" ,
85 ExtraData
= "Please use '-w' switch to pass it or set the WORKSPACE environment variable." )
87 Workspace
= os
. path
. normcase ( Options
. Workspace
)
88 GenFdsGlobalVariable
. WorkSpaceDir
= Workspace
89 if 'EDK_SOURCE' in os
. environ
. keys ():
90 GenFdsGlobalVariable
. EdkSourceDir
= os
. path
. normcase ( os
. environ
[ 'EDK_SOURCE' ])
92 GenFdsGlobalVariable
. VerboseLogger ( "Using Workspace:" + Workspace
)
93 os
. chdir ( GenFdsGlobalVariable
. WorkSpaceDir
)
95 if ( Options
. filename
):
96 FdfFilename
= Options
. filename
97 FdfFilename
= GenFdsGlobalVariable
. ReplaceWorkspaceMacro ( FdfFilename
)
99 if FdfFilename
[ 0 : 2 ] == '..' :
100 FdfFilename
= os
. path
. realpath ( FdfFilename
)
101 if not os
. path
. isabs ( FdfFilename
):
102 FdfFilename
= os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, FdfFilename
)
103 if not os
. path
. exists ( FdfFilename
):
104 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, ExtraData
= FdfFilename
)
105 if os
. path
. normcase ( FdfFilename
). find ( Workspace
) != 0 :
106 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, "FdfFile doesn't exist in Workspace!" )
108 GenFdsGlobalVariable
. FdfFile
= FdfFilename
109 GenFdsGlobalVariable
. FdfFileTimeStamp
= os
. path
. getmtime ( FdfFilename
)
111 EdkLogger
. error ( "GenFds" , OPTION_MISSING
, "Missing FDF filename" )
113 if ( Options
. BuildTarget
):
114 GenFdsGlobalVariable
. TargetName
= Options
. BuildTarget
116 EdkLogger
. error ( "GenFds" , OPTION_MISSING
, "Missing build target" )
118 if ( Options
. ToolChain
):
119 GenFdsGlobalVariable
. ToolChainTag
= Options
. ToolChain
121 EdkLogger
. error ( "GenFds" , OPTION_MISSING
, "Missing tool chain tag" )
123 if ( Options
. activePlatform
):
124 ActivePlatform
= Options
. activePlatform
125 ActivePlatform
= GenFdsGlobalVariable
. ReplaceWorkspaceMacro ( ActivePlatform
)
127 if ActivePlatform
[ 0 : 2 ] == '..' :
128 ActivePlatform
= os
. path
. realpath ( ActivePlatform
)
130 if not os
. path
. isabs ( ActivePlatform
):
131 ActivePlatform
= os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, ActivePlatform
)
133 if not os
. path
. exists ( ActivePlatform
) :
134 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, "ActivePlatform doesn't exist!" )
136 if os
. path
. normcase ( ActivePlatform
). find ( Workspace
) != 0 :
137 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, "ActivePlatform doesn't exist in Workspace!" )
139 ActivePlatform
= ActivePlatform
[ len ( Workspace
):]
140 if len ( ActivePlatform
) > 0 :
141 if ActivePlatform
[ 0 ] == ' \\ ' or ActivePlatform
[ 0 ] == '/' :
142 ActivePlatform
= ActivePlatform
[ 1 :]
144 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, "ActivePlatform doesn't exist!" )
146 EdkLogger
. error ( "GenFds" , OPTION_MISSING
, "Missing active platform" )
148 GenFdsGlobalVariable
. ActivePlatform
= PathClass ( NormPath ( ActivePlatform
), Workspace
)
150 BuildConfigurationFile
= os
. path
. normpath ( os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, "Conf/target.txt" ))
151 if os
. path
. isfile ( BuildConfigurationFile
) == True :
152 TargetTxtClassObject
. TargetTxtClassObject ( BuildConfigurationFile
)
154 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, ExtraData
= BuildConfigurationFile
)
157 for Pair
in Options
. Macros
:
159 List
= Pair
. split ( '=' )
161 if List
[ 0 ]. strip () == "EFI_SOURCE" :
162 GlobalData
. gEfiSource
= List
[ 1 ]. strip ()
164 elif List
[ 0 ]. strip () == "EDK_SOURCE" :
165 GlobalData
. gEdkSource
= List
[ 1 ]. strip ()
168 GlobalData
. gEdkGlobal
[ List
[ 0 ]. strip ()] = List
[ 1 ]. strip ()
169 FdfParser
. InputMacroDict
[ List
[ 0 ]. strip ()] = List
[ 1 ]. strip ()
171 FdfParser
. InputMacroDict
[ List
[ 0 ]. strip ()] = ""
173 """call Workspace build create database"""
174 os
. environ
[ "WORKSPACE" ] = Workspace
175 BuildWorkSpace
= WorkspaceDatabase ( ':memory:' , FdfParser
. InputMacroDict
)
176 BuildWorkSpace
. InitDatabase ()
179 # Get files real name in workspace dir
181 GlobalData
. gAllFiles
= DirCache ( Workspace
)
182 GlobalData
. gWorkspace
= Workspace
184 if ( Options
. archList
) :
185 ArchList
= Options
. archList
. split ( ',' )
187 # EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH")
188 ArchList
= BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, 'COMMON' ]. SupArchList
190 TargetArchList
= set ( BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, 'COMMON' ]. SupArchList
) & set ( ArchList
)
191 if len ( TargetArchList
) == 0 :
192 EdkLogger
. error ( "GenFds" , GENFDS_ERROR
, "Target ARCH %s not in platform supported ARCH %s " % ( str ( ArchList
), str ( BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, 'COMMON' ]. SupArchList
)))
194 for Arch
in ArchList
:
195 GenFdsGlobalVariable
. OutputDirFromDscDict
[ Arch
] = NormPath ( BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, Arch
]. OutputDirectory
)
196 GenFdsGlobalVariable
. PlatformName
= BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, Arch
]. PlatformName
198 if ( Options
. outputDir
):
199 OutputDirFromCommandLine
= GenFdsGlobalVariable
. ReplaceWorkspaceMacro ( Options
. outputDir
)
200 if not os
. path
. isabs ( OutputDirFromCommandLine
):
201 OutputDirFromCommandLine
= os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, OutputDirFromCommandLine
)
202 for Arch
in ArchList
:
203 GenFdsGlobalVariable
. OutputDirDict
[ Arch
] = OutputDirFromCommandLine
205 for Arch
in ArchList
:
206 GenFdsGlobalVariable
. OutputDirDict
[ Arch
] = os
. path
. join ( GenFdsGlobalVariable
. OutputDirFromDscDict
[ Arch
], GenFdsGlobalVariable
. TargetName
+ '_' + GenFdsGlobalVariable
. ToolChainTag
)
208 for Key
in GenFdsGlobalVariable
. OutputDirDict
:
209 OutputDir
= GenFdsGlobalVariable
. OutputDirDict
[ Key
]
210 if OutputDir
[ 0 : 2 ] == '..' :
211 OutputDir
= os
. path
. realpath ( OutputDir
)
213 if OutputDir
[ 1 ] != ':' :
214 OutputDir
= os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, OutputDir
)
216 if not os
. path
. exists ( OutputDir
):
217 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, ExtraData
= OutputDir
)
218 GenFdsGlobalVariable
. OutputDirDict
[ Key
] = OutputDir
220 """ Parse Fdf file, has to place after build Workspace as FDF may contain macros from DSC file """
221 FdfParserObj
= FdfParser
. FdfParser ( FdfFilename
)
222 FdfParserObj
. ParseFile ()
224 if FdfParserObj
. CycleReferenceCheck ():
225 EdkLogger
. error ( "GenFds" , FORMAT_NOT_SUPPORTED
, "Cycle Reference Detected in FDF file" )
227 if ( Options
. uiFdName
) :
228 if Options
. uiFdName
. upper () in FdfParserObj
. Profile
. FdDict
. keys ():
229 GenFds
. OnlyGenerateThisFd
= Options
. uiFdName
231 EdkLogger
. error ( "GenFds" , OPTION_VALUE_INVALID
,
232 "No such an FD in FDF file: %s " % Options
. uiFdName
)
234 if ( Options
. uiFvName
) :
235 if Options
. uiFvName
. upper () in FdfParserObj
. Profile
. FvDict
. keys ():
236 GenFds
. OnlyGenerateThisFv
= Options
. uiFvName
238 EdkLogger
. error ( "GenFds" , OPTION_VALUE_INVALID
,
239 "No such an FV in FDF file: %s " % Options
. uiFvName
)
241 """Modify images from build output if the feature of loading driver at fixed address is on."""
242 if GenFdsGlobalVariable
. FixedLoadAddress
:
243 GenFds
. PreprocessImage ( BuildWorkSpace
, GenFdsGlobalVariable
. ActivePlatform
)
245 GenFds
. GenFd ( '' , FdfParserObj
, BuildWorkSpace
, ArchList
)
247 """Generate GUID cross reference file"""
248 GenFds
. GenerateGuidXRefFile ( BuildWorkSpace
, ArchList
)
250 """Display FV space info."""
251 GenFds
. DisplayFvSpaceInfo ( FdfParserObj
)
253 except FdfParser
. Warning , X
:
254 EdkLogger
. error ( X
. ToolName
, FORMAT_INVALID
, File
= X
. FileName
, Line
= X
. LineNumber
, ExtraData
= X
. Message
, RaiseError
= False )
255 ReturnCode
= FORMAT_INVALID
256 except FatalError
, X
:
257 if Options
. debug
!= None :
259 EdkLogger
. quiet ( traceback
. format_exc ())
260 ReturnCode
= X
. args
[ 0 ]
266 "Tools code failure" ,
267 ExtraData
= "Please send email to edk2-buildtools-devel@lists.sourceforge.net for help, attaching following call stack trace! \n " ,
270 EdkLogger
. quiet ( traceback
. format_exc ())
271 ReturnCode
= CODE_ERROR
275 def SingleCheckCallback ( option
, opt_str
, value
, parser
):
276 if option
not in gParamCheck
:
277 setattr ( parser
. values
, option
. dest
, value
)
278 gParamCheck
. append ( option
)
280 parser
. error ( "Option %s only allows one instance in command line!" % option
)
282 ## Parse command line options
284 # Using standard Python module optparse to parse command line option of this tool.
286 # @retval Opt A optparse.Values object containing the parsed options
287 # @retval Args Target of build command
289 def myOptionParser ():
290 usage
= "%prog [options] -f input_file -a arch_list -b build_target -p active_platform -t tool_chain_tag -D \" MacroName [= MacroValue] \" "
291 Parser
= OptionParser ( usage
= usage
, description
= __copyright__
, version
= "%prog " + str ( versionNumber
))
292 Parser
. add_option ( "-f" , "--file" , dest
= "filename" , type = "string" , help = "Name of FDF file to convert" , action
= "callback" , callback
= SingleCheckCallback
)
293 Parser
. add_option ( "-a" , "--arch" , dest
= "archList" , help = "comma separated list containing one or more of: IA32, X64, IPF, ARM or EBC which should be built, overrides target.txt?s TARGET_ARCH" )
294 Parser
. add_option ( "-q" , "--quiet" , action
= "store_true" , type = None , help = "Disable all messages except FATAL ERRORS." )
295 Parser
. add_option ( "-v" , "--verbose" , action
= "store_true" , type = None , help = "Turn on verbose output with informational messages printed." )
296 Parser
. add_option ( "-d" , "--debug" , action
= "store" , type = "int" , help = "Enable debug messages at specified level." )
297 Parser
. add_option ( "-p" , "--platform" , type = "string" , dest
= "activePlatform" , help = "Set the ACTIVE_PLATFORM, overrides target.txt ACTIVE_PLATFORM setting." ,
298 action
= "callback" , callback
= SingleCheckCallback
)
299 Parser
. add_option ( "-w" , "--workspace" , type = "string" , dest
= "Workspace" , default
= os
. environ
. get ( 'WORKSPACE' ), help = "Set the WORKSPACE" ,
300 action
= "callback" , callback
= SingleCheckCallback
)
301 Parser
. add_option ( "-o" , "--outputDir" , type = "string" , dest
= "outputDir" , help = "Name of Build Output directory" ,
302 action
= "callback" , callback
= SingleCheckCallback
)
303 Parser
. add_option ( "-r" , "--rom_image" , dest
= "uiFdName" , help = "Build the image using the [FD] section named by FdUiName." )
304 Parser
. add_option ( "-i" , "--FvImage" , dest
= "uiFvName" , help = "Buld the FV image using the [FV] section named by UiFvName" )
305 Parser
. add_option ( "-b" , "--buildtarget" , type = "choice" , choices
=[ 'DEBUG' , 'RELEASE' ], dest
= "BuildTarget" , help = "Build TARGET is one of list: DEBUG, RELEASE." ,
306 action
= "callback" , callback
= SingleCheckCallback
)
307 Parser
. add_option ( "-t" , "--tagname" , type = "string" , dest
= "ToolChain" , help = "Using the tools: TOOL_CHAIN_TAG name to build the platform." ,
308 action
= "callback" , callback
= SingleCheckCallback
)
309 Parser
. add_option ( "-D" , "--define" , action
= "append" , type = "string" , dest
= "Macros" , help = "Macro: \" Name [= Value] \" ." )
310 Parser
. add_option ( "-s" , "--specifyaddress" , dest
= "FixedAddress" , action
= "store_true" , type = None , help = "Specify driver load address." )
311 ( Options
, args
) = Parser
. parse_args ()
314 ## The class implementing the EDK2 flash image generation process
316 # This process includes:
317 # 1. Collect workspace information, includes platform and module information
318 # 2. Call methods of Fd class to generate FD
319 # 3. Call methods of Fv class to generate FV that not belong to FD
323 # FvName, FdName, CapName in FDF, Image file name
325 OnlyGenerateThisFd
= None
326 OnlyGenerateThisFv
= None
330 # @param OutputDir Output directory
331 # @param FdfParser FDF contents parser
332 # @param Workspace The directory of workspace
333 # @param ArchList The Arch list of platform
335 def GenFd ( OutputDir
, FdfParser
, WorkSpace
, ArchList
):
336 GenFdsGlobalVariable
. SetDir ( '' , FdfParser
, WorkSpace
, ArchList
)
338 GenFdsGlobalVariable
. VerboseLogger ( " Generate all Fd images and their required FV and Capsule images!" )
339 if GenFds
. OnlyGenerateThisFd
!= None and GenFds
. OnlyGenerateThisFd
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. keys ():
340 FdObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. get ( GenFds
. OnlyGenerateThisFd
. upper ())
343 elif GenFds
. OnlyGenerateThisFd
== None :
344 for FdName
in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. keys ():
345 FdObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
[ FdName
]
348 GenFdsGlobalVariable
. VerboseLogger ( " \n Generate other FV images! " )
349 if GenFds
. OnlyGenerateThisFv
!= None and GenFds
. OnlyGenerateThisFv
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
. keys ():
350 FvObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
. get ( GenFds
. OnlyGenerateThisFv
. upper ())
352 Buffer
= StringIO
. StringIO ()
353 # Get FV base Address
354 FvObj
. AddToBuffer ( Buffer
, None , GenFds
. GetFvBlockSize ( FvObj
))
357 elif GenFds
. OnlyGenerateThisFv
== None :
358 for FvName
in GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
. keys ():
359 Buffer
= StringIO
. StringIO ( '' )
360 FvObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
[ FvName
]
361 # Get FV base Address
362 FvObj
. AddToBuffer ( Buffer
, None , GenFds
. GetFvBlockSize ( FvObj
))
365 if GenFds
. OnlyGenerateThisFv
== None and GenFds
. OnlyGenerateThisFd
== None :
366 if GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
!= {}:
367 GenFdsGlobalVariable
. VerboseLogger ( " \n Generate other Capsule images!" )
368 for CapsuleName
in GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
. keys ():
369 CapsuleObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
[ CapsuleName
]
370 CapsuleObj
. GenCapsule ()
372 if GenFdsGlobalVariable
. FdfParser
. Profile
. OptRomDict
!= {}:
373 GenFdsGlobalVariable
. VerboseLogger ( " \n Generate all Option ROM!" )
374 for DriverName
in GenFdsGlobalVariable
. FdfParser
. Profile
. OptRomDict
. keys ():
375 OptRomObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. OptRomDict
[ DriverName
]
376 OptRomObj
. AddToBuffer ( None )
380 # @param FvObj Whose block size to get
381 # @retval int Block size value
383 def GetFvBlockSize ( FvObj
):
384 DefaultBlockSize
= 0x1
386 if GenFds
. OnlyGenerateThisFd
!= None and GenFds
. OnlyGenerateThisFd
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. keys ():
387 FdObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
[ GenFds
. OnlyGenerateThisFd
. upper ()]
389 for ElementFd
in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. values ():
390 for ElementRegion
in ElementFd
. RegionList
:
391 if ElementRegion
. RegionType
== 'FV' :
392 for ElementRegionData
in ElementRegion
. RegionDataList
:
393 if ElementRegionData
!= None and ElementRegionData
. upper () == FvObj
. UiFvName
:
394 if FvObj
. BlockSizeList
!= []:
395 return FvObj
. BlockSizeList
[ 0 ][ 0 ]
397 return ElementRegion
. BlockSizeOfRegion ( ElementFd
. BlockSizeList
)
398 if FvObj
. BlockSizeList
!= []:
399 return FvObj
. BlockSizeList
[ 0 ][ 0 ]
400 return DefaultBlockSize
402 for ElementRegion
in FdObj
. RegionList
:
403 if ElementRegion
. RegionType
== 'FV' :
404 for ElementRegionData
in ElementRegion
. RegionDataList
:
405 if ElementRegionData
!= None and ElementRegionData
. upper () == FvObj
. UiFvName
:
406 if FvObj
. BlockSizeList
!= []:
407 return FvObj
. BlockSizeList
[ 0 ][ 0 ]
409 return ElementRegion
. BlockSizeOfRegion ( ElementFd
. BlockSizeList
)
410 return DefaultBlockSize
412 ## DisplayFvSpaceInfo()
414 # @param FvObj Whose block size to get
417 def DisplayFvSpaceInfo ( FdfParser
):
421 for FvName
in FdfParser
. Profile
. FvDict
:
422 if len ( FvName
) > MaxFvNameLength
:
423 MaxFvNameLength
= len ( FvName
)
424 FvSpaceInfoFileName
= os
. path
. join ( GenFdsGlobalVariable
. FvDir
, FvName
. upper () + '.Fv.map' )
425 if os
. path
. exists ( FvSpaceInfoFileName
):
426 FileLinesList
= linecache
. getlines ( FvSpaceInfoFileName
)
433 for Line
in FileLinesList
:
434 NameValue
= Line
. split ( '=' )
435 if len ( NameValue
) == 2 :
436 if NameValue
[ 0 ]. strip () == 'EFI_FV_TOTAL_SIZE' :
438 Total
= NameValue
[ 1 ]. strip ()
439 if NameValue
[ 0 ]. strip () == 'EFI_FV_TAKEN_SIZE' :
441 Used
= NameValue
[ 1 ]. strip ()
442 if NameValue
[ 0 ]. strip () == 'EFI_FV_SPACE_SIZE' :
444 Free
= NameValue
[ 1 ]. strip ()
446 if TotalFound
and UsedFound
and FreeFound
:
447 FvSpaceInfoList
. append (( FvName
, Total
, Used
, Free
))
449 GenFdsGlobalVariable
. InfLogger ( ' \n FV Space Information' )
450 for FvSpaceInfo
in FvSpaceInfoList
:
451 Name
= FvSpaceInfo
[ 0 ]
452 TotalSizeValue
= long ( FvSpaceInfo
[ 1 ], 0 )
453 UsedSizeValue
= long ( FvSpaceInfo
[ 2 ], 0 )
454 FreeSizeValue
= long ( FvSpaceInfo
[ 3 ], 0 )
455 GenFdsGlobalVariable
. InfLogger ( Name
+ ' ' + '[' + str (( UsedSizeValue
+ 0.0 )/ TotalSizeValue
)[ 0 : 4 ]. lstrip ( '0.' ) + ' %Fu ll] ' + str ( TotalSizeValue
) + ' total, ' + str ( UsedSizeValue
) + ' used, ' + str ( FreeSizeValue
) + ' free' )
459 # @param BuildDb Database from build meta data files
460 # @param DscFile modules from dsc file will be preprocessed
463 def PreprocessImage ( BuildDb
, DscFile
):
464 PcdDict
= BuildDb
. BuildObject
[ DscFile
, 'COMMON' ]. Pcds
467 PcdObj
= PcdDict
[ Key
]
468 if PcdObj
. TokenCName
== 'PcdBsBaseAddress' :
469 PcdValue
= PcdObj
. DefaultValue
475 Int64PcdValue
= long ( PcdValue
, 0 )
476 if Int64PcdValue
== 0 or Int64PcdValue
< - 1 :
480 if Int64PcdValue
> 0 :
481 TopAddress
= Int64PcdValue
483 ModuleDict
= BuildDb
. BuildObject
[ DscFile
, 'COMMON' ]. Modules
484 for Key
in ModuleDict
:
485 ModuleObj
= BuildDb
. BuildObject
[ Key
, 'COMMON' ]
486 print ModuleObj
. BaseName
+ ' ' + ModuleObj
. ModuleType
488 def GenerateGuidXRefFile ( BuildDb
, ArchList
):
489 GuidXRefFileName
= os
. path
. join ( GenFdsGlobalVariable
. FvDir
, "Guid.xref" )
490 GuidXRefFile
= StringIO
. StringIO ( '' )
491 for Arch
in ArchList
:
492 PlatformDataBase
= BuildDb
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, Arch
]
493 for ModuleFile
in PlatformDataBase
. Modules
:
494 Module
= BuildDb
. BuildObject
[ ModuleFile
, Arch
]
495 GuidXRefFile
. write ( " %s %s \n " % ( Module
. Guid
, Module
. BaseName
))
496 SaveFileOnChange ( GuidXRefFileName
, GuidXRefFile
. getvalue (), False )
498 GenFdsGlobalVariable
. InfLogger ( " \n GUID cross reference file can be found at %s " % GuidXRefFileName
)
500 ##Define GenFd as static function
501 GenFd
= staticmethod ( GenFd
)
502 GetFvBlockSize
= staticmethod ( GetFvBlockSize
)
503 DisplayFvSpaceInfo
= staticmethod ( DisplayFvSpaceInfo
)
504 PreprocessImage
= staticmethod ( PreprocessImage
)
505 GenerateGuidXRefFile
= staticmethod ( GenerateGuidXRefFile
)
507 if __name__
== '__main__' :
509 ## 0-127 is a safe return range, and 1 is a standard default error
510 if r
< 0 or r
> 127 : r
= 1