]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GenFds.py
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 FdfParser
. InputMacroDict
[ "WORKSPACE" ] = Workspace
176 BuildWorkSpace
= WorkspaceDatabase ( ':memory:' , FdfParser
. InputMacroDict
)
177 BuildWorkSpace
. InitDatabase ()
180 # Get files real name in workspace dir
182 GlobalData
. gAllFiles
= DirCache ( Workspace
)
183 GlobalData
. gWorkspace
= Workspace
185 if ( Options
. archList
) :
186 ArchList
= Options
. archList
. split ( ',' )
188 # EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH")
189 ArchList
= BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, 'COMMON' ]. SupArchList
191 TargetArchList
= set ( BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, 'COMMON' ]. SupArchList
) & set ( ArchList
)
192 if len ( TargetArchList
) == 0 :
193 EdkLogger
. error ( "GenFds" , GENFDS_ERROR
, "Target ARCH %s not in platform supported ARCH %s " % ( str ( ArchList
), str ( BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, 'COMMON' ]. SupArchList
)))
195 for Arch
in ArchList
:
196 GenFdsGlobalVariable
. OutputDirFromDscDict
[ Arch
] = NormPath ( BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, Arch
]. OutputDirectory
)
197 GenFdsGlobalVariable
. PlatformName
= BuildWorkSpace
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, Arch
]. PlatformName
199 if ( Options
. outputDir
):
200 OutputDirFromCommandLine
= GenFdsGlobalVariable
. ReplaceWorkspaceMacro ( Options
. outputDir
)
201 if not os
. path
. isabs ( OutputDirFromCommandLine
):
202 OutputDirFromCommandLine
= os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, OutputDirFromCommandLine
)
203 for Arch
in ArchList
:
204 GenFdsGlobalVariable
. OutputDirDict
[ Arch
] = OutputDirFromCommandLine
206 for Arch
in ArchList
:
207 GenFdsGlobalVariable
. OutputDirDict
[ Arch
] = os
. path
. join ( GenFdsGlobalVariable
. OutputDirFromDscDict
[ Arch
], GenFdsGlobalVariable
. TargetName
+ '_' + GenFdsGlobalVariable
. ToolChainTag
)
209 for Key
in GenFdsGlobalVariable
. OutputDirDict
:
210 OutputDir
= GenFdsGlobalVariable
. OutputDirDict
[ Key
]
211 if OutputDir
[ 0 : 2 ] == '..' :
212 OutputDir
= os
. path
. realpath ( OutputDir
)
214 if OutputDir
[ 1 ] != ':' :
215 OutputDir
= os
. path
. join ( GenFdsGlobalVariable
. WorkSpaceDir
, OutputDir
)
217 if not os
. path
. exists ( OutputDir
):
218 EdkLogger
. error ( "GenFds" , FILE_NOT_FOUND
, ExtraData
= OutputDir
)
219 GenFdsGlobalVariable
. OutputDirDict
[ Key
] = OutputDir
221 """ Parse Fdf file, has to place after build Workspace as FDF may contain macros from DSC file """
222 FdfParserObj
= FdfParser
. FdfParser ( FdfFilename
)
223 FdfParserObj
. ParseFile ()
225 if FdfParserObj
. CycleReferenceCheck ():
226 EdkLogger
. error ( "GenFds" , FORMAT_NOT_SUPPORTED
, "Cycle Reference Detected in FDF file" )
228 if ( Options
. uiFdName
) :
229 if Options
. uiFdName
. upper () in FdfParserObj
. Profile
. FdDict
. keys ():
230 GenFds
. OnlyGenerateThisFd
= Options
. uiFdName
232 EdkLogger
. error ( "GenFds" , OPTION_VALUE_INVALID
,
233 "No such an FD in FDF file: %s " % Options
. uiFdName
)
235 if ( Options
. uiFvName
) :
236 if Options
. uiFvName
. upper () in FdfParserObj
. Profile
. FvDict
. keys ():
237 GenFds
. OnlyGenerateThisFv
= Options
. uiFvName
239 EdkLogger
. error ( "GenFds" , OPTION_VALUE_INVALID
,
240 "No such an FV in FDF file: %s " % Options
. uiFvName
)
242 if ( Options
. uiCapName
) :
243 if Options
. uiCapName
. upper () in FdfParserObj
. Profile
. CapsuleDict
. keys ():
244 GenFds
. OnlyGenerateThisCap
= Options
. uiCapName
246 EdkLogger
. error ( "GenFds" , OPTION_VALUE_INVALID
,
247 "No such a Capsule in FDF file: %s " % Options
. uiCapName
)
249 """Modify images from build output if the feature of loading driver at fixed address is on."""
250 if GenFdsGlobalVariable
. FixedLoadAddress
:
251 GenFds
. PreprocessImage ( BuildWorkSpace
, GenFdsGlobalVariable
. ActivePlatform
)
253 GenFds
. GenFd ( '' , FdfParserObj
, BuildWorkSpace
, ArchList
)
255 """Generate GUID cross reference file"""
256 GenFds
. GenerateGuidXRefFile ( BuildWorkSpace
, ArchList
)
258 """Display FV space info."""
259 GenFds
. DisplayFvSpaceInfo ( FdfParserObj
)
261 except FdfParser
. Warning , X
:
262 EdkLogger
. error ( X
. ToolName
, FORMAT_INVALID
, File
= X
. FileName
, Line
= X
. LineNumber
, ExtraData
= X
. Message
, RaiseError
= False )
263 ReturnCode
= FORMAT_INVALID
264 except FatalError
, X
:
265 if Options
. debug
!= None :
267 EdkLogger
. quiet ( traceback
. format_exc ())
268 ReturnCode
= X
. args
[ 0 ]
274 "Tools code failure" ,
275 ExtraData
= "Please send email to edk2-buildtools-devel@lists.sourceforge.net for help, attaching following call stack trace! \n " ,
278 EdkLogger
. quiet ( traceback
. format_exc ())
279 ReturnCode
= CODE_ERROR
283 def SingleCheckCallback ( option
, opt_str
, value
, parser
):
284 if option
not in gParamCheck
:
285 setattr ( parser
. values
, option
. dest
, value
)
286 gParamCheck
. append ( option
)
288 parser
. error ( "Option %s only allows one instance in command line!" % option
)
290 ## Parse command line options
292 # Using standard Python module optparse to parse command line option of this tool.
294 # @retval Opt A optparse.Values object containing the parsed options
295 # @retval Args Target of build command
297 def myOptionParser ():
298 usage
= "%prog [options] -f input_file -a arch_list -b build_target -p active_platform -t tool_chain_tag -D \" MacroName [= MacroValue] \" "
299 Parser
= OptionParser ( usage
= usage
, description
= __copyright__
, version
= "%prog " + str ( versionNumber
))
300 Parser
. add_option ( "-f" , "--file" , dest
= "filename" , type = "string" , help = "Name of FDF file to convert" , action
= "callback" , callback
= SingleCheckCallback
)
301 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" )
302 Parser
. add_option ( "-q" , "--quiet" , action
= "store_true" , type = None , help = "Disable all messages except FATAL ERRORS." )
303 Parser
. add_option ( "-v" , "--verbose" , action
= "store_true" , type = None , help = "Turn on verbose output with informational messages printed." )
304 Parser
. add_option ( "-d" , "--debug" , action
= "store" , type = "int" , help = "Enable debug messages at specified level." )
305 Parser
. add_option ( "-p" , "--platform" , type = "string" , dest
= "activePlatform" , help = "Set the ACTIVE_PLATFORM, overrides target.txt ACTIVE_PLATFORM setting." ,
306 action
= "callback" , callback
= SingleCheckCallback
)
307 Parser
. add_option ( "-w" , "--workspace" , type = "string" , dest
= "Workspace" , default
= os
. environ
. get ( 'WORKSPACE' ), help = "Set the WORKSPACE" ,
308 action
= "callback" , callback
= SingleCheckCallback
)
309 Parser
. add_option ( "-o" , "--outputDir" , type = "string" , dest
= "outputDir" , help = "Name of Build Output directory" ,
310 action
= "callback" , callback
= SingleCheckCallback
)
311 Parser
. add_option ( "-r" , "--rom_image" , dest
= "uiFdName" , help = "Build the image using the [FD] section named by FdUiName." )
312 Parser
. add_option ( "-i" , "--FvImage" , dest
= "uiFvName" , help = "Build the FV image using the [FV] section named by UiFvName" )
313 Parser
. add_option ( "-C" , "--CapsuleImage" , dest
= "uiCapName" , help = "Build the Capsule image using the [Capsule] section named by UiCapName" )
314 Parser
. add_option ( "-b" , "--buildtarget" , type = "choice" , choices
=[ 'DEBUG' , 'RELEASE' ], dest
= "BuildTarget" , help = "Build TARGET is one of list: DEBUG, RELEASE." ,
315 action
= "callback" , callback
= SingleCheckCallback
)
316 Parser
. add_option ( "-t" , "--tagname" , type = "string" , dest
= "ToolChain" , help = "Using the tools: TOOL_CHAIN_TAG name to build the platform." ,
317 action
= "callback" , callback
= SingleCheckCallback
)
318 Parser
. add_option ( "-D" , "--define" , action
= "append" , type = "string" , dest
= "Macros" , help = "Macro: \" Name [= Value] \" ." )
319 Parser
. add_option ( "-s" , "--specifyaddress" , dest
= "FixedAddress" , action
= "store_true" , type = None , help = "Specify driver load address." )
320 ( Options
, args
) = Parser
. parse_args ()
323 ## The class implementing the EDK2 flash image generation process
325 # This process includes:
326 # 1. Collect workspace information, includes platform and module information
327 # 2. Call methods of Fd class to generate FD
328 # 3. Call methods of Fv class to generate FV that not belong to FD
332 # FvName, FdName, CapName in FDF, Image file name
334 OnlyGenerateThisFd
= None
335 OnlyGenerateThisFv
= None
336 OnlyGenerateThisCap
= None
340 # @param OutputDir Output directory
341 # @param FdfParser FDF contents parser
342 # @param Workspace The directory of workspace
343 # @param ArchList The Arch list of platform
345 def GenFd ( OutputDir
, FdfParser
, WorkSpace
, ArchList
):
346 GenFdsGlobalVariable
. SetDir ( '' , FdfParser
, WorkSpace
, ArchList
)
348 GenFdsGlobalVariable
. VerboseLogger ( " Generate all Fd images and their required FV and Capsule images!" )
349 if GenFds
. OnlyGenerateThisCap
!= None and GenFds
. OnlyGenerateThisCap
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
. keys ():
350 CapsuleObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
. get ( GenFds
. OnlyGenerateThisCap
. upper ())
351 if CapsuleObj
!= None :
352 CapsuleObj
. GenCapsule ()
355 if GenFds
. OnlyGenerateThisFd
!= None and GenFds
. OnlyGenerateThisFd
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. keys ():
356 FdObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. get ( GenFds
. OnlyGenerateThisFd
. upper ())
360 elif GenFds
. OnlyGenerateThisFd
== None and GenFds
. OnlyGenerateThisFv
== None :
361 for FdName
in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. keys ():
362 FdObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
[ FdName
]
365 GenFdsGlobalVariable
. VerboseLogger ( " \n Generate other FV images! " )
366 if GenFds
. OnlyGenerateThisFv
!= None and GenFds
. OnlyGenerateThisFv
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
. keys ():
367 FvObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
. get ( GenFds
. OnlyGenerateThisFv
. upper ())
369 Buffer
= StringIO
. StringIO ()
370 FvObj
. AddToBuffer ( Buffer
)
373 elif GenFds
. OnlyGenerateThisFv
== None :
374 for FvName
in GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
. keys ():
375 Buffer
= StringIO
. StringIO ( '' )
376 FvObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FvDict
[ FvName
]
377 FvObj
. AddToBuffer ( Buffer
)
380 if GenFds
. OnlyGenerateThisFv
== None and GenFds
. OnlyGenerateThisFd
== None and GenFds
. OnlyGenerateThisCap
== None :
381 if GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
!= {}:
382 GenFdsGlobalVariable
. VerboseLogger ( " \n Generate other Capsule images!" )
383 for CapsuleName
in GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
. keys ():
384 CapsuleObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. CapsuleDict
[ CapsuleName
]
385 CapsuleObj
. GenCapsule ()
387 if GenFdsGlobalVariable
. FdfParser
. Profile
. OptRomDict
!= {}:
388 GenFdsGlobalVariable
. VerboseLogger ( " \n Generate all Option ROM!" )
389 for DriverName
in GenFdsGlobalVariable
. FdfParser
. Profile
. OptRomDict
. keys ():
390 OptRomObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. OptRomDict
[ DriverName
]
391 OptRomObj
. AddToBuffer ( None )
395 # @param FvObj Whose block size to get
396 # @retval int Block size value
398 def GetFvBlockSize ( FvObj
):
399 DefaultBlockSize
= 0x1
401 if GenFds
. OnlyGenerateThisFd
!= None and GenFds
. OnlyGenerateThisFd
. upper () in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. keys ():
402 FdObj
= GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
[ GenFds
. OnlyGenerateThisFd
. upper ()]
404 for ElementFd
in GenFdsGlobalVariable
. FdfParser
. Profile
. FdDict
. values ():
405 for ElementRegion
in ElementFd
. RegionList
:
406 if ElementRegion
. RegionType
== 'FV' :
407 for ElementRegionData
in ElementRegion
. RegionDataList
:
408 if ElementRegionData
!= None and ElementRegionData
. upper () == FvObj
. UiFvName
:
409 if FvObj
. BlockSizeList
!= []:
410 return FvObj
. BlockSizeList
[ 0 ][ 0 ]
412 return ElementRegion
. BlockSizeOfRegion ( ElementFd
. BlockSizeList
)
413 if FvObj
. BlockSizeList
!= []:
414 return FvObj
. BlockSizeList
[ 0 ][ 0 ]
415 return DefaultBlockSize
417 for ElementRegion
in FdObj
. RegionList
:
418 if ElementRegion
. RegionType
== 'FV' :
419 for ElementRegionData
in ElementRegion
. RegionDataList
:
420 if ElementRegionData
!= None and ElementRegionData
. upper () == FvObj
. UiFvName
:
421 if FvObj
. BlockSizeList
!= []:
422 return FvObj
. BlockSizeList
[ 0 ][ 0 ]
424 return ElementRegion
. BlockSizeOfRegion ( ElementFd
. BlockSizeList
)
425 return DefaultBlockSize
427 ## DisplayFvSpaceInfo()
429 # @param FvObj Whose block size to get
432 def DisplayFvSpaceInfo ( FdfParser
):
436 for FvName
in FdfParser
. Profile
. FvDict
:
437 if len ( FvName
) > MaxFvNameLength
:
438 MaxFvNameLength
= len ( FvName
)
439 FvSpaceInfoFileName
= os
. path
. join ( GenFdsGlobalVariable
. FvDir
, FvName
. upper () + '.Fv.map' )
440 if os
. path
. exists ( FvSpaceInfoFileName
):
441 FileLinesList
= linecache
. getlines ( FvSpaceInfoFileName
)
448 for Line
in FileLinesList
:
449 NameValue
= Line
. split ( '=' )
450 if len ( NameValue
) == 2 :
451 if NameValue
[ 0 ]. strip () == 'EFI_FV_TOTAL_SIZE' :
453 Total
= NameValue
[ 1 ]. strip ()
454 if NameValue
[ 0 ]. strip () == 'EFI_FV_TAKEN_SIZE' :
456 Used
= NameValue
[ 1 ]. strip ()
457 if NameValue
[ 0 ]. strip () == 'EFI_FV_SPACE_SIZE' :
459 Free
= NameValue
[ 1 ]. strip ()
461 if TotalFound
and UsedFound
and FreeFound
:
462 FvSpaceInfoList
. append (( FvName
, Total
, Used
, Free
))
464 GenFdsGlobalVariable
. InfLogger ( ' \n FV Space Information' )
465 for FvSpaceInfo
in FvSpaceInfoList
:
466 Name
= FvSpaceInfo
[ 0 ]
467 TotalSizeValue
= long ( FvSpaceInfo
[ 1 ], 0 )
468 UsedSizeValue
= long ( FvSpaceInfo
[ 2 ], 0 )
469 FreeSizeValue
= long ( FvSpaceInfo
[ 3 ], 0 )
470 if UsedSizeValue
== TotalSizeValue
:
473 Percentage
= str (( UsedSizeValue
+ 0.0 )/ TotalSizeValue
)[ 0 : 4 ]. lstrip ( '0.' )
475 GenFdsGlobalVariable
. InfLogger ( Name
+ ' ' + '[' + Percentage
+ ' %Fu ll] ' + str ( TotalSizeValue
) + ' total, ' + str ( UsedSizeValue
) + ' used, ' + str ( FreeSizeValue
) + ' free' )
479 # @param BuildDb Database from build meta data files
480 # @param DscFile modules from dsc file will be preprocessed
483 def PreprocessImage ( BuildDb
, DscFile
):
484 PcdDict
= BuildDb
. BuildObject
[ DscFile
, 'COMMON' ]. Pcds
487 PcdObj
= PcdDict
[ Key
]
488 if PcdObj
. TokenCName
== 'PcdBsBaseAddress' :
489 PcdValue
= PcdObj
. DefaultValue
495 Int64PcdValue
= long ( PcdValue
, 0 )
496 if Int64PcdValue
== 0 or Int64PcdValue
< - 1 :
500 if Int64PcdValue
> 0 :
501 TopAddress
= Int64PcdValue
503 ModuleDict
= BuildDb
. BuildObject
[ DscFile
, 'COMMON' ]. Modules
504 for Key
in ModuleDict
:
505 ModuleObj
= BuildDb
. BuildObject
[ Key
, 'COMMON' ]
506 print ModuleObj
. BaseName
+ ' ' + ModuleObj
. ModuleType
508 def GenerateGuidXRefFile ( BuildDb
, ArchList
):
509 GuidXRefFileName
= os
. path
. join ( GenFdsGlobalVariable
. FvDir
, "Guid.xref" )
510 GuidXRefFile
= StringIO
. StringIO ( '' )
511 for Arch
in ArchList
:
512 PlatformDataBase
= BuildDb
. BuildObject
[ GenFdsGlobalVariable
. ActivePlatform
, Arch
]
513 for ModuleFile
in PlatformDataBase
. Modules
:
514 Module
= BuildDb
. BuildObject
[ ModuleFile
, Arch
]
515 GuidXRefFile
. write ( " %s %s \n " % ( Module
. Guid
, Module
. BaseName
))
516 SaveFileOnChange ( GuidXRefFileName
, GuidXRefFile
. getvalue (), False )
518 GenFdsGlobalVariable
. InfLogger ( " \n GUID cross reference file can be found at %s " % GuidXRefFileName
)
520 ##Define GenFd as static function
521 GenFd
= staticmethod ( GenFd
)
522 GetFvBlockSize
= staticmethod ( GetFvBlockSize
)
523 DisplayFvSpaceInfo
= staticmethod ( DisplayFvSpaceInfo
)
524 PreprocessImage
= staticmethod ( PreprocessImage
)
525 GenerateGuidXRefFile
= staticmethod ( GenerateGuidXRefFile
)
527 if __name__
== '__main__' :
529 ## 0-127 is a safe return range, and 1 is a standard default error
530 if r
< 0 or r
> 127 : r
= 1