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