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