IntelSiliconPkg IntelVTdDxe: Fix incorrect code to clear VTd error
[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
423 self.Depex = M.DepexExpressionList.get(M.ModuleType, "")\r
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
464 FileWrite(File, "%s" % self.Depex, True)\r
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
469 FileWrite(File, "%s" % self.Depex)\r
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
652 except Exception, X:\r
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
52302d4d 930\r
c8d07c5e 931 for Key in PcdDict:\r
52302d4d
LG
932 #\r
933 # Group PCD by their token space GUID C Name\r
934 #\r
935 First = True\r
c8d07c5e 936 for Type in PcdDict[Key]:\r
52302d4d
LG
937 #\r
938 # Group PCD by their usage type\r
939 #\r
940 TypeName, DecType = gPcdTypeMap.get(Type, ("", Type))\r
c8d07c5e 941 for Pcd in PcdDict[Key][Type]:\r
7cb63c87
YZ
942 PcdTokenCName = Pcd.TokenCName\r
943 MixedPcdFlag = False\r
944 if GlobalData.MixedPcd:\r
945 for PcdKey in GlobalData.MixedPcd:\r
946 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdKey]:\r
947 PcdTokenCName = PcdKey[0]\r
948 MixedPcdFlag = True\r
949 if MixedPcdFlag and not ModulePcdSet:\r
950 continue\r
52302d4d
LG
951 #\r
952 # Get PCD default value and their override relationship\r
953 #\r
954 DecDefaultValue = self.DecPcdDefault.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, DecType))\r
955 DscDefaultValue = self.DscPcdDefault.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
a676a246 956 DscDefaultValBak = DscDefaultValue\r
52302d4d 957 DscDefaultValue = self.FdfPcdSet.get((Pcd.TokenCName, Key), DscDefaultValue)\r
a676a246 958 if DscDefaultValue != DscDefaultValBak:\r
35f613d9
YF
959 try:\r
960 DscDefaultValue = ValueExpressionEx(DscDefaultValue, Pcd.DatumType, self._GuidDict)(True)\r
24326f38 961 except BadExpression, DscDefaultValue:\r
35f613d9
YF
962 EdkLogger.error('BuildReport', FORMAT_INVALID, "PCD Value: %s, Type: %s" %(DscDefaultValue, Pcd.DatumType))\r
963\r
52302d4d
LG
964 InfDefaultValue = None\r
965 \r
966 PcdValue = DecDefaultValue\r
967 if DscDefaultValue:\r
968 PcdValue = DscDefaultValue\r
4231a819 969 if ModulePcdSet is not None:\r
52302d4d
LG
970 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Type) not in ModulePcdSet:\r
971 continue\r
972 InfDefault, PcdValue = ModulePcdSet[Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Type]\r
64797018 973 Pcd.DefaultValue = PcdValue\r
52302d4d
LG
974 if InfDefault == "":\r
975 InfDefault = None\r
763e8edf
YZ
976\r
977 BuildOptionMatch = False\r
978 if GlobalData.BuildOptionPcd:\r
979 for pcd in GlobalData.BuildOptionPcd:\r
980 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (pcd[0], pcd[1]):\r
8565b582
YZ
981 if pcd[2]:\r
982 continue\r
983 PcdValue = pcd[3]\r
97e1ff1b 984 Pcd.DefaultValue = PcdValue\r
763e8edf
YZ
985 BuildOptionMatch = True\r
986 break\r
987\r
52302d4d 988 if First:\r
4231a819 989 if ModulePcdSet is None:\r
52302d4d
LG
990 FileWrite(File, "")\r
991 FileWrite(File, Key)\r
992 First = False\r
993\r
994\r
656d2539 995 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:\r
52302d4d 996 PcdValueNumber = int(PcdValue.strip(), 0)\r
4231a819 997 if DecDefaultValue is None:\r
52302d4d
LG
998 DecMatch = True\r
999 else:\r
1000 DecDefaultValueNumber = int(DecDefaultValue.strip(), 0)\r
1001 DecMatch = (DecDefaultValueNumber == PcdValueNumber)\r
1002\r
4231a819 1003 if InfDefaultValue is None:\r
52302d4d
LG
1004 InfMatch = True\r
1005 else:\r
1006 InfDefaultValueNumber = int(InfDefaultValue.strip(), 0)\r
1007 InfMatch = (InfDefaultValueNumber == PcdValueNumber)\r
1008\r
4231a819 1009 if DscDefaultValue is None:\r
52302d4d
LG
1010 DscMatch = True\r
1011 else:\r
1012 DscDefaultValueNumber = int(DscDefaultValue.strip(), 0)\r
1013 DscMatch = (DscDefaultValueNumber == PcdValueNumber)\r
1014 else:\r
4231a819 1015 if DecDefaultValue is None:\r
52302d4d
LG
1016 DecMatch = True\r
1017 else:\r
d5d56f1b 1018 DecMatch = (DecDefaultValue.strip() == PcdValue.strip())\r
52302d4d 1019\r
4231a819 1020 if InfDefaultValue is None:\r
52302d4d
LG
1021 InfMatch = True\r
1022 else:\r
d5d56f1b 1023 InfMatch = (InfDefaultValue.strip() == PcdValue.strip())\r
52302d4d 1024\r
4231a819 1025 if DscDefaultValue is None:\r
52302d4d
LG
1026 DscMatch = True\r
1027 else:\r
d5d56f1b 1028 DscMatch = (DscDefaultValue.strip() == PcdValue.strip())\r
52302d4d 1029\r
e651d06c 1030 IsStructure = False\r
9eb87141 1031 if GlobalData.gStructurePcd and (self.Arch in GlobalData.gStructurePcd) and ((Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.gStructurePcd[self.Arch]):\r
e651d06c
LG
1032 IsStructure = True\r
1033 if TypeName in ('DYNVPD', 'DEXVPD'):\r
1034 SkuInfoList = Pcd.SkuInfoList\r
1035 Pcd = GlobalData.gStructurePcd[self.Arch][(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)]\r
1036 Pcd.DatumType = Pcd.StructName\r
1037 if TypeName in ('DYNVPD', 'DEXVPD'):\r
1038 Pcd.SkuInfoList = SkuInfoList\r
24326f38
YZ
1039 if Pcd.PcdFieldValueFromComm:\r
1040 BuildOptionMatch = True\r
e651d06c 1041 DecMatch = False\r
24326f38
YZ
1042 elif Pcd.SkuOverrideValues:\r
1043 DscOverride = False\r
1044 if not Pcd.SkuInfoList:\r
1045 OverrideValues = Pcd.SkuOverrideValues\r
1046 if OverrideValues:\r
1047 Keys = OverrideValues.keys()\r
1048 Data = OverrideValues[Keys[0]]\r
1049 Struct = Data.values()[0]\r
1050 DscOverride = self.ParseStruct(Struct)\r
1051 else:\r
1052 SkuList = sorted(Pcd.SkuInfoList.keys())\r
1053 for Sku in SkuList:\r
1054 SkuInfo = Pcd.SkuInfoList[Sku]\r
1055 if TypeName in ('DYNHII', 'DEXHII'):\r
1056 if SkuInfo.DefaultStoreDict:\r
1057 DefaultStoreList = sorted(SkuInfo.DefaultStoreDict.keys())\r
1058 for DefaultStore in DefaultStoreList:\r
1059 OverrideValues = Pcd.SkuOverrideValues[Sku]\r
1060 DscOverride = self.ParseStruct(OverrideValues[DefaultStore])\r
1061 if DscOverride:\r
1062 break\r
1063 else:\r
1064 OverrideValues = Pcd.SkuOverrideValues[Sku]\r
1065 if OverrideValues:\r
1066 Keys = OverrideValues.keys()\r
1067 OverrideFieldStruct = self.OverrideFieldValue(Pcd, OverrideValues[Keys[0]])\r
1068 DscOverride = self.ParseStruct(OverrideFieldStruct)\r
1069 if DscOverride:\r
1070 break\r
1071 if DscOverride:\r
1072 DscMatch = True\r
1073 DecMatch = False\r
1074\r
52302d4d
LG
1075 #\r
1076 # Report PCD item according to their override relationship\r
1077 #\r
0e6be43f 1078 if DecMatch and InfMatch:\r
643e8e4b 1079 self.PrintPcdValue(File, Pcd, PcdTokenCName, TypeName, IsStructure, DscMatch, DscDefaultValBak, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue, ' ')\r
0e6be43f 1080 elif BuildOptionMatch:\r
643e8e4b 1081 self.PrintPcdValue(File, Pcd, PcdTokenCName, TypeName, IsStructure, DscMatch, DscDefaultValBak, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue, '*B')\r
52302d4d
LG
1082 else:\r
1083 if DscMatch:\r
1084 if (Pcd.TokenCName, Key) in self.FdfPcdSet:\r
643e8e4b 1085 self.PrintPcdValue(File, Pcd, PcdTokenCName, TypeName, IsStructure, DscMatch, DscDefaultValBak, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue, '*F')\r
52302d4d 1086 else:\r
643e8e4b 1087 self.PrintPcdValue(File, Pcd, PcdTokenCName, TypeName, IsStructure, DscMatch, DscDefaultValBak, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue, '*P')\r
52302d4d 1088 else:\r
643e8e4b 1089 self.PrintPcdValue(File, Pcd, PcdTokenCName, TypeName, IsStructure, DscMatch, DscDefaultValBak, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue, '*M')\r
52302d4d 1090\r
4231a819 1091 if ModulePcdSet is None:\r
e651d06c
LG
1092 if IsStructure:\r
1093 continue\r
1094 if not TypeName in ('PATCH', 'FLAG', 'FIXED'):\r
1095 continue\r
763e8edf
YZ
1096 if not BuildOptionMatch:\r
1097 ModuleOverride = self.ModulePcdOverride.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), {})\r
1098 for ModulePath in ModuleOverride:\r
1099 ModuleDefault = ModuleOverride[ModulePath]\r
656d2539 1100 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:\r
763e8edf
YZ
1101 ModulePcdDefaultValueNumber = int(ModuleDefault.strip(), 0)\r
1102 Match = (ModulePcdDefaultValueNumber == PcdValueNumber)\r
1103 else:\r
1104 Match = (ModuleDefault.strip() == PcdValue.strip())\r
1105 if Match:\r
1106 continue\r
e651d06c
LG
1107 IsByteArray, ArrayList = ByteArrayForamt(ModuleDefault.strip())\r
1108 if IsByteArray:\r
1109 FileWrite(File, ' *M %-*s = %s' % (self.MaxLen + 19, ModulePath, '{'))\r
1110 for Array in ArrayList:\r
1111 FileWrite(File, '%s' % (Array))\r
1112 else:\r
1113 FileWrite(File, ' *M %-*s = %s' % (self.MaxLen + 19, ModulePath, ModuleDefault.strip()))\r
52302d4d 1114\r
4231a819 1115 if ModulePcdSet is None:\r
52302d4d
LG
1116 FileWrite(File, gSectionEnd)\r
1117 else:\r
c2d0a1f6 1118 if not ReportSubType and ModulePcdSet:\r
c8d07c5e 1119 FileWrite(File, gSubSectionEnd)\r
52302d4d 1120\r
24326f38
YZ
1121 def ParseStruct(self, struct):\r
1122 HasDscOverride = False\r
1123 if struct:\r
1124 for _, Values in struct.items():\r
1125 if Values[1] and Values[1].endswith('.dsc'):\r
1126 HasDscOverride = True\r
1127 break\r
1128 return HasDscOverride\r
52302d4d 1129\r
e651d06c 1130 def PrintPcdDefault(self, File, Pcd, IsStructure, DscMatch, DscDefaultValue, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue):\r
4231a819 1131 if not DscMatch and DscDefaultValue is not None:\r
e651d06c
LG
1132 Value = DscDefaultValue.strip()\r
1133 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1134 if IsByteArray:\r
1135 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DSC DEFAULT', "{"))\r
1136 for Array in ArrayList:\r
1137 FileWrite(File, '%s' % (Array))\r
1138 else:\r
1139 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DSC DEFAULT', Value))\r
4231a819 1140 if not InfMatch and InfDefaultValue is not None:\r
e651d06c
LG
1141 Value = InfDefaultValue.strip()\r
1142 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1143 if IsByteArray:\r
1144 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'INF DEFAULT', "{"))\r
1145 for Array in ArrayList:\r
1146 FileWrite(File, '%s' % (Array))\r
1147 else:\r
1148 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'INF DEFAULT', Value))\r
1149\r
4231a819 1150 if not DecMatch and DecDefaultValue is not None:\r
e651d06c
LG
1151 Value = DecDefaultValue.strip()\r
1152 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1153 if IsByteArray:\r
1154 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DEC DEFAULT', "{"))\r
1155 for Array in ArrayList:\r
1156 FileWrite(File, '%s' % (Array))\r
1157 else:\r
1158 FileWrite(File, ' %*s = %s' % (self.MaxLen + 19, 'DEC DEFAULT', Value))\r
1159 if IsStructure:\r
1160 self.PrintStructureInfo(File, Pcd.DefaultValues)\r
24326f38
YZ
1161 if DecMatch and IsStructure:\r
1162 self.PrintStructureInfo(File, Pcd.DefaultValues)\r
e651d06c
LG
1163\r
1164 def PrintPcdValue(self, File, Pcd, PcdTokenCName, TypeName, IsStructure, DscMatch, DscDefaultValue, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue, Flag = ' '):\r
1165 if not Pcd.SkuInfoList:\r
1166 Value = Pcd.DefaultValue\r
1167 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1168 if IsByteArray:\r
1169 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '{'))\r
1170 for Array in ArrayList:\r
1171 FileWrite(File, '%s' % (Array))\r
1172 else:\r
1173 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', Value))\r
1174 if IsStructure:\r
65eff519 1175 OverrideValues = Pcd.SkuOverrideValues\r
e651d06c
LG
1176 if OverrideValues:\r
1177 Keys = OverrideValues.keys()\r
1178 Data = OverrideValues[Keys[0]]\r
1179 Struct = Data.values()[0]\r
24326f38
YZ
1180 OverrideFieldStruct = self.OverrideFieldValue(Pcd, Struct)\r
1181 self.PrintStructureInfo(File, OverrideFieldStruct)\r
e651d06c
LG
1182 self.PrintPcdDefault(File, Pcd, IsStructure, DscMatch, DscDefaultValue, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue)\r
1183 else:\r
1184 FirstPrint = True\r
1185 SkuList = sorted(Pcd.SkuInfoList.keys())\r
1186 for Sku in SkuList:\r
1187 SkuInfo = Pcd.SkuInfoList[Sku]\r
779ddcdf 1188 SkuIdName = SkuInfo.SkuIdName\r
e651d06c
LG
1189 if TypeName in ('DYNHII', 'DEXHII'):\r
1190 if SkuInfo.DefaultStoreDict:\r
1191 DefaultStoreList = sorted(SkuInfo.DefaultStoreDict.keys())\r
1192 for DefaultStore in DefaultStoreList:\r
1193 Value = SkuInfo.DefaultStoreDict[DefaultStore]\r
1194 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1195 if FirstPrint:\r
1196 FirstPrint = False\r
1197 if IsByteArray:\r
779ddcdf
YZ
1198 if self.DefaultStoreSingle and self.SkuSingle:\r
1199 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '{'))\r
1200 elif self.DefaultStoreSingle and not self.SkuSingle:\r
1201 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', '{'))\r
1202 elif not self.DefaultStoreSingle and self.SkuSingle:\r
1203 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + DefaultStore + ')', '{'))\r
1204 else:\r
1205 FileWrite(File, ' %-*s : %6s %10s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', '(' + DefaultStore + ')', '{'))\r
e651d06c
LG
1206 for Array in ArrayList:\r
1207 FileWrite(File, '%s' % (Array))\r
1208 else:\r
779ddcdf
YZ
1209 if self.DefaultStoreSingle and self.SkuSingle:\r
1210 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', Value))\r
1211 elif self.DefaultStoreSingle and not self.SkuSingle:\r
1212 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', Value))\r
1213 elif not self.DefaultStoreSingle and self.SkuSingle:\r
1214 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + DefaultStore + ')', Value))\r
1215 else:\r
1216 FileWrite(File, ' %-*s : %6s %10s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', '(' + DefaultStore + ')', Value))\r
e651d06c
LG
1217 else:\r
1218 if IsByteArray:\r
779ddcdf
YZ
1219 if self.DefaultStoreSingle and self.SkuSingle:\r
1220 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '{'))\r
1221 elif self.DefaultStoreSingle and not self.SkuSingle:\r
1222 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', '{'))\r
1223 elif not self.DefaultStoreSingle and self.SkuSingle:\r
1224 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + DefaultStore + ')', '{'))\r
1225 else:\r
1226 FileWrite(File, ' %-*s : %6s %10s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', '(' + DefaultStore + ')', '{'))\r
e651d06c
LG
1227 for Array in ArrayList:\r
1228 FileWrite(File, '%s' % (Array))\r
1229 else:\r
779ddcdf
YZ
1230 if self.DefaultStoreSingle and self.SkuSingle:\r
1231 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', Value))\r
1232 elif self.DefaultStoreSingle and not self.SkuSingle:\r
1233 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', Value))\r
1234 elif not self.DefaultStoreSingle and self.SkuSingle:\r
1235 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + DefaultStore + ')', Value))\r
1236 else:\r
1237 FileWrite(File, ' %-*s : %6s %10s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', '(' + DefaultStore + ')', Value))\r
e651d06c
LG
1238 FileWrite(File, '%*s: %s: %s' % (self.MaxLen + 4, SkuInfo.VariableGuid, SkuInfo.VariableName, SkuInfo.VariableOffset))\r
1239 if IsStructure:\r
65eff519 1240 OverrideValues = Pcd.SkuOverrideValues[Sku]\r
24326f38
YZ
1241 OverrideFieldStruct = self.OverrideFieldValue(Pcd, OverrideValues[DefaultStore])\r
1242 self.PrintStructureInfo(File, OverrideFieldStruct)\r
e651d06c 1243 self.PrintPcdDefault(File, Pcd, IsStructure, DscMatch, DscDefaultValue, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue)\r
e651d06c
LG
1244 else:\r
1245 Value = SkuInfo.DefaultValue\r
1246 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1247 if FirstPrint:\r
1248 FirstPrint = False\r
1249 if IsByteArray:\r
779ddcdf
YZ
1250 if self.SkuSingle:\r
1251 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', "{"))\r
1252 else:\r
1253 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', "{"))\r
e651d06c
LG
1254 for Array in ArrayList:\r
1255 FileWrite(File, '%s' % (Array))\r
1256 else:\r
779ddcdf
YZ
1257 if self.SkuSingle:\r
1258 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', Value))\r
1259 else:\r
1260 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, Flag + ' ' + PcdTokenCName, TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', Value))\r
e651d06c
LG
1261 else:\r
1262 if IsByteArray:\r
779ddcdf
YZ
1263 if self.SkuSingle:\r
1264 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, ' ' , TypeName, '(' + Pcd.DatumType + ')', "{"))\r
1265 else:\r
1266 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ' , TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', "{"))\r
e651d06c
LG
1267 for Array in ArrayList:\r
1268 FileWrite(File, '%s' % (Array))\r
1269 else:\r
779ddcdf
YZ
1270 if self.SkuSingle:\r
1271 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, ' ' , TypeName, '(' + Pcd.DatumType + ')', Value))\r
1272 else:\r
1273 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ' , TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', Value))\r
1274 if TypeName in ('DYNVPD', 'DEXVPD'):\r
1275 FileWrite(File, '%*s' % (self.MaxLen + 4, SkuInfo.VpdOffset))\r
e651d06c 1276 if IsStructure:\r
65eff519 1277 OverrideValues = Pcd.SkuOverrideValues[Sku]\r
e651d06c
LG
1278 if OverrideValues:\r
1279 Keys = OverrideValues.keys()\r
24326f38
YZ
1280 OverrideFieldStruct = self.OverrideFieldValue(Pcd, OverrideValues[Keys[0]])\r
1281 self.PrintStructureInfo(File, OverrideFieldStruct)\r
e651d06c
LG
1282 self.PrintPcdDefault(File, Pcd, IsStructure, DscMatch, DscDefaultValue, InfMatch, InfDefaultValue, DecMatch, DecDefaultValue)\r
1283\r
24326f38
YZ
1284 def OverrideFieldValue(self, Pcd, OverrideStruct):\r
1285 OverrideFieldStruct = collections.OrderedDict()\r
1286 if OverrideStruct:\r
1287 for Key, Values in OverrideStruct.items():\r
1288 if Values[1] and Values[1].endswith('.dsc'):\r
1289 OverrideFieldStruct[Key] = Values\r
1290 if Pcd.PcdFieldValueFromComm:\r
1291 for Key, Values in Pcd.PcdFieldValueFromComm.items():\r
1292 OverrideFieldStruct[Key] = Values\r
1293 return OverrideFieldStruct\r
1294\r
e651d06c 1295 def PrintStructureInfo(self, File, Struct):\r
e651d06c 1296 for Key, Value in Struct.items():\r
f440f7e3
YZ
1297 if Value[1] and 'build command options' in Value[1]:\r
1298 FileWrite(File, ' *B %-*s = %s' % (self.MaxLen + 4, '.' + Key, Value[0]))\r
e651d06c 1299 else:\r
f440f7e3 1300 FileWrite(File, ' %-*s = %s' % (self.MaxLen + 4, '.' + Key, Value[0]))\r
e651d06c
LG
1301\r
1302 def StrtoHex(self, value):\r
1303 try:\r
1304 value = hex(int(value))\r
1305 return value\r
1306 except:\r
1307 if value.startswith("L\"") and value.endswith("\""):\r
1308 valuelist = []\r
1309 for ch in value[2:-1]:\r
1310 valuelist.append(hex(ord(ch)))\r
1311 valuelist.append('0x00')\r
1312 return valuelist\r
1313 elif value.startswith("\"") and value.endswith("\""):\r
1314 return hex(ord(value[1:-1]))\r
1315 elif value.startswith("{") and value.endswith("}"):\r
1316 valuelist = []\r
1317 if ',' not in value:\r
1318 return value[1:-1]\r
1319 for ch in value[1:-1].split(','):\r
1320 ch = ch.strip()\r
1321 if ch.startswith('0x') or ch.startswith('0X'):\r
1322 valuelist.append(ch)\r
1323 continue\r
1324 try:\r
1325 valuelist.append(hex(int(ch.strip())))\r
1326 except:\r
1327 pass\r
1328 return valuelist\r
1329 else:\r
1330 return value\r
52302d4d
LG
1331\r
1332##\r
1333# Reports platform and module Prediction information\r
1334#\r
1335# This class reports the platform execution order prediction section and\r
1336# module load fixed address prediction subsection in the build report file.\r
1337#\r
1338class PredictionReport(object):\r
1339 ##\r
1340 # Constructor function for class PredictionReport\r
1341 #\r
1342 # This constructor function generates PredictionReport object for the platform.\r
1343 #\r
1344 # @param self: The object pointer\r
1345 # @param Wa Workspace context information\r
1346 #\r
1347 def __init__(self, Wa):\r
1348 self._MapFileName = os.path.join(Wa.BuildDir, Wa.Name + ".map")\r
1349 self._MapFileParsed = False\r
1350 self._EotToolInvoked = False\r
1351 self._FvDir = Wa.FvDir\r
1352 self._EotDir = Wa.BuildDir\r
1353 self._FfsEntryPoint = {}\r
1354 self._GuidMap = {}\r
1355 self._SourceList = []\r
1356 self.FixedMapDict = {}\r
1357 self.ItemList = []\r
1358 self.MaxLen = 0\r
1359\r
1360 #\r
1361 # Collect all platform reference source files and GUID C Name\r
1362 #\r
1363 for Pa in Wa.AutoGenObjectList:\r
1364 for Module in Pa.LibraryAutoGenList + Pa.ModuleAutoGenList:\r
1365 #\r
40d841f6
LG
1366 # BASE typed modules are EFI agnostic, so we need not scan\r
1367 # their source code to find PPI/Protocol produce or consume\r
1368 # information.\r
1369 #\r
8bb63e37 1370 if Module.ModuleType == SUP_MODULE_BASE:\r
40d841f6
LG
1371 continue\r
1372 #\r
52302d4d
LG
1373 # Add module referenced source files\r
1374 #\r
1375 self._SourceList.append(str(Module))\r
1376 IncludeList = {}\r
1377 for Source in Module.SourceFileList:\r
1378 if os.path.splitext(str(Source))[1].lower() == ".c":\r
1379 self._SourceList.append(" " + str(Source))\r
1380 FindIncludeFiles(Source.Path, Module.IncludePathList, IncludeList)\r
1381 for IncludeFile in IncludeList.values():\r
1382 self._SourceList.append(" " + IncludeFile)\r
1383\r
1384 for Guid in Module.PpiList:\r
1385 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.PpiList[Guid])\r
1386 for Guid in Module.ProtocolList:\r
1387 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.ProtocolList[Guid])\r
1388 for Guid in Module.GuidList:\r
1389 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.GuidList[Guid])\r
1390\r
1391 if Module.Guid and not Module.IsLibrary:\r
1392 EntryPoint = " ".join(Module.Module.ModuleEntryPointList)\r
1393 if int(str(Module.AutoGenVersion), 0) >= 0x00010005:\r
1394 RealEntryPoint = "_ModuleEntryPoint"\r
1395 else:\r
1396 RealEntryPoint = EntryPoint\r
1397 if EntryPoint == "_ModuleEntryPoint":\r
1398 CCFlags = Module.BuildOption.get("CC", {}).get("FLAGS", "")\r
1399 Match = gGlueLibEntryPoint.search(CCFlags)\r
1400 if Match:\r
1401 EntryPoint = Match.group(1)\r
1402\r
1403 self._FfsEntryPoint[Module.Guid.upper()] = (EntryPoint, RealEntryPoint)\r
1404\r
1405\r
1406 #\r
1407 # Collect platform firmware volume list as the input of EOT.\r
1408 #\r
1409 self._FvList = []\r
1410 if Wa.FdfProfile:\r
1411 for Fd in Wa.FdfProfile.FdDict:\r
1412 for FdRegion in Wa.FdfProfile.FdDict[Fd].RegionList:\r
91fa33ee 1413 if FdRegion.RegionType != BINARY_FILE_TYPE_FV:\r
52302d4d
LG
1414 continue\r
1415 for FvName in FdRegion.RegionDataList:\r
1416 if FvName in self._FvList:\r
1417 continue\r
1418 self._FvList.append(FvName)\r
1419 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:\r
1420 for Section in Ffs.SectionList:\r
1421 try:\r
1422 for FvSection in Section.SectionList:\r
1423 if FvSection.FvName in self._FvList:\r
1424 continue\r
1425 self._FvList.append(FvSection.FvName)\r
1426 except AttributeError:\r
1427 pass\r
1428\r
1429\r
1430 ##\r
1431 # Parse platform fixed address map files\r
1432 #\r
1433 # This function parses the platform final fixed address map file to get\r
1434 # the database of predicted fixed address for module image base, entry point\r
1435 # etc.\r
1436 #\r
1437 # @param self: The object pointer\r
1438 #\r
1439 def _ParseMapFile(self):\r
1440 if self._MapFileParsed:\r
1441 return\r
1442 self._MapFileParsed = True\r
1443 if os.path.isfile(self._MapFileName):\r
1444 try:\r
1445 FileContents = open(self._MapFileName).read()\r
1446 for Match in gMapFileItemPattern.finditer(FileContents):\r
1447 AddressType = Match.group(1)\r
1448 BaseAddress = Match.group(2)\r
1449 EntryPoint = Match.group(3)\r
1450 Guid = Match.group(4).upper()\r
1451 List = self.FixedMapDict.setdefault(Guid, [])\r
1452 List.append((AddressType, BaseAddress, "*I"))\r
1453 List.append((AddressType, EntryPoint, "*E"))\r
1454 except:\r
1455 EdkLogger.warn(None, "Cannot open file to read", self._MapFileName)\r
1456\r
1457 ##\r
1458 # Invokes EOT tool to get the predicted the execution order.\r
1459 #\r
1460 # This function invokes EOT tool to calculate the predicted dispatch order\r
1461 #\r
1462 # @param self: The object pointer\r
1463 #\r
1464 def _InvokeEotTool(self):\r
1465 if self._EotToolInvoked:\r
1466 return\r
1467\r
1468 self._EotToolInvoked = True\r
1469 FvFileList = []\r
1470 for FvName in self._FvList:\r
1471 FvFile = os.path.join(self._FvDir, FvName + ".Fv")\r
1472 if os.path.isfile(FvFile):\r
1473 FvFileList.append(FvFile)\r
1474\r
1475 if len(FvFileList) == 0:\r
1476 return\r
1477 #\r
1478 # Write source file list and GUID file list to an intermediate file\r
1479 # as the input for EOT tool and dispatch List as the output file\r
1480 # from EOT tool.\r
1481 #\r
1482 SourceList = os.path.join(self._EotDir, "SourceFile.txt")\r
1483 GuidList = os.path.join(self._EotDir, "GuidList.txt")\r
1484 DispatchList = os.path.join(self._EotDir, "Dispatch.txt")\r
1485\r
1486 TempFile = open(SourceList, "w+")\r
1487 for Item in self._SourceList:\r
1488 FileWrite(TempFile, Item)\r
1489 TempFile.close()\r
1490 TempFile = open(GuidList, "w+")\r
1491 for Key in self._GuidMap:\r
1492 FileWrite(TempFile, "%s %s" % (Key, self._GuidMap[Key]))\r
1493 TempFile.close()\r
1494\r
1495 try:\r
1496 from Eot.Eot import Eot\r
40d841f6 1497\r
52302d4d 1498 #\r
40d841f6 1499 # Invoke EOT tool and echo its runtime performance\r
52302d4d 1500 #\r
40d841f6 1501 EotStartTime = time.time()\r
52302d4d
LG
1502 Eot(CommandLineOption=False, SourceFileList=SourceList, GuidList=GuidList,\r
1503 FvFileList=' '.join(FvFileList), Dispatch=DispatchList, IsInit=True)\r
40d841f6
LG
1504 EotEndTime = time.time()\r
1505 EotDuration = time.strftime("%H:%M:%S", time.gmtime(int(round(EotEndTime - EotStartTime))))\r
1506 EdkLogger.quiet("EOT run time: %s\n" % EotDuration)\r
1507 \r
52302d4d
LG
1508 #\r
1509 # Parse the output of EOT tool\r
1510 #\r
1511 for Line in open(DispatchList):\r
1512 if len(Line.split()) < 4:\r
1513 continue\r
1514 (Guid, Phase, FfsName, FilePath) = Line.split()\r
1515 Symbol = self._FfsEntryPoint.get(Guid, [FfsName, ""])[0]\r
1516 if len(Symbol) > self.MaxLen:\r
1517 self.MaxLen = len(Symbol)\r
1518 self.ItemList.append((Phase, Symbol, FilePath))\r
1519 except:\r
1520 EdkLogger.quiet("(Python %s on %s\n%s)" % (platform.python_version(), sys.platform, traceback.format_exc()))\r
1521 EdkLogger.warn(None, "Failed to generate execution order prediction report, for some error occurred in executing EOT.")\r
1522\r
1523\r
1524 ##\r
1525 # Generate platform execution order report\r
1526 #\r
1527 # This function generates the predicted module execution order.\r
1528 #\r
1529 # @param self The object pointer\r
1530 # @param File The file object for report\r
1531 #\r
1532 def _GenerateExecutionOrderReport(self, File):\r
1533 self._InvokeEotTool()\r
1534 if len(self.ItemList) == 0:\r
1535 return\r
1536 FileWrite(File, gSectionStart)\r
1537 FileWrite(File, "Execution Order Prediction")\r
1538 FileWrite(File, "*P PEI phase")\r
1539 FileWrite(File, "*D DXE phase")\r
1540 FileWrite(File, "*E Module INF entry point name")\r
1541 FileWrite(File, "*N Module notification function name")\r
1542\r
1543 FileWrite(File, "Type %-*s %s" % (self.MaxLen, "Symbol", "Module INF Path"))\r
1544 FileWrite(File, gSectionSep)\r
1545 for Item in self.ItemList:\r
1546 FileWrite(File, "*%sE %-*s %s" % (Item[0], self.MaxLen, Item[1], Item[2]))\r
1547\r
1548 FileWrite(File, gSectionStart)\r
1549\r
1550 ##\r
1551 # Generate Fixed Address report.\r
1552 #\r
1553 # This function generate the predicted fixed address report for a module\r
1554 # specified by Guid.\r
1555 #\r
1556 # @param self The object pointer\r
1557 # @param File The file object for report\r
1558 # @param Guid The module Guid value.\r
1559 # @param NotifyList The list of all notify function in a module\r
1560 #\r
1561 def _GenerateFixedAddressReport(self, File, Guid, NotifyList):\r
1562 self._ParseMapFile()\r
1563 FixedAddressList = self.FixedMapDict.get(Guid)\r
1564 if not FixedAddressList:\r
1565 return\r
1566\r
1567 FileWrite(File, gSubSectionStart)\r
1568 FileWrite(File, "Fixed Address Prediction")\r
1569 FileWrite(File, "*I Image Loading Address")\r
1570 FileWrite(File, "*E Entry Point Address")\r
1571 FileWrite(File, "*N Notification Function Address")\r
1572 FileWrite(File, "*F Flash Address")\r
1573 FileWrite(File, "*M Memory Address")\r
1574 FileWrite(File, "*S SMM RAM Offset")\r
1575 FileWrite(File, "TOM Top of Memory")\r
1576\r
1577 FileWrite(File, "Type Address Name")\r
1578 FileWrite(File, gSubSectionSep)\r
1579 for Item in FixedAddressList:\r
1580 Type = Item[0]\r
1581 Value = Item[1]\r
1582 Symbol = Item[2]\r
1583 if Symbol == "*I":\r
1584 Name = "(Image Base)"\r
1585 elif Symbol == "*E":\r
1586 Name = self._FfsEntryPoint.get(Guid, ["", "_ModuleEntryPoint"])[1]\r
1587 elif Symbol in NotifyList:\r
1588 Name = Symbol\r
1589 Symbol = "*N"\r
1590 else:\r
1591 continue\r
1592\r
1593 if "Flash" in Type:\r
1594 Symbol += "F"\r
1595 elif "Memory" in Type:\r
1596 Symbol += "M"\r
1597 else:\r
1598 Symbol += "S"\r
1599\r
1600 if Value[0] == "-":\r
1601 Value = "TOM" + Value\r
1602\r
1603 FileWrite(File, "%s %-16s %s" % (Symbol, Value, Name))\r
1604\r
1605 ##\r
1606 # Generate report for the prediction part\r
1607 #\r
1608 # This function generate the predicted fixed address report for a module or\r
1609 # predicted module execution order for a platform.\r
1610 # If the input Guid is None, then, it generates the predicted module execution order;\r
1611 # otherwise it generated the module fixed loading address for the module specified by\r
1612 # Guid.\r
1613 #\r
1614 # @param self The object pointer\r
1615 # @param File The file object for report\r
1616 # @param Guid The module Guid value.\r
1617 #\r
1618 def GenerateReport(self, File, Guid):\r
1619 if Guid:\r
1620 self._GenerateFixedAddressReport(File, Guid.upper(), [])\r
1621 else:\r
1622 self._GenerateExecutionOrderReport(File)\r
1623\r
1624##\r
1625# Reports FD region information\r
1626#\r
1627# This class reports the FD subsection in the build report file.\r
1628# It collects region information of platform flash device.\r
1629# If the region is a firmware volume, it lists the set of modules\r
1630# and its space information; otherwise, it only lists its region name,\r
1631# base address and size in its sub-section header.\r
1632# If there are nesting FVs, the nested FVs will list immediate after\r
1633# this FD region subsection\r
1634#\r
1635class FdRegionReport(object):\r
1636 ##\r
1637 # Discover all the nested FV name list.\r
1638 #\r
1639 # This is an internal worker function to discover the all the nested FV information\r
1640 # in the parent firmware volume. It uses deep first search algorithm recursively to\r
1641 # find all the FV list name and append them to the list.\r
1642 #\r
1643 # @param self The object pointer\r
1644 # @param FvName The name of current firmware file system\r
1645 # @param Wa Workspace context information\r
1646 #\r
1647 def _DiscoverNestedFvList(self, FvName, Wa):\r
a2432972
EC
1648 FvDictKey=FvName.upper()\r
1649 if FvDictKey in Wa.FdfProfile.FvDict:\r
1650 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:\r
1651 for Section in Ffs.SectionList:\r
1652 try:\r
1653 for FvSection in Section.SectionList:\r
1654 if FvSection.FvName in self.FvList:\r
1655 continue\r
1656 self._GuidsDb[Ffs.NameGuid.upper()] = FvSection.FvName\r
1657 self.FvList.append(FvSection.FvName)\r
1658 self.FvInfo[FvSection.FvName] = ("Nested FV", 0, 0)\r
1659 self._DiscoverNestedFvList(FvSection.FvName, Wa)\r
1660 except AttributeError:\r
1661 pass\r
52302d4d
LG
1662\r
1663 ##\r
1664 # Constructor function for class FdRegionReport\r
1665 #\r
1666 # This constructor function generates FdRegionReport object for a specified FdRegion.\r
1667 # If the FdRegion is a firmware volume, it will recursively find all its nested Firmware\r
1668 # volume list. This function also collects GUID map in order to dump module identification\r
1669 # in the final report.\r
1670 #\r
1671 # @param self: The object pointer\r
1672 # @param FdRegion The current FdRegion object\r
1673 # @param Wa Workspace context information\r
1674 #\r
1675 def __init__(self, FdRegion, Wa):\r
1676 self.Type = FdRegion.RegionType\r
1677 self.BaseAddress = FdRegion.Offset\r
1678 self.Size = FdRegion.Size\r
1679 self.FvList = []\r
1680 self.FvInfo = {}\r
1681 self._GuidsDb = {}\r
1682 self._FvDir = Wa.FvDir\r
aebe5a36 1683 self._WorkspaceDir = Wa.WorkspaceDir\r
52302d4d
LG
1684\r
1685 #\r
1686 # If the input FdRegion is not a firmware volume,\r
1687 # we are done.\r
1688 #\r
91fa33ee 1689 if self.Type != BINARY_FILE_TYPE_FV:\r
52302d4d
LG
1690 return\r
1691\r
1692 #\r
1693 # Find all nested FVs in the FdRegion\r
1694 #\r
1695 for FvName in FdRegion.RegionDataList:\r
1696 if FvName in self.FvList:\r
1697 continue\r
1698 self.FvList.append(FvName)\r
1699 self.FvInfo[FvName] = ("Fd Region", self.BaseAddress, self.Size)\r
1700 self._DiscoverNestedFvList(FvName, Wa)\r
1701\r
1702 PlatformPcds = {}\r
52302d4d
LG
1703 #\r
1704 # Collect PCDs declared in DEC files.\r
0d2711a6
LG
1705 # \r
1706 for Pa in Wa.AutoGenObjectList:\r
1707 for Package in Pa.PackageList:\r
1708 for (TokenCName, TokenSpaceGuidCName, DecType) in Package.Pcds:\r
1709 DecDefaultValue = Package.Pcds[TokenCName, TokenSpaceGuidCName, DecType].DefaultValue\r
1710 PlatformPcds[(TokenCName, TokenSpaceGuidCName)] = DecDefaultValue\r
52302d4d 1711 #\r
af9785a9 1712 # Collect PCDs defined in DSC file\r
52302d4d 1713 #\r
e651d06c
LG
1714 for Pa in Wa.AutoGenObjectList:\r
1715 for (TokenCName, TokenSpaceGuidCName) in Pa.Platform.Pcds:\r
1716 DscDefaultValue = Pa.Platform.Pcds[(TokenCName, TokenSpaceGuidCName)].DefaultValue\r
af9785a9 1717 PlatformPcds[(TokenCName, TokenSpaceGuidCName)] = DscDefaultValue\r
52302d4d
LG
1718\r
1719 #\r
1720 # Add PEI and DXE a priori files GUIDs defined in PI specification.\r
1721 #\r
1722 self._GuidsDb["1B45CC0A-156A-428A-AF62-49864DA0E6E6"] = "PEI Apriori"\r
1723 self._GuidsDb["FC510EE7-FFDC-11D4-BD41-0080C73C8881"] = "DXE Apriori"\r
1724 #\r
1725 # Add ACPI table storage file\r
1726 #\r
1727 self._GuidsDb["7E374E25-8E01-4FEE-87F2-390C23C606CD"] = "ACPI table storage"\r
1728\r
1729 for Pa in Wa.AutoGenObjectList:\r
1730 for ModuleKey in Pa.Platform.Modules:\r
1731 M = Pa.Platform.Modules[ModuleKey].M\r
05cc51ad 1732 InfPath = mws.join(Wa.WorkspaceDir, M.MetaFile.File)\r
52302d4d
LG
1733 self._GuidsDb[M.Guid.upper()] = "%s (%s)" % (M.Module.BaseName, InfPath)\r
1734\r
1735 #\r
1736 # Collect the GUID map in the FV firmware volume\r
1737 #\r
1738 for FvName in self.FvList:\r
a2432972
EC
1739 FvDictKey=FvName.upper()\r
1740 if FvDictKey in Wa.FdfProfile.FvDict:\r
1741 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:\r
1742 try:\r
1743 #\r
1744 # collect GUID map for binary EFI file in FDF file.\r
1745 #\r
1746 Guid = Ffs.NameGuid.upper()\r
1747 Match = gPcdGuidPattern.match(Ffs.NameGuid)\r
1748 if Match:\r
1749 PcdTokenspace = Match.group(1)\r
1750 PcdToken = Match.group(2)\r
1751 if (PcdToken, PcdTokenspace) in PlatformPcds:\r
1752 GuidValue = PlatformPcds[(PcdToken, PcdTokenspace)]\r
1753 Guid = GuidStructureByteArrayToGuidString(GuidValue).upper()\r
1754 for Section in Ffs.SectionList:\r
1755 try:\r
1756 ModuleSectFile = mws.join(Wa.WorkspaceDir, Section.SectFileName)\r
1757 self._GuidsDb[Guid] = ModuleSectFile\r
1758 except AttributeError:\r
1759 pass\r
1760 except AttributeError:\r
1761 pass\r
52302d4d
LG
1762\r
1763\r
1764 ##\r
1765 # Internal worker function to generate report for the FD region\r
1766 #\r
1767 # This internal worker function to generate report for the FD region.\r
1768 # It the type is firmware volume, it lists offset and module identification.\r
1769 #\r
1770 # @param self The object pointer\r
1771 # @param File The file object for report\r
1772 # @param Title The title for the FD subsection\r
1773 # @param BaseAddress The base address for the FD region\r
1774 # @param Size The size of the FD region\r
1775 # @param FvName The FV name if the FD region is a firmware volume\r
1776 #\r
1777 def _GenerateReport(self, File, Title, Type, BaseAddress, Size=0, FvName=None):\r
1778 FileWrite(File, gSubSectionStart)\r
1779 FileWrite(File, Title)\r
1780 FileWrite(File, "Type: %s" % Type)\r
1781 FileWrite(File, "Base Address: 0x%X" % BaseAddress)\r
1782\r
91fa33ee 1783 if self.Type == BINARY_FILE_TYPE_FV:\r
52302d4d
LG
1784 FvTotalSize = 0\r
1785 FvTakenSize = 0\r
1786 FvFreeSize = 0\r
aebe5a36
YZ
1787 if FvName.upper().endswith('.FV'):\r
1788 FileExt = FvName + ".txt"\r
2157bc9c 1789 else:\r
aebe5a36
YZ
1790 FileExt = FvName + ".Fv.txt"\r
1791\r
1792 if not os.path.isfile(FileExt):\r
1793 FvReportFileName = mws.join(self._WorkspaceDir, FileExt)\r
1794 if not os.path.isfile(FvReportFileName):\r
1795 FvReportFileName = os.path.join(self._FvDir, FileExt)\r
52302d4d
LG
1796 try:\r
1797 #\r
1798 # Collect size info in the firmware volume.\r
1799 #\r
1800 FvReport = open(FvReportFileName).read()\r
1801 Match = gFvTotalSizePattern.search(FvReport)\r
1802 if Match:\r
1803 FvTotalSize = int(Match.group(1), 16)\r
1804 Match = gFvTakenSizePattern.search(FvReport)\r
1805 if Match:\r
1806 FvTakenSize = int(Match.group(1), 16)\r
1807 FvFreeSize = FvTotalSize - FvTakenSize\r
1808 #\r
1809 # Write size information to the report file.\r
1810 #\r
1811 FileWrite(File, "Size: 0x%X (%.0fK)" % (FvTotalSize, FvTotalSize / 1024.0))\r
1812 FileWrite(File, "Fv Name: %s (%.1f%% Full)" % (FvName, FvTakenSize * 100.0 / FvTotalSize))\r
1813 FileWrite(File, "Occupied Size: 0x%X (%.0fK)" % (FvTakenSize, FvTakenSize / 1024.0))\r
1814 FileWrite(File, "Free Size: 0x%X (%.0fK)" % (FvFreeSize, FvFreeSize / 1024.0))\r
1815 FileWrite(File, "Offset Module")\r
1816 FileWrite(File, gSubSectionSep)\r
1817 #\r
1818 # Write module offset and module identification to the report file.\r
1819 #\r
1820 OffsetInfo = {}\r
1821 for Match in gOffsetGuidPattern.finditer(FvReport):\r
1822 Guid = Match.group(2).upper()\r
1823 OffsetInfo[Match.group(1)] = self._GuidsDb.get(Guid, Guid)\r
1824 OffsetList = OffsetInfo.keys()\r
1825 OffsetList.sort()\r
1826 for Offset in OffsetList:\r
1827 FileWrite (File, "%s %s" % (Offset, OffsetInfo[Offset]))\r
1828 except IOError:\r
1829 EdkLogger.warn(None, "Fail to read report file", FvReportFileName)\r
1830 else:\r
1831 FileWrite(File, "Size: 0x%X (%.0fK)" % (Size, Size / 1024.0))\r
1832 FileWrite(File, gSubSectionEnd)\r
1833\r
1834 ##\r
1835 # Generate report for the FD region\r
1836 #\r
1837 # This function generates report for the FD region.\r
1838 #\r
1839 # @param self The object pointer\r
1840 # @param File The file object for report\r
1841 #\r
1842 def GenerateReport(self, File):\r
1843 if (len(self.FvList) > 0):\r
1844 for FvItem in self.FvList:\r
1845 Info = self.FvInfo[FvItem]\r
91fa33ee 1846 self._GenerateReport(File, Info[0], TAB_FV_DIRECTORY, Info[1], Info[2], FvItem)\r
52302d4d
LG
1847 else:\r
1848 self._GenerateReport(File, "FD Region", self.Type, self.BaseAddress, self.Size)\r
1849\r
1850##\r
1851# Reports FD information\r
1852#\r
1853# This class reports the FD section in the build report file.\r
1854# It collects flash device information for a platform.\r
1855#\r
1856class FdReport(object):\r
1857 ##\r
1858 # Constructor function for class FdReport\r
1859 #\r
1860 # This constructor function generates FdReport object for a specified\r
1861 # firmware device.\r
1862 #\r
1863 # @param self The object pointer\r
1864 # @param Fd The current Firmware device object\r
1865 # @param Wa Workspace context information\r
1866 #\r
1867 def __init__(self, Fd, Wa):\r
1868 self.FdName = Fd.FdUiName\r
1869 self.BaseAddress = Fd.BaseAddress\r
1870 self.Size = Fd.Size\r
1871 self.FdRegionList = [FdRegionReport(FdRegion, Wa) for FdRegion in Fd.RegionList]\r
91fa33ee 1872 self.FvPath = os.path.join(Wa.BuildDir, TAB_FV_DIRECTORY)\r
fb3d2279 1873 self.VpdFilePath = os.path.join(self.FvPath, "%s.map" % Wa.Platform.VpdToolGuid)\r
043928da
YZ
1874 self.VPDBaseAddress = 0\r
1875 self.VPDSize = 0\r
fb3d2279
YZ
1876 self.VPDInfoList = []\r
1877 for index, FdRegion in enumerate(Fd.RegionList):\r
043928da 1878 if str(FdRegion.RegionType) is 'FILE' and Wa.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
fb3d2279
YZ
1879 self.VPDBaseAddress = self.FdRegionList[index].BaseAddress\r
1880 self.VPDSize = self.FdRegionList[index].Size\r
1881 break\r
1882\r
1883 if os.path.isfile(self.VpdFilePath):\r
1884 fd = open(self.VpdFilePath, "r")\r
1885 Lines = fd.readlines()\r
1886 for Line in Lines:\r
1887 Line = Line.strip()\r
1888 if len(Line) == 0 or Line.startswith("#"):\r
1889 continue\r
1890 try:\r
1891 PcdName, SkuId, Offset, Size, Value = Line.split("#")[0].split("|")\r
1892 PcdName, SkuId, Offset, Size, Value = PcdName.strip(), SkuId.strip(), Offset.strip(), Size.strip(), Value.strip()\r
8401d398
YZ
1893 if Offset.lower().startswith('0x'):\r
1894 Offset = '0x%08X' % (int(Offset, 16) + self.VPDBaseAddress)\r
1895 else:\r
1896 Offset = '0x%08X' % (int(Offset, 10) + self.VPDBaseAddress)\r
fb3d2279
YZ
1897 self.VPDInfoList.append("%s | %s | %s | %s | %s" % (PcdName, SkuId, Offset, Size, Value))\r
1898 except:\r
1899 EdkLogger.error("BuildReport", CODE_ERROR, "Fail to parse VPD information file %s" % self.VpdFilePath)\r
1900 fd.close()\r
52302d4d
LG
1901\r
1902 ##\r
1903 # Generate report for the firmware device.\r
1904 #\r
1905 # This function generates report for the firmware device.\r
1906 #\r
1907 # @param self The object pointer\r
1908 # @param File The file object for report\r
1909 #\r
1910 def GenerateReport(self, File):\r
1911 FileWrite(File, gSectionStart)\r
1912 FileWrite(File, "Firmware Device (FD)")\r
1913 FileWrite(File, "FD Name: %s" % self.FdName)\r
1914 FileWrite(File, "Base Address: %s" % self.BaseAddress)\r
1915 FileWrite(File, "Size: 0x%X (%.0fK)" % (self.Size, self.Size / 1024.0))\r
1916 if len(self.FdRegionList) > 0:\r
1917 FileWrite(File, gSectionSep)\r
1918 for FdRegionItem in self.FdRegionList:\r
1919 FdRegionItem.GenerateReport(File)\r
1920\r
fb3d2279
YZ
1921 if len(self.VPDInfoList) > 0:\r
1922 FileWrite(File, gSubSectionStart)\r
1923 FileWrite(File, "FD VPD Region")\r
1924 FileWrite(File, "Base Address: 0x%X" % self.VPDBaseAddress)\r
1925 FileWrite(File, "Size: 0x%X (%.0fK)" % (self.VPDSize, self.VPDSize / 1024.0))\r
1926 FileWrite(File, gSubSectionSep)\r
1927 for item in self.VPDInfoList:\r
e651d06c
LG
1928 ValueList = item.split('|')\r
1929 Value = ValueList[-1].strip()\r
1930 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1931 if IsByteArray:\r
1932 ValueList[-1] = ' {'\r
1933 FileWrite(File, '|'.join(ValueList))\r
1934 for Array in ArrayList:\r
1935 FileWrite(File, '%s' % (Array))\r
1936 else:\r
1937 FileWrite(File, item)\r
fb3d2279 1938 FileWrite(File, gSubSectionEnd)\r
52302d4d
LG
1939 FileWrite(File, gSectionEnd)\r
1940\r
1941\r
1942\r
1943##\r
1944# Reports platform information\r
1945#\r
1946# This class reports the whole platform information\r
1947#\r
1948class PlatformReport(object):\r
1949 ##\r
1950 # Constructor function for class PlatformReport\r
1951 #\r
1952 # This constructor function generates PlatformReport object a platform build.\r
1953 # It generates report for platform summary, flash, global PCDs and detailed\r
1954 # module information for modules involved in platform build.\r
1955 #\r
1956 # @param self The object pointer\r
1957 # @param Wa Workspace context information\r
d5d56f1b 1958 # @param MaList The list of modules in the platform build\r
52302d4d 1959 #\r
d5d56f1b 1960 def __init__(self, Wa, MaList, ReportType):\r
52302d4d
LG
1961 self._WorkspaceDir = Wa.WorkspaceDir\r
1962 self.PlatformName = Wa.Name\r
1963 self.PlatformDscPath = Wa.Platform\r
1964 self.Architectures = " ".join(Wa.ArchList)\r
1965 self.ToolChain = Wa.ToolChain\r
1966 self.Target = Wa.BuildTarget\r
1967 self.OutputPath = os.path.join(Wa.WorkspaceDir, Wa.OutputDir)\r
1968 self.BuildEnvironment = platform.platform()\r
1969\r
1970 self.PcdReport = None\r
1971 if "PCD" in ReportType:\r
1972 self.PcdReport = PcdReport(Wa)\r
1973\r
1974 self.FdReportList = []\r
4231a819 1975 if "FLASH" in ReportType and Wa.FdfProfile and MaList is None:\r
52302d4d
LG
1976 for Fd in Wa.FdfProfile.FdDict:\r
1977 self.FdReportList.append(FdReport(Wa.FdfProfile.FdDict[Fd], Wa))\r
1978\r
1979 self.PredictionReport = None\r
1980 if "FIXED_ADDRESS" in ReportType or "EXECUTION_ORDER" in ReportType:\r
1981 self.PredictionReport = PredictionReport(Wa)\r
1982\r
e56468c0 1983 self.DepexParser = None\r
1984 if "DEPEX" in ReportType:\r
1985 self.DepexParser = DepexParser(Wa)\r
1986 \r
52302d4d 1987 self.ModuleReportList = []\r
4231a819 1988 if MaList is not None:\r
636f2be6 1989 self._IsModuleBuild = True\r
d5d56f1b
LG
1990 for Ma in MaList:\r
1991 self.ModuleReportList.append(ModuleReport(Ma, ReportType))\r
1992 else:\r
636f2be6 1993 self._IsModuleBuild = False\r
d5d56f1b 1994 for Pa in Wa.AutoGenObjectList:\r
25193a33 1995 ModuleAutoGenList = []\r
d5d56f1b 1996 for ModuleKey in Pa.Platform.Modules:\r
25193a33 1997 ModuleAutoGenList.append(Pa.Platform.Modules[ModuleKey].M)\r
4231a819 1998 if GlobalData.gFdfParser is not None:\r
25193a33
YZ
1999 if Pa.Arch in GlobalData.gFdfParser.Profile.InfDict:\r
2000 INFList = GlobalData.gFdfParser.Profile.InfDict[Pa.Arch]\r
2001 for InfName in INFList:\r
2002 InfClass = PathClass(NormPath(InfName), Wa.WorkspaceDir, Pa.Arch)\r
2003 Ma = ModuleAutoGen(Wa, InfClass, Pa.BuildTarget, Pa.ToolChain, Pa.Arch, Wa.MetaFile)\r
4231a819 2004 if Ma is None:\r
25193a33
YZ
2005 continue\r
2006 if Ma not in ModuleAutoGenList:\r
2007 ModuleAutoGenList.append(Ma)\r
2008 for MGen in ModuleAutoGenList:\r
2009 self.ModuleReportList.append(ModuleReport(MGen, ReportType))\r
52302d4d
LG
2010\r
2011\r
2012\r
2013 ##\r
2014 # Generate report for the whole platform.\r
2015 #\r
2016 # This function generates report for platform information.\r
2017 # It comprises of platform summary, global PCD, flash and\r
2018 # module list sections.\r
2019 #\r
2020 # @param self The object pointer\r
2021 # @param File The file object for report\r
2022 # @param BuildDuration The total time to build the modules\r
1b8eca8b
YZ
2023 # @param AutoGenTime The total time of AutoGen Phase\r
2024 # @param MakeTime The total time of Make Phase\r
2025 # @param GenFdsTime The total time of GenFds Phase\r
52302d4d
LG
2026 # @param ReportType The kind of report items in the final report file\r
2027 #\r
1b8eca8b 2028 def GenerateReport(self, File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, ReportType):\r
52302d4d
LG
2029 FileWrite(File, "Platform Summary")\r
2030 FileWrite(File, "Platform Name: %s" % self.PlatformName)\r
2031 FileWrite(File, "Platform DSC Path: %s" % self.PlatformDscPath)\r
2032 FileWrite(File, "Architectures: %s" % self.Architectures)\r
2033 FileWrite(File, "Tool Chain: %s" % self.ToolChain)\r
2034 FileWrite(File, "Target: %s" % self.Target)\r
e651d06c
LG
2035 if GlobalData.gSkuids:\r
2036 FileWrite(File, "SKUID: %s" % " ".join(GlobalData.gSkuids))\r
2037 if GlobalData.gDefaultStores:\r
2038 FileWrite(File, "DefaultStore: %s" % " ".join(GlobalData.gDefaultStores))\r
52302d4d
LG
2039 FileWrite(File, "Output Path: %s" % self.OutputPath)\r
2040 FileWrite(File, "Build Environment: %s" % self.BuildEnvironment)\r
2041 FileWrite(File, "Build Duration: %s" % BuildDuration)\r
1b8eca8b
YZ
2042 if AutoGenTime:\r
2043 FileWrite(File, "AutoGen Duration: %s" % AutoGenTime)\r
2044 if MakeTime:\r
2045 FileWrite(File, "Make Duration: %s" % MakeTime)\r
2046 if GenFdsTime:\r
2047 FileWrite(File, "GenFds Duration: %s" % GenFdsTime)\r
52302d4d
LG
2048 FileWrite(File, "Report Content: %s" % ", ".join(ReportType))\r
2049\r
2a29017e
YZ
2050 if GlobalData.MixedPcd:\r
2051 FileWrite(File, gSectionStart)\r
2052 FileWrite(File, "The following PCDs use different access methods:")\r
2053 FileWrite(File, gSectionSep)\r
2054 for PcdItem in GlobalData.MixedPcd:\r
2055 FileWrite(File, "%s.%s" % (str(PcdItem[1]), str(PcdItem[0])))\r
2056 FileWrite(File, gSectionEnd)\r
2057\r
636f2be6
LG
2058 if not self._IsModuleBuild:\r
2059 if "PCD" in ReportType:\r
2060 self.PcdReport.GenerateReport(File, None)\r
2061 \r
2062 if "FLASH" in ReportType:\r
2063 for FdReportListItem in self.FdReportList:\r
2064 FdReportListItem.GenerateReport(File)\r
52302d4d
LG
2065\r
2066 for ModuleReportItem in self.ModuleReportList:\r
e56468c0 2067 ModuleReportItem.GenerateReport(File, self.PcdReport, self.PredictionReport, self.DepexParser, ReportType)\r
52302d4d 2068\r
636f2be6
LG
2069 if not self._IsModuleBuild:\r
2070 if "EXECUTION_ORDER" in ReportType:\r
2071 self.PredictionReport.GenerateReport(File, None)\r
52302d4d
LG
2072\r
2073## BuildReport class\r
2074#\r
2075# This base class contain the routines to collect data and then\r
2076# applies certain format to the output report\r
2077#\r
2078class BuildReport(object):\r
2079 ##\r
2080 # Constructor function for class BuildReport\r
2081 #\r
2082 # This constructor function generates BuildReport object a platform build.\r
2083 # It generates report for platform summary, flash, global PCDs and detailed\r
2084 # module information for modules involved in platform build.\r
2085 #\r
2086 # @param self The object pointer\r
2087 # @param ReportFile The file name to save report file\r
2088 # @param ReportType The kind of report items in the final report file\r
2089 #\r
2090 def __init__(self, ReportFile, ReportType):\r
2091 self.ReportFile = ReportFile\r
2092 if ReportFile:\r
2093 self.ReportList = []\r
2094 self.ReportType = []\r
2095 if ReportType: \r
2096 for ReportTypeItem in ReportType:\r
2097 if ReportTypeItem not in self.ReportType:\r
2098 self.ReportType.append(ReportTypeItem)\r
2099 else:\r
eca5be7a 2100 self.ReportType = ["PCD", "LIBRARY", "BUILD_FLAGS", "DEPEX", "HASH", "FLASH", "FIXED_ADDRESS"]\r
52302d4d
LG
2101 ##\r
2102 # Adds platform report to the list\r
2103 #\r
2104 # This function adds a platform report to the final report list.\r
2105 #\r
2106 # @param self The object pointer\r
2107 # @param Wa Workspace context information\r
d5d56f1b 2108 # @param MaList The list of modules in the platform build\r
52302d4d 2109 #\r
d5d56f1b 2110 def AddPlatformReport(self, Wa, MaList=None):\r
52302d4d 2111 if self.ReportFile:\r
d5d56f1b 2112 self.ReportList.append((Wa, MaList))\r
52302d4d
LG
2113\r
2114 ##\r
2115 # Generates the final report.\r
2116 #\r
2117 # This function generates platform build report. It invokes GenerateReport()\r
2118 # method for every platform report in the list.\r
2119 #\r
2120 # @param self The object pointer\r
2121 # @param BuildDuration The total time to build the modules\r
1b8eca8b
YZ
2122 # @param AutoGenTime The total time of AutoGen phase\r
2123 # @param MakeTime The total time of Make phase\r
2124 # @param GenFdsTime The total time of GenFds phase\r
52302d4d 2125 #\r
1b8eca8b 2126 def GenerateReport(self, BuildDuration, AutoGenTime, MakeTime, GenFdsTime):\r
52302d4d
LG
2127 if self.ReportFile:\r
2128 try:\r
40d841f6 2129 File = StringIO('')\r
d5d56f1b 2130 for (Wa, MaList) in self.ReportList:\r
1b8eca8b 2131 PlatformReport(Wa, MaList, self.ReportType).GenerateReport(File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, self.ReportType)\r
64b2609f
LG
2132 Content = FileLinesSplit(File.getvalue(), gLineMaxLength)\r
2133 SaveFileOnChange(self.ReportFile, Content, True)\r
40d841f6 2134 EdkLogger.quiet("Build report can be found at %s" % os.path.abspath(self.ReportFile))\r
52302d4d
LG
2135 except IOError:\r
2136 EdkLogger.error(None, FILE_WRITE_FAILURE, ExtraData=self.ReportFile)\r
2137 except:\r
2138 EdkLogger.error("BuildReport", CODE_ERROR, "Unknown fatal error when generating build report", ExtraData=self.ReportFile, RaiseError=False)\r
2139 EdkLogger.quiet("(Python %s on %s\n%s)" % (platform.python_version(), sys.platform, traceback.format_exc()))\r
2140 File.close()\r
636f2be6 2141 \r
52302d4d
LG
2142# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
2143if __name__ == '__main__':\r
2144 pass\r
2145\r