]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/GenFds.py
Sync basetools' source and binary files with r1707 of the basetools project.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
CommitLineData
30fdf114
LG
1## @file
2# generate flash image
3#
4# Copyright (c) 2007, Intel Corporation
5#
6# All rights reserved. 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
10#
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.
13#
14
15##
16# Import Modules
17#
18from optparse import OptionParser
19import sys
20import os
21import linecache
22import FdfParser
fd171542 23import Common.BuildToolError as BuildToolError
30fdf114
LG
24from GenFdsGlobalVariable import GenFdsGlobalVariable
25from Workspace.WorkspaceDatabase import WorkspaceDatabase
26from Workspace.BuildClassObject import PcdClassObject
27from Workspace.BuildClassObject import ModuleBuildClassObject
28import RuleComplexFile
29from EfiSection import EfiSection
30import StringIO
31import Common.TargetTxtClassObject as TargetTxtClassObject
32import Common.ToolDefClassObject as ToolDefClassObject
33import Common.DataType
34import Common.GlobalData as GlobalData
35from Common import EdkLogger
36from Common.String import *
37from Common.Misc import DirCache,PathClass
38
39## Version and Copyright
40versionNumber = "1.0"
41__version__ = "%prog Version " + versionNumber
42__copyright__ = "Copyright (c) 2007, Intel Corporation All rights reserved."
43
44## Tool entrance method
45#
46# This method mainly dispatch specific methods per the command line options.
47# If no error found, return zero value so the caller of this tool can know
48# if it's executed successfully or not.
49#
50# @retval 0 Tool was successful
51# @retval 1 Tool failed
52#
53def main():
54 global Options
55 Options = myOptionParser()
56
57 global Workspace
58 Workspace = ""
59 ArchList = None
60 ReturnCode = 0
61
62 EdkLogger.Initialize()
63 try:
64 if Options.verbose != None:
65 EdkLogger.SetLevel(EdkLogger.VERBOSE)
66 GenFdsGlobalVariable.VerboseMode = True
67
68 if Options.FixedAddress != None:
69 GenFdsGlobalVariable.FixedLoadAddress = True
70
71 if Options.quiet != None:
72 EdkLogger.SetLevel(EdkLogger.QUIET)
73 if Options.debug != None:
74 EdkLogger.SetLevel(Options.debug + 1)
75 GenFdsGlobalVariable.DebugLevel = Options.debug
76 else:
77 EdkLogger.SetLevel(EdkLogger.INFO)
78
79 if (Options.Workspace == None):
fd171542 80 EdkLogger.error("GenFds", OPTION_MISSING, "WORKSPACE not defined",
30fdf114
LG
81 ExtraData="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")
82 elif not os.path.exists(Options.Workspace):
fd171542 83 EdkLogger.error("GenFds", PARAMETER_INVALID, "WORKSPACE is invalid",
30fdf114
LG
84 ExtraData="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")
85 else:
86 Workspace = os.path.normcase(Options.Workspace)
87 GenFdsGlobalVariable.WorkSpaceDir = Workspace
88 if 'EDK_SOURCE' in os.environ.keys():
89 GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE'])
90 if (Options.debug):
91 GenFdsGlobalVariable.VerboseLogger( "Using Workspace:" + Workspace)
92 os.chdir(GenFdsGlobalVariable.WorkSpaceDir)
93
94 if (Options.filename):
95 FdfFilename = Options.filename
96 FdfFilename = GenFdsGlobalVariable.ReplaceWorkspaceMacro(FdfFilename)
97 else:
fd171542 98 EdkLogger.error("GenFds", OPTION_MISSING, "Missing FDF filename")
30fdf114
LG
99
100 if (Options.BuildTarget):
101 GenFdsGlobalVariable.TargetName = Options.BuildTarget
102 else:
fd171542 103 EdkLogger.error("GenFds", OPTION_MISSING, "Missing build target")
30fdf114
LG
104
105 if (Options.ToolChain):
106 GenFdsGlobalVariable.ToolChainTag = Options.ToolChain
107 else:
fd171542 108 EdkLogger.error("GenFds", OPTION_MISSING, "Missing tool chain tag")
30fdf114
LG
109
110 if FdfFilename[0:2] == '..':
111 FdfFilename = os.path.realpath(FdfFilename)
112 if FdfFilename[1] != ':':
113 FdfFilename = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, FdfFilename)
114
115 if not os.path.exists(FdfFilename):
fd171542 116 EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=FdfFilename)
30fdf114
LG
117 GenFdsGlobalVariable.FdfFile = FdfFilename
118 GenFdsGlobalVariable.FdfFileTimeStamp = os.path.getmtime(FdfFilename)
119
120 if (Options.activePlatform):
121 ActivePlatform = Options.activePlatform
122 ActivePlatform = GenFdsGlobalVariable.ReplaceWorkspaceMacro(ActivePlatform)
123
124 if ActivePlatform[0:2] == '..':
125 ActivePlatform = os.path.realpath(ActivePlatform)
126
127 if ActivePlatform[1] != ':':
128 ActivePlatform = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ActivePlatform)
129
130 if not os.path.exists(ActivePlatform) :
fd171542 131 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!")
30fdf114
LG
132
133 if ActivePlatform.find(Workspace) == -1:
fd171542 134 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist in Workspace!")
30fdf114
LG
135
136 ActivePlatform = ActivePlatform.replace(Workspace, '')
137 if len(ActivePlatform) > 0 :
138 if ActivePlatform[0] == '\\' or ActivePlatform[0] == '/':
139 ActivePlatform = ActivePlatform[1:]
140 else:
fd171542 141 EdkLogger.error("GenFds", FILE_NOT_FOUND, "ActivePlatform doesn't exist!")
30fdf114 142 else :
fd171542 143 EdkLogger.error("GenFds", OPTION_MISSING, "Missing active platform")
30fdf114
LG
144
145 GenFdsGlobalVariable.ActivePlatform = PathClass(NormPath(ActivePlatform), Workspace)
146
147 BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.WorkSpaceDir, "Conf/target.txt"))
148 if os.path.isfile(BuildConfigurationFile) == True:
149 TargetTxtClassObject.TargetTxtClassObject(BuildConfigurationFile)
150 else:
fd171542 151 EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=BuildConfigurationFile)
30fdf114
LG
152
153 if Options.Macros:
154 for Pair in Options.Macros:
155 Pair.strip('"')
156 List = Pair.split('=')
157 if len(List) == 2:
30fdf114
LG
158 if List[0].strip() == "EFI_SOURCE":
159 GlobalData.gEfiSource = List[1].strip()
fd171542 160 continue
30fdf114
LG
161 elif List[0].strip() == "EDK_SOURCE":
162 GlobalData.gEdkSource = List[1].strip()
fd171542 163 continue
30fdf114
LG
164 else:
165 GlobalData.gEdkGlobal[List[0].strip()] = List[1].strip()
fd171542 166 FdfParser.InputMacroDict[List[0].strip()] = List[1].strip()
30fdf114 167 else:
fd171542 168 FdfParser.InputMacroDict[List[0].strip()] = ""
30fdf114
LG
169
170 """call Workspace build create database"""
171 os.environ["WORKSPACE"] = Workspace
fd171542 172 BuildWorkSpace = WorkspaceDatabase(':memory:', FdfParser.InputMacroDict)
30fdf114
LG
173 BuildWorkSpace.InitDatabase()
174
175 #
176 # Get files real name in workspace dir
177 #
178 GlobalData.gAllFiles = DirCache(Workspace)
179 GlobalData.gWorkspace = Workspace
180
181 if (Options.archList) :
182 ArchList = Options.archList.split(',')
183 else:
fd171542 184# EdkLogger.error("GenFds", OPTION_MISSING, "Missing build ARCH")
30fdf114
LG
185 ArchList = BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON'].SupArchList
186
187 TargetArchList = set(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON'].SupArchList) & set(ArchList)
188 if len(TargetArchList) == 0:
189 EdkLogger.error("GenFds", GENFDS_ERROR, "Target ARCH %s not in platform supported ARCH %s" % (str(ArchList), str(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON'].SupArchList)))
190
191 for Arch in ArchList:
192 GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].OutputDirectory)
193
194 if (Options.outputDir):
195 OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro(Options.outputDir)
196 for Arch in ArchList:
197 GenFdsGlobalVariable.OutputDirDict[Arch] = OutputDirFromCommandLine
198 else:
199 for Arch in ArchList:
200 GenFdsGlobalVariable.OutputDirDict[Arch] = os.path.join(GenFdsGlobalVariable.OutputDirFromDscDict[Arch], GenFdsGlobalVariable.TargetName + '_' + GenFdsGlobalVariable.ToolChainTag)
201
202 for Key in GenFdsGlobalVariable.OutputDirDict:
203 OutputDir = GenFdsGlobalVariable.OutputDirDict[Key]
204 if OutputDir[0:2] == '..':
205 OutputDir = os.path.realpath(OutputDir)
206
207 if OutputDir[1] != ':':
208 OutputDir = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, OutputDir)
209
210 if not os.path.exists(OutputDir):
fd171542 211 EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=OutputDir)
30fdf114
LG
212 GenFdsGlobalVariable.OutputDirDict[Key] = OutputDir
213
214 """ Parse Fdf file, has to place after build Workspace as FDF may contain macros from DSC file """
215 FdfParserObj = FdfParser.FdfParser(FdfFilename)
216 FdfParserObj.ParseFile()
217
218 if FdfParserObj.CycleReferenceCheck():
fd171542 219 EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file")
30fdf114
LG
220
221 if (Options.uiFdName) :
222 if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict.keys():
223 GenFds.OnlyGenerateThisFd = Options.uiFdName
224 else:
fd171542 225 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,
30fdf114
LG
226 "No such an FD in FDF file: %s" % Options.uiFdName)
227
228 if (Options.uiFvName) :
229 if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict.keys():
230 GenFds.OnlyGenerateThisFv = Options.uiFvName
231 else:
fd171542 232 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,
30fdf114
LG
233 "No such an FV in FDF file: %s" % Options.uiFvName)
234
235 """Modify images from build output if the feature of loading driver at fixed address is on."""
236 if GenFdsGlobalVariable.FixedLoadAddress:
237 GenFds.PreprocessImage(BuildWorkSpace, GenFdsGlobalVariable.ActivePlatform)
238 """Call GenFds"""
239 GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)
240
241 """Display FV space info."""
242 GenFds.DisplayFvSpaceInfo(FdfParserObj)
243
244 except FdfParser.Warning, X:
fd171542 245 EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError = False)
246 ReturnCode = FORMAT_INVALID
30fdf114
LG
247 except FatalError, X:
248 if Options.debug != None:
249 import traceback
250 EdkLogger.quiet(traceback.format_exc())
251 ReturnCode = X.args[0]
252 except:
253 import traceback
254 EdkLogger.error(
255 "\nPython",
256 CODE_ERROR,
257 "Tools code failure",
258 ExtraData="Please submit bug report in www.TianoCore.org, attaching following call stack trace!\n",
259 RaiseError=False
260 )
261 EdkLogger.quiet(traceback.format_exc())
262 ReturnCode = CODE_ERROR
263 return ReturnCode
264
265gParamCheck = []
266def SingleCheckCallback(option, opt_str, value, parser):
267 if option not in gParamCheck:
268 setattr(parser.values, option.dest, value)
269 gParamCheck.append(option)
270 else:
271 parser.error("Option %s only allows one instance in command line!" % option)
272
273## Parse command line options
274#
275# Using standard Python module optparse to parse command line option of this tool.
276#
277# @retval Opt A optparse.Values object containing the parsed options
278# @retval Args Target of build command
279#
280def myOptionParser():
281 usage = "%prog [options] -f input_file -a arch_list -b build_target -p active_platform -t tool_chain_tag -D \"MacroName [= MacroValue]\""
282 Parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(versionNumber))
283 Parser.add_option("-f", "--file", dest="filename", type="string", help="Name of FDF file to convert", action="callback", callback=SingleCheckCallback)
284 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")
285 Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")
286 Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed.")
287 Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")
288 Parser.add_option("-p", "--platform", type="string", dest="activePlatform", help="Set the ACTIVE_PLATFORM, overrides target.txt ACTIVE_PLATFORM setting.",
289 action="callback", callback=SingleCheckCallback)
290 Parser.add_option("-w", "--workspace", type="string", dest="Workspace", default=os.environ.get('WORKSPACE'), help="Set the WORKSPACE",
291 action="callback", callback=SingleCheckCallback)
292 Parser.add_option("-o", "--outputDir", type="string", dest="outputDir", help="Name of Build Output directory",
293 action="callback", callback=SingleCheckCallback)
294 Parser.add_option("-r", "--rom_image", dest="uiFdName", help="Build the image using the [FD] section named by FdUiName.")
295 Parser.add_option("-i", "--FvImage", dest="uiFvName", help="Buld the FV image using the [FV] section named by UiFvName")
296 Parser.add_option("-b", "--buildtarget", type="choice", choices=['DEBUG','RELEASE'], dest="BuildTarget", help="Build TARGET is one of list: DEBUG, RELEASE.",
297 action="callback", callback=SingleCheckCallback)
298 Parser.add_option("-t", "--tagname", type="string", dest="ToolChain", help="Using the tools: TOOL_CHAIN_TAG name to build the platform.",
299 action="callback", callback=SingleCheckCallback)
300 Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")
301 Parser.add_option("-s", "--specifyaddress", dest="FixedAddress", action="store_true", type=None, help="Specify driver load address.")
302 (Options, args) = Parser.parse_args()
303 return Options
304
305## The class implementing the EDK2 flash image generation process
306#
307# This process includes:
308# 1. Collect workspace information, includes platform and module information
309# 2. Call methods of Fd class to generate FD
310# 3. Call methods of Fv class to generate FV that not belong to FD
311#
312class GenFds :
313 FdfParsef = None
fd171542 314 # FvName, FdName, CapName in FDF, Image file name
315 ImageBinDict = {}
30fdf114
LG
316 OnlyGenerateThisFd = None
317 OnlyGenerateThisFv = None
318
319 ## GenFd()
320 #
321 # @param OutputDir Output directory
322 # @param FdfParser FDF contents parser
323 # @param Workspace The directory of workspace
324 # @param ArchList The Arch list of platform
325 #
326 def GenFd (OutputDir, FdfParser, WorkSpace, ArchList):
327 GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList)
328
fd171542 329 GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!")
30fdf114
LG
330 if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():
331 FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(GenFds.OnlyGenerateThisFd.upper())
332 if FdObj != None:
fd171542 333 FdObj.GenFd()
334 elif GenFds.OnlyGenerateThisFd == None:
30fdf114
LG
335 for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():
336 FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]
fd171542 337 FdObj.GenFd()
30fdf114 338
fd171542 339 GenFdsGlobalVariable.VerboseLogger("\n Generate other FV images! ")
30fdf114
LG
340 if GenFds.OnlyGenerateThisFv != None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():
341 FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(GenFds.OnlyGenerateThisFv.upper())
342 if FvObj != None:
343 Buffer = StringIO.StringIO()
344 # Get FV base Address
345 FvObj.AddToBuffer(Buffer, None, GenFds.GetFvBlockSize(FvObj))
346 Buffer.close()
347 return
fd171542 348 elif GenFds.OnlyGenerateThisFv == None:
30fdf114
LG
349 for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():
350 Buffer = StringIO.StringIO('')
351 FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]
352 # Get FV base Address
353 FvObj.AddToBuffer(Buffer, None, GenFds.GetFvBlockSize(FvObj))
354 Buffer.close()
355
356 if GenFds.OnlyGenerateThisFv == None and GenFds.OnlyGenerateThisFd == None:
fd171542 357 if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}:
358 GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!")
359 for CapsuleName in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():
360 CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[CapsuleName]
361 CapsuleObj.GenCapsule()
362
30fdf114 363 if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:
fd171542 364 GenFdsGlobalVariable.VerboseLogger("\n Generate all Option ROM!")
30fdf114
LG
365 for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():
366 OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]
367 OptRomObj.AddToBuffer(None)
368
369 ## GetFvBlockSize()
370 #
371 # @param FvObj Whose block size to get
372 # @retval int Block size value
373 #
374 def GetFvBlockSize(FvObj):
375 DefaultBlockSize = 0x10000
376 FdObj = None
377 if GenFds.OnlyGenerateThisFd != None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():
378 FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]
379 if FdObj == None:
380 for ElementFd in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():
381 for ElementRegion in ElementFd.RegionList:
382 if ElementRegion.RegionType == 'FV':
383 for ElementRegionData in ElementRegion.RegionDataList:
384 if ElementRegionData != None and ElementRegionData.upper() == FvObj.UiFvName:
385 if FvObj.BlockSizeList != []:
386 return FvObj.BlockSizeList[0][0]
387 else:
388 return ElementRegion.BlockSizeOfRegion(ElementFd.BlockSizeList)
389 if FvObj.BlockSizeList != []:
390 return FvObj.BlockSizeList[0][0]
391 return DefaultBlockSize
392 else:
393 for ElementRegion in FdObj.RegionList:
394 if ElementRegion.RegionType == 'FV':
395 for ElementRegionData in ElementRegion.RegionDataList:
396 if ElementRegionData != None and ElementRegionData.upper() == FvObj.UiFvName:
397 if FvObj.BlockSizeList != []:
398 return FvObj.BlockSizeList[0][0]
399 else:
400 return ElementRegion.BlockSizeOfRegion(ElementFd.BlockSizeList)
401 return DefaultBlockSize
402
403 ## DisplayFvSpaceInfo()
404 #
405 # @param FvObj Whose block size to get
406 # @retval None
407 #
408 def DisplayFvSpaceInfo(FdfParser):
409
410 FvSpaceInfoList = []
411 MaxFvNameLength = 0
412 for FvName in FdfParser.Profile.FvDict:
413 if len(FvName) > MaxFvNameLength:
414 MaxFvNameLength = len(FvName)
415 FvSpaceInfoFileName = os.path.join(GenFdsGlobalVariable.FvDir, FvName.upper() + '.Fv.map')
416 if os.path.exists(FvSpaceInfoFileName):
417 FileLinesList = linecache.getlines(FvSpaceInfoFileName)
418 TotalFound = False
419 Total = ''
420 UsedFound = False
421 Used = ''
422 FreeFound = False
423 Free = ''
424 for Line in FileLinesList:
425 NameValue = Line.split('=')
426 if len(NameValue) == 2:
427 if NameValue[0].strip() == 'EFI_FV_TOTAL_SIZE':
428 TotalFound = True
429 Total = NameValue[1].strip()
430 if NameValue[0].strip() == 'EFI_FV_TAKEN_SIZE':
431 UsedFound = True
432 Used = NameValue[1].strip()
433 if NameValue[0].strip() == 'EFI_FV_SPACE_SIZE':
434 FreeFound = True
435 Free = NameValue[1].strip()
436
437 if TotalFound and UsedFound and FreeFound:
438 FvSpaceInfoList.append((FvName, Total, Used, Free))
439
440 GenFdsGlobalVariable.InfLogger('\nFV Space Information')
441 for FvSpaceInfo in FvSpaceInfoList:
442 Name = FvSpaceInfo[0]
443 TotalSizeValue = long(FvSpaceInfo[1], 0)
444 UsedSizeValue = long(FvSpaceInfo[2], 0)
445 FreeSizeValue = long(FvSpaceInfo[3], 0)
446 GenFdsGlobalVariable.InfLogger(Name + ' ' + '[' + str((UsedSizeValue+0.0)/TotalSizeValue)[0:4].lstrip('0.') + '%Full] ' + str(TotalSizeValue) + ' total, ' + str(UsedSizeValue) + ' used, ' + str(FreeSizeValue) + ' free')
447
448 ## PreprocessImage()
449 #
450 # @param BuildDb Database from build meta data files
451 # @param DscFile modules from dsc file will be preprocessed
452 # @retval None
453 #
454 def PreprocessImage(BuildDb, DscFile):
455 PcdDict = BuildDb.BuildObject[DscFile, 'COMMON'].Pcds
456 PcdValue = ''
457 for Key in PcdDict:
458 PcdObj = PcdDict[Key]
459 if PcdObj.TokenCName == 'PcdBsBaseAddress':
460 PcdValue = PcdObj.DefaultValue
461 break
462
463 if PcdValue == '':
464 return
465
466 Int64PcdValue = long(PcdValue, 0)
467 if Int64PcdValue == 0 or Int64PcdValue < -1:
468 return
469
470 TopAddress = 0
471 if Int64PcdValue > 0:
472 TopAddress = Int64PcdValue
473
474 ModuleDict = BuildDb.BuildObject[DscFile, 'COMMON'].Modules
475 for Key in ModuleDict:
476 ModuleObj = BuildDb.BuildObject[Key, 'COMMON']
477 print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType
478
479 ##Define GenFd as static function
480 GenFd = staticmethod(GenFd)
481 GetFvBlockSize = staticmethod(GetFvBlockSize)
482 DisplayFvSpaceInfo = staticmethod(DisplayFvSpaceInfo)
483 PreprocessImage = staticmethod(PreprocessImage)
484
485if __name__ == '__main__':
486 r = main()
487 ## 0-127 is a safe return range, and 1 is a standard default error
488 if r < 0 or r > 127: r = 1
489 sys.exit(r)
490