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