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