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