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