058fa0c6a0b76f4b0622088ea6e94a9c4fb70d6d
4 # Copyright (c) 2007 - 2013, 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
39 from Common
.BuildVersion
import gBUILD_VERSION
41 ## Version and Copyright
42 versionNumber
= "1.0" + ' ' + gBUILD_VERSION
43 __version__
= "%prog Version " + versionNumber
44 __copyright__
= "Copyright (c) 2007 - 2013, Intel Corporation All rights reserved."
46 ## Tool entrance method
48 # This method mainly dispatch specific methods per the command line options.
49 # If no error found, return zero value so the caller of this tool can know
50 # if it's executed successfully or not.
52 # @retval 0 Tool was successful
53 # @retval 1 Tool failed
57 Options
= myOptionParser()
64 EdkLogger
.Initialize()
66 if Options
.verbose
!= None:
67 EdkLogger
.SetLevel(EdkLogger
.VERBOSE
)
68 GenFdsGlobalVariable
.VerboseMode
= True
70 if Options
.FixedAddress
!= None:
71 GenFdsGlobalVariable
.FixedLoadAddress
= True
73 if Options
.quiet
!= None:
74 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
75 if Options
.debug
!= None:
76 EdkLogger
.SetLevel(Options
.debug
+ 1)
77 GenFdsGlobalVariable
.DebugLevel
= Options
.debug
79 EdkLogger
.SetLevel(EdkLogger
.INFO
)
81 if (Options
.Workspace
== None):
82 EdkLogger
.error("GenFds", OPTION_MISSING
, "WORKSPACE not defined",
83 ExtraData
="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")
84 elif not os
.path
.exists(Options
.Workspace
):
85 EdkLogger
.error("GenFds", PARAMETER_INVALID
, "WORKSPACE is invalid",
86 ExtraData
="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")
88 Workspace
= os
.path
.normcase(Options
.Workspace
)
89 GenFdsGlobalVariable
.WorkSpaceDir
= Workspace
90 if 'EDK_SOURCE' in os
.environ
.keys():
91 GenFdsGlobalVariable
.EdkSourceDir
= os
.path
.normcase(os
.environ
['EDK_SOURCE'])
93 GenFdsGlobalVariable
.VerboseLogger( "Using Workspace:" + Workspace
)
94 os
.chdir(GenFdsGlobalVariable
.WorkSpaceDir
)
96 if (Options
.filename
):
97 FdfFilename
= Options
.filename
98 FdfFilename
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(FdfFilename
)
100 if FdfFilename
[0:2] == '..':
101 FdfFilename
= os
.path
.realpath(FdfFilename
)
102 if not os
.path
.isabs (FdfFilename
):
103 FdfFilename
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, FdfFilename
)
104 if not os
.path
.exists(FdfFilename
):
105 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, ExtraData
=FdfFilename
)
106 if os
.path
.normcase (FdfFilename
).find(Workspace
) != 0:
107 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, "FdfFile doesn't exist in Workspace!")
109 GenFdsGlobalVariable
.FdfFile
= FdfFilename
110 GenFdsGlobalVariable
.FdfFileTimeStamp
= os
.path
.getmtime(FdfFilename
)
112 EdkLogger
.error("GenFds", OPTION_MISSING
, "Missing FDF filename")
114 if (Options
.BuildTarget
):
115 GenFdsGlobalVariable
.TargetName
= Options
.BuildTarget
117 EdkLogger
.error("GenFds", OPTION_MISSING
, "Missing build target")
119 if (Options
.ToolChain
):
120 GenFdsGlobalVariable
.ToolChainTag
= Options
.ToolChain
122 EdkLogger
.error("GenFds", OPTION_MISSING
, "Missing tool chain tag")
124 if (Options
.activePlatform
):
125 ActivePlatform
= Options
.activePlatform
126 ActivePlatform
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(ActivePlatform
)
128 if ActivePlatform
[0:2] == '..':
129 ActivePlatform
= os
.path
.realpath(ActivePlatform
)
131 if not os
.path
.isabs (ActivePlatform
):
132 ActivePlatform
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, ActivePlatform
)
134 if not os
.path
.exists(ActivePlatform
) :
135 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, "ActivePlatform doesn't exist!")
137 if os
.path
.normcase (ActivePlatform
).find(Workspace
) != 0:
138 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, "ActivePlatform doesn't exist in Workspace!")
140 ActivePlatform
= ActivePlatform
[len(Workspace
):]
141 if len(ActivePlatform
) > 0 :
142 if ActivePlatform
[0] == '\\' or ActivePlatform
[0] == '/':
143 ActivePlatform
= ActivePlatform
[1:]
145 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, "ActivePlatform doesn't exist!")
147 EdkLogger
.error("GenFds", OPTION_MISSING
, "Missing active platform")
149 GenFdsGlobalVariable
.ActivePlatform
= PathClass(NormPath(ActivePlatform
), Workspace
)
151 BuildConfigurationFile
= os
.path
.normpath(os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, "Conf/target.txt"))
152 if os
.path
.isfile(BuildConfigurationFile
) == True:
153 TargetTxtClassObject
.TargetTxtClassObject(BuildConfigurationFile
)
155 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, ExtraData
=BuildConfigurationFile
)
158 for Pair
in Options
.Macros
:
160 List
= Pair
.split('=')
162 if List
[0].strip() == "EFI_SOURCE":
163 GlobalData
.gEfiSource
= List
[1].strip()
164 GlobalData
.gGlobalDefines
["EFI_SOURCE"] = GlobalData
.gEfiSource
166 elif List
[0].strip() == "EDK_SOURCE":
167 GlobalData
.gEdkSource
= List
[1].strip()
168 GlobalData
.gGlobalDefines
["EDK_SOURCE"] = GlobalData
.gEdkSource
170 elif List
[0].strip() in ["WORKSPACE", "TARGET", "TOOLCHAIN"]:
171 GlobalData
.gGlobalDefines
[List
[0].strip()] = List
[1].strip()
173 GlobalData
.gCommandLineDefines
[List
[0].strip()] = List
[1].strip()
175 GlobalData
.gCommandLineDefines
[List
[0].strip()] = "TRUE"
176 os
.environ
["WORKSPACE"] = Workspace
178 """call Workspace build create database"""
179 BuildWorkSpace
= WorkspaceDatabase(None)
180 BuildWorkSpace
.InitDatabase()
183 # Get files real name in workspace dir
185 GlobalData
.gAllFiles
= DirCache(Workspace
)
186 GlobalData
.gWorkspace
= Workspace
188 if (Options
.archList
) :
189 ArchList
= Options
.archList
.split(',')
191 # EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH")
192 ArchList
= BuildWorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, 'COMMON', Options
.BuildTarget
, Options
.ToolChain
].SupArchList
194 TargetArchList
= set(BuildWorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, 'COMMON', Options
.BuildTarget
, Options
.ToolChain
].SupArchList
) & set(ArchList
)
195 if len(TargetArchList
) == 0:
196 EdkLogger
.error("GenFds", GENFDS_ERROR
, "Target ARCH %s not in platform supported ARCH %s" % (str(ArchList
), str(BuildWorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, 'COMMON'].SupArchList
)))
198 for Arch
in ArchList
:
199 GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
] = NormPath(BuildWorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, Options
.BuildTarget
, Options
.ToolChain
].OutputDirectory
)
200 GenFdsGlobalVariable
.PlatformName
= BuildWorkSpace
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, Options
.BuildTarget
, Options
.ToolChain
].PlatformName
202 if (Options
.outputDir
):
203 OutputDirFromCommandLine
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(Options
.outputDir
)
204 if not os
.path
.isabs (OutputDirFromCommandLine
):
205 OutputDirFromCommandLine
= os
.path
.join(GenFdsGlobalVariable
.WorkSpaceDir
, OutputDirFromCommandLine
)
206 for Arch
in ArchList
:
207 GenFdsGlobalVariable
.OutputDirDict
[Arch
] = OutputDirFromCommandLine
209 for Arch
in ArchList
:
210 GenFdsGlobalVariable
.OutputDirDict
[Arch
] = os
.path
.join(GenFdsGlobalVariable
.OutputDirFromDscDict
[Arch
], GenFdsGlobalVariable
.TargetName
+ '_' + GenFdsGlobalVariable
.ToolChainTag
)
212 for Key
in GenFdsGlobalVariable
.OutputDirDict
:
213 OutputDir
= GenFdsGlobalVariable
.OutputDirDict
[Key
]
214 if OutputDir
[0:2] == '..':
215 OutputDir
= os
.path
.realpath(OutputDir
)
217 if OutputDir
[1] != ':':
218 OutputDir
= os
.path
.join (GenFdsGlobalVariable
.WorkSpaceDir
, OutputDir
)
220 if not os
.path
.exists(OutputDir
):
221 EdkLogger
.error("GenFds", FILE_NOT_FOUND
, ExtraData
=OutputDir
)
222 GenFdsGlobalVariable
.OutputDirDict
[Key
] = OutputDir
224 """ Parse Fdf file, has to place after build Workspace as FDF may contain macros from DSC file """
225 FdfParserObj
= FdfParser
.FdfParser(FdfFilename
)
226 FdfParserObj
.ParseFile()
228 if FdfParserObj
.CycleReferenceCheck():
229 EdkLogger
.error("GenFds", FORMAT_NOT_SUPPORTED
, "Cycle Reference Detected in FDF file")
231 if (Options
.uiFdName
) :
232 if Options
.uiFdName
.upper() in FdfParserObj
.Profile
.FdDict
.keys():
233 GenFds
.OnlyGenerateThisFd
= Options
.uiFdName
235 EdkLogger
.error("GenFds", OPTION_VALUE_INVALID
,
236 "No such an FD in FDF file: %s" % Options
.uiFdName
)
238 if (Options
.uiFvName
) :
239 if Options
.uiFvName
.upper() in FdfParserObj
.Profile
.FvDict
.keys():
240 GenFds
.OnlyGenerateThisFv
= Options
.uiFvName
242 EdkLogger
.error("GenFds", OPTION_VALUE_INVALID
,
243 "No such an FV in FDF file: %s" % Options
.uiFvName
)
245 if (Options
.uiCapName
) :
246 if Options
.uiCapName
.upper() in FdfParserObj
.Profile
.CapsuleDict
.keys():
247 GenFds
.OnlyGenerateThisCap
= Options
.uiCapName
249 EdkLogger
.error("GenFds", OPTION_VALUE_INVALID
,
250 "No such a Capsule in FDF file: %s" % Options
.uiCapName
)
252 """Modify images from build output if the feature of loading driver at fixed address is on."""
253 if GenFdsGlobalVariable
.FixedLoadAddress
:
254 GenFds
.PreprocessImage(BuildWorkSpace
, GenFdsGlobalVariable
.ActivePlatform
)
256 GenFds
.GenFd('', FdfParserObj
, BuildWorkSpace
, ArchList
)
258 """Generate GUID cross reference file"""
259 GenFds
.GenerateGuidXRefFile(BuildWorkSpace
, ArchList
)
261 """Display FV space info."""
262 GenFds
.DisplayFvSpaceInfo(FdfParserObj
)
264 except FdfParser
.Warning, X
:
265 EdkLogger
.error(X
.ToolName
, FORMAT_INVALID
, File
=X
.FileName
, Line
=X
.LineNumber
, ExtraData
=X
.Message
, RaiseError
= False)
266 ReturnCode
= FORMAT_INVALID
267 except FatalError
, X
:
268 if Options
.debug
!= None:
270 EdkLogger
.quiet(traceback
.format_exc())
271 ReturnCode
= X
.args
[0]
277 "Tools code failure",
278 ExtraData
="Please send email to edk2-buildtools-devel@lists.sourceforge.net for help, attaching following call stack trace!\n",
281 EdkLogger
.quiet(traceback
.format_exc())
282 ReturnCode
= CODE_ERROR
286 def SingleCheckCallback(option
, opt_str
, value
, parser
):
287 if option
not in gParamCheck
:
288 setattr(parser
.values
, option
.dest
, value
)
289 gParamCheck
.append(option
)
291 parser
.error("Option %s only allows one instance in command line!" % option
)
293 ## Parse command line options
295 # Using standard Python module optparse to parse command line option of this tool.
297 # @retval Opt A optparse.Values object containing the parsed options
298 # @retval Args Target of build command
300 def myOptionParser():
301 usage
= "%prog [options] -f input_file -a arch_list -b build_target -p active_platform -t tool_chain_tag -D \"MacroName [= MacroValue]\""
302 Parser
= OptionParser(usage
=usage
,description
=__copyright__
,version
="%prog " + str(versionNumber
))
303 Parser
.add_option("-f", "--file", dest
="filename", type="string", help="Name of FDF file to convert", action
="callback", callback
=SingleCheckCallback
)
304 Parser
.add_option("-a", "--arch", dest
="archList", help="comma separated list containing one or more of: IA32, X64, IPF, ARM, AARCH64 or EBC which should be built, overrides target.txt?s TARGET_ARCH")
305 Parser
.add_option("-q", "--quiet", action
="store_true", type=None, help="Disable all messages except FATAL ERRORS.")
306 Parser
.add_option("-v", "--verbose", action
="store_true", type=None, help="Turn on verbose output with informational messages printed.")
307 Parser
.add_option("-d", "--debug", action
="store", type="int", help="Enable debug messages at specified level.")
308 Parser
.add_option("-p", "--platform", type="string", dest
="activePlatform", help="Set the ACTIVE_PLATFORM, overrides target.txt ACTIVE_PLATFORM setting.",
309 action
="callback", callback
=SingleCheckCallback
)
310 Parser
.add_option("-w", "--workspace", type="string", dest
="Workspace", default
=os
.environ
.get('WORKSPACE'), help="Set the WORKSPACE",
311 action
="callback", callback
=SingleCheckCallback
)
312 Parser
.add_option("-o", "--outputDir", type="string", dest
="outputDir", help="Name of Build Output directory",
313 action
="callback", callback
=SingleCheckCallback
)
314 Parser
.add_option("-r", "--rom_image", dest
="uiFdName", help="Build the image using the [FD] section named by FdUiName.")
315 Parser
.add_option("-i", "--FvImage", dest
="uiFvName", help="Build the FV image using the [FV] section named by UiFvName")
316 Parser
.add_option("-C", "--CapsuleImage", dest
="uiCapName", help="Build the Capsule image using the [Capsule] section named by UiCapName")
317 Parser
.add_option("-b", "--buildtarget", type="string", dest
="BuildTarget", help="Set the build TARGET, overrides target.txt TARGET setting.",
318 action
="callback", callback
=SingleCheckCallback
)
319 Parser
.add_option("-t", "--tagname", type="string", dest
="ToolChain", help="Using the tools: TOOL_CHAIN_TAG name to build the platform.",
320 action
="callback", callback
=SingleCheckCallback
)
321 Parser
.add_option("-D", "--define", action
="append", type="string", dest
="Macros", help="Macro: \"Name [= Value]\".")
322 Parser
.add_option("-s", "--specifyaddress", dest
="FixedAddress", action
="store_true", type=None, help="Specify driver load address.")
323 (Options
, args
) = Parser
.parse_args()
326 ## The class implementing the EDK2 flash image generation process
328 # This process includes:
329 # 1. Collect workspace information, includes platform and module information
330 # 2. Call methods of Fd class to generate FD
331 # 3. Call methods of Fv class to generate FV that not belong to FD
335 # FvName, FdName, CapName in FDF, Image file name
337 OnlyGenerateThisFd
= None
338 OnlyGenerateThisFv
= None
339 OnlyGenerateThisCap
= None
343 # @param OutputDir Output directory
344 # @param FdfParser FDF contents parser
345 # @param Workspace The directory of workspace
346 # @param ArchList The Arch list of platform
348 def GenFd (OutputDir
, FdfParser
, WorkSpace
, ArchList
):
349 GenFdsGlobalVariable
.SetDir ('', FdfParser
, WorkSpace
, ArchList
)
351 GenFdsGlobalVariable
.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!")
352 if GenFds
.OnlyGenerateThisCap
!= None and GenFds
.OnlyGenerateThisCap
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.CapsuleDict
.keys():
353 CapsuleObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.CapsuleDict
.get(GenFds
.OnlyGenerateThisCap
.upper())
354 if CapsuleObj
!= None:
355 CapsuleObj
.GenCapsule()
358 if GenFds
.OnlyGenerateThisFd
!= None and GenFds
.OnlyGenerateThisFd
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
359 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.get(GenFds
.OnlyGenerateThisFd
.upper())
363 elif GenFds
.OnlyGenerateThisFd
== None and GenFds
.OnlyGenerateThisFv
== None:
364 for FdName
in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
365 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
[FdName
]
368 GenFdsGlobalVariable
.VerboseLogger("\n Generate other FV images! ")
369 if GenFds
.OnlyGenerateThisFv
!= None and GenFds
.OnlyGenerateThisFv
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.keys():
370 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(GenFds
.OnlyGenerateThisFv
.upper())
372 Buffer
= StringIO
.StringIO()
373 FvObj
.AddToBuffer(Buffer
)
376 elif GenFds
.OnlyGenerateThisFv
== None:
377 for FvName
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.keys():
378 Buffer
= StringIO
.StringIO('')
379 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
[FvName
]
380 FvObj
.AddToBuffer(Buffer
)
383 if GenFds
.OnlyGenerateThisFv
== None and GenFds
.OnlyGenerateThisFd
== None and GenFds
.OnlyGenerateThisCap
== None:
384 if GenFdsGlobalVariable
.FdfParser
.Profile
.CapsuleDict
!= {}:
385 GenFdsGlobalVariable
.VerboseLogger("\n Generate other Capsule images!")
386 for CapsuleName
in GenFdsGlobalVariable
.FdfParser
.Profile
.CapsuleDict
.keys():
387 CapsuleObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.CapsuleDict
[CapsuleName
]
388 CapsuleObj
.GenCapsule()
390 if GenFdsGlobalVariable
.FdfParser
.Profile
.OptRomDict
!= {}:
391 GenFdsGlobalVariable
.VerboseLogger("\n Generate all Option ROM!")
392 for DriverName
in GenFdsGlobalVariable
.FdfParser
.Profile
.OptRomDict
.keys():
393 OptRomObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.OptRomDict
[DriverName
]
394 OptRomObj
.AddToBuffer(None)
398 # @param FvObj Whose block size to get
399 # @retval int Block size value
401 def GetFvBlockSize(FvObj
):
402 DefaultBlockSize
= 0x1
404 if GenFds
.OnlyGenerateThisFd
!= None and GenFds
.OnlyGenerateThisFd
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
405 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
[GenFds
.OnlyGenerateThisFd
.upper()]
407 for ElementFd
in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.values():
408 for ElementRegion
in ElementFd
.RegionList
:
409 if ElementRegion
.RegionType
== 'FV':
410 for ElementRegionData
in ElementRegion
.RegionDataList
:
411 if ElementRegionData
!= None and ElementRegionData
.upper() == FvObj
.UiFvName
:
412 if FvObj
.BlockSizeList
!= []:
413 return FvObj
.BlockSizeList
[0][0]
415 return ElementRegion
.BlockSizeOfRegion(ElementFd
.BlockSizeList
)
416 if FvObj
.BlockSizeList
!= []:
417 return FvObj
.BlockSizeList
[0][0]
418 return DefaultBlockSize
420 for ElementRegion
in FdObj
.RegionList
:
421 if ElementRegion
.RegionType
== 'FV':
422 for ElementRegionData
in ElementRegion
.RegionDataList
:
423 if ElementRegionData
!= None and ElementRegionData
.upper() == FvObj
.UiFvName
:
424 if FvObj
.BlockSizeList
!= []:
425 return FvObj
.BlockSizeList
[0][0]
427 return ElementRegion
.BlockSizeOfRegion(ElementFd
.BlockSizeList
)
428 return DefaultBlockSize
430 ## DisplayFvSpaceInfo()
432 # @param FvObj Whose block size to get
435 def DisplayFvSpaceInfo(FdfParser
):
439 for FvName
in FdfParser
.Profile
.FvDict
:
440 if len(FvName
) > MaxFvNameLength
:
441 MaxFvNameLength
= len(FvName
)
442 FvSpaceInfoFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, FvName
.upper() + '.Fv.map')
443 if os
.path
.exists(FvSpaceInfoFileName
):
444 FileLinesList
= linecache
.getlines(FvSpaceInfoFileName
)
451 for Line
in FileLinesList
:
452 NameValue
= Line
.split('=')
453 if len(NameValue
) == 2:
454 if NameValue
[0].strip() == 'EFI_FV_TOTAL_SIZE':
456 Total
= NameValue
[1].strip()
457 if NameValue
[0].strip() == 'EFI_FV_TAKEN_SIZE':
459 Used
= NameValue
[1].strip()
460 if NameValue
[0].strip() == 'EFI_FV_SPACE_SIZE':
462 Free
= NameValue
[1].strip()
464 if TotalFound
and UsedFound
and FreeFound
:
465 FvSpaceInfoList
.append((FvName
, Total
, Used
, Free
))
467 GenFdsGlobalVariable
.InfLogger('\nFV Space Information')
468 for FvSpaceInfo
in FvSpaceInfoList
:
469 Name
= FvSpaceInfo
[0]
470 TotalSizeValue
= long(FvSpaceInfo
[1], 0)
471 UsedSizeValue
= long(FvSpaceInfo
[2], 0)
472 FreeSizeValue
= long(FvSpaceInfo
[3], 0)
473 if UsedSizeValue
== TotalSizeValue
:
476 Percentage
= str((UsedSizeValue
+0.0)/TotalSizeValue
)[0:4].lstrip('0.')
478 GenFdsGlobalVariable
.InfLogger(Name
+ ' ' + '[' + Percentage
+ '%Full] ' + str(TotalSizeValue
) + ' total, ' + str(UsedSizeValue
) + ' used, ' + str(FreeSizeValue
) + ' free')
482 # @param BuildDb Database from build meta data files
483 # @param DscFile modules from dsc file will be preprocessed
486 def PreprocessImage(BuildDb
, DscFile
):
487 PcdDict
= BuildDb
.BuildObject
[DscFile
, 'COMMON', GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].Pcds
490 PcdObj
= PcdDict
[Key
]
491 if PcdObj
.TokenCName
== 'PcdBsBaseAddress':
492 PcdValue
= PcdObj
.DefaultValue
498 Int64PcdValue
= long(PcdValue
, 0)
499 if Int64PcdValue
== 0 or Int64PcdValue
< -1:
503 if Int64PcdValue
> 0:
504 TopAddress
= Int64PcdValue
506 ModuleDict
= BuildDb
.BuildObject
[DscFile
, 'COMMON', GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
].Modules
507 for Key
in ModuleDict
:
508 ModuleObj
= BuildDb
.BuildObject
[Key
, 'COMMON', GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
509 print ModuleObj
.BaseName
+ ' ' + ModuleObj
.ModuleType
511 def GenerateGuidXRefFile(BuildDb
, ArchList
):
512 GuidXRefFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, "Guid.xref")
513 GuidXRefFile
= StringIO
.StringIO('')
514 for Arch
in ArchList
:
515 PlatformDataBase
= BuildDb
.BuildObject
[GenFdsGlobalVariable
.ActivePlatform
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
516 for ModuleFile
in PlatformDataBase
.Modules
:
517 Module
= BuildDb
.BuildObject
[ModuleFile
, Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
518 GuidXRefFile
.write("%s %s\n" % (Module
.Guid
, Module
.BaseName
))
519 if GuidXRefFile
.getvalue():
520 SaveFileOnChange(GuidXRefFileName
, GuidXRefFile
.getvalue(), False)
521 GenFdsGlobalVariable
.InfLogger("\nGUID cross reference file can be found at %s" % GuidXRefFileName
)
522 elif os
.path
.exists(GuidXRefFileName
):
523 os
.remove(GuidXRefFileName
)
526 ##Define GenFd as static function
527 GenFd
= staticmethod(GenFd
)
528 GetFvBlockSize
= staticmethod(GetFvBlockSize
)
529 DisplayFvSpaceInfo
= staticmethod(DisplayFvSpaceInfo
)
530 PreprocessImage
= staticmethod(PreprocessImage
)
531 GenerateGuidXRefFile
= staticmethod(GenerateGuidXRefFile
)
533 if __name__
== '__main__':
535 ## 0-127 is a safe return range, and 1 is a standard default error
536 if r
< 0 or r
> 127: r
= 1