]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/build/BuildReport.py
BaseTools: Add mixed PCD support feature
[mirror_edk2.git] / BaseTools / Source / Python / build / BuildReport.py
1 ## @file
2 # Routines for generating build report.
3 #
4 # This module contains the functionality to generate build report after
5 # build all target completes successfully.
6 #
7 # Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
8 # This program and the accompanying materials
9 # are licensed and made available under the terms and conditions of the BSD License
10 # which accompanies this distribution. The full text of the license may be found at
11 # http://opensource.org/licenses/bsd-license.php
12 #
13 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #
16
17 ## Import Modules
18 #
19 import Common.LongFilePathOs as os
20 import re
21 import platform
22 import textwrap
23 import traceback
24 import sys
25 import time
26 import struct
27 import hashlib
28 import subprocess
29 import threading
30 from datetime import datetime
31 from StringIO import StringIO
32 from Common import EdkLogger
33 from Common.Misc import SaveFileOnChange
34 from Common.Misc import GuidStructureByteArrayToGuidString
35 from Common.Misc import GuidStructureStringToGuidString
36 from Common.InfClassObject import gComponentType2ModuleType
37 from Common.BuildToolError import FILE_WRITE_FAILURE
38 from Common.BuildToolError import CODE_ERROR
39 from Common.BuildToolError import COMMAND_FAILURE
40 from Common.DataType import TAB_LINE_BREAK
41 from Common.DataType import TAB_DEPEX
42 from Common.DataType import TAB_SLASH
43 from Common.DataType import TAB_SPACE_SPLIT
44 from Common.DataType import TAB_BRG_PCD
45 from Common.DataType import TAB_BRG_LIBRARY
46 from Common.DataType import TAB_BACK_SLASH
47 from Common.LongFilePathSupport import OpenLongFilePath as open
48 from Common.MultipleWorkspace import MultipleWorkspace as mws
49 import Common.GlobalData as GlobalData
50
51 ## Pattern to extract contents in EDK DXS files
52 gDxsDependencyPattern = re.compile(r"DEPENDENCY_START(.+)DEPENDENCY_END", re.DOTALL)
53
54 ## Pattern to find total FV total size, occupied size in flash report intermediate file
55 gFvTotalSizePattern = re.compile(r"EFI_FV_TOTAL_SIZE = (0x[0-9a-fA-F]+)")
56 gFvTakenSizePattern = re.compile(r"EFI_FV_TAKEN_SIZE = (0x[0-9a-fA-F]+)")
57
58 ## Pattern to find module size and time stamp in module summary report intermediate file
59 gModuleSizePattern = re.compile(r"MODULE_SIZE = (\d+)")
60 gTimeStampPattern = re.compile(r"TIME_STAMP = (\d+)")
61
62 ## Pattern to find GUID value in flash description files
63 gPcdGuidPattern = re.compile(r"PCD\((\w+)[.](\w+)\)")
64
65 ## Pattern to collect offset, GUID value pair in the flash report intermediate file
66 gOffsetGuidPattern = re.compile(r"(0x[0-9A-Fa-f]+) ([-A-Fa-f0-9]+)")
67
68 ## Pattern to find module base address and entry point in fixed flash map file
69 gModulePattern = r"\n[-\w]+\s*\(([^,]+),\s*BaseAddress=%(Address)s,\s*EntryPoint=%(Address)s\)\s*\(GUID=([-0-9A-Fa-f]+)[^)]*\)"
70 gMapFileItemPattern = re.compile(gModulePattern % {"Address" : "(-?0[xX][0-9A-Fa-f]+)"})
71
72 ## Pattern to find all module referenced header files in source files
73 gIncludePattern = re.compile(r'#include\s*["<]([^">]+)[">]')
74 gIncludePattern2 = re.compile(r"#include\s+EFI_([A-Z_]+)\s*[(]\s*(\w+)\s*[)]")
75
76 ## Pattern to find the entry point for EDK module using EDKII Glue library
77 gGlueLibEntryPoint = re.compile(r"__EDKII_GLUE_MODULE_ENTRY_POINT__\s*=\s*(\w+)")
78
79 ## Tags for MaxLength of line in report
80 gLineMaxLength = 120
81
82 ## Tags for end of line in report
83 gEndOfLine = "\r\n"
84
85 ## Tags for section start, end and separator
86 gSectionStart = ">" + "=" * (gLineMaxLength - 2) + "<"
87 gSectionEnd = "<" + "=" * (gLineMaxLength - 2) + ">" + "\n"
88 gSectionSep = "=" * gLineMaxLength
89
90 ## Tags for subsection start, end and separator
91 gSubSectionStart = ">" + "-" * (gLineMaxLength - 2) + "<"
92 gSubSectionEnd = "<" + "-" * (gLineMaxLength - 2) + ">"
93 gSubSectionSep = "-" * gLineMaxLength
94
95
96 ## The look up table to map PCD type to pair of report display type and DEC type
97 gPcdTypeMap = {
98 'FixedAtBuild' : ('FIXED', 'FixedAtBuild'),
99 'PatchableInModule': ('PATCH', 'PatchableInModule'),
100 'FeatureFlag' : ('FLAG', 'FeatureFlag'),
101 'Dynamic' : ('DYN', 'Dynamic'),
102 'DynamicHii' : ('DYNHII', 'Dynamic'),
103 'DynamicVpd' : ('DYNVPD', 'Dynamic'),
104 'DynamicEx' : ('DEX', 'DynamicEx'),
105 'DynamicExHii' : ('DEXHII', 'DynamicEx'),
106 'DynamicExVpd' : ('DEXVPD', 'DynamicEx'),
107 }
108
109 ## The look up table to map module type to driver type
110 gDriverTypeMap = {
111 'SEC' : '0x3 (SECURITY_CORE)',
112 'PEI_CORE' : '0x4 (PEI_CORE)',
113 'PEIM' : '0x6 (PEIM)',
114 'DXE_CORE' : '0x5 (DXE_CORE)',
115 'DXE_DRIVER' : '0x7 (DRIVER)',
116 'DXE_SAL_DRIVER' : '0x7 (DRIVER)',
117 'DXE_SMM_DRIVER' : '0x7 (DRIVER)',
118 'DXE_RUNTIME_DRIVER': '0x7 (DRIVER)',
119 'UEFI_DRIVER' : '0x7 (DRIVER)',
120 'UEFI_APPLICATION' : '0x9 (APPLICATION)',
121 'SMM_CORE' : '0xD (SMM_CORE)',
122 'SMM_DRIVER' : '0xA (SMM)', # Extension of module type to support PI 1.1 SMM drivers
123 }
124
125 ## The look up table of the supported opcode in the dependency expression binaries
126 gOpCodeList = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "TRUE", "FALSE", "END", "SOR"]
127
128 ##
129 # Writes a string to the file object.
130 #
131 # This function writes a string to the file object and a new line is appended
132 # afterwards. It may optionally wraps the string for better readability.
133 #
134 # @File The file object to write
135 # @String The string to be written to the file
136 # @Wrapper Indicates whether to wrap the string
137 #
138 def FileWrite(File, String, Wrapper=False):
139 if Wrapper:
140 String = textwrap.fill(String, 120)
141 File.write(String + gEndOfLine)
142
143 ##
144 # Find all the header file that the module source directly includes.
145 #
146 # This function scans source code to find all header files the module may
147 # include. This is not accurate but very effective to find all the header
148 # file the module might include with #include statement.
149 #
150 # @Source The source file name
151 # @IncludePathList The list of include path to find the source file.
152 # @IncludeFiles The dictionary of current found include files.
153 #
154 def FindIncludeFiles(Source, IncludePathList, IncludeFiles):
155 FileContents = open(Source).read()
156 #
157 # Find header files with pattern #include "XXX.h" or #include <XXX.h>
158 #
159 for Match in gIncludePattern.finditer(FileContents):
160 FileName = Match.group(1).strip()
161 for Dir in [os.path.dirname(Source)] + IncludePathList:
162 FullFileName = os.path.normpath(os.path.join(Dir, FileName))
163 if os.path.exists(FullFileName):
164 IncludeFiles[FullFileName.lower().replace("\\", "/")] = FullFileName
165 break
166
167 #
168 # Find header files with pattern like #include EFI_PPI_CONSUMER(XXX)
169 #
170 for Match in gIncludePattern2.finditer(FileContents):
171 Key = Match.group(2)
172 Type = Match.group(1)
173 if "ARCH_PROTOCOL" in Type:
174 FileName = "ArchProtocol/%(Key)s/%(Key)s.h" % {"Key" : Key}
175 elif "PROTOCOL" in Type:
176 FileName = "Protocol/%(Key)s/%(Key)s.h" % {"Key" : Key}
177 elif "PPI" in Type:
178 FileName = "Ppi/%(Key)s/%(Key)s.h" % {"Key" : Key}
179 elif "GUID" in Type:
180 FileName = "Guid/%(Key)s/%(Key)s.h" % {"Key" : Key}
181 else:
182 continue
183 for Dir in IncludePathList:
184 FullFileName = os.path.normpath(os.path.join(Dir, FileName))
185 if os.path.exists(FullFileName):
186 IncludeFiles[FullFileName.lower().replace("\\", "/")] = FullFileName
187 break
188
189 ## Split each lines in file
190 #
191 # This method is used to split the lines in file to make the length of each line
192 # less than MaxLength.
193 #
194 # @param Content The content of file
195 # @param MaxLength The Max Length of the line
196 #
197 def FileLinesSplit(Content=None, MaxLength=None):
198 ContentList = Content.split(TAB_LINE_BREAK)
199 NewContent = ''
200 NewContentList = []
201 for Line in ContentList:
202 while len(Line.rstrip()) > MaxLength:
203 LineSpaceIndex = Line.rfind(TAB_SPACE_SPLIT, 0, MaxLength)
204 LineSlashIndex = Line.rfind(TAB_SLASH, 0, MaxLength)
205 LineBackSlashIndex = Line.rfind(TAB_BACK_SLASH, 0, MaxLength)
206 if max(LineSpaceIndex, LineSlashIndex, LineBackSlashIndex) > 0:
207 LineBreakIndex = max(LineSpaceIndex, LineSlashIndex, LineBackSlashIndex)
208 else:
209 LineBreakIndex = MaxLength
210 NewContentList.append(Line[:LineBreakIndex])
211 Line = Line[LineBreakIndex:]
212 if Line:
213 NewContentList.append(Line)
214 for NewLine in NewContentList:
215 NewContent += NewLine + TAB_LINE_BREAK
216
217 NewContent = NewContent.replace(TAB_LINE_BREAK, gEndOfLine).replace('\r\r\n', gEndOfLine)
218 return NewContent
219
220
221
222 ##
223 # Parse binary dependency expression section
224 #
225 # This utility class parses the dependency expression section and translate the readable
226 # GUID name and value.
227 #
228 class DepexParser(object):
229 ##
230 # Constructor function for class DepexParser
231 #
232 # This constructor function collect GUID values so that the readable
233 # GUID name can be translated.
234 #
235 # @param self The object pointer
236 # @param Wa Workspace context information
237 #
238 def __init__(self, Wa):
239 self._GuidDb = {}
240 for Pa in Wa.AutoGenObjectList:
241 for Package in Pa.PackageList:
242 for Protocol in Package.Protocols:
243 GuidValue = GuidStructureStringToGuidString(Package.Protocols[Protocol])
244 self._GuidDb[GuidValue.upper()] = Protocol
245 for Ppi in Package.Ppis:
246 GuidValue = GuidStructureStringToGuidString(Package.Ppis[Ppi])
247 self._GuidDb[GuidValue.upper()] = Ppi
248 for Guid in Package.Guids:
249 GuidValue = GuidStructureStringToGuidString(Package.Guids[Guid])
250 self._GuidDb[GuidValue.upper()] = Guid
251
252 ##
253 # Parse the binary dependency expression files.
254 #
255 # This function parses the binary dependency expression file and translate it
256 # to the instruction list.
257 #
258 # @param self The object pointer
259 # @param DepexFileName The file name of binary dependency expression file.
260 #
261 def ParseDepexFile(self, DepexFileName):
262 DepexFile = open(DepexFileName, "rb")
263 DepexStatement = []
264 OpCode = DepexFile.read(1)
265 while OpCode:
266 Statement = gOpCodeList[struct.unpack("B", OpCode)[0]]
267 if Statement in ["BEFORE", "AFTER", "PUSH"]:
268 GuidValue = "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X" % \
269 struct.unpack("=LHHBBBBBBBB", DepexFile.read(16))
270 GuidString = self._GuidDb.get(GuidValue, GuidValue)
271 Statement = "%s %s" % (Statement, GuidString)
272 DepexStatement.append(Statement)
273 OpCode = DepexFile.read(1)
274
275 return DepexStatement
276
277 ##
278 # Reports library information
279 #
280 # This class reports the module library subsection in the build report file.
281 #
282 class LibraryReport(object):
283 ##
284 # Constructor function for class LibraryReport
285 #
286 # This constructor function generates LibraryReport object for
287 # a module.
288 #
289 # @param self The object pointer
290 # @param M Module context information
291 #
292 def __init__(self, M):
293 self.LibraryList = []
294 if int(str(M.AutoGenVersion), 0) >= 0x00010005:
295 self._EdkIIModule = True
296 else:
297 self._EdkIIModule = False
298
299 for Lib in M.DependentLibraryList:
300 LibInfPath = str(Lib)
301 LibClassList = Lib.LibraryClass[0].LibraryClass
302 LibConstructorList = Lib.ConstructorList
303 LibDesstructorList = Lib.DestructorList
304 LibDepexList = Lib.DepexExpression[M.Arch, M.ModuleType]
305 self.LibraryList.append((LibInfPath, LibClassList, LibConstructorList, LibDesstructorList, LibDepexList))
306
307 ##
308 # Generate report for module library information
309 #
310 # This function generates report for the module library.
311 # If the module is EDKII style one, the additional library class, library
312 # constructor/destructor and dependency expression may also be reported.
313 #
314 # @param self The object pointer
315 # @param File The file object for report
316 #
317 def GenerateReport(self, File):
318 FileWrite(File, gSubSectionStart)
319 FileWrite(File, TAB_BRG_LIBRARY)
320 if len(self.LibraryList) > 0:
321 FileWrite(File, gSubSectionSep)
322 for LibraryItem in self.LibraryList:
323 LibInfPath = LibraryItem[0]
324 FileWrite(File, LibInfPath)
325
326 #
327 # Report library class, library constructor and destructor for
328 # EDKII style module.
329 #
330 if self._EdkIIModule:
331 LibClass = LibraryItem[1]
332 EdkIILibInfo = ""
333 LibConstructor = " ".join(LibraryItem[2])
334 if LibConstructor:
335 EdkIILibInfo += " C = " + LibConstructor
336 LibDestructor = " ".join(LibraryItem[3])
337 if LibDestructor:
338 EdkIILibInfo += " D = " + LibDestructor
339 LibDepex = " ".join(LibraryItem[4])
340 if LibDepex:
341 EdkIILibInfo += " Depex = " + LibDepex
342 if EdkIILibInfo:
343 FileWrite(File, "{%s: %s}" % (LibClass, EdkIILibInfo))
344 else:
345 FileWrite(File, "{%s}" % LibClass)
346
347 FileWrite(File, gSubSectionEnd)
348
349 ##
350 # Reports dependency expression information
351 #
352 # This class reports the module dependency expression subsection in the build report file.
353 #
354 class DepexReport(object):
355 ##
356 # Constructor function for class DepexReport
357 #
358 # This constructor function generates DepexReport object for
359 # a module. If the module source contains the DXS file (usually EDK
360 # style module), it uses the dependency in DXS file; otherwise,
361 # it uses the dependency expression from its own INF [Depex] section
362 # and then merges with the ones from its dependent library INF.
363 #
364 # @param self The object pointer
365 # @param M Module context information
366 #
367 def __init__(self, M):
368 self.Depex = ""
369 self._DepexFileName = os.path.join(M.BuildDir, "OUTPUT", M.Module.BaseName + ".depex")
370 ModuleType = M.ModuleType
371 if not ModuleType:
372 ModuleType = gComponentType2ModuleType.get(M.ComponentType, "")
373
374 if ModuleType in ["SEC", "PEI_CORE", "DXE_CORE", "SMM_CORE", "UEFI_APPLICATION"]:
375 return
376
377 for Source in M.SourceFileList:
378 if os.path.splitext(Source.Path)[1].lower() == ".dxs":
379 Match = gDxsDependencyPattern.search(open(Source.Path).read())
380 if Match:
381 self.Depex = Match.group(1).strip()
382 self.Source = "DXS"
383 break
384 else:
385 self.Depex = M.DepexExpressionList.get(M.ModuleType, "")
386 self.ModuleDepex = " ".join(M.Module.DepexExpression[M.Arch, M.ModuleType])
387 if not self.ModuleDepex:
388 self.ModuleDepex = "(None)"
389
390 LibDepexList = []
391 for Lib in M.DependentLibraryList:
392 LibDepex = " ".join(Lib.DepexExpression[M.Arch, M.ModuleType]).strip()
393 if LibDepex != "":
394 LibDepexList.append("(" + LibDepex + ")")
395 self.LibraryDepex = " AND ".join(LibDepexList)
396 if not self.LibraryDepex:
397 self.LibraryDepex = "(None)"
398 self.Source = "INF"
399
400 ##
401 # Generate report for module dependency expression information
402 #
403 # This function generates report for the module dependency expression.
404 #
405 # @param self The object pointer
406 # @param File The file object for report
407 # @param GlobalDepexParser The platform global Dependency expression parser object
408 #
409 def GenerateReport(self, File, GlobalDepexParser):
410 if not self.Depex:
411 FileWrite(File, gSubSectionStart)
412 FileWrite(File, TAB_DEPEX)
413 FileWrite(File, gSubSectionEnd)
414 return
415 FileWrite(File, gSubSectionStart)
416 if os.path.isfile(self._DepexFileName):
417 try:
418 DepexStatements = GlobalDepexParser.ParseDepexFile(self._DepexFileName)
419 FileWrite(File, "Final Dependency Expression (DEPEX) Instructions")
420 for DepexStatement in DepexStatements:
421 FileWrite(File, " %s" % DepexStatement)
422 FileWrite(File, gSubSectionSep)
423 except:
424 EdkLogger.warn(None, "Dependency expression file is corrupted", self._DepexFileName)
425
426 FileWrite(File, "Dependency Expression (DEPEX) from %s" % self.Source)
427
428 if self.Source == "INF":
429 FileWrite(File, "%s" % self.Depex, True)
430 FileWrite(File, gSubSectionSep)
431 FileWrite(File, "From Module INF: %s" % self.ModuleDepex, True)
432 FileWrite(File, "From Library INF: %s" % self.LibraryDepex, True)
433 else:
434 FileWrite(File, "%s" % self.Depex)
435 FileWrite(File, gSubSectionEnd)
436
437 ##
438 # Reports dependency expression information
439 #
440 # This class reports the module build flags subsection in the build report file.
441 #
442 class BuildFlagsReport(object):
443 ##
444 # Constructor function for class BuildFlagsReport
445 #
446 # This constructor function generates BuildFlagsReport object for
447 # a module. It reports the build tool chain tag and all relevant
448 # build flags to build the module.
449 #
450 # @param self The object pointer
451 # @param M Module context information
452 #
453 def __init__(self, M):
454 BuildOptions = {}
455 #
456 # Add build flags according to source file extension so that
457 # irrelevant ones can be filtered out.
458 #
459 for Source in M.SourceFileList:
460 Ext = os.path.splitext(Source.File)[1].lower()
461 if Ext in [".c", ".cc", ".cpp"]:
462 BuildOptions["CC"] = 1
463 elif Ext in [".s", ".asm"]:
464 BuildOptions["PP"] = 1
465 BuildOptions["ASM"] = 1
466 elif Ext in [".vfr"]:
467 BuildOptions["VFRPP"] = 1
468 BuildOptions["VFR"] = 1
469 elif Ext in [".dxs"]:
470 BuildOptions["APP"] = 1
471 BuildOptions["CC"] = 1
472 elif Ext in [".asl"]:
473 BuildOptions["ASLPP"] = 1
474 BuildOptions["ASL"] = 1
475 elif Ext in [".aslc"]:
476 BuildOptions["ASLCC"] = 1
477 BuildOptions["ASLDLINK"] = 1
478 BuildOptions["CC"] = 1
479 elif Ext in [".asm16"]:
480 BuildOptions["ASMLINK"] = 1
481 BuildOptions["SLINK"] = 1
482 BuildOptions["DLINK"] = 1
483
484 #
485 # Save module build flags.
486 #
487 self.ToolChainTag = M.ToolChain
488 self.BuildFlags = {}
489 for Tool in BuildOptions:
490 self.BuildFlags[Tool + "_FLAGS"] = M.BuildOption.get(Tool, {}).get("FLAGS", "")
491
492 ##
493 # Generate report for module build flags information
494 #
495 # This function generates report for the module build flags expression.
496 #
497 # @param self The object pointer
498 # @param File The file object for report
499 #
500 def GenerateReport(self, File):
501 FileWrite(File, gSubSectionStart)
502 FileWrite(File, "Build Flags")
503 FileWrite(File, "Tool Chain Tag: %s" % self.ToolChainTag)
504 for Tool in self.BuildFlags:
505 FileWrite(File, gSubSectionSep)
506 FileWrite(File, "%s = %s" % (Tool, self.BuildFlags[Tool]), True)
507
508 FileWrite(File, gSubSectionEnd)
509
510
511 ##
512 # Reports individual module information
513 #
514 # This class reports the module section in the build report file.
515 # It comprises of module summary, module PCD, library, dependency expression,
516 # build flags sections.
517 #
518 class ModuleReport(object):
519 ##
520 # Constructor function for class ModuleReport
521 #
522 # This constructor function generates ModuleReport object for
523 # a separate module in a platform build.
524 #
525 # @param self The object pointer
526 # @param M Module context information
527 # @param ReportType The kind of report items in the final report file
528 #
529 def __init__(self, M, ReportType):
530 self.ModuleName = M.Module.BaseName
531 self.ModuleInfPath = M.MetaFile.File
532 self.FileGuid = M.Guid
533 self.Size = 0
534 self.BuildTimeStamp = None
535 self.Hash = 0
536 self.DriverType = ""
537 if not M.IsLibrary:
538 ModuleType = M.ModuleType
539 if not ModuleType:
540 ModuleType = gComponentType2ModuleType.get(M.ComponentType, "")
541 #
542 # If a module complies to PI 1.1, promote Module type to "SMM_DRIVER"
543 #
544 if ModuleType == "DXE_SMM_DRIVER":
545 PiSpec = M.Module.Specification.get("PI_SPECIFICATION_VERSION", "0x00010000")
546 if int(PiSpec, 0) >= 0x0001000A:
547 ModuleType = "SMM_DRIVER"
548 self.DriverType = gDriverTypeMap.get(ModuleType, "0x2 (FREE_FORM)")
549 self.UefiSpecVersion = M.Module.Specification.get("UEFI_SPECIFICATION_VERSION", "")
550 self.PiSpecVersion = M.Module.Specification.get("PI_SPECIFICATION_VERSION", "")
551 self.PciDeviceId = M.Module.Defines.get("PCI_DEVICE_ID", "")
552 self.PciVendorId = M.Module.Defines.get("PCI_VENDOR_ID", "")
553 self.PciClassCode = M.Module.Defines.get("PCI_CLASS_CODE", "")
554
555 self._BuildDir = M.BuildDir
556 self.ModulePcdSet = {}
557 if "PCD" in ReportType:
558 #
559 # Collect all module used PCD set: module INF referenced directly or indirectly.
560 # It also saves module INF default values of them in case they exist.
561 #
562 for Pcd in M.ModulePcdList + M.LibraryPcdList:
563 self.ModulePcdSet.setdefault((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Type), (Pcd.InfDefaultValue, Pcd.DefaultValue))
564
565 self.LibraryReport = None
566 if "LIBRARY" in ReportType:
567 self.LibraryReport = LibraryReport(M)
568
569 self.DepexReport = None
570 if "DEPEX" in ReportType:
571 self.DepexReport = DepexReport(M)
572
573 if "BUILD_FLAGS" in ReportType:
574 self.BuildFlagsReport = BuildFlagsReport(M)
575
576
577 ##
578 # Generate report for module information
579 #
580 # This function generates report for separate module expression
581 # in a platform build.
582 #
583 # @param self The object pointer
584 # @param File The file object for report
585 # @param GlobalPcdReport The platform global PCD report object
586 # @param GlobalPredictionReport The platform global Prediction report object
587 # @param GlobalDepexParser The platform global Dependency expression parser object
588 # @param ReportType The kind of report items in the final report file
589 #
590 def GenerateReport(self, File, GlobalPcdReport, GlobalPredictionReport, GlobalDepexParser, ReportType):
591 FileWrite(File, gSectionStart)
592
593 FwReportFileName = os.path.join(self._BuildDir, "DEBUG", self.ModuleName + ".txt")
594 if os.path.isfile(FwReportFileName):
595 try:
596 FileContents = open(FwReportFileName).read()
597 Match = gModuleSizePattern.search(FileContents)
598 if Match:
599 self.Size = int(Match.group(1))
600
601 Match = gTimeStampPattern.search(FileContents)
602 if Match:
603 self.BuildTimeStamp = datetime.fromtimestamp(int(Match.group(1)))
604 except IOError:
605 EdkLogger.warn(None, "Fail to read report file", FwReportFileName)
606
607 if "HASH" in ReportType:
608 OutputDir = os.path.join(self._BuildDir, "OUTPUT")
609 DefaultEFIfile = os.path.join(OutputDir, self.ModuleName + ".efi")
610 if os.path.isfile(DefaultEFIfile):
611 Tempfile = os.path.join(OutputDir, self.ModuleName + "_hash.tmp")
612 # rebase the efi image since its base address may not zero
613 cmd = ["GenFw", "--rebase", str(0), "-o", Tempfile, DefaultEFIfile]
614 try:
615 PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
616 except Exception, X:
617 EdkLogger.error("GenFw", COMMAND_FAILURE, ExtraData="%s: %s" % (str(X), cmd[0]))
618 EndOfProcedure = threading.Event()
619 EndOfProcedure.clear()
620 if PopenObject.stderr:
621 StdErrThread = threading.Thread(target=ReadMessage, args=(PopenObject.stderr, EdkLogger.quiet, EndOfProcedure))
622 StdErrThread.setName("STDERR-Redirector")
623 StdErrThread.setDaemon(False)
624 StdErrThread.start()
625 # waiting for program exit
626 PopenObject.wait()
627 if PopenObject.stderr:
628 StdErrThread.join()
629 if PopenObject.returncode != 0:
630 EdkLogger.error("GenFw", COMMAND_FAILURE, "Failed to generate firmware hash image for %s" % (DefaultEFIfile))
631 if os.path.isfile(Tempfile):
632 self.Hash = hashlib.sha1()
633 buf = open(Tempfile, 'rb').read()
634 if self.Hash.update(buf):
635 self.Hash = self.Hash.update(buf)
636 self.Hash = self.Hash.hexdigest()
637 os.remove(Tempfile)
638
639 FileWrite(File, "Module Summary")
640 FileWrite(File, "Module Name: %s" % self.ModuleName)
641 FileWrite(File, "Module INF Path: %s" % self.ModuleInfPath)
642 FileWrite(File, "File GUID: %s" % self.FileGuid)
643 if self.Size:
644 FileWrite(File, "Size: 0x%X (%.2fK)" % (self.Size, self.Size / 1024.0))
645 if self.Hash:
646 FileWrite(File, "SHA1 HASH: %s *%s" % (self.Hash, self.ModuleName + ".efi"))
647 if self.BuildTimeStamp:
648 FileWrite(File, "Build Time Stamp: %s" % self.BuildTimeStamp)
649 if self.DriverType:
650 FileWrite(File, "Driver Type: %s" % self.DriverType)
651 if self.UefiSpecVersion:
652 FileWrite(File, "UEFI Spec Version: %s" % self.UefiSpecVersion)
653 if self.PiSpecVersion:
654 FileWrite(File, "PI Spec Version: %s" % self.PiSpecVersion)
655 if self.PciDeviceId:
656 FileWrite(File, "PCI Device ID: %s" % self.PciDeviceId)
657 if self.PciVendorId:
658 FileWrite(File, "PCI Vendor ID: %s" % self.PciVendorId)
659 if self.PciClassCode:
660 FileWrite(File, "PCI Class Code: %s" % self.PciClassCode)
661
662 FileWrite(File, gSectionSep)
663
664 if "PCD" in ReportType:
665 GlobalPcdReport.GenerateReport(File, self.ModulePcdSet)
666
667 if "LIBRARY" in ReportType:
668 self.LibraryReport.GenerateReport(File)
669
670 if "DEPEX" in ReportType:
671 self.DepexReport.GenerateReport(File, GlobalDepexParser)
672
673 if "BUILD_FLAGS" in ReportType:
674 self.BuildFlagsReport.GenerateReport(File)
675
676 if "FIXED_ADDRESS" in ReportType and self.FileGuid:
677 GlobalPredictionReport.GenerateReport(File, self.FileGuid)
678
679 FileWrite(File, gSectionEnd)
680
681 def ReadMessage(From, To, ExitFlag):
682 while True:
683 # read one line a time
684 Line = From.readline()
685 # empty string means "end"
686 if Line != None and Line != "":
687 To(Line.rstrip())
688 else:
689 break
690 if ExitFlag.isSet():
691 break
692
693 ##
694 # Reports platform and module PCD information
695 #
696 # This class reports the platform PCD section and module PCD subsection
697 # in the build report file.
698 #
699 class PcdReport(object):
700 ##
701 # Constructor function for class PcdReport
702 #
703 # This constructor function generates PcdReport object a platform build.
704 # It collects the whole PCD database from platform DSC files, platform
705 # flash description file and package DEC files.
706 #
707 # @param self The object pointer
708 # @param Wa Workspace context information
709 #
710 def __init__(self, Wa):
711 self.AllPcds = {}
712 self.UnusedPcds = {}
713 self.ConditionalPcds = {}
714 self.MaxLen = 0
715 if Wa.FdfProfile:
716 self.FdfPcdSet = Wa.FdfProfile.PcdDict
717 else:
718 self.FdfPcdSet = {}
719
720 self.ModulePcdOverride = {}
721 for Pa in Wa.AutoGenObjectList:
722 #
723 # Collect all platform referenced PCDs and grouped them by PCD token space
724 # GUID C Names
725 #
726 for Pcd in Pa.AllPcdList:
727 PcdList = self.AllPcds.setdefault(Pcd.TokenSpaceGuidCName, {}).setdefault(Pcd.Type, [])
728 if Pcd not in PcdList:
729 PcdList.append(Pcd)
730 if len(Pcd.TokenCName) > self.MaxLen:
731 self.MaxLen = len(Pcd.TokenCName)
732 #
733 # Collect the PCD defined in DSC/FDF file, but not used in module
734 #
735 UnusedPcdFullList = []
736 for item in Pa.Platform.Pcds:
737 Pcd = Pa.Platform.Pcds[item]
738 if not Pcd.Type:
739 PcdTypeFlag = False
740 for package in Pa.PackageList:
741 for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:
742 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, T) in package.Pcds:
743 Pcd.Type = T
744 PcdTypeFlag = True
745 if not Pcd.DatumType:
746 Pcd.DatumType = package.Pcds[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName, T)].DatumType
747 break
748 if PcdTypeFlag:
749 break
750 if not Pcd.DatumType:
751 PcdType = Pcd.Type
752 # Try to remove Hii and Vpd suffix
753 if PcdType.startswith("DynamicEx"):
754 PcdType = "DynamicEx"
755 elif PcdType.startswith("Dynamic"):
756 PcdType = "Dynamic"
757 for package in Pa.PackageList:
758 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, PcdType) in package.Pcds:
759 Pcd.DatumType = package.Pcds[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName, PcdType)].DatumType
760 break
761
762 PcdList = self.AllPcds.setdefault(Pcd.TokenSpaceGuidCName, {}).setdefault(Pcd.Type, [])
763 if Pcd not in PcdList and Pcd not in UnusedPcdFullList:
764 UnusedPcdFullList.append(Pcd)
765 if len(Pcd.TokenCName) > self.MaxLen:
766 self.MaxLen = len(Pcd.TokenCName)
767
768 if GlobalData.gConditionalPcds:
769 for PcdItem in GlobalData.gConditionalPcds:
770 if '.' in PcdItem:
771 (TokenSpaceGuidCName, TokenCName) = PcdItem.split('.')
772 if (TokenCName, TokenSpaceGuidCName) in Pa.Platform.Pcds.keys():
773 Pcd = Pa.Platform.Pcds[(TokenCName, TokenSpaceGuidCName)]
774 PcdList = self.ConditionalPcds.setdefault(Pcd.TokenSpaceGuidCName, {}).setdefault(Pcd.Type, [])
775 if Pcd not in PcdList:
776 PcdList.append(Pcd)
777
778 UnusedPcdList = []
779 if UnusedPcdFullList:
780 for Pcd in UnusedPcdFullList:
781 if Pcd.TokenSpaceGuidCName + '.' + Pcd.TokenCName in GlobalData.gConditionalPcds:
782 continue
783 UnusedPcdList.append(Pcd)
784
785 for Pcd in UnusedPcdList:
786 PcdList = self.UnusedPcds.setdefault(Pcd.TokenSpaceGuidCName, {}).setdefault(Pcd.Type, [])
787 if Pcd not in PcdList:
788 PcdList.append(Pcd)
789
790 for Module in Pa.Platform.Modules.values():
791 #
792 # Collect module override PCDs
793 #
794 for ModulePcd in Module.M.ModulePcdList + Module.M.LibraryPcdList:
795 TokenCName = ModulePcd.TokenCName
796 TokenSpaceGuid = ModulePcd.TokenSpaceGuidCName
797 ModuleDefault = ModulePcd.DefaultValue
798 ModulePath = os.path.basename(Module.M.MetaFile.File)
799 self.ModulePcdOverride.setdefault((TokenCName, TokenSpaceGuid), {})[ModulePath] = ModuleDefault
800
801
802 #
803 # Collect PCD DEC default value.
804 #
805 self.DecPcdDefault = {}
806 for Pa in Wa.AutoGenObjectList:
807 for Package in Pa.PackageList:
808 for (TokenCName, TokenSpaceGuidCName, DecType) in Package.Pcds:
809 DecDefaultValue = Package.Pcds[TokenCName, TokenSpaceGuidCName, DecType].DefaultValue
810 self.DecPcdDefault.setdefault((TokenCName, TokenSpaceGuidCName, DecType), DecDefaultValue)
811 #
812 # Collect PCDs defined in DSC common section
813 #
814 self.DscPcdDefault = {}
815 for Arch in Wa.ArchList:
816 Platform = Wa.BuildDatabase[Wa.MetaFile, Arch, Wa.BuildTarget, Wa.ToolChain]
817 for (TokenCName, TokenSpaceGuidCName) in Platform.Pcds:
818 DscDefaultValue = Platform.Pcds[(TokenCName, TokenSpaceGuidCName)].DefaultValue
819 if DscDefaultValue:
820 self.DscPcdDefault[(TokenCName, TokenSpaceGuidCName)] = DscDefaultValue
821
822 def GenerateReport(self, File, ModulePcdSet):
823 if self.ConditionalPcds:
824 self.GenerateReportDetail(File, ModulePcdSet, 1)
825 if self.UnusedPcds:
826 self.GenerateReportDetail(File, ModulePcdSet, 2)
827 self.GenerateReportDetail(File, ModulePcdSet)
828
829 ##
830 # Generate report for PCD information
831 #
832 # This function generates report for separate module expression
833 # in a platform build.
834 #
835 # @param self The object pointer
836 # @param File The file object for report
837 # @param ModulePcdSet Set of all PCDs referenced by module or None for
838 # platform PCD report
839 # @param ReportySubType 0 means platform/module PCD report, 1 means Conditional
840 # directives section report, 2 means Unused Pcds section report
841 # @param DscOverridePcds Module DSC override PCDs set
842 #
843 def GenerateReportDetail(self, File, ModulePcdSet, ReportSubType = 0):
844 PcdDict = self.AllPcds
845 if ReportSubType == 1:
846 PcdDict = self.ConditionalPcds
847 elif ReportSubType == 2:
848 PcdDict = self.UnusedPcds
849
850 if ModulePcdSet == None:
851 FileWrite(File, gSectionStart)
852 if ReportSubType == 1:
853 FileWrite(File, "Conditional Directives used by the build system")
854 elif ReportSubType == 2:
855 FileWrite(File, "PCDs not used by modules or in conditional directives")
856 else:
857 FileWrite(File, "Platform Configuration Database Report")
858
859 FileWrite(File, " *B - PCD override in the build option")
860 FileWrite(File, " *P - Platform scoped PCD override in DSC file")
861 FileWrite(File, " *F - Platform scoped PCD override in FDF file")
862 if not ReportSubType:
863 FileWrite(File, " *M - Module scoped PCD override")
864 FileWrite(File, gSectionSep)
865 else:
866 if not ReportSubType:
867 #
868 # For module PCD sub-section
869 #
870 FileWrite(File, gSubSectionStart)
871 FileWrite(File, TAB_BRG_PCD)
872 FileWrite(File, gSubSectionSep)
873
874 for Key in PcdDict:
875 #
876 # Group PCD by their token space GUID C Name
877 #
878 First = True
879 for Type in PcdDict[Key]:
880 #
881 # Group PCD by their usage type
882 #
883 TypeName, DecType = gPcdTypeMap.get(Type, ("", Type))
884 for Pcd in PcdDict[Key][Type]:
885 #
886 # Get PCD default value and their override relationship
887 #
888 DecDefaultValue = self.DecPcdDefault.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, DecType))
889 DscDefaultValue = self.DscPcdDefault.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName))
890 DscDefaultValue = self.FdfPcdSet.get((Pcd.TokenCName, Key), DscDefaultValue)
891 InfDefaultValue = None
892
893 PcdValue = DecDefaultValue
894 if DscDefaultValue:
895 PcdValue = DscDefaultValue
896 if ModulePcdSet != None:
897 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Type) not in ModulePcdSet:
898 continue
899 InfDefault, PcdValue = ModulePcdSet[Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Type]
900 if InfDefault == "":
901 InfDefault = None
902
903 BuildOptionMatch = False
904 if GlobalData.BuildOptionPcd:
905 for pcd in GlobalData.BuildOptionPcd:
906 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (pcd[0], pcd[1]):
907 PcdValue = pcd[2]
908 BuildOptionMatch = True
909 break
910
911 if First:
912 if ModulePcdSet == None:
913 FileWrite(File, "")
914 FileWrite(File, Key)
915 First = False
916
917
918 if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
919 PcdValueNumber = int(PcdValue.strip(), 0)
920 if DecDefaultValue == None:
921 DecMatch = True
922 else:
923 DecDefaultValueNumber = int(DecDefaultValue.strip(), 0)
924 DecMatch = (DecDefaultValueNumber == PcdValueNumber)
925
926 if InfDefaultValue == None:
927 InfMatch = True
928 else:
929 InfDefaultValueNumber = int(InfDefaultValue.strip(), 0)
930 InfMatch = (InfDefaultValueNumber == PcdValueNumber)
931
932 if DscDefaultValue == None:
933 DscMatch = True
934 else:
935 DscDefaultValueNumber = int(DscDefaultValue.strip(), 0)
936 DscMatch = (DscDefaultValueNumber == PcdValueNumber)
937 else:
938 if DecDefaultValue == None:
939 DecMatch = True
940 else:
941 DecMatch = (DecDefaultValue.strip() == PcdValue.strip())
942
943 if InfDefaultValue == None:
944 InfMatch = True
945 else:
946 InfMatch = (InfDefaultValue.strip() == PcdValue.strip())
947
948 if DscDefaultValue == None:
949 DscMatch = True
950 else:
951 DscMatch = (DscDefaultValue.strip() == PcdValue.strip())
952
953 #
954 # Report PCD item according to their override relationship
955 #
956 if BuildOptionMatch:
957 FileWrite(File, ' *B %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
958 elif DecMatch and InfMatch:
959 FileWrite(File, ' %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
960 else:
961 if DscMatch:
962 if (Pcd.TokenCName, Key) in self.FdfPcdSet:
963 FileWrite(File, ' *F %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
964 else:
965 FileWrite(File, ' *P %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
966 else:
967 FileWrite(File, ' *M %-*s: %6s %10s = %-22s' % (self.MaxLen, Pcd.TokenCName, TypeName, '(' + Pcd.DatumType + ')', PcdValue.strip()))
968
969 if TypeName in ('DYNHII', 'DEXHII', 'DYNVPD', 'DEXVPD'):
970 for SkuInfo in Pcd.SkuInfoList.values():
971 if TypeName in ('DYNHII', 'DEXHII'):
972 FileWrite(File, '%*s: %s: %s' % (self.MaxLen + 4, SkuInfo.VariableGuid, SkuInfo.VariableName, SkuInfo.VariableOffset))
973 else:
974 FileWrite(File, '%*s' % (self.MaxLen + 4, SkuInfo.VpdOffset))
975
976 if not DscMatch and DscDefaultValue != None:
977 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DSC DEFAULT', DscDefaultValue.strip()))
978
979 if not InfMatch and InfDefaultValue != None:
980 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'INF DEFAULT', InfDefaultValue.strip()))
981
982 if not DecMatch and DecDefaultValue != None:
983 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DEC DEFAULT', DecDefaultValue.strip()))
984
985 if ModulePcdSet == None:
986 if not BuildOptionMatch:
987 ModuleOverride = self.ModulePcdOverride.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), {})
988 for ModulePath in ModuleOverride:
989 ModuleDefault = ModuleOverride[ModulePath]
990 if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
991 ModulePcdDefaultValueNumber = int(ModuleDefault.strip(), 0)
992 Match = (ModulePcdDefaultValueNumber == PcdValueNumber)
993 else:
994 Match = (ModuleDefault.strip() == PcdValue.strip())
995 if Match:
996 continue
997 FileWrite(File, ' *M %-*s = %s' % (self.MaxLen + 19, ModulePath, ModuleDefault.strip()))
998
999 if ModulePcdSet == None:
1000 FileWrite(File, gSectionEnd)
1001 else:
1002 if not ReportSubType:
1003 FileWrite(File, gSubSectionEnd)
1004
1005
1006
1007 ##
1008 # Reports platform and module Prediction information
1009 #
1010 # This class reports the platform execution order prediction section and
1011 # module load fixed address prediction subsection in the build report file.
1012 #
1013 class PredictionReport(object):
1014 ##
1015 # Constructor function for class PredictionReport
1016 #
1017 # This constructor function generates PredictionReport object for the platform.
1018 #
1019 # @param self: The object pointer
1020 # @param Wa Workspace context information
1021 #
1022 def __init__(self, Wa):
1023 self._MapFileName = os.path.join(Wa.BuildDir, Wa.Name + ".map")
1024 self._MapFileParsed = False
1025 self._EotToolInvoked = False
1026 self._FvDir = Wa.FvDir
1027 self._EotDir = Wa.BuildDir
1028 self._FfsEntryPoint = {}
1029 self._GuidMap = {}
1030 self._SourceList = []
1031 self.FixedMapDict = {}
1032 self.ItemList = []
1033 self.MaxLen = 0
1034
1035 #
1036 # Collect all platform reference source files and GUID C Name
1037 #
1038 for Pa in Wa.AutoGenObjectList:
1039 for Module in Pa.LibraryAutoGenList + Pa.ModuleAutoGenList:
1040 #
1041 # BASE typed modules are EFI agnostic, so we need not scan
1042 # their source code to find PPI/Protocol produce or consume
1043 # information.
1044 #
1045 if Module.ModuleType == "BASE":
1046 continue
1047 #
1048 # Add module referenced source files
1049 #
1050 self._SourceList.append(str(Module))
1051 IncludeList = {}
1052 for Source in Module.SourceFileList:
1053 if os.path.splitext(str(Source))[1].lower() == ".c":
1054 self._SourceList.append(" " + str(Source))
1055 FindIncludeFiles(Source.Path, Module.IncludePathList, IncludeList)
1056 for IncludeFile in IncludeList.values():
1057 self._SourceList.append(" " + IncludeFile)
1058
1059 for Guid in Module.PpiList:
1060 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.PpiList[Guid])
1061 for Guid in Module.ProtocolList:
1062 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.ProtocolList[Guid])
1063 for Guid in Module.GuidList:
1064 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.GuidList[Guid])
1065
1066 if Module.Guid and not Module.IsLibrary:
1067 EntryPoint = " ".join(Module.Module.ModuleEntryPointList)
1068 if int(str(Module.AutoGenVersion), 0) >= 0x00010005:
1069 RealEntryPoint = "_ModuleEntryPoint"
1070 else:
1071 RealEntryPoint = EntryPoint
1072 if EntryPoint == "_ModuleEntryPoint":
1073 CCFlags = Module.BuildOption.get("CC", {}).get("FLAGS", "")
1074 Match = gGlueLibEntryPoint.search(CCFlags)
1075 if Match:
1076 EntryPoint = Match.group(1)
1077
1078 self._FfsEntryPoint[Module.Guid.upper()] = (EntryPoint, RealEntryPoint)
1079
1080
1081 #
1082 # Collect platform firmware volume list as the input of EOT.
1083 #
1084 self._FvList = []
1085 if Wa.FdfProfile:
1086 for Fd in Wa.FdfProfile.FdDict:
1087 for FdRegion in Wa.FdfProfile.FdDict[Fd].RegionList:
1088 if FdRegion.RegionType != "FV":
1089 continue
1090 for FvName in FdRegion.RegionDataList:
1091 if FvName in self._FvList:
1092 continue
1093 self._FvList.append(FvName)
1094 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:
1095 for Section in Ffs.SectionList:
1096 try:
1097 for FvSection in Section.SectionList:
1098 if FvSection.FvName in self._FvList:
1099 continue
1100 self._FvList.append(FvSection.FvName)
1101 except AttributeError:
1102 pass
1103
1104
1105 ##
1106 # Parse platform fixed address map files
1107 #
1108 # This function parses the platform final fixed address map file to get
1109 # the database of predicted fixed address for module image base, entry point
1110 # etc.
1111 #
1112 # @param self: The object pointer
1113 #
1114 def _ParseMapFile(self):
1115 if self._MapFileParsed:
1116 return
1117 self._MapFileParsed = True
1118 if os.path.isfile(self._MapFileName):
1119 try:
1120 FileContents = open(self._MapFileName).read()
1121 for Match in gMapFileItemPattern.finditer(FileContents):
1122 AddressType = Match.group(1)
1123 BaseAddress = Match.group(2)
1124 EntryPoint = Match.group(3)
1125 Guid = Match.group(4).upper()
1126 List = self.FixedMapDict.setdefault(Guid, [])
1127 List.append((AddressType, BaseAddress, "*I"))
1128 List.append((AddressType, EntryPoint, "*E"))
1129 except:
1130 EdkLogger.warn(None, "Cannot open file to read", self._MapFileName)
1131
1132 ##
1133 # Invokes EOT tool to get the predicted the execution order.
1134 #
1135 # This function invokes EOT tool to calculate the predicted dispatch order
1136 #
1137 # @param self: The object pointer
1138 #
1139 def _InvokeEotTool(self):
1140 if self._EotToolInvoked:
1141 return
1142
1143 self._EotToolInvoked = True
1144 FvFileList = []
1145 for FvName in self._FvList:
1146 FvFile = os.path.join(self._FvDir, FvName + ".Fv")
1147 if os.path.isfile(FvFile):
1148 FvFileList.append(FvFile)
1149
1150 if len(FvFileList) == 0:
1151 return
1152 #
1153 # Write source file list and GUID file list to an intermediate file
1154 # as the input for EOT tool and dispatch List as the output file
1155 # from EOT tool.
1156 #
1157 SourceList = os.path.join(self._EotDir, "SourceFile.txt")
1158 GuidList = os.path.join(self._EotDir, "GuidList.txt")
1159 DispatchList = os.path.join(self._EotDir, "Dispatch.txt")
1160
1161 TempFile = open(SourceList, "w+")
1162 for Item in self._SourceList:
1163 FileWrite(TempFile, Item)
1164 TempFile.close()
1165 TempFile = open(GuidList, "w+")
1166 for Key in self._GuidMap:
1167 FileWrite(TempFile, "%s %s" % (Key, self._GuidMap[Key]))
1168 TempFile.close()
1169
1170 try:
1171 from Eot.Eot import Eot
1172
1173 #
1174 # Invoke EOT tool and echo its runtime performance
1175 #
1176 EotStartTime = time.time()
1177 Eot(CommandLineOption=False, SourceFileList=SourceList, GuidList=GuidList,
1178 FvFileList=' '.join(FvFileList), Dispatch=DispatchList, IsInit=True)
1179 EotEndTime = time.time()
1180 EotDuration = time.strftime("%H:%M:%S", time.gmtime(int(round(EotEndTime - EotStartTime))))
1181 EdkLogger.quiet("EOT run time: %s\n" % EotDuration)
1182
1183 #
1184 # Parse the output of EOT tool
1185 #
1186 for Line in open(DispatchList):
1187 if len(Line.split()) < 4:
1188 continue
1189 (Guid, Phase, FfsName, FilePath) = Line.split()
1190 Symbol = self._FfsEntryPoint.get(Guid, [FfsName, ""])[0]
1191 if len(Symbol) > self.MaxLen:
1192 self.MaxLen = len(Symbol)
1193 self.ItemList.append((Phase, Symbol, FilePath))
1194 except:
1195 EdkLogger.quiet("(Python %s on %s\n%s)" % (platform.python_version(), sys.platform, traceback.format_exc()))
1196 EdkLogger.warn(None, "Failed to generate execution order prediction report, for some error occurred in executing EOT.")
1197
1198
1199 ##
1200 # Generate platform execution order report
1201 #
1202 # This function generates the predicted module execution order.
1203 #
1204 # @param self The object pointer
1205 # @param File The file object for report
1206 #
1207 def _GenerateExecutionOrderReport(self, File):
1208 self._InvokeEotTool()
1209 if len(self.ItemList) == 0:
1210 return
1211 FileWrite(File, gSectionStart)
1212 FileWrite(File, "Execution Order Prediction")
1213 FileWrite(File, "*P PEI phase")
1214 FileWrite(File, "*D DXE phase")
1215 FileWrite(File, "*E Module INF entry point name")
1216 FileWrite(File, "*N Module notification function name")
1217
1218 FileWrite(File, "Type %-*s %s" % (self.MaxLen, "Symbol", "Module INF Path"))
1219 FileWrite(File, gSectionSep)
1220 for Item in self.ItemList:
1221 FileWrite(File, "*%sE %-*s %s" % (Item[0], self.MaxLen, Item[1], Item[2]))
1222
1223 FileWrite(File, gSectionStart)
1224
1225 ##
1226 # Generate Fixed Address report.
1227 #
1228 # This function generate the predicted fixed address report for a module
1229 # specified by Guid.
1230 #
1231 # @param self The object pointer
1232 # @param File The file object for report
1233 # @param Guid The module Guid value.
1234 # @param NotifyList The list of all notify function in a module
1235 #
1236 def _GenerateFixedAddressReport(self, File, Guid, NotifyList):
1237 self._ParseMapFile()
1238 FixedAddressList = self.FixedMapDict.get(Guid)
1239 if not FixedAddressList:
1240 return
1241
1242 FileWrite(File, gSubSectionStart)
1243 FileWrite(File, "Fixed Address Prediction")
1244 FileWrite(File, "*I Image Loading Address")
1245 FileWrite(File, "*E Entry Point Address")
1246 FileWrite(File, "*N Notification Function Address")
1247 FileWrite(File, "*F Flash Address")
1248 FileWrite(File, "*M Memory Address")
1249 FileWrite(File, "*S SMM RAM Offset")
1250 FileWrite(File, "TOM Top of Memory")
1251
1252 FileWrite(File, "Type Address Name")
1253 FileWrite(File, gSubSectionSep)
1254 for Item in FixedAddressList:
1255 Type = Item[0]
1256 Value = Item[1]
1257 Symbol = Item[2]
1258 if Symbol == "*I":
1259 Name = "(Image Base)"
1260 elif Symbol == "*E":
1261 Name = self._FfsEntryPoint.get(Guid, ["", "_ModuleEntryPoint"])[1]
1262 elif Symbol in NotifyList:
1263 Name = Symbol
1264 Symbol = "*N"
1265 else:
1266 continue
1267
1268 if "Flash" in Type:
1269 Symbol += "F"
1270 elif "Memory" in Type:
1271 Symbol += "M"
1272 else:
1273 Symbol += "S"
1274
1275 if Value[0] == "-":
1276 Value = "TOM" + Value
1277
1278 FileWrite(File, "%s %-16s %s" % (Symbol, Value, Name))
1279
1280 ##
1281 # Generate report for the prediction part
1282 #
1283 # This function generate the predicted fixed address report for a module or
1284 # predicted module execution order for a platform.
1285 # If the input Guid is None, then, it generates the predicted module execution order;
1286 # otherwise it generated the module fixed loading address for the module specified by
1287 # Guid.
1288 #
1289 # @param self The object pointer
1290 # @param File The file object for report
1291 # @param Guid The module Guid value.
1292 #
1293 def GenerateReport(self, File, Guid):
1294 if Guid:
1295 self._GenerateFixedAddressReport(File, Guid.upper(), [])
1296 else:
1297 self._GenerateExecutionOrderReport(File)
1298
1299 ##
1300 # Reports FD region information
1301 #
1302 # This class reports the FD subsection in the build report file.
1303 # It collects region information of platform flash device.
1304 # If the region is a firmware volume, it lists the set of modules
1305 # and its space information; otherwise, it only lists its region name,
1306 # base address and size in its sub-section header.
1307 # If there are nesting FVs, the nested FVs will list immediate after
1308 # this FD region subsection
1309 #
1310 class FdRegionReport(object):
1311 ##
1312 # Discover all the nested FV name list.
1313 #
1314 # This is an internal worker function to discover the all the nested FV information
1315 # in the parent firmware volume. It uses deep first search algorithm recursively to
1316 # find all the FV list name and append them to the list.
1317 #
1318 # @param self The object pointer
1319 # @param FvName The name of current firmware file system
1320 # @param Wa Workspace context information
1321 #
1322 def _DiscoverNestedFvList(self, FvName, Wa):
1323 FvDictKey=FvName.upper()
1324 if FvDictKey in Wa.FdfProfile.FvDict:
1325 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:
1326 for Section in Ffs.SectionList:
1327 try:
1328 for FvSection in Section.SectionList:
1329 if FvSection.FvName in self.FvList:
1330 continue
1331 self._GuidsDb[Ffs.NameGuid.upper()] = FvSection.FvName
1332 self.FvList.append(FvSection.FvName)
1333 self.FvInfo[FvSection.FvName] = ("Nested FV", 0, 0)
1334 self._DiscoverNestedFvList(FvSection.FvName, Wa)
1335 except AttributeError:
1336 pass
1337
1338 ##
1339 # Constructor function for class FdRegionReport
1340 #
1341 # This constructor function generates FdRegionReport object for a specified FdRegion.
1342 # If the FdRegion is a firmware volume, it will recursively find all its nested Firmware
1343 # volume list. This function also collects GUID map in order to dump module identification
1344 # in the final report.
1345 #
1346 # @param self: The object pointer
1347 # @param FdRegion The current FdRegion object
1348 # @param Wa Workspace context information
1349 #
1350 def __init__(self, FdRegion, Wa):
1351 self.Type = FdRegion.RegionType
1352 self.BaseAddress = FdRegion.Offset
1353 self.Size = FdRegion.Size
1354 self.FvList = []
1355 self.FvInfo = {}
1356 self._GuidsDb = {}
1357 self._FvDir = Wa.FvDir
1358
1359 #
1360 # If the input FdRegion is not a firmware volume,
1361 # we are done.
1362 #
1363 if self.Type != "FV":
1364 return
1365
1366 #
1367 # Find all nested FVs in the FdRegion
1368 #
1369 for FvName in FdRegion.RegionDataList:
1370 if FvName in self.FvList:
1371 continue
1372 self.FvList.append(FvName)
1373 self.FvInfo[FvName] = ("Fd Region", self.BaseAddress, self.Size)
1374 self._DiscoverNestedFvList(FvName, Wa)
1375
1376 PlatformPcds = {}
1377 #
1378 # Collect PCDs declared in DEC files.
1379 #
1380 for Pa in Wa.AutoGenObjectList:
1381 for Package in Pa.PackageList:
1382 for (TokenCName, TokenSpaceGuidCName, DecType) in Package.Pcds:
1383 DecDefaultValue = Package.Pcds[TokenCName, TokenSpaceGuidCName, DecType].DefaultValue
1384 PlatformPcds[(TokenCName, TokenSpaceGuidCName)] = DecDefaultValue
1385 #
1386 # Collect PCDs defined in DSC file
1387 #
1388 for arch in Wa.ArchList:
1389 Platform = Wa.BuildDatabase[Wa.MetaFile, arch]
1390 for (TokenCName, TokenSpaceGuidCName) in Platform.Pcds:
1391 DscDefaultValue = Platform.Pcds[(TokenCName, TokenSpaceGuidCName)].DefaultValue
1392 PlatformPcds[(TokenCName, TokenSpaceGuidCName)] = DscDefaultValue
1393
1394 #
1395 # Add PEI and DXE a priori files GUIDs defined in PI specification.
1396 #
1397 self._GuidsDb["1B45CC0A-156A-428A-AF62-49864DA0E6E6"] = "PEI Apriori"
1398 self._GuidsDb["FC510EE7-FFDC-11D4-BD41-0080C73C8881"] = "DXE Apriori"
1399 #
1400 # Add ACPI table storage file
1401 #
1402 self._GuidsDb["7E374E25-8E01-4FEE-87F2-390C23C606CD"] = "ACPI table storage"
1403
1404 for Pa in Wa.AutoGenObjectList:
1405 for ModuleKey in Pa.Platform.Modules:
1406 M = Pa.Platform.Modules[ModuleKey].M
1407 InfPath = mws.join(Wa.WorkspaceDir, M.MetaFile.File)
1408 self._GuidsDb[M.Guid.upper()] = "%s (%s)" % (M.Module.BaseName, InfPath)
1409
1410 #
1411 # Collect the GUID map in the FV firmware volume
1412 #
1413 for FvName in self.FvList:
1414 FvDictKey=FvName.upper()
1415 if FvDictKey in Wa.FdfProfile.FvDict:
1416 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:
1417 try:
1418 #
1419 # collect GUID map for binary EFI file in FDF file.
1420 #
1421 Guid = Ffs.NameGuid.upper()
1422 Match = gPcdGuidPattern.match(Ffs.NameGuid)
1423 if Match:
1424 PcdTokenspace = Match.group(1)
1425 PcdToken = Match.group(2)
1426 if (PcdToken, PcdTokenspace) in PlatformPcds:
1427 GuidValue = PlatformPcds[(PcdToken, PcdTokenspace)]
1428 Guid = GuidStructureByteArrayToGuidString(GuidValue).upper()
1429 for Section in Ffs.SectionList:
1430 try:
1431 ModuleSectFile = mws.join(Wa.WorkspaceDir, Section.SectFileName)
1432 self._GuidsDb[Guid] = ModuleSectFile
1433 except AttributeError:
1434 pass
1435 except AttributeError:
1436 pass
1437
1438
1439 ##
1440 # Internal worker function to generate report for the FD region
1441 #
1442 # This internal worker function to generate report for the FD region.
1443 # It the type is firmware volume, it lists offset and module identification.
1444 #
1445 # @param self The object pointer
1446 # @param File The file object for report
1447 # @param Title The title for the FD subsection
1448 # @param BaseAddress The base address for the FD region
1449 # @param Size The size of the FD region
1450 # @param FvName The FV name if the FD region is a firmware volume
1451 #
1452 def _GenerateReport(self, File, Title, Type, BaseAddress, Size=0, FvName=None):
1453 FileWrite(File, gSubSectionStart)
1454 FileWrite(File, Title)
1455 FileWrite(File, "Type: %s" % Type)
1456 FileWrite(File, "Base Address: 0x%X" % BaseAddress)
1457
1458 if self.Type == "FV":
1459 FvTotalSize = 0
1460 FvTakenSize = 0
1461 FvFreeSize = 0
1462 FvReportFileName = os.path.join(self._FvDir, FvName + ".Fv.txt")
1463 try:
1464 #
1465 # Collect size info in the firmware volume.
1466 #
1467 FvReport = open(FvReportFileName).read()
1468 Match = gFvTotalSizePattern.search(FvReport)
1469 if Match:
1470 FvTotalSize = int(Match.group(1), 16)
1471 Match = gFvTakenSizePattern.search(FvReport)
1472 if Match:
1473 FvTakenSize = int(Match.group(1), 16)
1474 FvFreeSize = FvTotalSize - FvTakenSize
1475 #
1476 # Write size information to the report file.
1477 #
1478 FileWrite(File, "Size: 0x%X (%.0fK)" % (FvTotalSize, FvTotalSize / 1024.0))
1479 FileWrite(File, "Fv Name: %s (%.1f%% Full)" % (FvName, FvTakenSize * 100.0 / FvTotalSize))
1480 FileWrite(File, "Occupied Size: 0x%X (%.0fK)" % (FvTakenSize, FvTakenSize / 1024.0))
1481 FileWrite(File, "Free Size: 0x%X (%.0fK)" % (FvFreeSize, FvFreeSize / 1024.0))
1482 FileWrite(File, "Offset Module")
1483 FileWrite(File, gSubSectionSep)
1484 #
1485 # Write module offset and module identification to the report file.
1486 #
1487 OffsetInfo = {}
1488 for Match in gOffsetGuidPattern.finditer(FvReport):
1489 Guid = Match.group(2).upper()
1490 OffsetInfo[Match.group(1)] = self._GuidsDb.get(Guid, Guid)
1491 OffsetList = OffsetInfo.keys()
1492 OffsetList.sort()
1493 for Offset in OffsetList:
1494 FileWrite (File, "%s %s" % (Offset, OffsetInfo[Offset]))
1495 except IOError:
1496 EdkLogger.warn(None, "Fail to read report file", FvReportFileName)
1497 else:
1498 FileWrite(File, "Size: 0x%X (%.0fK)" % (Size, Size / 1024.0))
1499 FileWrite(File, gSubSectionEnd)
1500
1501 ##
1502 # Generate report for the FD region
1503 #
1504 # This function generates report for the FD region.
1505 #
1506 # @param self The object pointer
1507 # @param File The file object for report
1508 #
1509 def GenerateReport(self, File):
1510 if (len(self.FvList) > 0):
1511 for FvItem in self.FvList:
1512 Info = self.FvInfo[FvItem]
1513 self._GenerateReport(File, Info[0], "FV", Info[1], Info[2], FvItem)
1514 else:
1515 self._GenerateReport(File, "FD Region", self.Type, self.BaseAddress, self.Size)
1516
1517 ##
1518 # Reports FD information
1519 #
1520 # This class reports the FD section in the build report file.
1521 # It collects flash device information for a platform.
1522 #
1523 class FdReport(object):
1524 ##
1525 # Constructor function for class FdReport
1526 #
1527 # This constructor function generates FdReport object for a specified
1528 # firmware device.
1529 #
1530 # @param self The object pointer
1531 # @param Fd The current Firmware device object
1532 # @param Wa Workspace context information
1533 #
1534 def __init__(self, Fd, Wa):
1535 self.FdName = Fd.FdUiName
1536 self.BaseAddress = Fd.BaseAddress
1537 self.Size = Fd.Size
1538 self.FdRegionList = [FdRegionReport(FdRegion, Wa) for FdRegion in Fd.RegionList]
1539 self.FvPath = os.path.join(Wa.BuildDir, "FV")
1540 self.VpdFilePath = os.path.join(self.FvPath, "%s.map" % Wa.Platform.VpdToolGuid)
1541 self.VPDBaseAddress = 0
1542 self.VPDSize = 0
1543 self.VPDInfoList = []
1544 for index, FdRegion in enumerate(Fd.RegionList):
1545 if str(FdRegion.RegionType) is 'FILE' and Wa.Platform.VpdToolGuid in str(FdRegion.RegionDataList):
1546 self.VPDBaseAddress = self.FdRegionList[index].BaseAddress
1547 self.VPDSize = self.FdRegionList[index].Size
1548 break
1549
1550 if os.path.isfile(self.VpdFilePath):
1551 fd = open(self.VpdFilePath, "r")
1552 Lines = fd.readlines()
1553 for Line in Lines:
1554 Line = Line.strip()
1555 if len(Line) == 0 or Line.startswith("#"):
1556 continue
1557 try:
1558 PcdName, SkuId, Offset, Size, Value = Line.split("#")[0].split("|")
1559 PcdName, SkuId, Offset, Size, Value = PcdName.strip(), SkuId.strip(), Offset.strip(), Size.strip(), Value.strip()
1560 Offset = '0x%08X' % (int(Offset, 16) + self.VPDBaseAddress)
1561 self.VPDInfoList.append("%s | %s | %s | %s | %s" % (PcdName, SkuId, Offset, Size, Value))
1562 except:
1563 EdkLogger.error("BuildReport", CODE_ERROR, "Fail to parse VPD information file %s" % self.VpdFilePath)
1564 fd.close()
1565
1566 ##
1567 # Generate report for the firmware device.
1568 #
1569 # This function generates report for the firmware device.
1570 #
1571 # @param self The object pointer
1572 # @param File The file object for report
1573 #
1574 def GenerateReport(self, File):
1575 FileWrite(File, gSectionStart)
1576 FileWrite(File, "Firmware Device (FD)")
1577 FileWrite(File, "FD Name: %s" % self.FdName)
1578 FileWrite(File, "Base Address: %s" % self.BaseAddress)
1579 FileWrite(File, "Size: 0x%X (%.0fK)" % (self.Size, self.Size / 1024.0))
1580 if len(self.FdRegionList) > 0:
1581 FileWrite(File, gSectionSep)
1582 for FdRegionItem in self.FdRegionList:
1583 FdRegionItem.GenerateReport(File)
1584
1585 if len(self.VPDInfoList) > 0:
1586 FileWrite(File, gSubSectionStart)
1587 FileWrite(File, "FD VPD Region")
1588 FileWrite(File, "Base Address: 0x%X" % self.VPDBaseAddress)
1589 FileWrite(File, "Size: 0x%X (%.0fK)" % (self.VPDSize, self.VPDSize / 1024.0))
1590 FileWrite(File, gSubSectionSep)
1591 for item in self.VPDInfoList:
1592 FileWrite(File, item)
1593 FileWrite(File, gSubSectionEnd)
1594 FileWrite(File, gSectionEnd)
1595
1596
1597
1598 ##
1599 # Reports platform information
1600 #
1601 # This class reports the whole platform information
1602 #
1603 class PlatformReport(object):
1604 ##
1605 # Constructor function for class PlatformReport
1606 #
1607 # This constructor function generates PlatformReport object a platform build.
1608 # It generates report for platform summary, flash, global PCDs and detailed
1609 # module information for modules involved in platform build.
1610 #
1611 # @param self The object pointer
1612 # @param Wa Workspace context information
1613 # @param MaList The list of modules in the platform build
1614 #
1615 def __init__(self, Wa, MaList, ReportType):
1616 self._WorkspaceDir = Wa.WorkspaceDir
1617 self.PlatformName = Wa.Name
1618 self.PlatformDscPath = Wa.Platform
1619 self.Architectures = " ".join(Wa.ArchList)
1620 self.ToolChain = Wa.ToolChain
1621 self.Target = Wa.BuildTarget
1622 self.OutputPath = os.path.join(Wa.WorkspaceDir, Wa.OutputDir)
1623 self.BuildEnvironment = platform.platform()
1624
1625 self.PcdReport = None
1626 if "PCD" in ReportType:
1627 self.PcdReport = PcdReport(Wa)
1628
1629 self.FdReportList = []
1630 if "FLASH" in ReportType and Wa.FdfProfile and MaList == None:
1631 for Fd in Wa.FdfProfile.FdDict:
1632 self.FdReportList.append(FdReport(Wa.FdfProfile.FdDict[Fd], Wa))
1633
1634 self.PredictionReport = None
1635 if "FIXED_ADDRESS" in ReportType or "EXECUTION_ORDER" in ReportType:
1636 self.PredictionReport = PredictionReport(Wa)
1637
1638 self.DepexParser = None
1639 if "DEPEX" in ReportType:
1640 self.DepexParser = DepexParser(Wa)
1641
1642 self.ModuleReportList = []
1643 if MaList != None:
1644 self._IsModuleBuild = True
1645 for Ma in MaList:
1646 self.ModuleReportList.append(ModuleReport(Ma, ReportType))
1647 else:
1648 self._IsModuleBuild = False
1649 for Pa in Wa.AutoGenObjectList:
1650 for ModuleKey in Pa.Platform.Modules:
1651 self.ModuleReportList.append(ModuleReport(Pa.Platform.Modules[ModuleKey].M, ReportType))
1652
1653
1654
1655 ##
1656 # Generate report for the whole platform.
1657 #
1658 # This function generates report for platform information.
1659 # It comprises of platform summary, global PCD, flash and
1660 # module list sections.
1661 #
1662 # @param self The object pointer
1663 # @param File The file object for report
1664 # @param BuildDuration The total time to build the modules
1665 # @param ReportType The kind of report items in the final report file
1666 #
1667 def GenerateReport(self, File, BuildDuration, ReportType):
1668 FileWrite(File, "Platform Summary")
1669 FileWrite(File, "Platform Name: %s" % self.PlatformName)
1670 FileWrite(File, "Platform DSC Path: %s" % self.PlatformDscPath)
1671 FileWrite(File, "Architectures: %s" % self.Architectures)
1672 FileWrite(File, "Tool Chain: %s" % self.ToolChain)
1673 FileWrite(File, "Target: %s" % self.Target)
1674 FileWrite(File, "Output Path: %s" % self.OutputPath)
1675 FileWrite(File, "Build Environment: %s" % self.BuildEnvironment)
1676 FileWrite(File, "Build Duration: %s" % BuildDuration)
1677 FileWrite(File, "Report Content: %s" % ", ".join(ReportType))
1678
1679 if GlobalData.MixedPcd:
1680 FileWrite(File, gSectionStart)
1681 FileWrite(File, "The following PCDs use different access methods:")
1682 FileWrite(File, gSectionSep)
1683 for PcdItem in GlobalData.MixedPcd:
1684 FileWrite(File, "%s.%s" % (str(PcdItem[1]), str(PcdItem[0])))
1685 FileWrite(File, gSectionEnd)
1686
1687 if not self._IsModuleBuild:
1688 if "PCD" in ReportType:
1689 self.PcdReport.GenerateReport(File, None)
1690
1691 if "FLASH" in ReportType:
1692 for FdReportListItem in self.FdReportList:
1693 FdReportListItem.GenerateReport(File)
1694
1695 for ModuleReportItem in self.ModuleReportList:
1696 ModuleReportItem.GenerateReport(File, self.PcdReport, self.PredictionReport, self.DepexParser, ReportType)
1697
1698 if not self._IsModuleBuild:
1699 if "EXECUTION_ORDER" in ReportType:
1700 self.PredictionReport.GenerateReport(File, None)
1701
1702 ## BuildReport class
1703 #
1704 # This base class contain the routines to collect data and then
1705 # applies certain format to the output report
1706 #
1707 class BuildReport(object):
1708 ##
1709 # Constructor function for class BuildReport
1710 #
1711 # This constructor function generates BuildReport object a platform build.
1712 # It generates report for platform summary, flash, global PCDs and detailed
1713 # module information for modules involved in platform build.
1714 #
1715 # @param self The object pointer
1716 # @param ReportFile The file name to save report file
1717 # @param ReportType The kind of report items in the final report file
1718 #
1719 def __init__(self, ReportFile, ReportType):
1720 self.ReportFile = ReportFile
1721 if ReportFile:
1722 self.ReportList = []
1723 self.ReportType = []
1724 if ReportType:
1725 for ReportTypeItem in ReportType:
1726 if ReportTypeItem not in self.ReportType:
1727 self.ReportType.append(ReportTypeItem)
1728 else:
1729 self.ReportType = ["PCD", "LIBRARY", "BUILD_FLAGS", "DEPEX", "HASH", "FLASH", "FIXED_ADDRESS"]
1730 ##
1731 # Adds platform report to the list
1732 #
1733 # This function adds a platform report to the final report list.
1734 #
1735 # @param self The object pointer
1736 # @param Wa Workspace context information
1737 # @param MaList The list of modules in the platform build
1738 #
1739 def AddPlatformReport(self, Wa, MaList=None):
1740 if self.ReportFile:
1741 self.ReportList.append((Wa, MaList))
1742
1743 ##
1744 # Generates the final report.
1745 #
1746 # This function generates platform build report. It invokes GenerateReport()
1747 # method for every platform report in the list.
1748 #
1749 # @param self The object pointer
1750 # @param BuildDuration The total time to build the modules
1751 #
1752 def GenerateReport(self, BuildDuration):
1753 if self.ReportFile:
1754 try:
1755 File = StringIO('')
1756 for (Wa, MaList) in self.ReportList:
1757 PlatformReport(Wa, MaList, self.ReportType).GenerateReport(File, BuildDuration, self.ReportType)
1758 Content = FileLinesSplit(File.getvalue(), gLineMaxLength)
1759 SaveFileOnChange(self.ReportFile, Content, True)
1760 EdkLogger.quiet("Build report can be found at %s" % os.path.abspath(self.ReportFile))
1761 except IOError:
1762 EdkLogger.error(None, FILE_WRITE_FAILURE, ExtraData=self.ReportFile)
1763 except:
1764 EdkLogger.error("BuildReport", CODE_ERROR, "Unknown fatal error when generating build report", ExtraData=self.ReportFile, RaiseError=False)
1765 EdkLogger.quiet("(Python %s on %s\n%s)" % (platform.python_version(), sys.platform, traceback.format_exc()))
1766 File.close()
1767
1768 # This acts like the main() function for the script, unless it is 'import'ed into another script.
1769 if __name__ == '__main__':
1770 pass
1771