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