2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 from __future__
import absolute_import
16 from Common
.DataType
import *
17 from Common
.Misc
import *
18 from Common
.caching
import cached_property
, cached_class_function
20 from .MetaFileParser
import *
21 from collections
import OrderedDict
22 from Workspace
.BuildClassObject
import ModuleBuildClassObject
, LibraryClassObject
, PcdClassObject
24 ## Get Protocol value from given packages
26 # @param CName The CName of the GUID
27 # @param PackageList List of packages looking-up in
28 # @param Inffile The driver file
30 # @retval GuidValue if the CName is found in any given package
31 # @retval None if the CName is not found in all given packages
33 def _ProtocolValue(CName
, PackageList
, Inffile
= None):
35 ProtocolKeys
= list(P
.Protocols
.keys())
36 if Inffile
and P
._PrivateProtocols
:
37 if not Inffile
.startswith(P
.MetaFile
.Dir
):
38 ProtocolKeys
= [x
for x
in P
.Protocols
if x
not in P
._PrivateProtocols
]
39 if CName
in ProtocolKeys
:
40 return P
.Protocols
[CName
]
43 ## Get PPI value from given packages
45 # @param CName The CName of the GUID
46 # @param PackageList List of packages looking-up in
47 # @param Inffile The driver file
49 # @retval GuidValue if the CName is found in any given package
50 # @retval None if the CName is not found in all given packages
52 def _PpiValue(CName
, PackageList
, Inffile
= None):
54 PpiKeys
= list(P
.Ppis
.keys())
55 if Inffile
and P
._PrivatePpis
:
56 if not Inffile
.startswith(P
.MetaFile
.Dir
):
57 PpiKeys
= [x
for x
in P
.Ppis
if x
not in P
._PrivatePpis
]
62 ## Module build information from INF file
64 # This class is used to retrieve information stored in database and convert them
65 # into ModuleBuildClassObject form for easier use for AutoGen.
67 class InfBuildData(ModuleBuildClassObject
):
68 # dict used to convert PCD type in database to string used by build tool
70 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
71 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
72 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
73 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
74 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
75 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
76 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
77 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
78 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
79 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
80 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
83 # dict used to convert part of [Defines] to members of InfBuildData directly
88 TAB_INF_DEFINES_BASE_NAME
: "_BaseName",
89 TAB_INF_DEFINES_FILE_GUID
: "_Guid",
90 TAB_INF_DEFINES_MODULE_TYPE
: "_ModuleType",
94 # TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
95 TAB_INF_DEFINES_COMPONENT_TYPE
: "_ComponentType",
96 TAB_INF_DEFINES_MAKEFILE_NAME
: "_MakefileName",
97 # TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
98 TAB_INF_DEFINES_DPX_SOURCE
:"_DxsFile",
99 TAB_INF_DEFINES_VERSION_NUMBER
: "_Version",
100 TAB_INF_DEFINES_VERSION_STRING
: "_Version",
101 TAB_INF_DEFINES_VERSION
: "_Version",
102 TAB_INF_DEFINES_PCD_IS_DRIVER
: "_PcdIsDriver",
103 TAB_INF_DEFINES_SHADOW
: "_Shadow",
105 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH
: "_SourceOverridePath",
108 # regular expression for converting XXX_FLAGS in [nmake] section to new type
109 _NMAKE_FLAG_PATTERN_
= re
.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re
.UNICODE
)
110 # dict used to convert old tool name used in [nmake] section to new ones
113 BINARY_FILE_TYPE_LIB
: "SLINK",
118 ## Constructor of InfBuildData
120 # Initialize object of InfBuildData
122 # @param FilePath The path of platform description file
123 # @param RawData The raw data of DSC file
124 # @param BuildDataBase Database used to retrieve module/package information
125 # @param Arch The target architecture
126 # @param Platform The name of platform employing this module
127 # @param Macros Macros used for replacement in DSC file
129 def __init__(self
, FilePath
, RawData
, BuildDatabase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
130 self
.MetaFile
= FilePath
131 self
._ModuleDir
= FilePath
.Dir
132 self
._RawData
= RawData
133 self
._Bdb
= BuildDatabase
135 self
._Target
= Target
136 self
._Toolchain
= Toolchain
137 self
._Platform
= TAB_COMMON
138 if FilePath
.Key
in GlobalData
.gOverrideDir
:
139 self
._SourceOverridePath
= GlobalData
.gOverrideDir
[FilePath
.Key
]
141 self
._SourceOverridePath
= None
142 self
._TailComments
= None
143 self
._BaseName
= None
145 self
._ModuleType
= None
146 self
._ComponentType
= None
147 self
._BuildType
= None
150 self
._PcdIsDriver
= None
151 self
._BinaryModule
= None
153 self
._MakefileName
= None
154 self
._CustomMakefile
= None
155 self
._Specification
= None
156 self
._LibraryClass
= None
157 self
._ModuleEntryPointList
= None
158 self
._ModuleUnloadImageList
= None
159 self
._ConstructorList
= None
160 self
._DestructorList
= None
161 self
._Defs
= OrderedDict()
162 self
._ProtocolComments
= None
163 self
._PpiComments
= None
164 self
._GuidsUsedByPcd
= OrderedDict()
165 self
._GuidComments
= None
166 self
._PcdComments
= None
167 self
._BuildOptions
= None
168 self
._DependencyFileList
= None
171 def __setitem__(self
, key
, value
):
172 self
.__dict
__[self
._PROPERTY
_[key
]] = value
175 def __getitem__(self
, key
):
176 return self
.__dict
__[self
._PROPERTY
_[key
]]
179 def __contains__(self
, key
):
180 return key
in self
._PROPERTY
_
182 ## Get current effective macros
193 ## Return the name of platform employing this module
196 return self
._Platform
199 def HeaderComments(self
):
200 return [a
[0] for a
in self
._RawData
[MODEL_META_DATA_HEADER_COMMENT
]]
203 def TailComments(self
):
204 return [a
[0] for a
in self
._RawData
[MODEL_META_DATA_TAIL_COMMENT
]]
206 ## Retrieve all information in [Defines] section
208 # (Retrieving all [Defines] information in one-shot is just to save time.)
210 @cached_class_function
211 def _GetHeaderInfo(self
):
212 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
213 for Record
in RecordList
:
214 Name
, Value
= Record
[1], ReplaceMacro(Record
[2], self
._Macros
, False)
215 # items defined _PROPERTY_ don't need additional processing
218 self
._Defs
[Name
] = Value
219 self
._Macros
[Name
] = Value
220 # some special items in [Defines] section need special treatment
221 elif Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
222 if Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
223 Name
= 'UEFI_SPECIFICATION_VERSION'
224 if self
._Specification
is None:
225 self
._Specification
= OrderedDict()
226 self
._Specification
[Name
] = GetHexVerValue(Value
)
227 if self
._Specification
[Name
] is None:
228 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
229 "'%s' format is not supported for %s" % (Value
, Name
),
230 File
=self
.MetaFile
, Line
=Record
[-1])
231 elif Name
== 'LIBRARY_CLASS':
232 if self
._LibraryClass
is None:
233 self
._LibraryClass
= []
234 ValueList
= GetSplitValueList(Value
)
235 LibraryClass
= ValueList
[0]
236 if len(ValueList
) > 1:
237 SupModuleList
= GetSplitValueList(ValueList
[1], ' ')
239 SupModuleList
= SUP_MODULE_LIST
240 self
._LibraryClass
.append(LibraryClassObject(LibraryClass
, SupModuleList
))
241 elif Name
== 'ENTRY_POINT':
242 if self
._ModuleEntryPointList
is None:
243 self
._ModuleEntryPointList
= []
244 self
._ModuleEntryPointList
.append(Value
)
245 elif Name
== 'UNLOAD_IMAGE':
246 if self
._ModuleUnloadImageList
is None:
247 self
._ModuleUnloadImageList
= []
250 self
._ModuleUnloadImageList
.append(Value
)
251 elif Name
== 'CONSTRUCTOR':
252 if self
._ConstructorList
is None:
253 self
._ConstructorList
= []
256 self
._ConstructorList
.append(Value
)
257 elif Name
== 'DESTRUCTOR':
258 if self
._DestructorList
is None:
259 self
._DestructorList
= []
262 self
._DestructorList
.append(Value
)
263 elif Name
== TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
264 TokenList
= GetSplitValueList(Value
)
265 if self
._CustomMakefile
is None:
266 self
._CustomMakefile
= {}
267 if len(TokenList
) < 2:
268 self
._CustomMakefile
[TAB_COMPILER_MSFT
] = TokenList
[0]
269 self
._CustomMakefile
['GCC'] = TokenList
[0]
271 if TokenList
[0] not in [TAB_COMPILER_MSFT
, 'GCC']:
272 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
273 "No supported family [%s]" % TokenList
[0],
274 File
=self
.MetaFile
, Line
=Record
[-1])
275 self
._CustomMakefile
[TokenList
[0]] = TokenList
[1]
277 self
._Defs
[Name
] = Value
278 self
._Macros
[Name
] = Value
281 # Retrieve information in sections specific to Edk.x modules
283 if not self
._ModuleType
:
284 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
285 "MODULE_TYPE is not given", File
=self
.MetaFile
)
286 if self
._ModuleType
not in SUP_MODULE_LIST
:
287 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
288 for Record
in RecordList
:
290 if Name
== "MODULE_TYPE":
293 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
294 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self
._ModuleType
, ' '.join(l
for l
in SUP_MODULE_LIST
)),
295 File
=self
.MetaFile
, Line
=LineNo
)
296 if (self
._Specification
is None) or (not 'PI_SPECIFICATION_VERSION' in self
._Specification
) or (int(self
._Specification
['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
297 if self
._ModuleType
== SUP_MODULE_SMM_CORE
:
298 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File
=self
.MetaFile
)
299 if (self
._Specification
is None) or (not 'PI_SPECIFICATION_VERSION' in self
._Specification
) or (int(self
._Specification
['PI_SPECIFICATION_VERSION'], 16) < 0x00010032):
300 if self
._ModuleType
== SUP_MODULE_MM_CORE_STANDALONE
:
301 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "MM_CORE_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File
=self
.MetaFile
)
302 if self
._ModuleType
== SUP_MODULE_MM_STANDALONE
:
303 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "MM_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File
=self
.MetaFile
)
304 if 'PCI_DEVICE_ID' in self
._Defs
and 'PCI_VENDOR_ID' in self
._Defs \
305 and 'PCI_CLASS_CODE' in self
._Defs
and 'PCI_REVISION' in self
._Defs
:
306 self
._BuildType
= 'UEFI_OPTIONROM'
307 if 'PCI_COMPRESS' in self
._Defs
:
308 if self
._Defs
['PCI_COMPRESS'] not in ('TRUE', 'FALSE'):
309 EdkLogger
.error("build", FORMAT_INVALID
, "Expected TRUE/FALSE for PCI_COMPRESS: %s" % self
.MetaFile
)
311 elif 'UEFI_HII_RESOURCE_SECTION' in self
._Defs \
312 and self
._Defs
['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
313 self
._BuildType
= 'UEFI_HII'
315 self
._BuildType
= self
._ModuleType
.upper()
318 File
= PathClass(NormPath(self
._DxsFile
), self
._ModuleDir
, Arch
=self
._Arch
)
319 # check the file validation
320 ErrorCode
, ErrorInfo
= File
.Validate(".dxs", CaseSensitive
=False)
322 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
,
323 File
=self
.MetaFile
, Line
=LineNo
)
324 if not self
._DependencyFileList
:
325 self
._DependencyFileList
= []
326 self
._DependencyFileList
.append(File
)
328 ## Retrieve file version
330 def AutoGenVersion(self
):
332 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
333 for Record
in RecordList
:
334 if Record
[1] == TAB_INF_DEFINES_INF_VERSION
:
336 ValueList
= Record
[2].split('.')
337 Major
= '%04o' % int(ValueList
[0], 0)
338 Minor
= '%04o' % int(ValueList
[1], 0)
339 RetVal
= int('0x' + Major
+ Minor
, 0)
341 RetVal
= int(Record
[2], 0)
345 ## Retrieve BASE_NAME
348 if self
._BaseName
is None:
349 self
._GetHeaderInfo
()
350 if self
._BaseName
is None:
351 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BASE_NAME name", File
=self
.MetaFile
)
352 return self
._BaseName
357 if self
._DxsFile
is None:
358 self
._GetHeaderInfo
()
359 if self
._DxsFile
is None:
363 ## Retrieve MODULE_TYPE
365 def ModuleType(self
):
366 if self
._ModuleType
is None:
367 self
._GetHeaderInfo
()
368 if self
._ModuleType
is None:
369 self
._ModuleType
= SUP_MODULE_BASE
370 if self
._ModuleType
not in SUP_MODULE_LIST
:
371 self
._ModuleType
= SUP_MODULE_USER_DEFINED
372 return self
._ModuleType
374 ## Retrieve COMPONENT_TYPE
376 def ComponentType(self
):
377 if self
._ComponentType
is None:
378 self
._GetHeaderInfo
()
379 if self
._ComponentType
is None:
380 self
._ComponentType
= SUP_MODULE_USER_DEFINED
381 return self
._ComponentType
383 ## Retrieve "BUILD_TYPE"
386 if self
._BuildType
is None:
387 self
._GetHeaderInfo
()
388 if not self
._BuildType
:
389 self
._BuildType
= SUP_MODULE_BASE
390 return self
._BuildType
392 ## Retrieve file guid
395 if self
._Guid
is None:
396 self
._GetHeaderInfo
()
397 if self
._Guid
is None:
398 self
._Guid
= '00000000-0000-0000-0000-000000000000'
401 ## Retrieve module version
404 if self
._Version
is None:
405 self
._GetHeaderInfo
()
406 if self
._Version
is None:
407 self
._Version
= '0.0'
410 ## Retrieve PCD_IS_DRIVER
412 def PcdIsDriver(self
):
413 if self
._PcdIsDriver
is None:
414 self
._GetHeaderInfo
()
415 if self
._PcdIsDriver
is None:
416 self
._PcdIsDriver
= ''
417 return self
._PcdIsDriver
422 if self
._Shadow
is None:
423 self
._GetHeaderInfo
()
424 if self
._Shadow
and self
._Shadow
.upper() == 'TRUE':
430 ## Retrieve CUSTOM_MAKEFILE
432 def CustomMakefile(self
):
433 if self
._CustomMakefile
is None:
434 self
._GetHeaderInfo
()
435 if self
._CustomMakefile
is None:
436 self
._CustomMakefile
= {}
437 return self
._CustomMakefile
439 ## Retrieve EFI_SPECIFICATION_VERSION
441 def Specification(self
):
442 if self
._Specification
is None:
443 self
._GetHeaderInfo
()
444 if self
._Specification
is None:
445 self
._Specification
= {}
446 return self
._Specification
448 ## Retrieve LIBRARY_CLASS
450 def LibraryClass(self
):
451 if self
._LibraryClass
is None:
452 self
._GetHeaderInfo
()
453 if self
._LibraryClass
is None:
454 self
._LibraryClass
= []
455 return self
._LibraryClass
457 ## Retrieve ENTRY_POINT
459 def ModuleEntryPointList(self
):
460 if self
._ModuleEntryPointList
is None:
461 self
._GetHeaderInfo
()
462 if self
._ModuleEntryPointList
is None:
463 self
._ModuleEntryPointList
= []
464 return self
._ModuleEntryPointList
466 ## Retrieve UNLOAD_IMAGE
468 def ModuleUnloadImageList(self
):
469 if self
._ModuleUnloadImageList
is None:
470 self
._GetHeaderInfo
()
471 if self
._ModuleUnloadImageList
is None:
472 self
._ModuleUnloadImageList
= []
473 return self
._ModuleUnloadImageList
475 ## Retrieve CONSTRUCTOR
477 def ConstructorList(self
):
478 if self
._ConstructorList
is None:
479 self
._GetHeaderInfo
()
480 if self
._ConstructorList
is None:
481 self
._ConstructorList
= []
482 return self
._ConstructorList
484 ## Retrieve DESTRUCTOR
486 def DestructorList(self
):
487 if self
._DestructorList
is None:
488 self
._GetHeaderInfo
()
489 if self
._DestructorList
is None:
490 self
._DestructorList
= []
491 return self
._DestructorList
493 ## Retrieve definies other than above ones
496 self
._GetHeaderInfo
()
499 ## Retrieve binary files
500 @cached_class_function
501 def _GetBinaries(self
):
503 RecordList
= self
._RawData
[MODEL_EFI_BINARY_FILE
, self
._Arch
, self
._Platform
]
504 Macros
= self
._Macros
505 Macros
['PROCESSOR'] = self
._Arch
506 for Record
in RecordList
:
512 TokenList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
514 Target
= TokenList
[0]
515 if len(TokenList
) > 1:
516 FeatureFlag
= Record
[1:]
518 File
= PathClass(NormPath(Record
[1], Macros
), self
._ModuleDir
, '', FileType
, True, self
._Arch
, '', Target
)
519 # check the file validation
520 ErrorCode
, ErrorInfo
= File
.Validate()
522 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
526 ## Retrieve binary files with error check.
529 RetVal
= self
._GetBinaries
()
530 if GlobalData
.gIgnoreSource
and not RetVal
:
531 ErrorInfo
= "The INF file does not contain any RetVal to use in creating the image\n"
532 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
)
536 ## Retrieve source files
539 self
._GetHeaderInfo
()
540 # Ignore all source files in a binary build mode
541 if GlobalData
.gIgnoreSource
:
545 RecordList
= self
._RawData
[MODEL_EFI_SOURCE_FILE
, self
._Arch
, self
._Platform
]
546 Macros
= self
._Macros
547 for Record
in RecordList
:
549 ToolChainFamily
= Record
[1]
553 File
= PathClass(NormPath(Record
[0], Macros
), self
._ModuleDir
, '',
554 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
555 # check the file validation
556 ErrorCode
, ErrorInfo
= File
.Validate()
558 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
561 # add any previously found dependency files to the source list
562 if self
._DependencyFileList
:
563 RetVal
.extend(self
._DependencyFileList
)
566 ## Retrieve library classes employed by this module
568 def LibraryClasses(self
):
569 RetVal
= OrderedDict()
570 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, self
._Platform
]
571 for Record
in RecordList
:
575 Instance
= NormPath(Instance
, self
._Macros
)
576 RetVal
[Lib
] = Instance
581 ## Retrieve library names (for Edk.x style of modules)
585 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
, self
._Platform
]
586 for Record
in RecordList
:
587 LibraryName
= ReplaceMacro(Record
[0], self
._Macros
, False)
588 # in case of name with '.lib' extension, which is unusual in Edk.x inf
589 LibraryName
= os
.path
.splitext(LibraryName
)[0]
590 if LibraryName
not in RetVal
:
591 RetVal
.append(LibraryName
)
595 def ProtocolComments(self
):
597 return self
._ProtocolComments
599 ## Retrieve protocols consumed/produced by this module
602 RetVal
= OrderedDict()
603 self
._ProtocolComments
= OrderedDict()
604 RecordList
= self
._RawData
[MODEL_EFI_PROTOCOL
, self
._Arch
, self
._Platform
]
605 for Record
in RecordList
:
607 Value
= _ProtocolValue(CName
, self
.Packages
, self
.MetaFile
.Path
)
609 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
610 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
611 "Value of Protocol [%s] is not found under [Protocols] section in" % CName
,
612 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
613 RetVal
[CName
] = Value
614 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
615 self
._ProtocolComments
[CName
] = [a
[0] for a
in CommentRecords
]
619 def PpiComments(self
):
621 return self
._PpiComments
623 ## Retrieve PPIs consumed/produced by this module
626 RetVal
= OrderedDict()
627 self
._PpiComments
= OrderedDict()
628 RecordList
= self
._RawData
[MODEL_EFI_PPI
, self
._Arch
, self
._Platform
]
629 for Record
in RecordList
:
631 Value
= _PpiValue(CName
, self
.Packages
, self
.MetaFile
.Path
)
633 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
634 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
635 "Value of PPI [%s] is not found under [Ppis] section in " % CName
,
636 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
637 RetVal
[CName
] = Value
638 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
639 self
._PpiComments
[CName
] = [a
[0] for a
in CommentRecords
]
643 def GuidComments(self
):
645 return self
._GuidComments
647 ## Retrieve GUIDs consumed/produced by this module
650 RetVal
= OrderedDict()
651 self
._GuidComments
= OrderedDict()
652 RecordList
= self
._RawData
[MODEL_EFI_GUID
, self
._Arch
, self
._Platform
]
653 for Record
in RecordList
:
655 Value
= GuidValue(CName
, self
.Packages
, self
.MetaFile
.Path
)
657 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
658 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
659 "Value of Guid [%s] is not found under [Guids] section in" % CName
,
660 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
661 RetVal
[CName
] = Value
662 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
663 self
._GuidComments
[CName
] = [a
[0] for a
in CommentRecords
]
666 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
670 if self
._SourceOverridePath
:
671 RetVal
.append(self
._SourceOverridePath
)
673 Macros
= self
._Macros
674 Macros
['PROCESSOR'] = GlobalData
.gEdkGlobal
.get('PROCESSOR', self
._Arch
)
675 RecordList
= self
._RawData
[MODEL_EFI_INCLUDE
, self
._Arch
, self
._Platform
]
676 for Record
in RecordList
:
677 File
= NormPath(Record
[0], Macros
)
679 File
= os
.path
.join(self
._ModuleDir
, File
)
681 File
= mws
.join(GlobalData
.gWorkspace
, File
)
682 File
= RealPath(os
.path
.normpath(File
))
687 ## Retrieve packages this module depends on
691 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
, self
._Platform
]
692 Macros
= self
._Macros
693 for Record
in RecordList
:
694 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
695 # check the file validation
696 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
699 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
700 # parse this package now. we need it to get protocol/ppi/guid value
701 RetVal
.append(self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
])
704 ## Retrieve PCD comments
706 def PcdComments(self
):
708 return self
._PcdComments
710 ## Retrieve PCDs used in this module
713 self
._PcdComments
= OrderedDict()
714 RetVal
= OrderedDict()
715 RetVal
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
716 RetVal
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
717 RetVal
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
718 RetVal
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC
))
719 RetVal
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC_EX
))
725 for Type
in (MODEL_PCD_FIXED_AT_BUILD
,MODEL_PCD_PATCHABLE_IN_MODULE
,MODEL_PCD_FEATURE_FLAG
,MODEL_PCD_DYNAMIC
,MODEL_PCD_DYNAMIC_EX
):
726 RecordList
= self
._RawData
[Type
, self
._Arch
, self
._Platform
]
727 for TokenSpaceGuid
, PcdCName
, _
, _
, _
, _
, _
in RecordList
:
728 PcdsName
.add((PcdCName
, TokenSpaceGuid
))
731 ## Retrieve build options specific to this module
733 def BuildOptions(self
):
734 if self
._BuildOptions
is None:
735 self
._BuildOptions
= OrderedDict()
736 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, self
._Platform
]
737 for Record
in RecordList
:
738 ToolChainFamily
= Record
[0]
739 ToolChain
= Record
[1]
741 if (ToolChainFamily
, ToolChain
) not in self
._BuildOptions
or Option
.startswith('='):
742 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = Option
744 # concatenate the option string if they're for the same tool
745 OptionString
= self
._BuildOptions
[ToolChainFamily
, ToolChain
]
746 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
747 return self
._BuildOptions
749 ## Retrieve dependency expression
752 RetVal
= tdict(False, 2)
754 # If the module has only Binaries and no Sources, then ignore [Depex]
755 if not self
.Sources
and self
.Binaries
:
758 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
759 # PEIM and DXE drivers must have a valid [Depex] section
760 if len(self
.LibraryClass
) == 0 and len(RecordList
) == 0:
761 if self
.ModuleType
== SUP_MODULE_DXE_DRIVER
or self
.ModuleType
== SUP_MODULE_PEIM
or self
.ModuleType
== SUP_MODULE_DXE_SMM_DRIVER
or \
762 self
.ModuleType
== SUP_MODULE_DXE_SAL_DRIVER
or self
.ModuleType
== SUP_MODULE_DXE_RUNTIME_DRIVER
:
763 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
764 % self
.ModuleType
, File
=self
.MetaFile
)
766 if len(RecordList
) != 0 and self
.ModuleType
== SUP_MODULE_USER_DEFINED
:
767 for Record
in RecordList
:
768 if Record
[4] not in [SUP_MODULE_PEIM
, SUP_MODULE_DXE_DRIVER
, SUP_MODULE_DXE_SMM_DRIVER
]:
769 EdkLogger
.error('build', FORMAT_INVALID
,
770 "'%s' module must specify the type of [Depex] section" % self
.ModuleType
,
773 TemporaryDictionary
= OrderedDict()
774 for Record
in RecordList
:
775 DepexStr
= ReplaceMacro(Record
[0], self
._Macros
, False)
777 ModuleType
= Record
[4]
778 TokenList
= DepexStr
.split()
779 if (Arch
, ModuleType
) not in TemporaryDictionary
:
780 TemporaryDictionary
[Arch
, ModuleType
] = []
781 DepexList
= TemporaryDictionary
[Arch
, ModuleType
]
782 for Token
in TokenList
:
783 if Token
in DEPEX_SUPPORTED_OPCODE_SET
:
784 DepexList
.append(Token
)
785 elif Token
.endswith(".inf"): # module file name
786 ModuleFile
= os
.path
.normpath(Token
)
787 Module
= self
.BuildDatabase
[ModuleFile
]
789 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "Module is not found in active platform",
790 ExtraData
=Token
, File
=self
.MetaFile
, Line
=Record
[-1])
791 DepexList
.append(Module
.Guid
)
793 # it use the Fixed PCD format
795 if tuple(Token
.split('.')[::-1]) not in self
.Pcds
:
796 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "PCD [{}] used in [Depex] section should be listed in module PCD section".format(Token
), File
=self
.MetaFile
, Line
=Record
[-1])
798 if self
.Pcds
[tuple(Token
.split('.')[::-1])].DatumType
!= TAB_VOID
:
799 EdkLogger
.error('build', FORMAT_INVALID
, "PCD [{}] used in [Depex] section should be VOID* datum type".format(Token
), File
=self
.MetaFile
, Line
=Record
[-1])
802 # get the GUID value now
803 Value
= _ProtocolValue(Token
, self
.Packages
, self
.MetaFile
.Path
)
805 Value
= _PpiValue(Token
, self
.Packages
, self
.MetaFile
.Path
)
807 Value
= GuidValue(Token
, self
.Packages
, self
.MetaFile
.Path
)
810 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
811 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
812 "Value of [%s] is not found in" % Token
,
813 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
814 DepexList
.append(Value
)
815 for Arch
, ModuleType
in TemporaryDictionary
:
816 RetVal
[Arch
, ModuleType
] = TemporaryDictionary
[Arch
, ModuleType
]
819 ## Retrieve dependency expression
821 def DepexExpression(self
):
822 RetVal
= tdict(False, 2)
823 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
824 TemporaryDictionary
= OrderedDict()
825 for Record
in RecordList
:
826 DepexStr
= ReplaceMacro(Record
[0], self
._Macros
, False)
828 ModuleType
= Record
[4]
829 TokenList
= DepexStr
.split()
830 if (Arch
, ModuleType
) not in TemporaryDictionary
:
831 TemporaryDictionary
[Arch
, ModuleType
] = ''
832 for Token
in TokenList
:
833 TemporaryDictionary
[Arch
, ModuleType
] = TemporaryDictionary
[Arch
, ModuleType
] + Token
.strip() + ' '
834 for Arch
, ModuleType
in TemporaryDictionary
:
835 RetVal
[Arch
, ModuleType
] = TemporaryDictionary
[Arch
, ModuleType
]
838 @cached_class_function
839 def GetGuidsUsedByPcd(self
):
841 return self
._GuidsUsedByPcd
843 ## Retrieve PCD for given type
844 def _GetPcd(self
, Type
):
846 PcdDict
= tdict(True, 4)
848 RecordList
= self
._RawData
[Type
, self
._Arch
, self
._Platform
]
849 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, Platform
, Id
, LineNo
in RecordList
:
850 PcdDict
[Arch
, Platform
, PcdCName
, TokenSpaceGuid
] = (Setting
, LineNo
)
851 PcdList
.append((PcdCName
, TokenSpaceGuid
))
853 if TokenSpaceGuid
not in self
.Guids
:
854 Value
= GuidValue(TokenSpaceGuid
, self
.Packages
, self
.MetaFile
.Path
)
856 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
857 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
858 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid
,
859 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=LineNo
)
860 self
.Guids
[TokenSpaceGuid
] = Value
861 self
._GuidsUsedByPcd
[TokenSpaceGuid
] = Value
862 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Id
]
864 for CmtRec
in CommentRecords
:
865 Comments
.append(CmtRec
[0])
866 self
._PcdComments
[TokenSpaceGuid
, PcdCName
] = Comments
868 # resolve PCD type, value, datum info, etc. by getting its definition from package
869 _GuidDict
= self
.Guids
.copy()
870 for PcdCName
, TokenSpaceGuid
in PcdList
:
871 PcdRealName
= PcdCName
872 Setting
, LineNo
= PcdDict
[self
._Arch
, self
.Platform
, PcdCName
, TokenSpaceGuid
]
875 ValueList
= AnalyzePcdData(Setting
)
876 DefaultValue
= ValueList
[0]
877 Pcd
= PcdClassObject(
887 self
.Guids
[TokenSpaceGuid
]
889 if Type
== MODEL_PCD_PATCHABLE_IN_MODULE
and ValueList
[1]:
890 # Patch PCD: TokenSpace.PcdCName|Value|Offset
891 Pcd
.Offset
= ValueList
[1]
893 if (PcdRealName
, TokenSpaceGuid
) in GlobalData
.MixedPcd
:
894 for Package
in self
.Packages
:
895 for key
in Package
.Pcds
:
896 if (Package
.Pcds
[key
].TokenCName
, Package
.Pcds
[key
].TokenSpaceGuidCName
) == (PcdRealName
, TokenSpaceGuid
):
897 for item
in GlobalData
.MixedPcd
[(PcdRealName
, TokenSpaceGuid
)]:
898 Pcd_Type
= item
[0].split('_')[-1]
899 if Pcd_Type
== Package
.Pcds
[key
].Type
:
900 Value
= Package
.Pcds
[key
]
901 Value
.TokenCName
= Package
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
903 newkey
= (Value
.TokenCName
, key
[1])
905 newkey
= (Value
.TokenCName
, key
[1], key
[2])
906 del Package
.Pcds
[key
]
907 Package
.Pcds
[newkey
] = Value
914 # get necessary info from package declaring this PCD
915 for Package
in self
.Packages
:
917 # 'dynamic' in INF means its type is determined by platform;
918 # if platform doesn't give its type, use 'lowest' one in the
919 # following order, if any
921 # TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE, TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX
923 _GuidDict
.update(Package
.Guids
)
924 PcdType
= self
._PCD
_TYPE
_STRING
_[Type
]
925 if Type
== MODEL_PCD_DYNAMIC
:
927 for T
in PCD_TYPE_LIST
:
928 if (PcdRealName
, TokenSpaceGuid
) in GlobalData
.MixedPcd
:
929 for item
in GlobalData
.MixedPcd
[(PcdRealName
, TokenSpaceGuid
)]:
930 if str(item
[0]).endswith(T
) and (item
[0], item
[1], T
) in Package
.Pcds
:
938 if (PcdRealName
, TokenSpaceGuid
, T
) in Package
.Pcds
:
944 if (PcdRealName
, TokenSpaceGuid
) in GlobalData
.MixedPcd
:
945 for item
in GlobalData
.MixedPcd
[(PcdRealName
, TokenSpaceGuid
)]:
946 Pcd_Type
= item
[0].split('_')[-1]
947 if Pcd_Type
== PcdType
:
955 if (PcdCName
, TokenSpaceGuid
, PcdType
) in Package
.Pcds
:
956 PcdInPackage
= Package
.Pcds
[PcdCName
, TokenSpaceGuid
, PcdType
]
958 Pcd
.TokenValue
= PcdInPackage
.TokenValue
961 # Check whether the token value exist or not.
963 if Pcd
.TokenValue
is None or Pcd
.TokenValue
== "":
967 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid
, PcdRealName
, str(Package
)),
968 File
=self
.MetaFile
, Line
=LineNo
,
972 # Check hexadecimal token value length and format.
974 ReIsValidPcdTokenValue
= re
.compile(r
"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re
.DOTALL
)
975 if Pcd
.TokenValue
.startswith("0x") or Pcd
.TokenValue
.startswith("0X"):
976 if ReIsValidPcdTokenValue
.match(Pcd
.TokenValue
) is None:
980 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdRealName
, str(Package
)),
981 File
=self
.MetaFile
, Line
=LineNo
,
986 # Check decimal token value length and format.
990 TokenValueInt
= int (Pcd
.TokenValue
, 10)
991 if (TokenValueInt
< 0 or TokenValueInt
> 4294967295):
995 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdRealName
, str(Package
)),
996 File
=self
.MetaFile
, Line
=LineNo
,
1003 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdRealName
, str(Package
)),
1004 File
=self
.MetaFile
, Line
=LineNo
,
1008 Pcd
.DatumType
= PcdInPackage
.DatumType
1009 Pcd
.MaxDatumSize
= PcdInPackage
.MaxDatumSize
1010 Pcd
.InfDefaultValue
= Pcd
.DefaultValue
1011 if not Pcd
.DefaultValue
:
1012 Pcd
.DefaultValue
= PcdInPackage
.DefaultValue
1015 Pcd
.DefaultValue
= ValueExpressionEx(Pcd
.DefaultValue
, Pcd
.DatumType
, _GuidDict
)(True)
1016 except BadExpression
as Value
:
1017 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(TokenSpaceGuid
, PcdRealName
, Pcd
.DefaultValue
, Value
),
1018 File
=self
.MetaFile
, Line
=LineNo
)
1024 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid
, PcdRealName
, self
.MetaFile
),
1025 File
=self
.MetaFile
, Line
=LineNo
,
1026 ExtraData
="\t%s" % '\n\t'.join(str(P
) for P
in self
.Packages
)
1028 Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
1032 ## check whether current module is binary module
1034 def IsBinaryModule(self
):
1035 if (self
.Binaries
and not self
.Sources
) or GlobalData
.gIgnoreSource
: