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