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