BaseTools: Enable structure pcd in FDF file
[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
86379ac4 31from io import BytesIO\r
52302d4d 32from Common import EdkLogger\r
40d841f6 33from Common.Misc import SaveFileOnChange\r
52302d4d
LG
34from Common.Misc import GuidStructureByteArrayToGuidString\r
35from Common.Misc import GuidStructureStringToGuidString\r
52302d4d
LG
36from Common.BuildToolError import FILE_WRITE_FAILURE\r
37from Common.BuildToolError import CODE_ERROR\r
eca5be7a 38from Common.BuildToolError import COMMAND_FAILURE\r
35f613d9 39from Common.BuildToolError import FORMAT_INVALID\r
1be2ed90 40from Common.LongFilePathSupport import OpenLongFilePath as open\r
05cc51ad 41from Common.MultipleWorkspace import MultipleWorkspace as mws\r
763e8edf 42import Common.GlobalData as GlobalData\r
25193a33
YZ
43from AutoGen.AutoGen import ModuleAutoGen\r
44from Common.Misc import PathClass\r
5a57246e 45from Common.StringUtils import NormPath\r
e651d06c
LG
46from Common.DataType import *\r
47import collections\r
35f613d9 48from Common.Expression import *\r
52302d4d
LG
49\r
50## Pattern to extract contents in EDK DXS files\r
51gDxsDependencyPattern = re.compile(r"DEPENDENCY_START(.+)DEPENDENCY_END", re.DOTALL)\r
52\r
53## Pattern to find total FV total size, occupied size in flash report intermediate file\r
54gFvTotalSizePattern = re.compile(r"EFI_FV_TOTAL_SIZE = (0x[0-9a-fA-F]+)")\r
55gFvTakenSizePattern = re.compile(r"EFI_FV_TAKEN_SIZE = (0x[0-9a-fA-F]+)")\r
56\r
57## Pattern to find module size and time stamp in module summary report intermediate file\r
58gModuleSizePattern = re.compile(r"MODULE_SIZE = (\d+)")\r
59gTimeStampPattern = re.compile(r"TIME_STAMP = (\d+)")\r
60\r
61## Pattern to find GUID value in flash description files\r
62gPcdGuidPattern = re.compile(r"PCD\((\w+)[.](\w+)\)")\r
63\r
64## Pattern to collect offset, GUID value pair in the flash report intermediate file\r
65gOffsetGuidPattern = re.compile(r"(0x[0-9A-Fa-f]+) ([-A-Fa-f0-9]+)")\r
66\r
67## Pattern to find module base address and entry point in fixed flash map file\r
68gModulePattern = r"\n[-\w]+\s*\(([^,]+),\s*BaseAddress=%(Address)s,\s*EntryPoint=%(Address)s\)\s*\(GUID=([-0-9A-Fa-f]+)[^)]*\)"\r
69gMapFileItemPattern = re.compile(gModulePattern % {"Address" : "(-?0[xX][0-9A-Fa-f]+)"})\r
70\r
71## Pattern to find all module referenced header files in source files\r
72gIncludePattern = re.compile(r'#include\s*["<]([^">]+)[">]')\r
73gIncludePattern2 = re.compile(r"#include\s+EFI_([A-Z_]+)\s*[(]\s*(\w+)\s*[)]")\r
74\r
75## Pattern to find the entry point for EDK module using EDKII Glue library\r
76gGlueLibEntryPoint = re.compile(r"__EDKII_GLUE_MODULE_ENTRY_POINT__\s*=\s*(\w+)")\r
77\r
64b2609f
LG
78## Tags for MaxLength of line in report\r
79gLineMaxLength = 120\r
80\r
4afd3d04
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
f7496d71 223# This method is used to split the lines in file to make the length of each line\r
64b2609f
LG
224# less than MaxLength.\r
225#\r
226# @param Content The content of file\r
227# @param MaxLength The Max Length of the line\r
228#\r
229def FileLinesSplit(Content=None, MaxLength=None):\r
230 ContentList = Content.split(TAB_LINE_BREAK)\r
231 NewContent = ''\r
232 NewContentList = []\r
233 for Line in ContentList:\r
234 while len(Line.rstrip()) > MaxLength:\r
235 LineSpaceIndex = Line.rfind(TAB_SPACE_SPLIT, 0, MaxLength)\r
236 LineSlashIndex = Line.rfind(TAB_SLASH, 0, MaxLength)\r
25918452
LG
237 LineBackSlashIndex = Line.rfind(TAB_BACK_SLASH, 0, MaxLength)\r
238 if max(LineSpaceIndex, LineSlashIndex, LineBackSlashIndex) > 0:\r
239 LineBreakIndex = max(LineSpaceIndex, LineSlashIndex, LineBackSlashIndex)\r
240 else:\r
241 LineBreakIndex = MaxLength\r
64b2609f
LG
242 NewContentList.append(Line[:LineBreakIndex])\r
243 Line = Line[LineBreakIndex:]\r
244 if Line:\r
245 NewContentList.append(Line)\r
246 for NewLine in NewContentList:\r
247 NewContent += NewLine + TAB_LINE_BREAK\r
f7496d71 248\r
4afd3d04 249 NewContent = NewContent.replace(TAB_LINE_BREAK, gEndOfLine).replace('\r\r\n', gEndOfLine)\r
64b2609f 250 return NewContent\r
f7496d71
LG
251\r
252\r
253\r
e56468c0 254##\r
255# Parse binary dependency expression section\r
256#\r
257# This utility class parses the dependency expression section and translate the readable\r
258# GUID name and value.\r
259#\r
260class DepexParser(object):\r
261 ##\r
262 # Constructor function for class DepexParser\r
263 #\r
264 # This constructor function collect GUID values so that the readable\r
265 # GUID name can be translated.\r
266 #\r
267 # @param self The object pointer\r
268 # @param Wa Workspace context information\r
269 #\r
270 def __init__(self, Wa):\r
271 self._GuidDb = {}\r
0d2711a6 272 for Pa in Wa.AutoGenObjectList:\r
47fea6af 273 for Package in Pa.PackageList:\r
0d2711a6
LG
274 for Protocol in Package.Protocols:\r
275 GuidValue = GuidStructureStringToGuidString(Package.Protocols[Protocol])\r
276 self._GuidDb[GuidValue.upper()] = Protocol\r
277 for Ppi in Package.Ppis:\r
278 GuidValue = GuidStructureStringToGuidString(Package.Ppis[Ppi])\r
279 self._GuidDb[GuidValue.upper()] = Ppi\r
280 for Guid in Package.Guids:\r
281 GuidValue = GuidStructureStringToGuidString(Package.Guids[Guid])\r
282 self._GuidDb[GuidValue.upper()] = Guid\r
f7496d71 283\r
e56468c0 284 ##\r
285 # Parse the binary dependency expression files.\r
f7496d71 286 #\r
e56468c0 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
f7496d71 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 413 return\r
f7496d71 414\r
52302d4d
LG
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
f7496d71 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 1192 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:\r
ccaa7754 1193 if Value.startswith(('0x', '0X')):\r
179c2f97
YF
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 1302 if self.SkuSingle:\r
ccaa7754 1303 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', "{"))\r
779ddcdf 1304 else:\r
ccaa7754 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 1314 if self.SkuSingle:\r
ccaa7754 1315 FileWrite(File, ' %-*s : %6s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', Value))\r
779ddcdf 1316 else:\r
ccaa7754 1317 FileWrite(File, ' %-*s : %6s %10s %10s = %s' % (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + ')', '(' + SkuIdName + ')', Value))\r
779ddcdf
YZ
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
543f5ac3
B
1334 if Pcd.PcdFieldValueFromFdf:\r
1335 for Key, Values in Pcd.PcdFieldValueFromFdf.items():\r
1336 OverrideFieldStruct[Key] = Values\r
24326f38
YZ
1337 if Pcd.PcdFieldValueFromComm:\r
1338 for Key, Values in Pcd.PcdFieldValueFromComm.items():\r
1339 OverrideFieldStruct[Key] = Values\r
1340 return OverrideFieldStruct\r
1341\r
e651d06c 1342 def PrintStructureInfo(self, File, Struct):\r
e651d06c 1343 for Key, Value in Struct.items():\r
f440f7e3
YZ
1344 if Value[1] and 'build command options' in Value[1]:\r
1345 FileWrite(File, ' *B %-*s = %s' % (self.MaxLen + 4, '.' + Key, Value[0]))\r
e651d06c 1346 else:\r
f440f7e3 1347 FileWrite(File, ' %-*s = %s' % (self.MaxLen + 4, '.' + Key, Value[0]))\r
e651d06c
LG
1348\r
1349 def StrtoHex(self, value):\r
1350 try:\r
1351 value = hex(int(value))\r
1352 return value\r
1353 except:\r
1354 if value.startswith("L\"") and value.endswith("\""):\r
1355 valuelist = []\r
1356 for ch in value[2:-1]:\r
1357 valuelist.append(hex(ord(ch)))\r
1358 valuelist.append('0x00')\r
1359 return valuelist\r
1360 elif value.startswith("\"") and value.endswith("\""):\r
1361 return hex(ord(value[1:-1]))\r
1362 elif value.startswith("{") and value.endswith("}"):\r
1363 valuelist = []\r
1364 if ',' not in value:\r
1365 return value[1:-1]\r
1366 for ch in value[1:-1].split(','):\r
1367 ch = ch.strip()\r
1368 if ch.startswith('0x') or ch.startswith('0X'):\r
1369 valuelist.append(ch)\r
1370 continue\r
1371 try:\r
1372 valuelist.append(hex(int(ch.strip())))\r
1373 except:\r
1374 pass\r
1375 return valuelist\r
1376 else:\r
1377 return value\r
52302d4d
LG
1378\r
1379##\r
1380# Reports platform and module Prediction information\r
1381#\r
1382# This class reports the platform execution order prediction section and\r
1383# module load fixed address prediction subsection in the build report file.\r
1384#\r
1385class PredictionReport(object):\r
1386 ##\r
1387 # Constructor function for class PredictionReport\r
1388 #\r
1389 # This constructor function generates PredictionReport object for the platform.\r
1390 #\r
1391 # @param self: The object pointer\r
1392 # @param Wa Workspace context information\r
1393 #\r
1394 def __init__(self, Wa):\r
1395 self._MapFileName = os.path.join(Wa.BuildDir, Wa.Name + ".map")\r
1396 self._MapFileParsed = False\r
1397 self._EotToolInvoked = False\r
1398 self._FvDir = Wa.FvDir\r
1399 self._EotDir = Wa.BuildDir\r
1400 self._FfsEntryPoint = {}\r
1401 self._GuidMap = {}\r
1402 self._SourceList = []\r
1403 self.FixedMapDict = {}\r
1404 self.ItemList = []\r
1405 self.MaxLen = 0\r
1406\r
1407 #\r
1408 # Collect all platform reference source files and GUID C Name\r
1409 #\r
1410 for Pa in Wa.AutoGenObjectList:\r
1411 for Module in Pa.LibraryAutoGenList + Pa.ModuleAutoGenList:\r
1412 #\r
40d841f6
LG
1413 # BASE typed modules are EFI agnostic, so we need not scan\r
1414 # their source code to find PPI/Protocol produce or consume\r
1415 # information.\r
1416 #\r
8bb63e37 1417 if Module.ModuleType == SUP_MODULE_BASE:\r
40d841f6
LG
1418 continue\r
1419 #\r
52302d4d
LG
1420 # Add module referenced source files\r
1421 #\r
1422 self._SourceList.append(str(Module))\r
1423 IncludeList = {}\r
1424 for Source in Module.SourceFileList:\r
1425 if os.path.splitext(str(Source))[1].lower() == ".c":\r
1426 self._SourceList.append(" " + str(Source))\r
1427 FindIncludeFiles(Source.Path, Module.IncludePathList, IncludeList)\r
1428 for IncludeFile in IncludeList.values():\r
1429 self._SourceList.append(" " + IncludeFile)\r
1430\r
1431 for Guid in Module.PpiList:\r
1432 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.PpiList[Guid])\r
1433 for Guid in Module.ProtocolList:\r
1434 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.ProtocolList[Guid])\r
1435 for Guid in Module.GuidList:\r
1436 self._GuidMap[Guid] = GuidStructureStringToGuidString(Module.GuidList[Guid])\r
1437\r
1438 if Module.Guid and not Module.IsLibrary:\r
1439 EntryPoint = " ".join(Module.Module.ModuleEntryPointList)\r
1440 if int(str(Module.AutoGenVersion), 0) >= 0x00010005:\r
1441 RealEntryPoint = "_ModuleEntryPoint"\r
1442 else:\r
1443 RealEntryPoint = EntryPoint\r
1444 if EntryPoint == "_ModuleEntryPoint":\r
1445 CCFlags = Module.BuildOption.get("CC", {}).get("FLAGS", "")\r
1446 Match = gGlueLibEntryPoint.search(CCFlags)\r
1447 if Match:\r
1448 EntryPoint = Match.group(1)\r
1449\r
1450 self._FfsEntryPoint[Module.Guid.upper()] = (EntryPoint, RealEntryPoint)\r
1451\r
1452\r
1453 #\r
1454 # Collect platform firmware volume list as the input of EOT.\r
1455 #\r
1456 self._FvList = []\r
1457 if Wa.FdfProfile:\r
1458 for Fd in Wa.FdfProfile.FdDict:\r
1459 for FdRegion in Wa.FdfProfile.FdDict[Fd].RegionList:\r
91fa33ee 1460 if FdRegion.RegionType != BINARY_FILE_TYPE_FV:\r
52302d4d
LG
1461 continue\r
1462 for FvName in FdRegion.RegionDataList:\r
1463 if FvName in self._FvList:\r
1464 continue\r
1465 self._FvList.append(FvName)\r
1466 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:\r
1467 for Section in Ffs.SectionList:\r
1468 try:\r
1469 for FvSection in Section.SectionList:\r
1470 if FvSection.FvName in self._FvList:\r
1471 continue\r
1472 self._FvList.append(FvSection.FvName)\r
1473 except AttributeError:\r
1474 pass\r
1475\r
1476\r
1477 ##\r
1478 # Parse platform fixed address map files\r
1479 #\r
1480 # This function parses the platform final fixed address map file to get\r
1481 # the database of predicted fixed address for module image base, entry point\r
1482 # etc.\r
1483 #\r
1484 # @param self: The object pointer\r
1485 #\r
1486 def _ParseMapFile(self):\r
1487 if self._MapFileParsed:\r
1488 return\r
1489 self._MapFileParsed = True\r
1490 if os.path.isfile(self._MapFileName):\r
1491 try:\r
1492 FileContents = open(self._MapFileName).read()\r
1493 for Match in gMapFileItemPattern.finditer(FileContents):\r
1494 AddressType = Match.group(1)\r
1495 BaseAddress = Match.group(2)\r
1496 EntryPoint = Match.group(3)\r
1497 Guid = Match.group(4).upper()\r
1498 List = self.FixedMapDict.setdefault(Guid, [])\r
1499 List.append((AddressType, BaseAddress, "*I"))\r
1500 List.append((AddressType, EntryPoint, "*E"))\r
1501 except:\r
1502 EdkLogger.warn(None, "Cannot open file to read", self._MapFileName)\r
1503\r
1504 ##\r
1505 # Invokes EOT tool to get the predicted the execution order.\r
1506 #\r
1507 # This function invokes EOT tool to calculate the predicted dispatch order\r
1508 #\r
1509 # @param self: The object pointer\r
1510 #\r
1511 def _InvokeEotTool(self):\r
1512 if self._EotToolInvoked:\r
1513 return\r
1514\r
1515 self._EotToolInvoked = True\r
1516 FvFileList = []\r
1517 for FvName in self._FvList:\r
1518 FvFile = os.path.join(self._FvDir, FvName + ".Fv")\r
1519 if os.path.isfile(FvFile):\r
1520 FvFileList.append(FvFile)\r
1521\r
1522 if len(FvFileList) == 0:\r
1523 return\r
1524 #\r
1525 # Write source file list and GUID file list to an intermediate file\r
1526 # as the input for EOT tool and dispatch List as the output file\r
1527 # from EOT tool.\r
1528 #\r
1529 SourceList = os.path.join(self._EotDir, "SourceFile.txt")\r
1530 GuidList = os.path.join(self._EotDir, "GuidList.txt")\r
1531 DispatchList = os.path.join(self._EotDir, "Dispatch.txt")\r
1532\r
1533 TempFile = open(SourceList, "w+")\r
1534 for Item in self._SourceList:\r
1535 FileWrite(TempFile, Item)\r
1536 TempFile.close()\r
1537 TempFile = open(GuidList, "w+")\r
1538 for Key in self._GuidMap:\r
1539 FileWrite(TempFile, "%s %s" % (Key, self._GuidMap[Key]))\r
1540 TempFile.close()\r
1541\r
1542 try:\r
1543 from Eot.Eot import Eot\r
40d841f6 1544\r
52302d4d 1545 #\r
40d841f6 1546 # Invoke EOT tool and echo its runtime performance\r
52302d4d 1547 #\r
40d841f6 1548 EotStartTime = time.time()\r
52302d4d
LG
1549 Eot(CommandLineOption=False, SourceFileList=SourceList, GuidList=GuidList,\r
1550 FvFileList=' '.join(FvFileList), Dispatch=DispatchList, IsInit=True)\r
40d841f6
LG
1551 EotEndTime = time.time()\r
1552 EotDuration = time.strftime("%H:%M:%S", time.gmtime(int(round(EotEndTime - EotStartTime))))\r
1553 EdkLogger.quiet("EOT run time: %s\n" % EotDuration)\r
f7496d71 1554\r
52302d4d
LG
1555 #\r
1556 # Parse the output of EOT tool\r
1557 #\r
1558 for Line in open(DispatchList):\r
1559 if len(Line.split()) < 4:\r
1560 continue\r
1561 (Guid, Phase, FfsName, FilePath) = Line.split()\r
1562 Symbol = self._FfsEntryPoint.get(Guid, [FfsName, ""])[0]\r
1563 if len(Symbol) > self.MaxLen:\r
1564 self.MaxLen = len(Symbol)\r
1565 self.ItemList.append((Phase, Symbol, FilePath))\r
1566 except:\r
1567 EdkLogger.quiet("(Python %s on %s\n%s)" % (platform.python_version(), sys.platform, traceback.format_exc()))\r
1568 EdkLogger.warn(None, "Failed to generate execution order prediction report, for some error occurred in executing EOT.")\r
1569\r
1570\r
1571 ##\r
1572 # Generate platform execution order report\r
1573 #\r
1574 # This function generates the predicted module execution order.\r
1575 #\r
1576 # @param self The object pointer\r
1577 # @param File The file object for report\r
1578 #\r
1579 def _GenerateExecutionOrderReport(self, File):\r
1580 self._InvokeEotTool()\r
1581 if len(self.ItemList) == 0:\r
1582 return\r
1583 FileWrite(File, gSectionStart)\r
1584 FileWrite(File, "Execution Order Prediction")\r
1585 FileWrite(File, "*P PEI phase")\r
1586 FileWrite(File, "*D DXE phase")\r
1587 FileWrite(File, "*E Module INF entry point name")\r
1588 FileWrite(File, "*N Module notification function name")\r
1589\r
1590 FileWrite(File, "Type %-*s %s" % (self.MaxLen, "Symbol", "Module INF Path"))\r
1591 FileWrite(File, gSectionSep)\r
1592 for Item in self.ItemList:\r
1593 FileWrite(File, "*%sE %-*s %s" % (Item[0], self.MaxLen, Item[1], Item[2]))\r
1594\r
1595 FileWrite(File, gSectionStart)\r
1596\r
1597 ##\r
1598 # Generate Fixed Address report.\r
1599 #\r
1600 # This function generate the predicted fixed address report for a module\r
1601 # specified by Guid.\r
1602 #\r
1603 # @param self The object pointer\r
1604 # @param File The file object for report\r
1605 # @param Guid The module Guid value.\r
1606 # @param NotifyList The list of all notify function in a module\r
1607 #\r
1608 def _GenerateFixedAddressReport(self, File, Guid, NotifyList):\r
1609 self._ParseMapFile()\r
1610 FixedAddressList = self.FixedMapDict.get(Guid)\r
1611 if not FixedAddressList:\r
1612 return\r
1613\r
1614 FileWrite(File, gSubSectionStart)\r
1615 FileWrite(File, "Fixed Address Prediction")\r
1616 FileWrite(File, "*I Image Loading Address")\r
1617 FileWrite(File, "*E Entry Point Address")\r
1618 FileWrite(File, "*N Notification Function Address")\r
1619 FileWrite(File, "*F Flash Address")\r
1620 FileWrite(File, "*M Memory Address")\r
1621 FileWrite(File, "*S SMM RAM Offset")\r
1622 FileWrite(File, "TOM Top of Memory")\r
1623\r
1624 FileWrite(File, "Type Address Name")\r
1625 FileWrite(File, gSubSectionSep)\r
1626 for Item in FixedAddressList:\r
1627 Type = Item[0]\r
1628 Value = Item[1]\r
1629 Symbol = Item[2]\r
1630 if Symbol == "*I":\r
1631 Name = "(Image Base)"\r
1632 elif Symbol == "*E":\r
1633 Name = self._FfsEntryPoint.get(Guid, ["", "_ModuleEntryPoint"])[1]\r
1634 elif Symbol in NotifyList:\r
1635 Name = Symbol\r
1636 Symbol = "*N"\r
1637 else:\r
1638 continue\r
1639\r
1640 if "Flash" in Type:\r
1641 Symbol += "F"\r
1642 elif "Memory" in Type:\r
1643 Symbol += "M"\r
1644 else:\r
1645 Symbol += "S"\r
1646\r
1647 if Value[0] == "-":\r
1648 Value = "TOM" + Value\r
1649\r
1650 FileWrite(File, "%s %-16s %s" % (Symbol, Value, Name))\r
1651\r
1652 ##\r
1653 # Generate report for the prediction part\r
1654 #\r
1655 # This function generate the predicted fixed address report for a module or\r
1656 # predicted module execution order for a platform.\r
1657 # If the input Guid is None, then, it generates the predicted module execution order;\r
1658 # otherwise it generated the module fixed loading address for the module specified by\r
1659 # Guid.\r
1660 #\r
1661 # @param self The object pointer\r
1662 # @param File The file object for report\r
1663 # @param Guid The module Guid value.\r
1664 #\r
1665 def GenerateReport(self, File, Guid):\r
1666 if Guid:\r
1667 self._GenerateFixedAddressReport(File, Guid.upper(), [])\r
1668 else:\r
1669 self._GenerateExecutionOrderReport(File)\r
1670\r
1671##\r
1672# Reports FD region information\r
1673#\r
1674# This class reports the FD subsection in the build report file.\r
1675# It collects region information of platform flash device.\r
1676# If the region is a firmware volume, it lists the set of modules\r
1677# and its space information; otherwise, it only lists its region name,\r
1678# base address and size in its sub-section header.\r
1679# If there are nesting FVs, the nested FVs will list immediate after\r
1680# this FD region subsection\r
1681#\r
1682class FdRegionReport(object):\r
1683 ##\r
1684 # Discover all the nested FV name list.\r
1685 #\r
1686 # This is an internal worker function to discover the all the nested FV information\r
1687 # in the parent firmware volume. It uses deep first search algorithm recursively to\r
1688 # find all the FV list name and append them to the list.\r
1689 #\r
1690 # @param self The object pointer\r
1691 # @param FvName The name of current firmware file system\r
1692 # @param Wa Workspace context information\r
1693 #\r
1694 def _DiscoverNestedFvList(self, FvName, Wa):\r
a2432972
EC
1695 FvDictKey=FvName.upper()\r
1696 if FvDictKey in Wa.FdfProfile.FvDict:\r
1697 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:\r
1698 for Section in Ffs.SectionList:\r
1699 try:\r
1700 for FvSection in Section.SectionList:\r
1701 if FvSection.FvName in self.FvList:\r
1702 continue\r
1703 self._GuidsDb[Ffs.NameGuid.upper()] = FvSection.FvName\r
1704 self.FvList.append(FvSection.FvName)\r
1705 self.FvInfo[FvSection.FvName] = ("Nested FV", 0, 0)\r
1706 self._DiscoverNestedFvList(FvSection.FvName, Wa)\r
1707 except AttributeError:\r
1708 pass\r
52302d4d
LG
1709\r
1710 ##\r
1711 # Constructor function for class FdRegionReport\r
1712 #\r
1713 # This constructor function generates FdRegionReport object for a specified FdRegion.\r
1714 # If the FdRegion is a firmware volume, it will recursively find all its nested Firmware\r
1715 # volume list. This function also collects GUID map in order to dump module identification\r
1716 # in the final report.\r
1717 #\r
1718 # @param self: The object pointer\r
1719 # @param FdRegion The current FdRegion object\r
1720 # @param Wa Workspace context information\r
1721 #\r
1722 def __init__(self, FdRegion, Wa):\r
1723 self.Type = FdRegion.RegionType\r
1724 self.BaseAddress = FdRegion.Offset\r
1725 self.Size = FdRegion.Size\r
1726 self.FvList = []\r
1727 self.FvInfo = {}\r
1728 self._GuidsDb = {}\r
1729 self._FvDir = Wa.FvDir\r
aebe5a36 1730 self._WorkspaceDir = Wa.WorkspaceDir\r
52302d4d
LG
1731\r
1732 #\r
1733 # If the input FdRegion is not a firmware volume,\r
1734 # we are done.\r
1735 #\r
91fa33ee 1736 if self.Type != BINARY_FILE_TYPE_FV:\r
52302d4d
LG
1737 return\r
1738\r
1739 #\r
1740 # Find all nested FVs in the FdRegion\r
1741 #\r
1742 for FvName in FdRegion.RegionDataList:\r
1743 if FvName in self.FvList:\r
1744 continue\r
1745 self.FvList.append(FvName)\r
1746 self.FvInfo[FvName] = ("Fd Region", self.BaseAddress, self.Size)\r
1747 self._DiscoverNestedFvList(FvName, Wa)\r
1748\r
1749 PlatformPcds = {}\r
52302d4d
LG
1750 #\r
1751 # Collect PCDs declared in DEC files.\r
f7496d71 1752 #\r
0d2711a6
LG
1753 for Pa in Wa.AutoGenObjectList:\r
1754 for Package in Pa.PackageList:\r
1755 for (TokenCName, TokenSpaceGuidCName, DecType) in Package.Pcds:\r
1756 DecDefaultValue = Package.Pcds[TokenCName, TokenSpaceGuidCName, DecType].DefaultValue\r
1757 PlatformPcds[(TokenCName, TokenSpaceGuidCName)] = DecDefaultValue\r
52302d4d 1758 #\r
af9785a9 1759 # Collect PCDs defined in DSC file\r
52302d4d 1760 #\r
e651d06c
LG
1761 for Pa in Wa.AutoGenObjectList:\r
1762 for (TokenCName, TokenSpaceGuidCName) in Pa.Platform.Pcds:\r
1763 DscDefaultValue = Pa.Platform.Pcds[(TokenCName, TokenSpaceGuidCName)].DefaultValue\r
af9785a9 1764 PlatformPcds[(TokenCName, TokenSpaceGuidCName)] = DscDefaultValue\r
52302d4d
LG
1765\r
1766 #\r
1767 # Add PEI and DXE a priori files GUIDs defined in PI specification.\r
1768 #\r
1769 self._GuidsDb["1B45CC0A-156A-428A-AF62-49864DA0E6E6"] = "PEI Apriori"\r
1770 self._GuidsDb["FC510EE7-FFDC-11D4-BD41-0080C73C8881"] = "DXE Apriori"\r
1771 #\r
1772 # Add ACPI table storage file\r
1773 #\r
1774 self._GuidsDb["7E374E25-8E01-4FEE-87F2-390C23C606CD"] = "ACPI table storage"\r
1775\r
1776 for Pa in Wa.AutoGenObjectList:\r
1777 for ModuleKey in Pa.Platform.Modules:\r
1778 M = Pa.Platform.Modules[ModuleKey].M\r
05cc51ad 1779 InfPath = mws.join(Wa.WorkspaceDir, M.MetaFile.File)\r
52302d4d
LG
1780 self._GuidsDb[M.Guid.upper()] = "%s (%s)" % (M.Module.BaseName, InfPath)\r
1781\r
1782 #\r
1783 # Collect the GUID map in the FV firmware volume\r
1784 #\r
1785 for FvName in self.FvList:\r
a2432972
EC
1786 FvDictKey=FvName.upper()\r
1787 if FvDictKey in Wa.FdfProfile.FvDict:\r
1788 for Ffs in Wa.FdfProfile.FvDict[FvName.upper()].FfsList:\r
1789 try:\r
1790 #\r
1791 # collect GUID map for binary EFI file in FDF file.\r
1792 #\r
1793 Guid = Ffs.NameGuid.upper()\r
1794 Match = gPcdGuidPattern.match(Ffs.NameGuid)\r
1795 if Match:\r
1796 PcdTokenspace = Match.group(1)\r
1797 PcdToken = Match.group(2)\r
1798 if (PcdToken, PcdTokenspace) in PlatformPcds:\r
1799 GuidValue = PlatformPcds[(PcdToken, PcdTokenspace)]\r
1800 Guid = GuidStructureByteArrayToGuidString(GuidValue).upper()\r
1801 for Section in Ffs.SectionList:\r
1802 try:\r
1803 ModuleSectFile = mws.join(Wa.WorkspaceDir, Section.SectFileName)\r
1804 self._GuidsDb[Guid] = ModuleSectFile\r
1805 except AttributeError:\r
1806 pass\r
1807 except AttributeError:\r
1808 pass\r
52302d4d
LG
1809\r
1810\r
1811 ##\r
1812 # Internal worker function to generate report for the FD region\r
1813 #\r
1814 # This internal worker function to generate report for the FD region.\r
1815 # It the type is firmware volume, it lists offset and module identification.\r
1816 #\r
1817 # @param self The object pointer\r
1818 # @param File The file object for report\r
1819 # @param Title The title for the FD subsection\r
1820 # @param BaseAddress The base address for the FD region\r
1821 # @param Size The size of the FD region\r
1822 # @param FvName The FV name if the FD region is a firmware volume\r
1823 #\r
1824 def _GenerateReport(self, File, Title, Type, BaseAddress, Size=0, FvName=None):\r
1825 FileWrite(File, gSubSectionStart)\r
1826 FileWrite(File, Title)\r
1827 FileWrite(File, "Type: %s" % Type)\r
1828 FileWrite(File, "Base Address: 0x%X" % BaseAddress)\r
1829\r
91fa33ee 1830 if self.Type == BINARY_FILE_TYPE_FV:\r
52302d4d
LG
1831 FvTotalSize = 0\r
1832 FvTakenSize = 0\r
1833 FvFreeSize = 0\r
aebe5a36
YZ
1834 if FvName.upper().endswith('.FV'):\r
1835 FileExt = FvName + ".txt"\r
2157bc9c 1836 else:\r
aebe5a36
YZ
1837 FileExt = FvName + ".Fv.txt"\r
1838\r
1839 if not os.path.isfile(FileExt):\r
1840 FvReportFileName = mws.join(self._WorkspaceDir, FileExt)\r
1841 if not os.path.isfile(FvReportFileName):\r
1842 FvReportFileName = os.path.join(self._FvDir, FileExt)\r
52302d4d
LG
1843 try:\r
1844 #\r
1845 # Collect size info in the firmware volume.\r
1846 #\r
1847 FvReport = open(FvReportFileName).read()\r
1848 Match = gFvTotalSizePattern.search(FvReport)\r
1849 if Match:\r
1850 FvTotalSize = int(Match.group(1), 16)\r
1851 Match = gFvTakenSizePattern.search(FvReport)\r
1852 if Match:\r
1853 FvTakenSize = int(Match.group(1), 16)\r
1854 FvFreeSize = FvTotalSize - FvTakenSize\r
1855 #\r
1856 # Write size information to the report file.\r
1857 #\r
1858 FileWrite(File, "Size: 0x%X (%.0fK)" % (FvTotalSize, FvTotalSize / 1024.0))\r
1859 FileWrite(File, "Fv Name: %s (%.1f%% Full)" % (FvName, FvTakenSize * 100.0 / FvTotalSize))\r
1860 FileWrite(File, "Occupied Size: 0x%X (%.0fK)" % (FvTakenSize, FvTakenSize / 1024.0))\r
1861 FileWrite(File, "Free Size: 0x%X (%.0fK)" % (FvFreeSize, FvFreeSize / 1024.0))\r
1862 FileWrite(File, "Offset Module")\r
1863 FileWrite(File, gSubSectionSep)\r
1864 #\r
1865 # Write module offset and module identification to the report file.\r
1866 #\r
1867 OffsetInfo = {}\r
1868 for Match in gOffsetGuidPattern.finditer(FvReport):\r
1869 Guid = Match.group(2).upper()\r
1870 OffsetInfo[Match.group(1)] = self._GuidsDb.get(Guid, Guid)\r
0d1f5b2b 1871 OffsetList = sorted(OffsetInfo.keys())\r
52302d4d
LG
1872 for Offset in OffsetList:\r
1873 FileWrite (File, "%s %s" % (Offset, OffsetInfo[Offset]))\r
1874 except IOError:\r
1875 EdkLogger.warn(None, "Fail to read report file", FvReportFileName)\r
1876 else:\r
1877 FileWrite(File, "Size: 0x%X (%.0fK)" % (Size, Size / 1024.0))\r
1878 FileWrite(File, gSubSectionEnd)\r
1879\r
1880 ##\r
1881 # Generate report for the FD region\r
1882 #\r
1883 # This function generates report for the FD region.\r
1884 #\r
1885 # @param self The object pointer\r
1886 # @param File The file object for report\r
1887 #\r
1888 def GenerateReport(self, File):\r
1889 if (len(self.FvList) > 0):\r
1890 for FvItem in self.FvList:\r
1891 Info = self.FvInfo[FvItem]\r
91fa33ee 1892 self._GenerateReport(File, Info[0], TAB_FV_DIRECTORY, Info[1], Info[2], FvItem)\r
52302d4d
LG
1893 else:\r
1894 self._GenerateReport(File, "FD Region", self.Type, self.BaseAddress, self.Size)\r
1895\r
1896##\r
1897# Reports FD information\r
1898#\r
1899# This class reports the FD section in the build report file.\r
1900# It collects flash device information for a platform.\r
1901#\r
1902class FdReport(object):\r
1903 ##\r
1904 # Constructor function for class FdReport\r
1905 #\r
1906 # This constructor function generates FdReport object for a specified\r
1907 # firmware device.\r
1908 #\r
1909 # @param self The object pointer\r
1910 # @param Fd The current Firmware device object\r
1911 # @param Wa Workspace context information\r
1912 #\r
1913 def __init__(self, Fd, Wa):\r
1914 self.FdName = Fd.FdUiName\r
1915 self.BaseAddress = Fd.BaseAddress\r
1916 self.Size = Fd.Size\r
1917 self.FdRegionList = [FdRegionReport(FdRegion, Wa) for FdRegion in Fd.RegionList]\r
91fa33ee 1918 self.FvPath = os.path.join(Wa.BuildDir, TAB_FV_DIRECTORY)\r
fb3d2279 1919 self.VpdFilePath = os.path.join(self.FvPath, "%s.map" % Wa.Platform.VpdToolGuid)\r
043928da
YZ
1920 self.VPDBaseAddress = 0\r
1921 self.VPDSize = 0\r
fb3d2279
YZ
1922 self.VPDInfoList = []\r
1923 for index, FdRegion in enumerate(Fd.RegionList):\r
043928da 1924 if str(FdRegion.RegionType) is 'FILE' and Wa.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
fb3d2279
YZ
1925 self.VPDBaseAddress = self.FdRegionList[index].BaseAddress\r
1926 self.VPDSize = self.FdRegionList[index].Size\r
1927 break\r
1928\r
1929 if os.path.isfile(self.VpdFilePath):\r
1930 fd = open(self.VpdFilePath, "r")\r
1931 Lines = fd.readlines()\r
1932 for Line in Lines:\r
1933 Line = Line.strip()\r
1934 if len(Line) == 0 or Line.startswith("#"):\r
1935 continue\r
1936 try:\r
1937 PcdName, SkuId, Offset, Size, Value = Line.split("#")[0].split("|")\r
1938 PcdName, SkuId, Offset, Size, Value = PcdName.strip(), SkuId.strip(), Offset.strip(), Size.strip(), Value.strip()\r
8401d398
YZ
1939 if Offset.lower().startswith('0x'):\r
1940 Offset = '0x%08X' % (int(Offset, 16) + self.VPDBaseAddress)\r
1941 else:\r
1942 Offset = '0x%08X' % (int(Offset, 10) + self.VPDBaseAddress)\r
fb3d2279
YZ
1943 self.VPDInfoList.append("%s | %s | %s | %s | %s" % (PcdName, SkuId, Offset, Size, Value))\r
1944 except:\r
1945 EdkLogger.error("BuildReport", CODE_ERROR, "Fail to parse VPD information file %s" % self.VpdFilePath)\r
1946 fd.close()\r
52302d4d
LG
1947\r
1948 ##\r
1949 # Generate report for the firmware device.\r
1950 #\r
1951 # This function generates report for the firmware device.\r
1952 #\r
1953 # @param self The object pointer\r
1954 # @param File The file object for report\r
1955 #\r
1956 def GenerateReport(self, File):\r
1957 FileWrite(File, gSectionStart)\r
1958 FileWrite(File, "Firmware Device (FD)")\r
1959 FileWrite(File, "FD Name: %s" % self.FdName)\r
1960 FileWrite(File, "Base Address: %s" % self.BaseAddress)\r
1961 FileWrite(File, "Size: 0x%X (%.0fK)" % (self.Size, self.Size / 1024.0))\r
1962 if len(self.FdRegionList) > 0:\r
1963 FileWrite(File, gSectionSep)\r
1964 for FdRegionItem in self.FdRegionList:\r
1965 FdRegionItem.GenerateReport(File)\r
1966\r
fb3d2279
YZ
1967 if len(self.VPDInfoList) > 0:\r
1968 FileWrite(File, gSubSectionStart)\r
1969 FileWrite(File, "FD VPD Region")\r
1970 FileWrite(File, "Base Address: 0x%X" % self.VPDBaseAddress)\r
1971 FileWrite(File, "Size: 0x%X (%.0fK)" % (self.VPDSize, self.VPDSize / 1024.0))\r
1972 FileWrite(File, gSubSectionSep)\r
1973 for item in self.VPDInfoList:\r
e651d06c
LG
1974 ValueList = item.split('|')\r
1975 Value = ValueList[-1].strip()\r
1976 IsByteArray, ArrayList = ByteArrayForamt(Value)\r
1977 if IsByteArray:\r
1978 ValueList[-1] = ' {'\r
1979 FileWrite(File, '|'.join(ValueList))\r
1980 for Array in ArrayList:\r
caf74495 1981 FileWrite(File, Array)\r
e651d06c
LG
1982 else:\r
1983 FileWrite(File, item)\r
fb3d2279 1984 FileWrite(File, gSubSectionEnd)\r
52302d4d
LG
1985 FileWrite(File, gSectionEnd)\r
1986\r
1987\r
1988\r
1989##\r
1990# Reports platform information\r
1991#\r
1992# This class reports the whole platform information\r
1993#\r
1994class PlatformReport(object):\r
1995 ##\r
1996 # Constructor function for class PlatformReport\r
1997 #\r
1998 # This constructor function generates PlatformReport object a platform build.\r
1999 # It generates report for platform summary, flash, global PCDs and detailed\r
2000 # module information for modules involved in platform build.\r
2001 #\r
2002 # @param self The object pointer\r
2003 # @param Wa Workspace context information\r
d5d56f1b 2004 # @param MaList The list of modules in the platform build\r
52302d4d 2005 #\r
d5d56f1b 2006 def __init__(self, Wa, MaList, ReportType):\r
52302d4d
LG
2007 self._WorkspaceDir = Wa.WorkspaceDir\r
2008 self.PlatformName = Wa.Name\r
2009 self.PlatformDscPath = Wa.Platform\r
2010 self.Architectures = " ".join(Wa.ArchList)\r
2011 self.ToolChain = Wa.ToolChain\r
2012 self.Target = Wa.BuildTarget\r
2013 self.OutputPath = os.path.join(Wa.WorkspaceDir, Wa.OutputDir)\r
2014 self.BuildEnvironment = platform.platform()\r
2015\r
2016 self.PcdReport = None\r
2017 if "PCD" in ReportType:\r
2018 self.PcdReport = PcdReport(Wa)\r
2019\r
2020 self.FdReportList = []\r
4231a819 2021 if "FLASH" in ReportType and Wa.FdfProfile and MaList is None:\r
52302d4d
LG
2022 for Fd in Wa.FdfProfile.FdDict:\r
2023 self.FdReportList.append(FdReport(Wa.FdfProfile.FdDict[Fd], Wa))\r
2024\r
2025 self.PredictionReport = None\r
2026 if "FIXED_ADDRESS" in ReportType or "EXECUTION_ORDER" in ReportType:\r
2027 self.PredictionReport = PredictionReport(Wa)\r
2028\r
e56468c0 2029 self.DepexParser = None\r
2030 if "DEPEX" in ReportType:\r
2031 self.DepexParser = DepexParser(Wa)\r
f7496d71 2032\r
52302d4d 2033 self.ModuleReportList = []\r
4231a819 2034 if MaList is not None:\r
636f2be6 2035 self._IsModuleBuild = True\r
d5d56f1b
LG
2036 for Ma in MaList:\r
2037 self.ModuleReportList.append(ModuleReport(Ma, ReportType))\r
2038 else:\r
636f2be6 2039 self._IsModuleBuild = False\r
d5d56f1b 2040 for Pa in Wa.AutoGenObjectList:\r
25193a33 2041 ModuleAutoGenList = []\r
d5d56f1b 2042 for ModuleKey in Pa.Platform.Modules:\r
25193a33 2043 ModuleAutoGenList.append(Pa.Platform.Modules[ModuleKey].M)\r
4231a819 2044 if GlobalData.gFdfParser is not None:\r
25193a33
YZ
2045 if Pa.Arch in GlobalData.gFdfParser.Profile.InfDict:\r
2046 INFList = GlobalData.gFdfParser.Profile.InfDict[Pa.Arch]\r
2047 for InfName in INFList:\r
2048 InfClass = PathClass(NormPath(InfName), Wa.WorkspaceDir, Pa.Arch)\r
2049 Ma = ModuleAutoGen(Wa, InfClass, Pa.BuildTarget, Pa.ToolChain, Pa.Arch, Wa.MetaFile)\r
4231a819 2050 if Ma is None:\r
25193a33
YZ
2051 continue\r
2052 if Ma not in ModuleAutoGenList:\r
2053 ModuleAutoGenList.append(Ma)\r
2054 for MGen in ModuleAutoGenList:\r
2055 self.ModuleReportList.append(ModuleReport(MGen, ReportType))\r
52302d4d
LG
2056\r
2057\r
2058\r
2059 ##\r
2060 # Generate report for the whole platform.\r
2061 #\r
2062 # This function generates report for platform information.\r
2063 # It comprises of platform summary, global PCD, flash and\r
2064 # module list sections.\r
2065 #\r
2066 # @param self The object pointer\r
2067 # @param File The file object for report\r
2068 # @param BuildDuration The total time to build the modules\r
1b8eca8b
YZ
2069 # @param AutoGenTime The total time of AutoGen Phase\r
2070 # @param MakeTime The total time of Make Phase\r
2071 # @param GenFdsTime The total time of GenFds Phase\r
52302d4d
LG
2072 # @param ReportType The kind of report items in the final report file\r
2073 #\r
1b8eca8b 2074 def GenerateReport(self, File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, ReportType):\r
52302d4d
LG
2075 FileWrite(File, "Platform Summary")\r
2076 FileWrite(File, "Platform Name: %s" % self.PlatformName)\r
2077 FileWrite(File, "Platform DSC Path: %s" % self.PlatformDscPath)\r
2078 FileWrite(File, "Architectures: %s" % self.Architectures)\r
2079 FileWrite(File, "Tool Chain: %s" % self.ToolChain)\r
2080 FileWrite(File, "Target: %s" % self.Target)\r
e651d06c
LG
2081 if GlobalData.gSkuids:\r
2082 FileWrite(File, "SKUID: %s" % " ".join(GlobalData.gSkuids))\r
2083 if GlobalData.gDefaultStores:\r
2084 FileWrite(File, "DefaultStore: %s" % " ".join(GlobalData.gDefaultStores))\r
52302d4d
LG
2085 FileWrite(File, "Output Path: %s" % self.OutputPath)\r
2086 FileWrite(File, "Build Environment: %s" % self.BuildEnvironment)\r
2087 FileWrite(File, "Build Duration: %s" % BuildDuration)\r
1b8eca8b
YZ
2088 if AutoGenTime:\r
2089 FileWrite(File, "AutoGen Duration: %s" % AutoGenTime)\r
2090 if MakeTime:\r
2091 FileWrite(File, "Make Duration: %s" % MakeTime)\r
2092 if GenFdsTime:\r
2093 FileWrite(File, "GenFds Duration: %s" % GenFdsTime)\r
52302d4d
LG
2094 FileWrite(File, "Report Content: %s" % ", ".join(ReportType))\r
2095\r
2a29017e
YZ
2096 if GlobalData.MixedPcd:\r
2097 FileWrite(File, gSectionStart)\r
2098 FileWrite(File, "The following PCDs use different access methods:")\r
2099 FileWrite(File, gSectionSep)\r
2100 for PcdItem in GlobalData.MixedPcd:\r
2101 FileWrite(File, "%s.%s" % (str(PcdItem[1]), str(PcdItem[0])))\r
2102 FileWrite(File, gSectionEnd)\r
2103\r
636f2be6
LG
2104 if not self._IsModuleBuild:\r
2105 if "PCD" in ReportType:\r
2106 self.PcdReport.GenerateReport(File, None)\r
f7496d71 2107\r
636f2be6
LG
2108 if "FLASH" in ReportType:\r
2109 for FdReportListItem in self.FdReportList:\r
2110 FdReportListItem.GenerateReport(File)\r
52302d4d
LG
2111\r
2112 for ModuleReportItem in self.ModuleReportList:\r
e56468c0 2113 ModuleReportItem.GenerateReport(File, self.PcdReport, self.PredictionReport, self.DepexParser, ReportType)\r
52302d4d 2114\r
636f2be6
LG
2115 if not self._IsModuleBuild:\r
2116 if "EXECUTION_ORDER" in ReportType:\r
2117 self.PredictionReport.GenerateReport(File, None)\r
52302d4d
LG
2118\r
2119## BuildReport class\r
2120#\r
2121# This base class contain the routines to collect data and then\r
2122# applies certain format to the output report\r
2123#\r
2124class BuildReport(object):\r
2125 ##\r
2126 # Constructor function for class BuildReport\r
2127 #\r
2128 # This constructor function generates BuildReport object a platform build.\r
2129 # It generates report for platform summary, flash, global PCDs and detailed\r
2130 # module information for modules involved in platform build.\r
2131 #\r
2132 # @param self The object pointer\r
2133 # @param ReportFile The file name to save report file\r
2134 # @param ReportType The kind of report items in the final report file\r
2135 #\r
2136 def __init__(self, ReportFile, ReportType):\r
2137 self.ReportFile = ReportFile\r
2138 if ReportFile:\r
2139 self.ReportList = []\r
2140 self.ReportType = []\r
f7496d71 2141 if ReportType:\r
52302d4d
LG
2142 for ReportTypeItem in ReportType:\r
2143 if ReportTypeItem not in self.ReportType:\r
2144 self.ReportType.append(ReportTypeItem)\r
2145 else:\r
eca5be7a 2146 self.ReportType = ["PCD", "LIBRARY", "BUILD_FLAGS", "DEPEX", "HASH", "FLASH", "FIXED_ADDRESS"]\r
52302d4d
LG
2147 ##\r
2148 # Adds platform report to the list\r
2149 #\r
2150 # This function adds a platform report to the final report list.\r
2151 #\r
2152 # @param self The object pointer\r
2153 # @param Wa Workspace context information\r
d5d56f1b 2154 # @param MaList The list of modules in the platform build\r
52302d4d 2155 #\r
d5d56f1b 2156 def AddPlatformReport(self, Wa, MaList=None):\r
52302d4d 2157 if self.ReportFile:\r
d5d56f1b 2158 self.ReportList.append((Wa, MaList))\r
52302d4d
LG
2159\r
2160 ##\r
2161 # Generates the final report.\r
2162 #\r
2163 # This function generates platform build report. It invokes GenerateReport()\r
2164 # method for every platform report in the list.\r
2165 #\r
2166 # @param self The object pointer\r
2167 # @param BuildDuration The total time to build the modules\r
1b8eca8b
YZ
2168 # @param AutoGenTime The total time of AutoGen phase\r
2169 # @param MakeTime The total time of Make phase\r
2170 # @param GenFdsTime The total time of GenFds phase\r
52302d4d 2171 #\r
1b8eca8b 2172 def GenerateReport(self, BuildDuration, AutoGenTime, MakeTime, GenFdsTime):\r
52302d4d
LG
2173 if self.ReportFile:\r
2174 try:\r
86379ac4 2175 File = BytesIO('')\r
d5d56f1b 2176 for (Wa, MaList) in self.ReportList:\r
1b8eca8b 2177 PlatformReport(Wa, MaList, self.ReportType).GenerateReport(File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, self.ReportType)\r
64b2609f
LG
2178 Content = FileLinesSplit(File.getvalue(), gLineMaxLength)\r
2179 SaveFileOnChange(self.ReportFile, Content, True)\r
40d841f6 2180 EdkLogger.quiet("Build report can be found at %s" % os.path.abspath(self.ReportFile))\r
52302d4d
LG
2181 except IOError:\r
2182 EdkLogger.error(None, FILE_WRITE_FAILURE, ExtraData=self.ReportFile)\r
2183 except:\r
2184 EdkLogger.error("BuildReport", CODE_ERROR, "Unknown fatal error when generating build report", ExtraData=self.ReportFile, RaiseError=False)\r
2185 EdkLogger.quiet("(Python %s on %s\n%s)" % (platform.python_version(), sys.platform, traceback.format_exc()))\r
2186 File.close()\r
f7496d71 2187\r
52302d4d
LG
2188# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
2189if __name__ == '__main__':\r
2190 pass\r
2191\r