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