2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
7 # This program and the accompanying materials
8 # are licensed and made available under the terms and conditions of the BSD License
9 # which accompanies this distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 import Common
.LongFilePathOs
as os
20 import os
.path
as path
26 from . import GenDepex
27 from io
import BytesIO
29 from .StrGather
import *
30 from .BuildEngine
import BuildRule
32 from Common
.LongFilePathSupport
import CopyLongFilePath
33 from Common
.BuildToolError
import *
34 from Common
.DataType
import *
35 from Common
.Misc
import *
36 from Common
.StringUtils
import *
37 import Common
.GlobalData
as GlobalData
38 from GenFds
.FdfParser
import *
39 from CommonDataClass
.CommonClass
import SkuInfoClass
40 from GenPatchPcdTable
.GenPatchPcdTable
import parsePcdInfoFromMapFile
41 import Common
.VpdInfoFile
as VpdInfoFile
42 from .GenPcdDb
import CreatePcdDatabaseCode
43 from Workspace
.MetaFileCommentParser
import UsageList
44 from Workspace
.WorkspaceCommon
import GetModuleLibInstances
45 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
46 from . import InfSectionParser
49 from .GenVar
import VariableMgr
, var_info
50 from collections
import OrderedDict
51 from collections
import defaultdict
52 from Workspace
.WorkspaceCommon
import OrderedListDict
54 from Common
.caching
import cached_property
, cached_class_function
56 ## Regular expression for splitting Dependency Expression string into tokens
57 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
59 ## Regular expression for match: PCD(xxxx.yyy)
60 gPCDAsGuidPattern
= re
.compile(r
"^PCD\(.+\..+\)$")
63 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
64 # is the former use /I , the Latter used -I to specify include directories
66 gBuildOptIncludePatternMsft
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
67 gBuildOptIncludePatternOther
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
70 # Match name = variable
72 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
74 # The format of guid in efivarstore statement likes following and must be correct:
75 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
77 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
79 ## Mapping Makefile type
80 gMakeTypeMap
= {TAB_COMPILER_MSFT
:"nmake", "GCC":"gmake"}
83 ## Build rule configuration file
84 gDefaultBuildRuleFile
= 'build_rule.txt'
86 ## Tools definition configuration file
87 gDefaultToolsDefFile
= 'tools_def.txt'
89 ## Build rule default version
90 AutoGenReqBuildRuleVerNum
= "0.1"
92 ## default file name for AutoGen
93 gAutoGenCodeFileName
= "AutoGen.c"
94 gAutoGenHeaderFileName
= "AutoGen.h"
95 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
96 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
97 gAutoGenDepexFileName
= "%(module_name)s.depex"
98 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
99 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
100 gInfSpecVersion
= "0x00010017"
103 # Template string to generic AsBuilt INF
105 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
108 # FILE auto-generated
111 INF_VERSION = ${module_inf_version}
112 BASE_NAME = ${module_name}
113 FILE_GUID = ${module_guid}
114 MODULE_TYPE = ${module_module_type}${BEGIN}
115 VERSION_STRING = ${module_version_string}${END}${BEGIN}
116 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
117 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
118 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
119 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
120 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
121 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
122 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
123 SHADOW = ${module_shadow}${END}${BEGIN}
124 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
125 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
126 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
127 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
128 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
129 SPEC = ${module_spec}${END}${BEGIN}
130 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
131 MODULE_UNI_FILE = ${module_uni_file}${END}
133 [Packages.${module_arch}]${BEGIN}
134 ${package_item}${END}
136 [Binaries.${module_arch}]${BEGIN}
139 [PatchPcd.${module_arch}]${BEGIN}
143 [Protocols.${module_arch}]${BEGIN}
147 [Ppis.${module_arch}]${BEGIN}
151 [Guids.${module_arch}]${BEGIN}
155 [PcdEx.${module_arch}]${BEGIN}
159 [LibraryClasses.${module_arch}]
160 ## @LIB_INSTANCES${BEGIN}
161 # ${libraryclasses_item}${END}
165 ${userextension_tianocore_item}
169 [BuildOptions.${module_arch}]
171 ## ${flags_item}${END}
174 ## Base class for AutoGen
176 # This class just implements the cache mechanism of AutoGen objects.
178 class AutoGen(object):
179 # database to maintain the objects in each child class
180 __ObjectCache
= {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object
184 # @param Class class object of real AutoGen class
185 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
186 # @param Workspace Workspace directory or WorkspaceAutoGen object
187 # @param MetaFile The path of meta file
188 # @param Target Build target
189 # @param Toolchain Tool chain name
190 # @param Arch Target arch
191 # @param *args The specific class related parameters
192 # @param **kwargs The specific class related dict parameters
194 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
195 # check if the object has been created
196 Key
= (Target
, Toolchain
, Arch
, MetaFile
)
197 if Key
in cls
.__ObjectCache
:
198 # if it exists, just return it directly
199 return cls
.__ObjectCache
[Key
]
200 # it didnt exist. create it, cache it, then return it
201 RetVal
= cls
.__ObjectCache
[Key
] = super().__new
__(cls
)
204 def __init__ (self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
209 # The file path of platform file will be used to represent hash value of this object
211 # @retval int Hash value of the file path of platform file
214 return hash(self
.MetaFile
)
218 # The file path of platform file will be used to represent this object
220 # @retval string String of platform file path
223 return str(self
.MetaFile
)
226 def __eq__(self
, Other
):
227 return Other
and self
.MetaFile
== Other
229 ## Workspace AutoGen class
231 # This class is used mainly to control the whole platform build for different
232 # architecture. This class will generate top level makefile.
234 class WorkspaceAutoGen(AutoGen
):
235 # call super().__init__ then call the worker function with different parameter count
236 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
237 if not hasattr(self
, "_Init"):
238 super().__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
239 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
242 ## Initialize WorkspaceAutoGen
244 # @param WorkspaceDir Root directory of workspace
245 # @param ActivePlatform Meta-file of active platform
246 # @param Target Build target
247 # @param Toolchain Tool chain name
248 # @param ArchList List of architecture of current build
249 # @param MetaFileDb Database containing meta-files
250 # @param BuildConfig Configuration of build
251 # @param ToolDefinition Tool chain definitions
252 # @param FlashDefinitionFile File of flash definition
253 # @param Fds FD list to be generated
254 # @param Fvs FV list to be generated
255 # @param Caps Capsule list to be generated
256 # @param SkuId SKU id from command line
258 def _InitWorker(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
259 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
260 Progress
=None, BuildModule
=None):
261 self
.BuildDatabase
= MetaFileDb
262 self
.MetaFile
= ActivePlatform
263 self
.WorkspaceDir
= WorkspaceDir
264 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, TAB_ARCH_COMMON
, Target
, Toolchain
]
265 GlobalData
.gActivePlatform
= self
.Platform
266 self
.BuildTarget
= Target
267 self
.ToolChain
= Toolchain
268 self
.ArchList
= ArchList
270 self
.UniFlag
= UniFlag
272 self
.TargetTxt
= BuildConfig
273 self
.ToolDef
= ToolDefinition
274 self
.FdfFile
= FlashDefinitionFile
275 self
.FdTargetList
= Fds
if Fds
else []
276 self
.FvTargetList
= Fvs
if Fvs
else []
277 self
.CapTargetList
= Caps
if Caps
else []
278 self
.AutoGenObjectList
= []
281 # there's many relative directory operations, so ...
282 os
.chdir(self
.WorkspaceDir
)
287 if not self
.ArchList
:
288 ArchList
= set(self
.Platform
.SupArchList
)
290 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
292 EdkLogger
.error("build", PARAMETER_INVALID
,
293 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
294 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
295 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
296 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
297 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
298 self
.ArchList
= tuple(ArchList
)
300 # Validate build target
301 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
302 EdkLogger
.error("build", PARAMETER_INVALID
,
303 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
304 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
307 # parse FDF file to get PCDs in it, if any
309 self
.FdfFile
= self
.Platform
.FlashDefinition
313 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
314 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
315 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
317 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
319 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
322 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
324 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
327 Progress
.Start("\nProcessing meta-data")
331 # Mark now build in AutoGen Phase
333 GlobalData
.gAutoGenPhase
= True
334 Fdf
= FdfParser(self
.FdfFile
.Path
)
336 GlobalData
.gFdfParser
= Fdf
337 GlobalData
.gAutoGenPhase
= False
338 PcdSet
= Fdf
.Profile
.PcdDict
339 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
340 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
341 for FdRegion
in FdDict
.RegionList
:
342 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
343 if int(FdRegion
.Offset
) % 8 != 0:
344 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
345 ModuleList
= Fdf
.Profile
.InfList
346 self
.FdfProfile
= Fdf
.Profile
347 for fvname
in self
.FvTargetList
:
348 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
349 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
350 "No such an FV in FDF file: %s" % fvname
)
352 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
353 # but the path (self.MetaFile.Path) is the real path
354 for key
in self
.FdfProfile
.InfDict
:
356 MetaFile_cache
= defaultdict(set)
357 for Arch
in self
.ArchList
:
358 Current_Platform_cache
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
359 for Pkey
in Current_Platform_cache
.Modules
:
360 MetaFile_cache
[Arch
].add(Current_Platform_cache
.Modules
[Pkey
].MetaFile
)
361 for Inf
in self
.FdfProfile
.InfDict
[key
]:
362 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
363 for Arch
in self
.ArchList
:
364 if ModuleFile
in MetaFile_cache
[Arch
]:
367 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
368 if not ModuleData
.IsBinaryModule
:
369 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
372 for Arch
in self
.ArchList
:
374 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
376 for Pkey
in Platform
.Modules
:
377 MetaFileList
.add(Platform
.Modules
[Pkey
].MetaFile
)
378 for Inf
in self
.FdfProfile
.InfDict
[key
]:
379 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
380 if ModuleFile
in MetaFileList
:
382 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
383 if not ModuleData
.IsBinaryModule
:
384 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
389 self
.FdfProfile
= None
390 if self
.FdTargetList
:
391 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
392 self
.FdTargetList
= []
393 if self
.FvTargetList
:
394 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
395 self
.FvTargetList
= []
396 if self
.CapTargetList
:
397 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
398 self
.CapTargetList
= []
400 # apply SKU and inject PCDs from Flash Definition file
401 for Arch
in self
.ArchList
:
402 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
403 PlatformPcds
= Platform
.Pcds
404 self
._GuidDict
= Platform
._GuidDict
405 SourcePcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set(),TAB_PCDS_DYNAMIC
:set(),TAB_PCDS_FIXED_AT_BUILD
:set()}
406 BinaryPcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set()}
407 SourcePcdDict_Keys
= SourcePcdDict
.keys()
408 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
410 # generate the SourcePcdDict and BinaryPcdDict
411 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
412 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
413 if BuildData
.Arch
!= Arch
:
415 if BuildData
.MetaFile
.Ext
== '.inf':
416 for key
in BuildData
.Pcds
:
417 if BuildData
.Pcds
[key
].Pending
:
418 if key
in Platform
.Pcds
:
419 PcdInPlatform
= Platform
.Pcds
[key
]
420 if PcdInPlatform
.Type
:
421 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
422 BuildData
.Pcds
[key
].Pending
= False
424 if BuildData
.MetaFile
in Platform
.Modules
:
425 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
426 if key
in PlatformModule
.Pcds
:
427 PcdInPlatform
= PlatformModule
.Pcds
[key
]
428 if PcdInPlatform
.Type
:
429 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
430 BuildData
.Pcds
[key
].Pending
= False
432 #Pcd used in Library, Pcd Type from reference module if Pcd Type is Pending
433 if BuildData
.Pcds
[key
].Pending
:
434 MGen
= ModuleAutoGen(self
, BuildData
.MetaFile
, Target
, Toolchain
, Arch
, self
.MetaFile
)
435 if MGen
and MGen
.IsLibrary
:
436 if MGen
in PGen
.LibraryAutoGenList
:
437 ReferenceModules
= MGen
.ReferenceModules
438 for ReferenceModule
in ReferenceModules
:
439 if ReferenceModule
.MetaFile
in Platform
.Modules
:
440 RefPlatformModule
= Platform
.Modules
[str(ReferenceModule
.MetaFile
)]
441 if key
in RefPlatformModule
.Pcds
:
442 PcdInReferenceModule
= RefPlatformModule
.Pcds
[key
]
443 if PcdInReferenceModule
.Type
:
444 BuildData
.Pcds
[key
].Type
= PcdInReferenceModule
.Type
445 BuildData
.Pcds
[key
].Pending
= False
448 if TAB_PCDS_DYNAMIC_EX
in BuildData
.Pcds
[key
].Type
:
449 if BuildData
.IsBinaryModule
:
450 BinaryPcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
452 SourcePcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
454 elif TAB_PCDS_PATCHABLE_IN_MODULE
in BuildData
.Pcds
[key
].Type
:
455 if BuildData
.MetaFile
.Ext
== '.inf':
456 if BuildData
.IsBinaryModule
:
457 BinaryPcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
459 SourcePcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
461 elif TAB_PCDS_DYNAMIC
in BuildData
.Pcds
[key
].Type
:
462 SourcePcdDict
[TAB_PCDS_DYNAMIC
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
463 elif TAB_PCDS_FIXED_AT_BUILD
in BuildData
.Pcds
[key
].Type
:
464 SourcePcdDict
[TAB_PCDS_FIXED_AT_BUILD
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
468 # A PCD can only use one type for all source modules
470 for i
in SourcePcdDict_Keys
:
471 for j
in SourcePcdDict_Keys
:
473 Intersections
= SourcePcdDict
[i
].intersection(SourcePcdDict
[j
])
474 if len(Intersections
) > 0:
478 "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i
, j
),
479 ExtraData
='\n\t'.join(str(P
[1]+'.'+P
[0]) for P
in Intersections
)
483 # intersection the BinaryPCD for Mixed PCD
485 for i
in BinaryPcdDict_Keys
:
486 for j
in BinaryPcdDict_Keys
:
488 Intersections
= BinaryPcdDict
[i
].intersection(BinaryPcdDict
[j
])
489 for item
in Intersections
:
490 NewPcd1
= (item
[0] + '_' + i
, item
[1])
491 NewPcd2
= (item
[0] + '_' + j
, item
[1])
492 if item
not in GlobalData
.MixedPcd
:
493 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
495 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
496 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
497 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
498 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
501 # intersection the SourcePCD and BinaryPCD for Mixed PCD
503 for i
in SourcePcdDict_Keys
:
504 for j
in BinaryPcdDict_Keys
:
506 Intersections
= SourcePcdDict
[i
].intersection(BinaryPcdDict
[j
])
507 for item
in Intersections
:
508 NewPcd1
= (item
[0] + '_' + i
, item
[1])
509 NewPcd2
= (item
[0] + '_' + j
, item
[1])
510 if item
not in GlobalData
.MixedPcd
:
511 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
513 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
514 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
515 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
516 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
518 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
519 if BuildData
.Arch
!= Arch
:
521 for key
in list(BuildData
.Pcds
.keys()):
522 for SinglePcd
in GlobalData
.MixedPcd
:
523 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
524 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
525 Pcd_Type
= item
[0].split('_')[-1]
526 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in PCD_DYNAMIC_EX_TYPE_SET
) or \
527 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
528 Value
= BuildData
.Pcds
[key
]
529 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
531 newkey
= (Value
.TokenCName
, key
[1])
533 newkey
= (Value
.TokenCName
, key
[1], key
[2])
534 del BuildData
.Pcds
[key
]
535 BuildData
.Pcds
[newkey
] = Value
539 # handle the mixed pcd in FDF file
541 if key
in GlobalData
.MixedPcd
:
544 for item
in GlobalData
.MixedPcd
[key
]:
547 #Collect package set information from INF of FDF
549 for Inf
in ModuleList
:
550 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
551 if ModuleFile
in Platform
.Modules
:
553 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
554 PkgSet
.update(ModuleData
.Packages
)
555 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
560 DecPcds
.add((Pcd
[0], Pcd
[1]))
561 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
563 Platform
.SkuName
= self
.SkuId
564 for Name
, Guid
,Fileds
in PcdSet
:
565 if (Name
, Guid
) not in DecPcds
:
569 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
570 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
571 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
574 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
575 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
576 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
577 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
579 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
583 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
584 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
585 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
588 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
590 # Explicitly collect platform's dynamic PCDs
592 Pa
.CollectPlatformDynamicPcds()
593 Pa
.CollectFixedAtBuildPcds()
594 self
.AutoGenObjectList
.append(Pa
)
597 # Generate Package level hash value
599 GlobalData
.gPackageHash
[Arch
] = {}
600 if GlobalData
.gUseHashCache
:
602 self
._GenPkgLevelHash
(Pkg
)
605 # Check PCDs token value conflict in each DEC file.
607 self
._CheckAllPcdsTokenValueConflict
()
610 # Check PCD type and definition between DSC and DEC
612 self
._CheckPcdDefineAndType
()
615 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.
617 content
= 'gCommandLineDefines: '
618 content
+= str(GlobalData
.gCommandLineDefines
)
619 content
+= os
.linesep
620 content
+= 'BuildOptionPcd: '
621 content
+= str(GlobalData
.BuildOptionPcd
)
622 content
+= os
.linesep
623 content
+= 'Active Platform: '
624 content
+= str(self
.Platform
)
625 content
+= os
.linesep
627 content
+= 'Flash Image Definition: '
628 content
+= str(self
.FdfFile
)
629 content
+= os
.linesep
630 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
633 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
635 PcdTokenNumber
= 'PcdTokenNumber: '
636 if Pa
.PcdTokenNumber
:
637 if Pa
.DynamicPcdList
:
638 for Pcd
in Pa
.DynamicPcdList
:
639 PcdTokenNumber
+= os
.linesep
640 PcdTokenNumber
+= str((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
))
641 PcdTokenNumber
+= ' : '
642 PcdTokenNumber
+= str(Pa
.PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
])
643 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'), PcdTokenNumber
, False)
646 # Get set of workspace metafiles
648 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
651 # Retrieve latest modified time of all metafiles
654 for f
in AllWorkSpaceMetaFiles
:
655 if os
.stat(f
)[8] > SrcTimeStamp
:
656 SrcTimeStamp
= os
.stat(f
)[8]
657 self
._SrcTimeStamp
= SrcTimeStamp
659 if GlobalData
.gUseHashCache
:
661 for files
in AllWorkSpaceMetaFiles
:
662 if files
.endswith('.dec'):
664 f
= open(files
, 'rb')
668 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'AutoGen.hash'), m
.hexdigest(), True)
669 GlobalData
.gPlatformHash
= m
.hexdigest()
672 # Write metafile list to build directory
674 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
675 if os
.path
.exists (AutoGenFilePath
):
676 os
.remove(AutoGenFilePath
)
677 if not os
.path
.exists(self
.BuildDir
):
678 os
.makedirs(self
.BuildDir
)
679 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
680 for f
in AllWorkSpaceMetaFiles
:
684 def _GenPkgLevelHash(self
, Pkg
):
685 if Pkg
.PackageName
in GlobalData
.gPackageHash
[Pkg
.Arch
]:
688 PkgDir
= os
.path
.join(self
.BuildDir
, Pkg
.Arch
, Pkg
.PackageName
)
689 CreateDirectory(PkgDir
)
690 HashFile
= os
.path
.join(PkgDir
, Pkg
.PackageName
+ '.hash')
692 # Get .dec file's hash value
693 f
= open(Pkg
.MetaFile
.Path
, 'rb')
697 # Get include files hash value
699 for inc
in sorted(Pkg
.Includes
, key
=lambda x
: str(x
)):
700 for Root
, Dirs
, Files
in os
.walk(str(inc
)):
701 for File
in sorted(Files
):
702 File_Path
= os
.path
.join(Root
, File
)
703 f
= open(File_Path
, 'rb')
707 SaveFileOnChange(HashFile
, m
.hexdigest(), True)
708 GlobalData
.gPackageHash
[Pkg
.Arch
][Pkg
.PackageName
] = m
.hexdigest()
710 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
711 AllWorkSpaceMetaFiles
= set()
716 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
717 for f
in GlobalData
.gFdfParser
.GetAllIncludedFile():
718 AllWorkSpaceMetaFiles
.add (f
.FileName
)
722 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
725 # add build_rule.txt & tools_def.txt
727 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
728 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
730 # add BuildOption metafile
732 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
734 # add PcdToken Number file for Dynamic/DynamicEx Pcd
736 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'))
738 for Arch
in self
.ArchList
:
742 for Package
in PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
).PackageList
:
743 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
748 for filePath
in self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]._RawData
.IncludedFiles
:
749 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
751 return AllWorkSpaceMetaFiles
753 def _CheckPcdDefineAndType(self
):
754 PcdTypeSet
= {TAB_PCDS_FIXED_AT_BUILD
,
755 TAB_PCDS_PATCHABLE_IN_MODULE
,
756 TAB_PCDS_FEATURE_FLAG
,
760 # This dict store PCDs which are not used by any modules with specified arches
761 UnusedPcd
= OrderedDict()
762 for Pa
in self
.AutoGenObjectList
:
763 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
764 for Pcd
in Pa
.Platform
.Pcds
:
765 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
767 # If no PCD type, this PCD comes from FDF
771 # Try to remove Hii and Vpd suffix
772 if PcdType
.startswith(TAB_PCDS_DYNAMIC_EX
):
773 PcdType
= TAB_PCDS_DYNAMIC_EX
774 elif PcdType
.startswith(TAB_PCDS_DYNAMIC
):
775 PcdType
= TAB_PCDS_DYNAMIC
777 for Package
in Pa
.PackageList
:
778 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
779 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
781 for Type
in PcdTypeSet
:
782 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
786 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
787 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
792 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
794 for Pcd
in UnusedPcd
:
797 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
798 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
799 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
804 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
806 ## Return the directory to store FV files
809 return path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
811 ## Return the directory to store all intermediate and final files built
814 return self
.AutoGenObjectList
[0].BuildDir
816 ## Return the build output directory platform specifies
819 return self
.Platform
.OutputDirectory
821 ## Return platform name
824 return self
.Platform
.PlatformName
826 ## Return meta-file GUID
829 return self
.Platform
.Guid
831 ## Return platform version
834 return self
.Platform
.Version
836 ## Return paths of tools
838 def ToolDefinition(self
):
839 return self
.AutoGenObjectList
[0].ToolDefinition
841 ## Return directory of platform makefile
843 # @retval string Makefile directory
846 def MakeFileDir(self
):
849 ## Return build command string
851 # @retval string Build command string
854 def BuildCommand(self
):
855 # BuildCommand should be all the same. So just get one from platform AutoGen
856 return self
.AutoGenObjectList
[0].BuildCommand
858 ## Check the PCDs token value conflict in each DEC file.
860 # Will cause build break and raise error message while two PCDs conflict.
864 def _CheckAllPcdsTokenValueConflict(self
):
865 for Pa
in self
.AutoGenObjectList
:
866 for Package
in Pa
.PackageList
:
867 PcdList
= list(Package
.Pcds
.values())
868 PcdList
.sort(key
=lambda x
: int(x
.TokenValue
, 0))
870 while (Count
< len(PcdList
) - 1) :
871 Item
= PcdList
[Count
]
872 ItemNext
= PcdList
[Count
+ 1]
874 # Make sure in the same token space the TokenValue should be unique
876 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
877 SameTokenValuePcdList
= []
878 SameTokenValuePcdList
.append(Item
)
879 SameTokenValuePcdList
.append(ItemNext
)
880 RemainPcdListLength
= len(PcdList
) - Count
- 2
881 for ValueSameCount
in range(RemainPcdListLength
):
882 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
883 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
887 # Sort same token value PCD list with TokenGuid and TokenCName
889 SameTokenValuePcdList
.sort(key
=lambda x
: "%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
))
890 SameTokenValuePcdListCount
= 0
891 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
893 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
894 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
896 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
897 for PcdItem
in GlobalData
.MixedPcd
:
898 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
899 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
905 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
906 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
909 SameTokenValuePcdListCount
+= 1
910 Count
+= SameTokenValuePcdListCount
913 PcdList
= list(Package
.Pcds
.values())
914 PcdList
.sort(key
=lambda x
: "%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
))
916 while (Count
< len(PcdList
) - 1) :
917 Item
= PcdList
[Count
]
918 ItemNext
= PcdList
[Count
+ 1]
920 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
922 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
926 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
927 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
931 ## Generate fds command
933 def GenFdsCommand(self
):
934 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
936 ## Create makefile for the platform and modules in it
938 # @param CreateDepsMakeFile Flag indicating if the makefile for
939 # modules will be created as well
941 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
942 if not CreateDepsMakeFile
:
944 for Pa
in self
.AutoGenObjectList
:
945 Pa
.CreateMakeFile(True)
947 ## Create autogen code for platform and modules
949 # Since there's no autogen code for platform, this method will do nothing
950 # if CreateModuleCodeFile is set to False.
952 # @param CreateDepsCodeFile Flag indicating if creating module's
953 # autogen code file or not
955 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
956 if not CreateDepsCodeFile
:
958 for Pa
in self
.AutoGenObjectList
:
959 Pa
.CreateCodeFile(True)
961 ## Create AsBuilt INF file the platform
963 def CreateAsBuiltInf(self
):
967 ## AutoGen class for platform
969 # PlatformAutoGen class will process the original information in platform
970 # file in order to generate makefile for platform.
972 class PlatformAutoGen(AutoGen
):
973 # call super().__init__ then call the worker function with different parameter count
974 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
975 if not hasattr(self
, "_Init"):
976 super().__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
977 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
)
980 # Used to store all PCDs for both PEI and DXE phase, in order to generate
981 # correct PCD database
984 _NonDynaPcdList_
= []
988 # The priority list while override build option
990 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
991 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
992 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
993 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
994 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
995 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
996 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
997 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
998 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
999 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1000 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1001 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1002 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1003 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1004 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1005 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1007 ## Initialize PlatformAutoGen
1010 # @param Workspace WorkspaceAutoGen object
1011 # @param PlatformFile Platform file (DSC file)
1012 # @param Target Build target (DEBUG, RELEASE)
1013 # @param Toolchain Name of tool chain
1014 # @param Arch arch of the platform supports
1016 def _InitWorker(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1017 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1018 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1020 self
.MetaFile
= PlatformFile
1021 self
.Workspace
= Workspace
1022 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1023 self
.ToolChain
= Toolchain
1024 self
.BuildTarget
= Target
1026 self
.SourceDir
= PlatformFile
.SubDir
1027 self
.SourceOverrideDir
= None
1028 self
.FdTargetList
= self
.Workspace
.FdTargetList
1029 self
.FvTargetList
= self
.Workspace
.FvTargetList
1030 self
.AllPcdList
= []
1031 # get the original module/package/platform objects
1032 self
.BuildDatabase
= Workspace
.BuildDatabase
1033 self
.DscBuildDataObj
= Workspace
.Platform
1035 # flag indicating if the makefile/C-code file has been created or not
1036 self
.IsMakeFileCreated
= False
1038 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1039 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1041 self
._AsBuildInfList
= []
1042 self
._AsBuildModuleList
= []
1044 self
.VariableInfo
= None
1046 if GlobalData
.gFdfParser
is not None:
1047 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1048 for Inf
in self
._AsBuildInfList
:
1049 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1050 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1051 if not M
.IsBinaryModule
:
1053 self
._AsBuildModuleList
.append(InfClass
)
1054 # get library/modules for build
1055 self
.LibraryBuildDirectoryList
= []
1056 self
.ModuleBuildDirectoryList
= []
1060 @cached_class_function
1062 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1064 ## Create autogen code for platform and modules
1066 # Since there's no autogen code for platform, this method will do nothing
1067 # if CreateModuleCodeFile is set to False.
1069 # @param CreateModuleCodeFile Flag indicating if creating module's
1070 # autogen code file or not
1072 @cached_class_function
1073 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1074 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1075 if not CreateModuleCodeFile
:
1078 for Ma
in self
.ModuleAutoGenList
:
1079 Ma
.CreateCodeFile(True)
1081 ## Generate Fds Command
1083 def GenFdsCommand(self
):
1084 return self
.Workspace
.GenFdsCommand
1086 ## Create makefile for the platform and modules in it
1088 # @param CreateModuleMakeFile Flag indicating if the makefile for
1089 # modules will be created as well
1091 def CreateMakeFile(self
, CreateModuleMakeFile
=False, FfsCommand
= {}):
1092 if CreateModuleMakeFile
:
1093 for Ma
in self
._MaList
:
1094 key
= (Ma
.MetaFile
.File
, self
.Arch
)
1095 if key
in FfsCommand
:
1096 Ma
.CreateMakeFile(True, FfsCommand
[key
])
1098 Ma
.CreateMakeFile(True)
1100 # no need to create makefile for the platform more than once
1101 if self
.IsMakeFileCreated
:
1104 # create library/module build dirs for platform
1105 Makefile
= GenMake
.PlatformMakefile(self
)
1106 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1107 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1109 self
.IsMakeFileCreated
= True
1111 ## Deal with Shared FixedAtBuild Pcds
1113 def CollectFixedAtBuildPcds(self
):
1114 for LibAuto
in self
.LibraryAutoGenList
:
1115 FixedAtBuildPcds
= {}
1116 ShareFixedAtBuildPcdsSameValue
= {}
1117 for Module
in LibAuto
.ReferenceModules
:
1118 for Pcd
in set(Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
):
1119 DefaultValue
= Pcd
.DefaultValue
1120 # Cover the case: DSC component override the Pcd value and the Pcd only used in one Lib
1121 if Pcd
in Module
.LibraryPcdList
:
1122 Index
= Module
.LibraryPcdList
.index(Pcd
)
1123 DefaultValue
= Module
.LibraryPcdList
[Index
].DefaultValue
1124 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1125 if key
not in FixedAtBuildPcds
:
1126 ShareFixedAtBuildPcdsSameValue
[key
] = True
1127 FixedAtBuildPcds
[key
] = DefaultValue
1129 if FixedAtBuildPcds
[key
] != DefaultValue
:
1130 ShareFixedAtBuildPcdsSameValue
[key
] = False
1131 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1132 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1133 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1136 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)]
1137 if DscPcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
1139 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1140 LibAuto
.ConstPcd
[key
] = FixedAtBuildPcds
[key
]
1142 def CollectVariables(self
, DynamicPcdSet
):
1145 if self
.Workspace
.FdfFile
:
1146 FdDict
= self
.Workspace
.FdfProfile
.FdDict
[GlobalData
.gFdfParser
.CurrentFdName
]
1147 for FdRegion
in FdDict
.RegionList
:
1148 for item
in FdRegion
.RegionDataList
:
1149 if self
.Platform
.VpdToolGuid
.strip() and self
.Platform
.VpdToolGuid
in item
:
1150 VpdRegionSize
= FdRegion
.Size
1151 VpdRegionBase
= FdRegion
.Offset
1154 VariableInfo
= VariableMgr(self
.DscBuildDataObj
._GetDefaultStores
(), self
.DscBuildDataObj
.SkuIds
)
1155 VariableInfo
.SetVpdRegionMaxSize(VpdRegionSize
)
1156 VariableInfo
.SetVpdRegionOffset(VpdRegionBase
)
1158 for Pcd
in DynamicPcdSet
:
1159 pcdname
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1160 for SkuName
in Pcd
.SkuInfoList
:
1161 Sku
= Pcd
.SkuInfoList
[SkuName
]
1163 if SkuId
is None or SkuId
== '':
1165 if len(Sku
.VariableName
) > 0:
1166 VariableGuidStructure
= Sku
.VariableGuidValue
1167 VariableGuid
= GuidStructureStringToGuidString(VariableGuidStructure
)
1168 for StorageName
in Sku
.DefaultStoreDict
:
1169 VariableInfo
.append_variable(var_info(Index
, pcdname
, StorageName
, SkuName
, StringToArray(Sku
.VariableName
), VariableGuid
, Sku
.VariableOffset
, Sku
.VariableAttribute
, Sku
.HiiDefaultValue
, Sku
.DefaultStoreDict
[StorageName
], Pcd
.DatumType
, Pcd
.CustomAttribute
['DscPosition'], Pcd
.CustomAttribute
.get('IsStru',False)))
1173 def UpdateNVStoreMaxSize(self
, OrgVpdFile
):
1174 if self
.VariableInfo
:
1175 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1176 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
1178 if PcdNvStoreDfBuffer
:
1179 if os
.path
.exists(VpdMapFilePath
):
1180 OrgVpdFile
.Read(VpdMapFilePath
)
1181 PcdItems
= OrgVpdFile
.GetOffset(PcdNvStoreDfBuffer
[0])
1182 NvStoreOffset
= list(PcdItems
.values())[0].strip() if PcdItems
else '0'
1184 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1186 NvStoreOffset
= int(NvStoreOffset
, 16) if NvStoreOffset
.upper().startswith("0X") else int(NvStoreOffset
)
1187 default_skuobj
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
1188 maxsize
= self
.VariableInfo
.VpdRegionSize
- NvStoreOffset
if self
.VariableInfo
.VpdRegionSize
else len(default_skuobj
.DefaultValue
.split(","))
1189 var_data
= self
.VariableInfo
.PatchNVStoreDefaultMaxSize(maxsize
)
1191 if var_data
and default_skuobj
:
1192 default_skuobj
.DefaultValue
= var_data
1193 PcdNvStoreDfBuffer
[0].DefaultValue
= var_data
1194 PcdNvStoreDfBuffer
[0].SkuInfoList
.clear()
1195 PcdNvStoreDfBuffer
[0].SkuInfoList
[TAB_DEFAULT
] = default_skuobj
1196 PcdNvStoreDfBuffer
[0].MaxDatumSize
= str(len(default_skuobj
.DefaultValue
.split(",")))
1200 ## Collect dynamic PCDs
1202 # Gather dynamic PCDs list from each module and their settings from platform
1203 # This interface should be invoked explicitly when platform action is created.
1205 def CollectPlatformDynamicPcds(self
):
1206 for key
in self
.Platform
.Pcds
:
1207 for SinglePcd
in GlobalData
.MixedPcd
:
1208 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1209 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1210 Pcd_Type
= item
[0].split('_')[-1]
1211 if (Pcd_Type
== self
.Platform
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and self
.Platform
.Pcds
[key
].Type
in PCD_DYNAMIC_EX_TYPE_SET
) or \
1212 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
1213 Value
= self
.Platform
.Pcds
[key
]
1214 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1216 newkey
= (Value
.TokenCName
, key
[1])
1218 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1219 del self
.Platform
.Pcds
[key
]
1220 self
.Platform
.Pcds
[newkey
] = Value
1224 # for gathering error information
1225 NoDatumTypePcdList
= set()
1227 for InfName
in self
._AsBuildInfList
:
1228 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1229 FdfModuleList
.append(os
.path
.normpath(InfName
))
1230 for M
in self
._MaList
:
1231 # F is the Module for which M is the module autogen
1232 for PcdFromModule
in list(M
.ModulePcdList
) + list(M
.LibraryPcdList
):
1233 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1234 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1235 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, M
.MetaFile
))
1237 # Check the PCD from Binary INF or Source INF
1238 if M
.IsBinaryModule
== True:
1239 PcdFromModule
.IsFromBinaryInf
= True
1241 # Check the PCD from DSC or not
1242 PcdFromModule
.IsFromDsc
= (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
1244 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
or PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1245 if M
.MetaFile
.Path
not in FdfModuleList
:
1246 # If one of the Source built modules listed in the DSC is not listed
1247 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1248 # access method (it is only listed in the DEC file that declares the
1249 # PCD as PcdsDynamic), then build tool will report warning message
1250 # notify the PI that they are attempting to build a module that must
1251 # be included in a flash image in order to be functional. These Dynamic
1252 # PCD will not be added into the Database unless it is used by other
1253 # modules that are included in the FDF file.
1254 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
and \
1255 PcdFromModule
.IsFromBinaryInf
== False:
1256 # Print warning message to let the developer make a determine.
1258 # If one of the Source built modules listed in the DSC is not listed in
1259 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1260 # access method (it is only listed in the DEC file that declares the
1261 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1262 # PCD to the Platform's PCD Database.
1263 if PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1266 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1267 # it should be stored in Pcd PEI database, If a dynamic only
1268 # used by DXE module, it should be stored in DXE PCD database.
1269 # The default Phase is DXE
1271 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1272 PcdFromModule
.Phase
= "PEI"
1273 if PcdFromModule
not in self
._DynaPcdList
_:
1274 self
._DynaPcdList
_.append(PcdFromModule
)
1275 elif PcdFromModule
.Phase
== 'PEI':
1276 # overwrite any the same PCD existing, if Phase is PEI
1277 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1278 self
._DynaPcdList
_[Index
] = PcdFromModule
1279 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1280 self
._NonDynaPcdList
_.append(PcdFromModule
)
1281 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1282 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1283 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1284 #The PCD from Binary INF will override the same one from source INF
1285 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1286 PcdFromModule
.Pending
= False
1287 self
._NonDynaPcdList
_.append (PcdFromModule
)
1288 DscModuleSet
= {os
.path
.normpath(ModuleInf
.Path
) for ModuleInf
in self
.Platform
.Modules
}
1289 # add the PCD from modules that listed in FDF but not in DSC to Database
1290 for InfName
in FdfModuleList
:
1291 if InfName
not in DscModuleSet
:
1292 InfClass
= PathClass(InfName
)
1293 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1294 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1295 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1296 # For binary module, if in current arch, we need to list the PCDs into database.
1297 if not M
.IsBinaryModule
:
1299 # Override the module PCD setting by platform setting
1300 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1301 for PcdFromModule
in ModulePcdList
:
1302 PcdFromModule
.IsFromBinaryInf
= True
1303 PcdFromModule
.IsFromDsc
= False
1304 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1305 if PcdFromModule
.Type
not in PCD_DYNAMIC_EX_TYPE_SET
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1306 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1308 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1309 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1310 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1311 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1312 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1313 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1314 PcdFromModule
.Phase
= "PEI"
1315 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1316 self
._DynaPcdList
_.append(PcdFromModule
)
1317 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1318 self
._NonDynaPcdList
_.append(PcdFromModule
)
1319 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1320 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1321 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1322 # module & DXE module at a same time.
1323 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1324 # INF file as DynamicEx.
1325 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1326 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1327 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1328 for PcdFromModule
in self
._NonDynaPcdList
_:
1329 # If a PCD is not listed in the DSC file, but binary INF files used by
1330 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1331 # section, AND all source INF files used by this platform the build
1332 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1333 # section, then the tools must NOT add the PCD to the Platform's PCD
1334 # Database; the build must assign the access method for this PCD as
1335 # PcdsPatchableInModule.
1336 if PcdFromModule
not in self
._DynaPcdList
_:
1338 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1339 if PcdFromModule
.IsFromDsc
== False and \
1340 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1341 PcdFromModule
.IsFromBinaryInf
== True and \
1342 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1343 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1344 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1346 # print out error information and break the build, if error found
1347 if len(NoDatumTypePcdList
) > 0:
1348 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1349 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1351 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1352 % NoDatumTypePcdListString
)
1353 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1354 self
._DynamicPcdList
= self
._DynaPcdList
_
1356 # Sort dynamic PCD list to:
1357 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1358 # try to be put header of dynamicd List
1359 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1361 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1363 UnicodePcdArray
= set()
1365 OtherPcdArray
= set()
1367 VpdFile
= VpdInfoFile
.VpdInfoFile()
1368 NeedProcessVpdMapFile
= False
1370 for pcd
in self
.Platform
.Pcds
:
1371 if pcd
not in self
._PlatformPcds
:
1372 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1374 for item
in self
._PlatformPcds
:
1375 if self
._PlatformPcds
[item
].DatumType
and self
._PlatformPcds
[item
].DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1376 self
._PlatformPcds
[item
].DatumType
= TAB_VOID
1378 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1379 for Pcd
in self
._DynamicPcdList
:
1380 # just pick the a value to determine whether is unicode string type
1381 Sku
= list(Pcd
.SkuInfoList
.values())[0]
1382 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1384 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1385 Pcd
.DatumType
= TAB_VOID
1387 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1388 # if found HII type PCD then insert to right of UnicodeIndex
1389 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1390 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1392 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer
1393 PcdNvStoreDfBuffer
= VpdPcdDict
.get(("PcdNvStoreDefaultValueBuffer", "gEfiMdeModulePkgTokenSpaceGuid"))
1394 if PcdNvStoreDfBuffer
:
1395 self
.VariableInfo
= self
.CollectVariables(self
._DynamicPcdList
)
1396 vardump
= self
.VariableInfo
.dump()
1398 PcdNvStoreDfBuffer
.DefaultValue
= vardump
1399 for skuname
in PcdNvStoreDfBuffer
.SkuInfoList
:
1400 PcdNvStoreDfBuffer
.SkuInfoList
[skuname
].DefaultValue
= vardump
1401 PcdNvStoreDfBuffer
.MaxDatumSize
= str(len(vardump
.split(",")))
1403 #If the end user define [DefaultStores] and [XXX.Menufacturing] in DSC, but forget to configure PcdNvStoreDefaultValueBuffer to PcdsDynamicVpd
1404 if [Pcd
for Pcd
in self
._DynamicPcdList
if Pcd
.UserDefinedDefaultStoresFlag
]:
1405 EdkLogger
.warn("build", "PcdNvStoreDefaultValueBuffer should be defined as PcdsDynamicExVpd in dsc file since the DefaultStores is enabled for this platform.\n%s" %self
.Platform
.MetaFile
.Path
)
1406 PlatformPcds
= sorted(self
._PlatformPcds
.keys())
1408 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1411 for PcdKey
in PlatformPcds
:
1412 Pcd
= self
._PlatformPcds
[PcdKey
]
1413 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1414 PcdKey
in VpdPcdDict
:
1415 Pcd
= VpdPcdDict
[PcdKey
]
1417 DefaultSku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
1419 PcdValue
= DefaultSku
.DefaultValue
1420 if PcdValue
not in SkuValueMap
:
1421 SkuValueMap
[PcdValue
] = []
1422 VpdFile
.Add(Pcd
, TAB_DEFAULT
, DefaultSku
.VpdOffset
)
1423 SkuValueMap
[PcdValue
].append(DefaultSku
)
1425 for (SkuName
, Sku
) in Pcd
.SkuInfoList
.items():
1426 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1427 PcdValue
= Sku
.DefaultValue
1429 PcdValue
= Pcd
.DefaultValue
1430 if Sku
.VpdOffset
!= '*':
1431 if PcdValue
.startswith("{"):
1433 elif PcdValue
.startswith("L"):
1438 VpdOffset
= int(Sku
.VpdOffset
)
1441 VpdOffset
= int(Sku
.VpdOffset
, 16)
1443 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1444 if VpdOffset
% Alignment
!= 0:
1445 if PcdValue
.startswith("{"):
1446 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1448 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1449 if PcdValue
not in SkuValueMap
:
1450 SkuValueMap
[PcdValue
] = []
1451 VpdFile
.Add(Pcd
, SkuName
, Sku
.VpdOffset
)
1452 SkuValueMap
[PcdValue
].append(Sku
)
1453 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1454 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1455 NeedProcessVpdMapFile
= True
1456 if self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== '':
1457 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1458 "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")
1460 VpdSkuMap
[PcdKey
] = SkuValueMap
1462 # Fix the PCDs define in VPD PCD section that never referenced by module.
1463 # An example is PCD for signature usage.
1465 for DscPcd
in PlatformPcds
:
1466 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1467 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1468 if not (self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== ''):
1470 for VpdPcd
in VpdFile
._VpdArray
:
1471 # This PCD has been referenced by module
1472 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1473 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1476 # Not found, it should be signature
1478 # just pick the a value to determine whether is unicode string type
1480 SkuObjList
= list(DscPcdEntry
.SkuInfoList
.items())
1481 DefaultSku
= DscPcdEntry
.SkuInfoList
.get(TAB_DEFAULT
)
1483 defaultindex
= SkuObjList
.index((TAB_DEFAULT
, DefaultSku
))
1484 SkuObjList
[0], SkuObjList
[defaultindex
] = SkuObjList
[defaultindex
], SkuObjList
[0]
1485 for (SkuName
, Sku
) in SkuObjList
:
1486 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1488 # Need to iterate DEC pcd information to get the value & datumtype
1489 for eachDec
in self
.PackageList
:
1490 for DecPcd
in eachDec
.Pcds
:
1491 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1492 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1493 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1494 # Print warning message to let the developer make a determine.
1495 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1496 File
=self
.MetaFile
, \
1497 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1498 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1500 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1501 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1502 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1503 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1504 # Only fix the value while no value provided in DSC file.
1505 if not Sku
.DefaultValue
:
1506 DscPcdEntry
.SkuInfoList
[list(DscPcdEntry
.SkuInfoList
.keys())[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1508 if DscPcdEntry
not in self
._DynamicPcdList
:
1509 self
._DynamicPcdList
.append(DscPcdEntry
)
1510 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1511 PcdValue
= Sku
.DefaultValue
1513 PcdValue
= DscPcdEntry
.DefaultValue
1514 if Sku
.VpdOffset
!= '*':
1515 if PcdValue
.startswith("{"):
1517 elif PcdValue
.startswith("L"):
1522 VpdOffset
= int(Sku
.VpdOffset
)
1525 VpdOffset
= int(Sku
.VpdOffset
, 16)
1527 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1528 if VpdOffset
% Alignment
!= 0:
1529 if PcdValue
.startswith("{"):
1530 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1532 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1533 if PcdValue
not in SkuValueMap
:
1534 SkuValueMap
[PcdValue
] = []
1535 VpdFile
.Add(DscPcdEntry
, SkuName
, Sku
.VpdOffset
)
1536 SkuValueMap
[PcdValue
].append(Sku
)
1537 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1538 NeedProcessVpdMapFile
= True
1539 if DscPcdEntry
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1540 UnicodePcdArray
.add(DscPcdEntry
)
1541 elif len(Sku
.VariableName
) > 0:
1542 HiiPcdArray
.add(DscPcdEntry
)
1544 OtherPcdArray
.add(DscPcdEntry
)
1546 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1547 VpdSkuMap
[DscPcd
] = SkuValueMap
1548 if (self
.Platform
.FlashDefinition
is None or self
.Platform
.FlashDefinition
== '') and \
1549 VpdFile
.GetCount() != 0:
1550 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1551 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1553 if VpdFile
.GetCount() != 0:
1555 self
.FixVpdOffset(VpdFile
)
1557 self
.FixVpdOffset(self
.UpdateNVStoreMaxSize(VpdFile
))
1559 # Process VPD map file generated by third party BPDG tool
1560 if NeedProcessVpdMapFile
:
1561 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1562 if os
.path
.exists(VpdMapFilePath
):
1563 VpdFile
.Read(VpdMapFilePath
)
1566 for pcd
in VpdSkuMap
:
1567 vpdinfo
= VpdFile
.GetVpdInfo(pcd
)
1569 # just pick the a value to determine whether is unicode string type
1571 for pcdvalue
in VpdSkuMap
[pcd
]:
1572 for sku
in VpdSkuMap
[pcd
][pcdvalue
]:
1573 for item
in vpdinfo
:
1574 if item
[2] == pcdvalue
:
1575 sku
.VpdOffset
= item
[1]
1577 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1579 # Delete the DynamicPcdList At the last time enter into this function
1580 for Pcd
in self
._DynamicPcdList
:
1581 # just pick the a value to determine whether is unicode string type
1582 Sku
= list(Pcd
.SkuInfoList
.values())[0]
1583 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1585 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1586 Pcd
.DatumType
= TAB_VOID
1588 PcdValue
= Sku
.DefaultValue
1589 if Pcd
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1590 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1591 UnicodePcdArray
.add(Pcd
)
1592 elif len(Sku
.VariableName
) > 0:
1593 # if found HII type PCD then insert to right of UnicodeIndex
1594 HiiPcdArray
.add(Pcd
)
1596 OtherPcdArray
.add(Pcd
)
1597 del self
._DynamicPcdList
[:]
1598 self
._DynamicPcdList
.extend(list(UnicodePcdArray
))
1599 self
._DynamicPcdList
.extend(list(HiiPcdArray
))
1600 self
._DynamicPcdList
.extend(list(OtherPcdArray
))
1601 allskuset
= [(SkuName
, Sku
.SkuId
) for pcd
in self
._DynamicPcdList
for (SkuName
, Sku
) in pcd
.SkuInfoList
.items()]
1602 for pcd
in self
._DynamicPcdList
:
1603 if len(pcd
.SkuInfoList
) == 1:
1604 for (SkuName
, SkuId
) in allskuset
:
1605 if isinstance(SkuId
, str) and eval(SkuId
) == 0 or SkuId
== 0:
1607 pcd
.SkuInfoList
[SkuName
] = copy
.deepcopy(pcd
.SkuInfoList
[TAB_DEFAULT
])
1608 pcd
.SkuInfoList
[SkuName
].SkuId
= SkuId
1609 pcd
.SkuInfoList
[SkuName
].SkuIdName
= SkuName
1610 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1612 def FixVpdOffset(self
, VpdFile
):
1613 FvPath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
1614 if not os
.path
.exists(FvPath
):
1618 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1620 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1622 if VpdFile
.Write(VpdFilePath
):
1623 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1625 for ToolDef
in self
.ToolDefinition
.values():
1626 if TAB_GUID
in ToolDef
and ToolDef
[TAB_GUID
] == self
.Platform
.VpdToolGuid
:
1627 if "PATH" not in ToolDef
:
1628 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1629 BPDGToolName
= ToolDef
["PATH"]
1631 # Call third party GUID BPDG tool.
1632 if BPDGToolName
is not None:
1633 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1635 EdkLogger
.error("Build", FILE_NOT_FOUND
, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")
1637 ## Return the platform build data object
1640 return self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1642 ## Return platform name
1645 return self
.Platform
.PlatformName
1647 ## Return the meta file GUID
1650 return self
.Platform
.Guid
1652 ## Return the platform version
1655 return self
.Platform
.Version
1657 ## Return the FDF file name
1660 if self
.Workspace
.FdfFile
:
1661 RetVal
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1666 ## Return the build output directory platform specifies
1668 def OutputDir(self
):
1669 return self
.Platform
.OutputDirectory
1671 ## Return the directory to store all intermediate and final files built
1674 if os
.path
.isabs(self
.OutputDir
):
1675 GlobalData
.gBuildDirectory
= RetVal
= path
.join(
1676 path
.abspath(self
.OutputDir
),
1677 self
.BuildTarget
+ "_" + self
.ToolChain
,
1680 GlobalData
.gBuildDirectory
= RetVal
= path
.join(
1683 self
.BuildTarget
+ "_" + self
.ToolChain
,
1687 ## Return directory of platform makefile
1689 # @retval string Makefile directory
1692 def MakeFileDir(self
):
1693 return path
.join(self
.BuildDir
, self
.Arch
)
1695 ## Return build command string
1697 # @retval string Build command string
1700 def BuildCommand(self
):
1702 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1703 RetVal
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1704 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1705 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1707 RetVal
+= SplitOption(NewOption
)
1708 if "MAKE" in self
.EdkIIBuildOption
:
1709 if "FLAGS" in self
.EdkIIBuildOption
["MAKE"]:
1710 Flags
= self
.EdkIIBuildOption
["MAKE"]["FLAGS"]
1711 if Flags
.startswith('='):
1712 RetVal
= [RetVal
[0]] + [Flags
[1:]]
1714 RetVal
.append(Flags
)
1717 ## Get tool chain definition
1719 # Get each tool defition for given tool chain from tools_def.txt and platform
1722 def ToolDefinition(self
):
1723 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1724 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1725 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1726 ExtraData
="[%s]" % self
.MetaFile
)
1729 for Def
in ToolDefinition
:
1730 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1731 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1734 Value
= ToolDefinition
[Def
]
1735 # don't record the DLL
1737 DllPathList
.add(Value
)
1740 if Tool
not in RetVal
:
1742 RetVal
[Tool
][Attr
] = Value
1745 if GlobalData
.gOptions
.SilentMode
and "MAKE" in RetVal
:
1746 if "FLAGS" not in RetVal
["MAKE"]:
1747 RetVal
["MAKE"]["FLAGS"] = ""
1748 RetVal
["MAKE"]["FLAGS"] += " -s"
1751 for Attr
in RetVal
[Tool
]:
1752 Value
= RetVal
[Tool
][Attr
]
1753 if Tool
in self
._BuildOptionWithToolDef
(RetVal
) and Attr
in self
._BuildOptionWithToolDef
(RetVal
)[Tool
]:
1754 # check if override is indicated
1755 if self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
].startswith('='):
1756 Value
= self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
][1:]
1759 Value
+= " " + self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
]
1761 Value
= self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
]
1764 # Don't put MAKE definition in the file
1766 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1768 # Don't put MAKE definition in the file
1773 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1776 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1777 for DllPath
in DllPathList
:
1778 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1779 os
.environ
["MAKE_FLAGS"] = MakeFlags
1783 ## Return the paths of tools
1785 def ToolDefinitionFile(self
):
1786 return os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1788 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1790 def ToolChainFamily(self
):
1791 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1792 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1793 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1794 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1795 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1797 RetVal
= TAB_COMPILER_MSFT
1799 RetVal
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1803 def BuildRuleFamily(self
):
1804 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1805 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1806 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1807 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1808 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1810 return TAB_COMPILER_MSFT
1812 return ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1814 ## Return the build options specific for all modules in this platform
1816 def BuildOption(self
):
1817 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1819 def _BuildOptionWithToolDef(self
, ToolDef
):
1820 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, ToolDef
=ToolDef
)
1822 ## Return the build options specific for EDK modules in this platform
1824 def EdkBuildOption(self
):
1825 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1827 ## Return the build options specific for EDKII modules in this platform
1829 def EdkIIBuildOption(self
):
1830 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1832 ## Parse build_rule.txt in Conf Directory.
1834 # @retval BuildRule object
1837 def BuildRule(self
):
1838 BuildRuleFile
= None
1839 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1840 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1841 if not BuildRuleFile
:
1842 BuildRuleFile
= gDefaultBuildRuleFile
1843 RetVal
= BuildRule(BuildRuleFile
)
1844 if RetVal
._FileVersion
== "":
1845 RetVal
._FileVersion
= AutoGenReqBuildRuleVerNum
1847 if RetVal
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1848 # If Build Rule's version is less than the version number required by the tools, halting the build.
1849 EdkLogger
.error("build", AUTOGEN_ERROR
,
1850 ExtraData
="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\
1851 % (RetVal
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1854 ## Summarize the packages used by modules in this platform
1856 def PackageList(self
):
1858 for La
in self
.LibraryAutoGenList
:
1859 RetVal
.update(La
.DependentPackageList
)
1860 for Ma
in self
.ModuleAutoGenList
:
1861 RetVal
.update(Ma
.DependentPackageList
)
1862 #Collect package set information from INF of FDF
1863 for ModuleFile
in self
._AsBuildModuleList
:
1864 if ModuleFile
in self
.Platform
.Modules
:
1866 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1867 RetVal
.update(ModuleData
.Packages
)
1871 def NonDynamicPcdDict(self
):
1872 return {(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
):Pcd
for Pcd
in self
.NonDynamicPcdList
}
1874 ## Get list of non-dynamic PCDs
1876 def NonDynamicPcdList(self
):
1877 self
.CollectPlatformDynamicPcds()
1878 return self
._NonDynamicPcdList
1880 ## Get list of dynamic PCDs
1882 def DynamicPcdList(self
):
1883 self
.CollectPlatformDynamicPcds()
1884 return self
._DynamicPcdList
1886 ## Generate Token Number for all PCD
1888 def PcdTokenNumber(self
):
1889 RetVal
= OrderedDict()
1892 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1896 # TokenNumber 0 ~ 10
1898 # TokeNumber 11 ~ 20
1900 for Pcd
in self
.DynamicPcdList
:
1901 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
1902 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1903 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1906 for Pcd
in self
.DynamicPcdList
:
1907 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1908 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1909 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1912 for Pcd
in self
.DynamicPcdList
:
1913 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
1914 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1915 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1918 for Pcd
in self
.DynamicPcdList
:
1919 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1920 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1921 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1924 for Pcd
in self
.NonDynamicPcdList
:
1925 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1931 for ModuleFile
in self
.Platform
.Modules
:
1940 self
.Platform
.Modules
[ModuleFile
].M
= Ma
1941 return [x
.M
for x
in self
.Platform
.Modules
.values()]
1943 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
1945 def ModuleAutoGenList(self
):
1947 for Ma
in self
._MaList
:
1948 if Ma
not in RetVal
:
1952 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
1954 def LibraryAutoGenList(self
):
1956 for Ma
in self
._MaList
:
1957 for La
in Ma
.LibraryAutoGenList
:
1958 if La
not in RetVal
:
1960 if Ma
not in La
.ReferenceModules
:
1961 La
.ReferenceModules
.append(Ma
)
1964 ## Test if a module is supported by the platform
1966 # An error will be raised directly if the module or its arch is not supported
1967 # by the platform or current configuration
1969 def ValidModule(self
, Module
):
1970 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
1971 or Module
in self
._AsBuildModuleList
1973 ## Resolve the library classes in a module to library instances
1975 # This method will not only resolve library classes but also sort the library
1976 # instances according to the dependency-ship.
1978 # @param Module The module from which the library classes will be resolved
1980 # @retval library_list List of library instances sorted
1982 def ApplyLibraryInstance(self
, Module
):
1983 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
1984 if str(Module
) not in self
.Platform
.Modules
:
1987 return GetModuleLibInstances(Module
,
1996 ## Override PCD setting (type, value, ...)
1998 # @param ToPcd The PCD to be overrided
1999 # @param FromPcd The PCD overrideing from
2001 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
="", Msg
="", Library
=""):
2003 # in case there's PCDs coming from FDF file, which have no type given.
2004 # at this point, ToPcd.Type has the type found from dependent
2007 TokenCName
= ToPcd
.TokenCName
2008 for PcdItem
in GlobalData
.MixedPcd
:
2009 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2010 TokenCName
= PcdItem
[0]
2012 if FromPcd
is not None:
2013 if ToPcd
.Pending
and FromPcd
.Type
:
2014 ToPcd
.Type
= FromPcd
.Type
2015 elif ToPcd
.Type
and FromPcd
.Type\
2016 and ToPcd
.Type
!= FromPcd
.Type
and ToPcd
.Type
in FromPcd
.Type
:
2017 if ToPcd
.Type
.strip() == TAB_PCDS_DYNAMIC_EX
:
2018 ToPcd
.Type
= FromPcd
.Type
2019 elif ToPcd
.Type
and FromPcd
.Type \
2020 and ToPcd
.Type
!= FromPcd
.Type
:
2022 Module
= str(Module
) + " 's library file (" + str(Library
) + ")"
2023 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2024 ExtraData
="%s.%s is used as [%s] in module %s, but as [%s] in %s."\
2025 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2026 ToPcd
.Type
, Module
, FromPcd
.Type
, Msg
),
2029 if FromPcd
.MaxDatumSize
:
2030 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2031 ToPcd
.MaxSizeUserSet
= FromPcd
.MaxDatumSize
2032 if FromPcd
.DefaultValue
:
2033 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2034 if FromPcd
.TokenValue
:
2035 ToPcd
.TokenValue
= FromPcd
.TokenValue
2036 if FromPcd
.DatumType
:
2037 ToPcd
.DatumType
= FromPcd
.DatumType
2038 if FromPcd
.SkuInfoList
:
2039 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2040 if FromPcd
.UserDefinedDefaultStoresFlag
:
2041 ToPcd
.UserDefinedDefaultStoresFlag
= FromPcd
.UserDefinedDefaultStoresFlag
2042 # Add Flexible PCD format parse
2043 if ToPcd
.DefaultValue
:
2045 ToPcd
.DefaultValue
= ValueExpressionEx(ToPcd
.DefaultValue
, ToPcd
.DatumType
, self
.Workspace
._GuidDict
)(True)
2046 except BadExpression
as Value
:
2047 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
, ToPcd
.DefaultValue
, Value
),
2050 # check the validation of datum
2051 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2053 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2054 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2055 ToPcd
.validateranges
= FromPcd
.validateranges
2056 ToPcd
.validlists
= FromPcd
.validlists
2057 ToPcd
.expressions
= FromPcd
.expressions
2058 ToPcd
.CustomAttribute
= FromPcd
.CustomAttribute
2060 if FromPcd
is not None and ToPcd
.DatumType
== TAB_VOID
and not ToPcd
.MaxDatumSize
:
2061 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2062 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2063 Value
= ToPcd
.DefaultValue
2065 ToPcd
.MaxDatumSize
= '1'
2066 elif Value
[0] == 'L':
2067 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2068 elif Value
[0] == '{':
2069 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2071 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2073 # apply default SKU for dynamic PCDS if specified one is not available
2074 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_SET
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
) \
2075 and not ToPcd
.SkuInfoList
:
2076 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2077 SkuName
= self
.Platform
.SkuName
2079 SkuName
= TAB_DEFAULT
2080 ToPcd
.SkuInfoList
= {
2081 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
][0], '', '', '', '', '', ToPcd
.DefaultValue
)
2084 ## Apply PCD setting defined platform to a module
2086 # @param Module The module from which the PCD setting will be overrided
2088 # @retval PCD_list The list PCDs with settings from platform
2090 def ApplyPcdSetting(self
, Module
, Pcds
, Library
=""):
2091 # for each PCD in module
2092 for Name
, Guid
in Pcds
:
2093 PcdInModule
= Pcds
[Name
, Guid
]
2094 # find out the PCD setting in platform
2095 if (Name
, Guid
) in self
.Platform
.Pcds
:
2096 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2098 PcdInPlatform
= None
2099 # then override the settings if any
2100 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
, Msg
="DSC PCD sections", Library
=Library
)
2101 # resolve the VariableGuid value
2102 for SkuId
in PcdInModule
.SkuInfoList
:
2103 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2104 if Sku
.VariableGuid
== '': continue
2105 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2106 if Sku
.VariableGuidValue
is None:
2107 PackageList
= "\n\t".join(str(P
) for P
in self
.PackageList
)
2110 RESOURCE_NOT_AVAILABLE
,
2111 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2112 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2113 % (Guid
, Name
, str(Module
)),
2117 # override PCD settings with module specific setting
2118 if Module
in self
.Platform
.Modules
:
2119 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2120 for Key
in PlatformModule
.Pcds
:
2125 elif Key
in GlobalData
.MixedPcd
:
2126 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
2128 ToPcd
= Pcds
[PcdItem
]
2132 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
, Msg
="DSC Components Module scoped PCD section", Library
=Library
)
2133 # use PCD value to calculate the MaxDatumSize when it is not specified
2134 for Name
, Guid
in Pcds
:
2135 Pcd
= Pcds
[Name
, Guid
]
2136 if Pcd
.DatumType
== TAB_VOID
and not Pcd
.MaxDatumSize
:
2137 Pcd
.MaxSizeUserSet
= None
2138 Value
= Pcd
.DefaultValue
2140 Pcd
.MaxDatumSize
= '1'
2141 elif Value
[0] == 'L':
2142 Pcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2143 elif Value
[0] == '{':
2144 Pcd
.MaxDatumSize
= str(len(Value
.split(',')))
2146 Pcd
.MaxDatumSize
= str(len(Value
) - 1)
2147 return list(Pcds
.values())
2149 ## Resolve library names to library modules
2151 # (for Edk.x modules)
2153 # @param Module The module from which the library names will be resolved
2155 # @retval library_list The list of library modules
2157 def ResolveLibraryReference(self
, Module
):
2158 EdkLogger
.verbose("")
2159 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2160 LibraryConsumerList
= [Module
]
2162 # "CompilerStub" is a must for Edk modules
2163 if Module
.Libraries
:
2164 Module
.Libraries
.append("CompilerStub")
2166 while len(LibraryConsumerList
) > 0:
2167 M
= LibraryConsumerList
.pop()
2168 for LibraryName
in M
.Libraries
:
2169 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2171 for Key
in self
.Platform
.LibraryClasses
.data
:
2172 if LibraryName
.upper() == Key
.upper():
2173 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2176 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2177 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2180 if Library
not in LibraryList
:
2181 LibraryList
.append(Library
)
2182 LibraryConsumerList
.append(Library
)
2183 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2186 ## Calculate the priority value of the build option
2188 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2190 # @retval Value Priority value based on the priority list.
2192 def CalculatePriorityValue(self
, Key
):
2193 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2194 PriorityValue
= 0x11111
2196 PriorityValue
&= 0x01111
2197 if ToolChain
== "*":
2198 PriorityValue
&= 0x10111
2200 PriorityValue
&= 0x11011
2201 if CommandType
== "*":
2202 PriorityValue
&= 0x11101
2204 PriorityValue
&= 0x11110
2206 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2209 ## Expand * in build option key
2211 # @param Options Options to be expanded
2212 # @param ToolDef Use specified ToolDef instead of full version.
2213 # This is needed during initialization to prevent
2214 # infinite recursion betweeh BuildOptions,
2215 # ToolDefinition, and this function.
2217 # @retval options Options expanded
2219 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None, ToolDef
=None):
2221 ToolDef
= self
.ToolDefinition
2228 # Construct a list contain the build options which need override.
2232 # Key[0] -- tool family
2233 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2235 if (Key
[0] == self
.BuildRuleFamily
and
2236 (ModuleStyle
is None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2237 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2238 if (Target
== self
.BuildTarget
or Target
== "*") and\
2239 (ToolChain
== self
.ToolChain
or ToolChain
== "*") and\
2240 (Arch
== self
.Arch
or Arch
== "*") and\
2241 Options
[Key
].startswith("="):
2243 if OverrideList
.get(Key
[1]) is not None:
2244 OverrideList
.pop(Key
[1])
2245 OverrideList
[Key
[1]] = Options
[Key
]
2248 # Use the highest priority value.
2250 if (len(OverrideList
) >= 2):
2251 KeyList
= list(OverrideList
.keys())
2252 for Index
in range(len(KeyList
)):
2253 NowKey
= KeyList
[Index
]
2254 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2255 for Index1
in range(len(KeyList
) - Index
- 1):
2256 NextKey
= KeyList
[Index1
+ Index
+ 1]
2258 # Compare two Key, if one is included by another, choose the higher priority one
2260 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2261 if (Target1
== Target2
or Target1
== "*" or Target2
== "*") and\
2262 (ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*") and\
2263 (Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*") and\
2264 (CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*") and\
2265 (Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*"):
2267 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2268 if Options
.get((self
.BuildRuleFamily
, NextKey
)) is not None:
2269 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2271 if Options
.get((self
.BuildRuleFamily
, NowKey
)) is not None:
2272 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2275 if ModuleStyle
is not None and len (Key
) > 2:
2276 # Check Module style is EDK or EDKII.
2277 # Only append build option for the matched style module.
2278 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2280 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2283 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2284 # if tool chain family doesn't match, skip it
2285 if Tool
in ToolDef
and Family
!= "":
2286 FamilyIsNull
= False
2287 if ToolDef
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2288 if Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2290 elif Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2293 # expand any wildcard
2294 if Target
== "*" or Target
== self
.BuildTarget
:
2295 if Tag
== "*" or Tag
== self
.ToolChain
:
2296 if Arch
== "*" or Arch
== self
.Arch
:
2297 if Tool
not in BuildOptions
:
2298 BuildOptions
[Tool
] = {}
2299 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2300 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2302 # append options for the same tool except PATH
2304 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2306 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2307 # Build Option Family has been checked, which need't to be checked again for family.
2308 if FamilyMatch
or FamilyIsNull
:
2312 if ModuleStyle
is not None and len (Key
) > 2:
2313 # Check Module style is EDK or EDKII.
2314 # Only append build option for the matched style module.
2315 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2317 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2320 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2321 # if tool chain family doesn't match, skip it
2322 if Tool
not in ToolDef
or Family
== "":
2324 # option has been added before
2325 if Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2328 # expand any wildcard
2329 if Target
== "*" or Target
== self
.BuildTarget
:
2330 if Tag
== "*" or Tag
== self
.ToolChain
:
2331 if Arch
== "*" or Arch
== self
.Arch
:
2332 if Tool
not in BuildOptions
:
2333 BuildOptions
[Tool
] = {}
2334 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2335 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2337 # append options for the same tool except PATH
2339 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2341 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2344 ## Append build options in platform to a module
2346 # @param Module The module to which the build options will be appened
2348 # @retval options The options appended with build options in platform
2350 def ApplyBuildOption(self
, Module
):
2351 # Get the different options for the different style module
2352 if Module
.AutoGenVersion
< 0x00010005:
2353 PlatformOptions
= self
.EdkBuildOption
2354 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2356 PlatformOptions
= self
.EdkIIBuildOption
2357 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2358 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2359 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2360 if Module
in self
.Platform
.Modules
:
2361 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2362 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2364 PlatformModuleOptions
= {}
2366 BuildRuleOrder
= None
2367 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2368 for Tool
in Options
:
2369 for Attr
in Options
[Tool
]:
2370 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2371 BuildRuleOrder
= Options
[Tool
][Attr
]
2373 AllTools
= set(list(ModuleOptions
.keys()) + list(PlatformOptions
.keys()) +
2374 list(PlatformModuleOptions
.keys()) + list(ModuleTypeOptions
.keys()) +
2375 list(self
.ToolDefinition
.keys()))
2376 BuildOptions
= defaultdict(lambda: defaultdict(str))
2377 for Tool
in AllTools
:
2378 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2379 if Tool
not in Options
:
2381 for Attr
in Options
[Tool
]:
2383 # Do not generate it in Makefile
2385 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2387 Value
= Options
[Tool
][Attr
]
2388 # check if override is indicated
2389 if Value
.startswith('='):
2390 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
[1:])
2393 BuildOptions
[Tool
][Attr
] += " " + mws
.handleWsMacro(Value
)
2395 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
)
2397 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
is not None:
2399 # Override UNI flag only for EDK module.
2401 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2402 return BuildOptions
, BuildRuleOrder
2405 # extend lists contained in a dictionary with lists stored in another dictionary
2406 # if CopyToDict is not derived from DefaultDict(list) then this may raise exception
2408 def ExtendCopyDictionaryLists(CopyToDict
, CopyFromDict
):
2409 for Key
in CopyFromDict
:
2410 CopyToDict
[Key
].extend(CopyFromDict
[Key
])
2412 # Create a directory specified by a set of path elements and return the full path
2413 def _MakeDir(PathList
):
2414 RetVal
= path
.join(*PathList
)
2415 CreateDirectory(RetVal
)
2418 ## ModuleAutoGen class
2420 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2421 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2422 # to the [depex] section in module's inf file.
2424 class ModuleAutoGen(AutoGen
):
2425 # call super().__init__ then call the worker function with different parameter count
2426 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2427 if not hasattr(self
, "_Init"):
2428 super().__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2429 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
)
2432 ## Cache the timestamps of metafiles of every module in a class attribute
2436 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2437 # check if this module is employed by active platform
2438 if not PlatformAutoGen(Workspace
, args
[0], Target
, Toolchain
, Arch
).ValidModule(MetaFile
):
2439 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2442 return super().__new
__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2444 ## Initialize ModuleAutoGen
2446 # @param Workspace EdkIIWorkspaceBuild object
2447 # @param ModuleFile The path of module file
2448 # @param Target Build target (DEBUG, RELEASE)
2449 # @param Toolchain Name of tool chain
2450 # @param Arch The arch the module supports
2451 # @param PlatformFile Platform meta-file
2453 def _InitWorker(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2454 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2455 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2457 self
.Workspace
= Workspace
2458 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2459 self
.MetaFile
= ModuleFile
2460 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2462 self
.SourceDir
= self
.MetaFile
.SubDir
2463 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2465 self
.SourceOverrideDir
= None
2466 # use overrided path defined in DSC file
2467 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2468 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2470 self
.ToolChain
= Toolchain
2471 self
.BuildTarget
= Target
2473 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2474 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2476 self
.IsCodeFileCreated
= False
2477 self
.IsAsBuiltInfCreated
= False
2478 self
.DepexGenerated
= False
2480 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2481 self
.BuildRuleOrder
= None
2484 self
._PcdComments
= OrderedListDict()
2485 self
._GuidComments
= OrderedListDict()
2486 self
._ProtocolComments
= OrderedListDict()
2487 self
._PpiComments
= OrderedListDict()
2488 self
._BuildTargets
= None
2489 self
._IntroBuildTargetList
= None
2490 self
._FinalBuildTargetList
= None
2491 self
._FileTypes
= None
2493 self
.AutoGenDepSet
= set()
2494 self
.ReferenceModules
= []
2499 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2501 # Get FixedAtBuild Pcds of this Module
2503 def FixedAtBuildPcds(self
):
2505 for Pcd
in self
.ModulePcdList
:
2506 if Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
2508 if Pcd
not in RetVal
:
2513 def FixedVoidTypePcds(self
):
2515 for Pcd
in self
.FixedAtBuildPcds
:
2516 if Pcd
.DatumType
== TAB_VOID
:
2517 if '{}.{}'.format(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in RetVal
:
2518 RetVal
['{}.{}'.format(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)] = Pcd
.DefaultValue
2522 def UniqueBaseName(self
):
2523 BaseName
= self
.Name
2524 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2525 if Module
.MetaFile
== self
.MetaFile
:
2527 if Module
.Name
== self
.Name
:
2528 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2529 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2530 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2531 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2534 # Macros could be used in build_rule.txt (also Makefile)
2537 return OrderedDict((
2538 ("WORKSPACE" ,self
.WorkspaceDir
),
2539 ("MODULE_NAME" ,self
.Name
),
2540 ("MODULE_NAME_GUID" ,self
.UniqueBaseName
),
2541 ("MODULE_GUID" ,self
.Guid
),
2542 ("MODULE_VERSION" ,self
.Version
),
2543 ("MODULE_TYPE" ,self
.ModuleType
),
2544 ("MODULE_FILE" ,str(self
.MetaFile
)),
2545 ("MODULE_FILE_BASE_NAME" ,self
.MetaFile
.BaseName
),
2546 ("MODULE_RELATIVE_DIR" ,self
.SourceDir
),
2547 ("MODULE_DIR" ,self
.SourceDir
),
2548 ("BASE_NAME" ,self
.Name
),
2549 ("ARCH" ,self
.Arch
),
2550 ("TOOLCHAIN" ,self
.ToolChain
),
2551 ("TOOLCHAIN_TAG" ,self
.ToolChain
),
2552 ("TOOL_CHAIN_TAG" ,self
.ToolChain
),
2553 ("TARGET" ,self
.BuildTarget
),
2554 ("BUILD_DIR" ,self
.PlatformInfo
.BuildDir
),
2555 ("BIN_DIR" ,os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)),
2556 ("LIB_DIR" ,os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)),
2557 ("MODULE_BUILD_DIR" ,self
.BuildDir
),
2558 ("OUTPUT_DIR" ,self
.OutputDir
),
2559 ("DEBUG_DIR" ,self
.DebugDir
),
2560 ("DEST_DIR_OUTPUT" ,self
.OutputDir
),
2561 ("DEST_DIR_DEBUG" ,self
.DebugDir
),
2562 ("PLATFORM_NAME" ,self
.PlatformInfo
.Name
),
2563 ("PLATFORM_GUID" ,self
.PlatformInfo
.Guid
),
2564 ("PLATFORM_VERSION" ,self
.PlatformInfo
.Version
),
2565 ("PLATFORM_RELATIVE_DIR" ,self
.PlatformInfo
.SourceDir
),
2566 ("PLATFORM_DIR" ,mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)),
2567 ("PLATFORM_OUTPUT_DIR" ,self
.PlatformInfo
.OutputDir
),
2568 ("FFS_OUTPUT_DIR" ,self
.FfsOutputDir
)
2571 ## Return the module build data object
2574 return self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2576 ## Return the module name
2579 return self
.Module
.BaseName
2581 ## Return the module DxsFile if exist
2584 return self
.Module
.DxsFile
2586 ## Return the module meta-file GUID
2590 # To build same module more than once, the module path with FILE_GUID overridden has
2591 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2592 # in DSC. The overridden GUID can be retrieved from file name
2594 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2596 # Length of GUID is 36
2598 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2599 return self
.Module
.Guid
2601 ## Return the module version
2604 return self
.Module
.Version
2606 ## Return the module type
2608 def ModuleType(self
):
2609 return self
.Module
.ModuleType
2611 ## Return the component type (for Edk.x style of module)
2613 def ComponentType(self
):
2614 return self
.Module
.ComponentType
2616 ## Return the build type
2618 def BuildType(self
):
2619 return self
.Module
.BuildType
2621 ## Return the PCD_IS_DRIVER setting
2623 def PcdIsDriver(self
):
2624 return self
.Module
.PcdIsDriver
2626 ## Return the autogen version, i.e. module meta-file version
2628 def AutoGenVersion(self
):
2629 return self
.Module
.AutoGenVersion
2631 ## Check if the module is library or not
2633 def IsLibrary(self
):
2634 return bool(self
.Module
.LibraryClass
)
2636 ## Check if the module is binary module or not
2638 def IsBinaryModule(self
):
2639 return self
.Module
.IsBinaryModule
2641 ## Return the directory to store intermediate files of the module
2645 self
.PlatformInfo
.BuildDir
,
2648 self
.MetaFile
.BaseName
2651 ## Return the directory to store the intermediate object files of the mdoule
2653 def OutputDir(self
):
2654 return _MakeDir((self
.BuildDir
, "OUTPUT"))
2656 ## Return the directory path to store ffs file
2658 def FfsOutputDir(self
):
2659 if GlobalData
.gFdfParser
:
2660 return path
.join(self
.PlatformInfo
.BuildDir
, TAB_FV_DIRECTORY
, "Ffs", self
.Guid
+ self
.Name
)
2663 ## Return the directory to store auto-gened source files of the mdoule
2666 return _MakeDir((self
.BuildDir
, "DEBUG"))
2668 ## Return the path of custom file
2670 def CustomMakefile(self
):
2672 for Type
in self
.Module
.CustomMakefile
:
2673 MakeType
= gMakeTypeMap
[Type
] if Type
in gMakeTypeMap
else 'nmake'
2674 if self
.SourceOverrideDir
is not None:
2675 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2676 if not os
.path
.exists(File
):
2677 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2679 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2680 RetVal
[MakeType
] = File
2683 ## Return the directory of the makefile
2685 # @retval string The directory string of module's makefile
2688 def MakeFileDir(self
):
2689 return self
.BuildDir
2691 ## Return build command string
2693 # @retval string Build command string
2696 def BuildCommand(self
):
2697 return self
.PlatformInfo
.BuildCommand
2699 ## Get object list of all packages the module and its dependent libraries belong to
2701 # @retval list The list of package object
2704 def DerivedPackageList(self
):
2706 for M
in [self
.Module
] + self
.DependentLibraryList
:
2707 for Package
in M
.Packages
:
2708 if Package
in PackageList
:
2710 PackageList
.append(Package
)
2713 ## Get the depex string
2715 # @return : a string contain all depex expresion.
2716 def _GetDepexExpresionString(self
):
2719 ## DPX_SOURCE IN Define section.
2720 if self
.Module
.DxsFile
:
2722 for M
in [self
.Module
] + self
.DependentLibraryList
:
2723 Filename
= M
.MetaFile
.Path
2724 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2725 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2726 for DepexExpresion
in DepexExpresionList
:
2727 for key
in DepexExpresion
:
2728 Arch
, ModuleType
= key
2729 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2730 # the type of build module is USER_DEFINED.
2731 # All different DEPEX section tags would be copied into the As Built INF file
2732 # and there would be separate DEPEX section tags
2733 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2734 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2735 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2737 if Arch
.upper() == TAB_ARCH_COMMON
or \
2738 (Arch
.upper() == self
.Arch
.upper() and \
2739 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2740 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2742 #the type of build module is USER_DEFINED.
2743 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2744 for Depex
in DepexList
:
2746 DepexStr
+= '[Depex.%s.%s]\n' % key
2747 DepexStr
+= '\n'.join('# '+ val
for val
in Depex
[key
])
2750 return '[Depex.%s]\n' % self
.Arch
2753 #the type of build module not is USER_DEFINED.
2755 for Depex
in DepexList
:
2760 for D
in Depex
.values():
2761 DepexStr
+= ' '.join(val
for val
in D
)
2762 Index
= DepexStr
.find('END')
2763 if Index
> -1 and Index
== len(DepexStr
) - 3:
2764 DepexStr
= DepexStr
[:-3]
2765 DepexStr
= DepexStr
.strip()
2768 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2770 return '[Depex.%s]\n' % self
.Arch
2771 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2773 ## Merge dependency expression
2775 # @retval list The token list of the dependency expression after parsed
2778 def DepexList(self
):
2779 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2784 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2786 for M
in [self
.Module
] + self
.DependentLibraryList
:
2788 for D
in M
.Depex
[self
.Arch
, self
.ModuleType
]:
2790 DepexList
.append('AND')
2791 DepexList
.append('(')
2792 #replace D with value if D is FixedAtBuild PCD
2796 NewList
.append(item
)
2798 if item
not in self
._FixedPcdVoidTypeDict
:
2799 EdkLogger
.error("build", FORMAT_INVALID
, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item
))
2801 Value
= self
._FixedPcdVoidTypeDict
[item
]
2802 if len(Value
.split(',')) != 16:
2803 EdkLogger
.error("build", FORMAT_INVALID
,
2804 "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item
))
2805 NewList
.append(Value
)
2806 DepexList
.extend(NewList
)
2807 if DepexList
[-1] == 'END': # no need of a END at this time
2809 DepexList
.append(')')
2812 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2813 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2815 if len(DepexList
) > 0:
2816 EdkLogger
.verbose('')
2817 return {self
.ModuleType
:DepexList
}
2819 ## Merge dependency expression
2821 # @retval list The token list of the dependency expression after parsed
2824 def DepexExpressionDict(self
):
2825 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2828 DepexExpressionString
= ''
2830 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2832 for M
in [self
.Module
] + self
.DependentLibraryList
:
2834 for D
in M
.DepexExpression
[self
.Arch
, self
.ModuleType
]:
2835 if DepexExpressionString
!= '':
2836 DepexExpressionString
+= ' AND '
2837 DepexExpressionString
+= '('
2838 DepexExpressionString
+= D
2839 DepexExpressionString
= DepexExpressionString
.rstrip('END').strip()
2840 DepexExpressionString
+= ')'
2843 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionString
))
2844 if 'BEFORE' in DepexExpressionString
or 'AFTER' in DepexExpressionString
:
2846 if len(DepexExpressionString
) > 0:
2847 EdkLogger
.verbose('')
2849 return {self
.ModuleType
:DepexExpressionString
}
2851 # Get the tiano core user extension, it is contain dependent library.
2852 # @retval: a list contain tiano core userextension.
2854 def _GetTianoCoreUserExtensionList(self
):
2855 TianoCoreUserExtentionList
= []
2856 for M
in [self
.Module
] + self
.DependentLibraryList
:
2857 Filename
= M
.MetaFile
.Path
2858 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2859 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
2860 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
2861 for Section
in TianoCoreUserExtent
:
2862 ItemList
= Section
.split(TAB_SPLIT
)
2864 if len(ItemList
) == 4:
2866 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
2868 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
2869 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
2870 TianoCoreList
.append('\n')
2871 TianoCoreUserExtentionList
.append(TianoCoreList
)
2873 return TianoCoreUserExtentionList
2875 ## Return the list of specification version required for the module
2877 # @retval list The list of specification defined in module file
2880 def Specification(self
):
2881 return self
.Module
.Specification
2883 ## Tool option for the module build
2885 # @param PlatformInfo The object of PlatformBuildInfo
2886 # @retval dict The dict containing valid options
2889 def BuildOption(self
):
2890 RetVal
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2891 if self
.BuildRuleOrder
:
2892 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
2895 ## Get include path list from tool option for the module build
2897 # @retval list The include path list
2900 def BuildOptionIncPathList(self
):
2902 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2903 # is the former use /I , the Latter used -I to specify include directories
2905 if self
.PlatformInfo
.ToolChainFamily
in (TAB_COMPILER_MSFT
):
2906 BuildOptIncludeRegEx
= gBuildOptIncludePatternMsft
2907 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
2908 BuildOptIncludeRegEx
= gBuildOptIncludePatternOther
2911 # New ToolChainFamily, don't known whether there is option to specify include directories
2916 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2918 FlagOption
= self
.BuildOption
[Tool
]['FLAGS']
2922 if self
.ToolChainFamily
!= 'RVCT':
2923 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in BuildOptIncludeRegEx
.findall(FlagOption
)]
2926 # RVCT may specify a list of directory seperated by commas
2929 for Path
in BuildOptIncludeRegEx
.findall(FlagOption
):
2930 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
2931 IncPathList
.extend(NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
)
2934 # EDK II modules must not reference header files outside of the packages they depend on or
2935 # within the module's directory tree. Report error if violation.
2937 if self
.AutoGenVersion
>= 0x00010005:
2938 for Path
in IncPathList
:
2939 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
2940 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
2941 EdkLogger
.error("build",
2944 File
=str(self
.MetaFile
))
2945 RetVal
+= IncPathList
2948 ## Return a list of files which can be built from source
2950 # What kind of files can be built is determined by build rules in
2951 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
2954 def SourceFileList(self
):
2956 ToolChainTagSet
= {"", "*", self
.ToolChain
}
2957 ToolChainFamilySet
= {"", "*", self
.ToolChainFamily
, self
.BuildRuleFamily
}
2958 for F
in self
.Module
.Sources
:
2960 if F
.TagName
not in ToolChainTagSet
:
2961 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
2962 "but [%s] is currently used" % (F
.TagName
, str(F
), self
.ToolChain
))
2964 # match tool chain family or build rule family
2965 if F
.ToolChainFamily
not in ToolChainFamilySet
:
2968 "The file [%s] must be built by tools of [%s], " \
2969 "but current toolchain family is [%s], buildrule family is [%s]" \
2970 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
, self
.BuildRuleFamily
))
2973 # add the file path into search path list for file including
2974 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
2975 self
.IncludePathList
.insert(0, F
.Dir
)
2978 self
._MatchBuildRuleOrder
(RetVal
)
2981 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
2984 def _MatchBuildRuleOrder(self
, FileList
):
2987 for SingleFile
in FileList
:
2988 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
2989 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
2990 if key
in Order_Dict
:
2991 Order_Dict
[key
].append(SingleFile
.Ext
)
2993 Order_Dict
[key
] = [SingleFile
.Ext
]
2996 for F
in Order_Dict
:
2997 if len(Order_Dict
[F
]) > 1:
2998 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
2999 for Ext
in Order_Dict
[F
][1:]:
3000 RemoveList
.append(F
+ Ext
)
3002 for item
in RemoveList
:
3003 FileList
.remove(item
)
3007 ## Return the list of unicode files
3009 def UnicodeFileList(self
):
3010 return self
.FileTypes
.get(TAB_UNICODE_FILE
,[])
3012 ## Return the list of vfr files
3014 def VfrFileList(self
):
3015 return self
.FileTypes
.get(TAB_VFR_FILE
, [])
3017 ## Return the list of Image Definition files
3019 def IdfFileList(self
):
3020 return self
.FileTypes
.get(TAB_IMAGE_FILE
,[])
3022 ## Return a list of files which can be built from binary
3024 # "Build" binary files are just to copy them to build directory.
3026 # @retval list The list of files which can be built later
3029 def BinaryFileList(self
):
3031 for F
in self
.Module
.Binaries
:
3032 if F
.Target
not in [TAB_ARCH_COMMON
, '*'] and F
.Target
!= self
.BuildTarget
:
3035 self
._ApplyBuildRule
(F
, F
.Type
, BinaryFileList
=RetVal
)
3039 def BuildRules(self
):
3041 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3042 for Type
in BuildRuleDatabase
.FileTypeList
:
3043 #first try getting build rule by BuildRuleFamily
3044 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3046 # build type is always module type, but ...
3047 if self
.ModuleType
!= self
.BuildType
:
3048 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3049 #second try getting build rule by ToolChainFamily
3051 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3053 # build type is always module type, but ...
3054 if self
.ModuleType
!= self
.BuildType
:
3055 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3058 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3059 RetVal
[Type
] = RuleObject
3060 for Ext
in RuleObject
.SourceFileExtList
:
3061 RetVal
[Ext
] = RuleObject
3064 def _ApplyBuildRule(self
, File
, FileType
, BinaryFileList
=None):
3065 if self
._BuildTargets
is None:
3066 self
._IntroBuildTargetList
= set()
3067 self
._FinalBuildTargetList
= set()
3068 self
._BuildTargets
= defaultdict(set)
3069 self
._FileTypes
= defaultdict(set)
3071 if not BinaryFileList
:
3072 BinaryFileList
= self
.BinaryFileList
3074 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3075 if not os
.path
.exists(SubDirectory
):
3076 CreateDirectory(SubDirectory
)
3082 # Make sure to get build rule order value
3086 while Index
< len(SourceList
):
3087 Source
= SourceList
[Index
]
3091 CreateDirectory(Source
.Dir
)
3093 if File
.IsBinary
and File
== Source
and File
in BinaryFileList
:
3094 # Skip all files that are not binary libraries
3095 if not self
.IsLibrary
:
3097 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3098 elif FileType
in self
.BuildRules
:
3099 RuleObject
= self
.BuildRules
[FileType
]
3100 elif Source
.Ext
in self
.BuildRules
:
3101 RuleObject
= self
.BuildRules
[Source
.Ext
]
3103 # stop at no more rules
3105 self
._FinalBuildTargetList
.add(LastTarget
)
3108 FileType
= RuleObject
.SourceFileType
3109 self
._FileTypes
[FileType
].add(Source
)
3111 # stop at STATIC_LIBRARY for library
3112 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3114 self
._FinalBuildTargetList
.add(LastTarget
)
3117 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3120 self
._FinalBuildTargetList
.add(LastTarget
)
3122 elif not Target
.Outputs
:
3123 # Only do build for target with outputs
3124 self
._FinalBuildTargetList
.add(Target
)
3126 self
._BuildTargets
[FileType
].add(Target
)
3128 if not Source
.IsBinary
and Source
== File
:
3129 self
._IntroBuildTargetList
.add(Target
)
3131 # to avoid cyclic rule
3132 if FileType
in RuleChain
:
3135 RuleChain
.add(FileType
)
3136 SourceList
.extend(Target
.Outputs
)
3138 FileType
= TAB_UNKNOWN_FILE
3142 if self
._BuildTargets
is None:
3143 self
._IntroBuildTargetList
= set()
3144 self
._FinalBuildTargetList
= set()
3145 self
._BuildTargets
= defaultdict(set)
3146 self
._FileTypes
= defaultdict(set)
3148 #TRICK: call SourceFileList property to apply build rule for source files
3151 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3154 return self
._BuildTargets
3157 def IntroTargetList(self
):
3159 return self
._IntroBuildTargetList
3162 def CodaTargetList(self
):
3164 return self
._FinalBuildTargetList
3167 def FileTypes(self
):
3169 return self
._FileTypes
3171 ## Get the list of package object the module depends on
3173 # @retval list The package object list
3176 def DependentPackageList(self
):
3177 return self
.Module
.Packages
3179 ## Return the list of auto-generated code file
3181 # @retval list The list of auto-generated file
3184 def AutoGenFileList(self
):
3185 AutoGenUniIdf
= self
.BuildType
!= 'UEFI_HII'
3186 UniStringBinBuffer
= BytesIO()
3187 IdfGenBinBuffer
= BytesIO()
3189 AutoGenC
= TemplateString()
3190 AutoGenH
= TemplateString()
3191 StringH
= TemplateString()
3192 StringIdf
= TemplateString()
3193 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, AutoGenUniIdf
, UniStringBinBuffer
, StringIdf
, AutoGenUniIdf
, IdfGenBinBuffer
)
3195 # AutoGen.c is generated if there are library classes in inf, or there are object files
3197 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3198 or TAB_OBJECT_FILE
in self
.FileTypes
):
3199 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3200 RetVal
[AutoFile
] = str(AutoGenC
)
3201 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3202 if str(AutoGenH
) != "":
3203 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3204 RetVal
[AutoFile
] = str(AutoGenH
)
3205 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3206 if str(StringH
) != "":
3207 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3208 RetVal
[AutoFile
] = str(StringH
)
3209 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3210 if UniStringBinBuffer
is not None and UniStringBinBuffer
.getvalue() != b
"":
3211 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3212 RetVal
[AutoFile
] = UniStringBinBuffer
.getvalue()
3213 AutoFile
.IsBinary
= True
3214 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3215 if UniStringBinBuffer
is not None:
3216 UniStringBinBuffer
.close()
3217 if str(StringIdf
) != "":
3218 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3219 RetVal
[AutoFile
] = str(StringIdf
)
3220 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3221 if IdfGenBinBuffer
is not None and IdfGenBinBuffer
.getvalue() != b
"":
3222 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3223 RetVal
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3224 AutoFile
.IsBinary
= True
3225 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3226 if IdfGenBinBuffer
is not None:
3227 IdfGenBinBuffer
.close()
3230 ## Return the list of library modules explicitly or implicityly used by this module
3232 def DependentLibraryList(self
):
3233 # only merge library classes and PCD for non-library module
3236 if self
.AutoGenVersion
< 0x00010005:
3237 return self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3238 return self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3240 ## Get the list of PCDs from current module
3242 # @retval list The list of PCD
3245 def ModulePcdList(self
):
3246 # apply PCD settings from platform
3247 RetVal
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3248 ExtendCopyDictionaryLists(self
._PcdComments
, self
.Module
.PcdComments
)
3251 ## Get the list of PCDs from dependent libraries
3253 # @retval list The list of PCD
3256 def LibraryPcdList(self
):
3261 # get PCDs from dependent libraries
3262 for Library
in self
.DependentLibraryList
:
3263 PcdsInLibrary
= OrderedDict()
3264 ExtendCopyDictionaryLists(self
._PcdComments
, Library
.PcdComments
)
3265 for Key
in Library
.Pcds
:
3266 # skip duplicated PCDs
3267 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3270 PcdsInLibrary
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3271 RetVal
.extend(self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, PcdsInLibrary
, Library
=Library
))
3274 ## Get the GUID value mapping
3276 # @retval dict The mapping between GUID cname and its value
3280 RetVal
= OrderedDict(self
.Module
.Guids
)
3281 for Library
in self
.DependentLibraryList
:
3282 RetVal
.update(Library
.Guids
)
3283 ExtendCopyDictionaryLists(self
._GuidComments
, Library
.GuidComments
)
3284 ExtendCopyDictionaryLists(self
._GuidComments
, self
.Module
.GuidComments
)
3288 def GetGuidsUsedByPcd(self
):
3289 RetVal
= OrderedDict(self
.Module
.GetGuidsUsedByPcd())
3290 for Library
in self
.DependentLibraryList
:
3291 RetVal
.update(Library
.GetGuidsUsedByPcd())
3293 ## Get the protocol value mapping
3295 # @retval dict The mapping between protocol cname and its value
3298 def ProtocolList(self
):
3299 RetVal
= OrderedDict(self
.Module
.Protocols
)
3300 for Library
in self
.DependentLibraryList
:
3301 RetVal
.update(Library
.Protocols
)
3302 ExtendCopyDictionaryLists(self
._ProtocolComments
, Library
.ProtocolComments
)
3303 ExtendCopyDictionaryLists(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3306 ## Get the PPI value mapping
3308 # @retval dict The mapping between PPI cname and its value
3312 RetVal
= OrderedDict(self
.Module
.Ppis
)
3313 for Library
in self
.DependentLibraryList
:
3314 RetVal
.update(Library
.Ppis
)
3315 ExtendCopyDictionaryLists(self
._PpiComments
, Library
.PpiComments
)
3316 ExtendCopyDictionaryLists(self
._PpiComments
, self
.Module
.PpiComments
)
3319 ## Get the list of include search path
3321 # @retval list The list path
3324 def IncludePathList(self
):
3326 if self
.AutoGenVersion
< 0x00010005:
3327 for Inc
in self
.Module
.Includes
:
3328 if Inc
not in RetVal
:
3331 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3332 if os
.path
.exists(Inc
) and Inc
not in RetVal
:
3334 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3335 RetVal
.append(self
.DebugDir
)
3337 RetVal
.append(self
.MetaFile
.Dir
)
3338 RetVal
.append(self
.DebugDir
)
3340 for Package
in self
.Module
.Packages
:
3341 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3342 if PackageDir
not in RetVal
:
3343 RetVal
.append(PackageDir
)
3344 IncludesList
= Package
.Includes
3345 if Package
._PrivateIncludes
:
3346 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3347 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3348 for Inc
in IncludesList
:
3349 if Inc
not in RetVal
:
3350 RetVal
.append(str(Inc
))
3354 def IncludePathLength(self
):
3355 return sum(len(inc
)+1 for inc
in self
.IncludePathList
)
3357 ## Get HII EX PCDs which maybe used by VFR
3359 # efivarstore used by VFR may relate with HII EX PCDs
3360 # Get the variable name and GUID from efivarstore and HII EX PCD
3361 # List the HII EX PCDs in As Built INF if both name and GUID match.
3363 # @retval list HII EX PCDs
3365 def _GetPcdsMaybeUsedByVfr(self
):
3366 if not self
.SourceFileList
:
3370 for SrcFile
in self
.SourceFileList
:
3371 if SrcFile
.Ext
.lower() != '.vfr':
3373 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3374 if not os
.path
.exists(Vfri
):
3376 VfriFile
= open(Vfri
, 'r')
3377 Content
= VfriFile
.read()
3379 Pos
= Content
.find('efivarstore')
3382 # Make sure 'efivarstore' is the start of efivarstore statement
3383 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3386 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3388 if Index
>= 0 and Content
[Index
] != ';':
3389 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3392 # 'efivarstore' must be followed by name and guid
3394 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3397 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3400 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3401 NameGuids
.add((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3402 Pos
= Content
.find('efivarstore', Name
.end())
3406 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3407 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3409 for SkuInfo
in Pcd
.SkuInfoList
.values():
3410 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3413 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3414 Guid
= GuidStructureStringToGuidString(Value
)
3415 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3416 HiiExPcds
.append(Pcd
)
3421 def _GenOffsetBin(self
):
3423 for SourceFile
in self
.Module
.Sources
:
3424 if SourceFile
.Type
.upper() == ".VFR" :
3426 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3428 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3429 elif SourceFile
.Type
.upper() == ".UNI" :
3431 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3433 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3435 if not VfrUniBaseName
:
3437 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3438 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3439 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, list(VfrUniBaseName
.values()))
3440 if not VfrUniOffsetList
:
3443 OutputName
= '%sOffset.bin' % self
.Name
3444 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3447 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3449 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
, None)
3451 # Use a instance of BytesIO to cache data
3452 fStringIO
= BytesIO()
3454 for Item
in VfrUniOffsetList
:
3455 if (Item
[0].find("Strings") != -1):
3457 # UNI offset in image.
3459 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3461 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3462 fStringIO
.write(bytes(UniGuid
))
3463 UniValue
= pack ('Q', int (Item
[1], 16))
3464 fStringIO
.write (UniValue
)
3467 # VFR binary offset in image.
3469 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3471 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3472 fStringIO
.write(bytes(VfrGuid
))
3473 VfrValue
= pack ('Q', int (Item
[1], 16))
3474 fStringIO
.write (VfrValue
)
3476 # write data into file.
3479 fInputfile
.write (fStringIO
.getvalue())
3481 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3482 "file been locked or using by other applications." %UniVfrOffsetFileName
, None)
3488 ## Create AsBuilt INF file the module
3490 def CreateAsBuiltInf(self
, IsOnlyCopy
= False):
3491 self
.OutputFile
= set()
3492 if IsOnlyCopy
and GlobalData
.gBinCacheDest
:
3493 self
.CopyModuleToCache()
3496 if self
.IsAsBuiltInfCreated
:
3499 # Skip the following code for EDK I inf
3500 if self
.AutoGenVersion
< 0x00010005:
3503 # Skip the following code for libraries
3507 # Skip the following code for modules with no source files
3508 if not self
.SourceFileList
:
3511 # Skip the following code for modules without any binary files
3512 if self
.BinaryFileList
:
3515 ### TODO: How to handles mixed source and binary modules
3517 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3518 # Also find all packages that the DynamicEx PCDs depend on
3523 PcdTokenSpaceList
= []
3524 for Pcd
in list(self
.ModulePcdList
) + list(self
.LibraryPcdList
):
3525 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3526 PatchablePcds
.append(Pcd
)
3527 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_PATCHABLE_IN_MODULE
))
3528 elif Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
3531 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
))
3532 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
))
3533 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3534 GuidList
= OrderedDict(self
.GuidList
)
3535 for TokenSpace
in self
.GetGuidsUsedByPcd
:
3536 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3537 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3538 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3539 GuidList
.pop(TokenSpace
)
3540 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3541 for Package
in self
.DerivedPackageList
:
3542 if Package
in Packages
:
3544 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3546 for Index
in range(len(BeChecked
)):
3547 for Item
in CheckList
[Index
]:
3548 if Item
in BeChecked
[Index
]:
3549 Packages
.append(Package
)
3555 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3556 for Pkg
in self
.PlatformInfo
.PackageList
:
3559 for VfrPcd
in VfrPcds
:
3560 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
) in Pkg
.Pcds
or
3561 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
) in Pkg
.Pcds
):
3562 Packages
.append(Pkg
)
3565 ModuleType
= SUP_MODULE_DXE_DRIVER
if self
.ModuleType
== SUP_MODULE_UEFI_DRIVER
and self
.DepexGenerated
else self
.ModuleType
3566 DriverType
= self
.PcdIsDriver
if self
.PcdIsDriver
else ''
3568 MDefs
= self
.Module
.Defines
3571 'module_name' : self
.Name
,
3572 'module_guid' : Guid
,
3573 'module_module_type' : ModuleType
,
3574 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3575 'pcd_is_driver_string' : [],
3576 'module_uefi_specification_version' : [],
3577 'module_pi_specification_version' : [],
3578 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3579 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3580 'module_constructor' : self
.Module
.ConstructorList
,
3581 'module_destructor' : self
.Module
.DestructorList
,
3582 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3583 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3584 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3585 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3586 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3587 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3588 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3589 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3590 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3591 'module_arch' : self
.Arch
,
3592 'package_item' : [Package
.MetaFile
.File
.replace('\\', '/') for Package
in Packages
],
3594 'patchablepcd_item' : [],
3596 'protocol_item' : [],
3600 'libraryclasses_item' : []
3603 if 'MODULE_UNI_FILE' in MDefs
:
3604 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3605 if os
.path
.isfile(UNIFile
):
3606 shutil
.copy2(UNIFile
, self
.OutputDir
)
3608 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3609 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3611 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3614 AsBuiltInfDict
['pcd_is_driver_string'].append(DriverType
)
3616 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3617 AsBuiltInfDict
['module_uefi_specification_version'].append(self
.Specification
['UEFI_SPECIFICATION_VERSION'])
3618 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3619 AsBuiltInfDict
['module_pi_specification_version'].append(self
.Specification
['PI_SPECIFICATION_VERSION'])
3621 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3622 DebugDir
= self
.DebugDir
.replace('\\', '/').strip('/')
3623 for Item
in self
.CodaTargetList
:
3624 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(DebugDir
, '').replace(OutputDir
, '').strip('/')
3625 self
.OutputFile
.add(File
)
3626 if os
.path
.isabs(File
):
3627 File
= File
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3628 if Item
.Target
.Ext
.lower() == '.aml':
3629 AsBuiltInfDict
['binary_item'].append('ASL|' + File
)
3630 elif Item
.Target
.Ext
.lower() == '.acpi':
3631 AsBuiltInfDict
['binary_item'].append('ACPI|' + File
)
3632 elif Item
.Target
.Ext
.lower() == '.efi':
3633 AsBuiltInfDict
['binary_item'].append('PE32|' + self
.Name
+ '.efi')
3635 AsBuiltInfDict
['binary_item'].append('BIN|' + File
)
3636 if self
.DepexGenerated
:
3637 self
.OutputFile
.add(self
.Name
+ '.depex')
3638 if self
.ModuleType
in [SUP_MODULE_PEIM
]:
3639 AsBuiltInfDict
['binary_item'].append('PEI_DEPEX|' + self
.Name
+ '.depex')
3640 elif self
.ModuleType
in [SUP_MODULE_DXE_DRIVER
, SUP_MODULE_DXE_RUNTIME_DRIVER
, SUP_MODULE_DXE_SAL_DRIVER
, SUP_MODULE_UEFI_DRIVER
]:
3641 AsBuiltInfDict
['binary_item'].append('DXE_DEPEX|' + self
.Name
+ '.depex')
3642 elif self
.ModuleType
in [SUP_MODULE_DXE_SMM_DRIVER
]:
3643 AsBuiltInfDict
['binary_item'].append('SMM_DEPEX|' + self
.Name
+ '.depex')
3645 Bin
= self
._GenOffsetBin
()
3647 AsBuiltInfDict
['binary_item'].append('BIN|%s' % Bin
)
3648 self
.OutputFile
.add(Bin
)
3650 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3652 if File
.lower().endswith('.pdb'):
3653 AsBuiltInfDict
['binary_item'].append('DISPOSABLE|' + File
)
3654 self
.OutputFile
.add(File
)
3655 HeaderComments
= self
.Module
.HeaderComments
3657 for Index
in range(len(HeaderComments
)):
3658 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3659 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3662 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3663 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3666 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3667 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3668 (GuidList
, self
._GuidComments
, 'guid_item')
3670 for Item
in GenList
:
3671 for CName
in Item
[0]:
3672 Comments
= '\n '.join(Item
[1][CName
]) if CName
in Item
[1] else ''
3673 Entry
= Comments
+ '\n ' + CName
if Comments
else CName
3674 AsBuiltInfDict
[Item
[2]].append(Entry
)
3675 PatchList
= parsePcdInfoFromMapFile(
3676 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3677 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3680 for Pcd
in PatchablePcds
:
3681 TokenCName
= Pcd
.TokenCName
3682 for PcdItem
in GlobalData
.MixedPcd
:
3683 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3684 TokenCName
= PcdItem
[0]
3686 for PatchPcd
in PatchList
:
3687 if TokenCName
== PatchPcd
[0]:
3692 if Pcd
.DatumType
== 'BOOLEAN':
3693 BoolValue
= Pcd
.DefaultValue
.upper()
3694 if BoolValue
== 'TRUE':
3695 Pcd
.DefaultValue
= '1'
3696 elif BoolValue
== 'FALSE':
3697 Pcd
.DefaultValue
= '0'
3699 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
3700 HexFormat
= '0x%02x'
3701 if Pcd
.DatumType
== TAB_UINT16
:
3702 HexFormat
= '0x%04x'
3703 elif Pcd
.DatumType
== TAB_UINT32
:
3704 HexFormat
= '0x%08x'
3705 elif Pcd
.DatumType
== TAB_UINT64
:
3706 HexFormat
= '0x%016x'
3707 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3709 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
3710 EdkLogger
.error("build", AUTOGEN_ERROR
,
3711 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3713 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3714 PcdValue
= Pcd
.DefaultValue
3715 if PcdValue
[0] != '{':
3717 if PcdValue
[0] == 'L':
3719 PcdValue
= PcdValue
.lstrip('L')
3720 PcdValue
= eval(PcdValue
)
3722 for Index
in range(0, len(PcdValue
)):
3724 CharVal
= ord(PcdValue
[Index
])
3725 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3726 + '0x%02x' % (CharVal
>> 8) + ', '
3728 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3731 Padding
= Padding
* 2
3732 ArraySize
= ArraySize
/ 2
3733 if ArraySize
< (len(PcdValue
) + 1):
3734 if Pcd
.MaxSizeUserSet
:
3735 EdkLogger
.error("build", AUTOGEN_ERROR
,
3736 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3739 ArraySize
= len(PcdValue
) + 1
3740 if ArraySize
> len(PcdValue
) + 1:
3741 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3742 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3743 elif len(PcdValue
.split(',')) <= ArraySize
:
3744 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3747 if Pcd
.MaxSizeUserSet
:
3748 EdkLogger
.error("build", AUTOGEN_ERROR
,
3749 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3752 ArraySize
= len(PcdValue
) + 1
3753 PcdItem
= '%s.%s|%s|0x%X' % \
3754 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
3756 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3757 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3759 PcdItem
= PcdComments
+ '\n ' + PcdItem
3760 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3762 for Pcd
in Pcds
+ VfrPcds
:
3765 TokenCName
= Pcd
.TokenCName
3766 for PcdItem
in GlobalData
.MixedPcd
:
3767 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3768 TokenCName
= PcdItem
[0]
3770 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3771 for SkuName
in Pcd
.SkuInfoList
:
3772 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3773 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3775 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3776 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3780 for Index
, Comment
in enumerate(PcdCommentList
):
3781 for Usage
in UsageList
:
3782 if Comment
.find(Usage
) != -1:
3786 if UsageIndex
!= -1:
3787 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3789 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3790 PcdComments
= '\n '.join(PcdCommentList
)
3791 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
3793 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3794 AsBuiltInfDict
['pcd_item'].append(PcdEntry
)
3795 for Item
in self
.BuildOption
:
3796 if 'FLAGS' in self
.BuildOption
[Item
]:
3797 AsBuiltInfDict
['flags_item'].append('%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip()))
3799 # Generated LibraryClasses section in comments.
3800 for Library
in self
.LibraryAutoGenList
:
3801 AsBuiltInfDict
['libraryclasses_item'].append(Library
.MetaFile
.File
.replace('\\', '/'))
3803 # Generated UserExtensions TianoCore section.
3804 # All tianocore user extensions are copied.
3806 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
3807 UserExtStr
+= '\n'.join(TianoCore
)
3808 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
3809 if os
.path
.isfile(ExtensionFile
):
3810 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
3811 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
3813 # Generated depex expression section in comments.
3814 DepexExpresion
= self
._GetDepexExpresionString
()
3815 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
if DepexExpresion
else ''
3817 AsBuiltInf
= TemplateString()
3818 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3820 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3822 self
.IsAsBuiltInfCreated
= True
3823 if GlobalData
.gBinCacheDest
:
3824 self
.CopyModuleToCache()
3826 def CopyModuleToCache(self
):
3827 FileDir
= path
.join(GlobalData
.gBinCacheDest
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
3828 CreateDirectory (FileDir
)
3829 HashFile
= path
.join(self
.BuildDir
, self
.Name
+ '.hash')
3830 ModuleFile
= path
.join(self
.OutputDir
, self
.Name
+ '.inf')
3831 if os
.path
.exists(HashFile
):
3832 shutil
.copy2(HashFile
, FileDir
)
3833 if os
.path
.exists(ModuleFile
):
3834 shutil
.copy2(ModuleFile
, FileDir
)
3835 if not self
.OutputFile
:
3836 Ma
= self
.BuildDatabase
[PathClass(ModuleFile
), self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
3837 self
.OutputFile
= Ma
.Binaries
3839 for File
in self
.OutputFile
:
3841 if not os
.path
.isabs(File
):
3842 File
= os
.path
.join(self
.OutputDir
, File
)
3843 if os
.path
.exists(File
):
3844 shutil
.copy2(File
, FileDir
)
3846 def AttemptModuleCacheCopy(self
):
3847 if self
.IsBinaryModule
:
3849 FileDir
= path
.join(GlobalData
.gBinCacheSource
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
3850 HashFile
= path
.join(FileDir
, self
.Name
+ '.hash')
3851 if os
.path
.exists(HashFile
):
3852 f
= open(HashFile
, 'r')
3853 CacheHash
= f
.read()
3855 if GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
3856 if CacheHash
== GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
3857 for root
, dir, files
in os
.walk(FileDir
):
3859 if self
.Name
+ '.hash' in f
:
3860 shutil
.copy2(HashFile
, self
.BuildDir
)
3862 File
= path
.join(root
, f
)
3863 shutil
.copy2(File
, self
.OutputDir
)
3864 if self
.Name
== "PcdPeim" or self
.Name
== "PcdDxe":
3865 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3869 ## Create makefile for the module and its dependent libraries
3871 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3872 # dependent libraries will be created
3874 @cached_class_function
3875 def CreateMakeFile(self
, CreateLibraryMakeFile
=True, GenFfsList
= []):
3876 # nest this function inside it's only caller.
3877 def CreateTimeStamp():
3878 FileSet
= {self
.MetaFile
.Path
}
3880 for SourceFile
in self
.Module
.Sources
:
3881 FileSet
.add (SourceFile
.Path
)
3883 for Lib
in self
.DependentLibraryList
:
3884 FileSet
.add (Lib
.MetaFile
.Path
)
3886 for f
in self
.AutoGenDepSet
:
3887 FileSet
.add (f
.Path
)
3889 if os
.path
.exists (self
.TimeStampPath
):
3890 os
.remove (self
.TimeStampPath
)
3891 with
open(self
.TimeStampPath
, 'w+') as file:
3895 # Ignore generating makefile when it is a binary module
3896 if self
.IsBinaryModule
:
3899 self
.GenFfsList
= GenFfsList
3900 if not self
.IsLibrary
and CreateLibraryMakeFile
:
3901 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3902 LibraryAutoGen
.CreateMakeFile()
3907 if len(self
.CustomMakefile
) == 0:
3908 Makefile
= GenMake
.ModuleMakefile(self
)
3910 Makefile
= GenMake
.CustomMakefile(self
)
3911 if Makefile
.Generate():
3912 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
3913 (self
.Name
, self
.Arch
))
3915 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
3916 (self
.Name
, self
.Arch
))
3920 def CopyBinaryFiles(self
):
3921 for File
in self
.Module
.Binaries
:
3923 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
3924 CopyLongFilePath(SrcPath
, DstPath
)
3925 ## Create autogen code for the module and its dependent libraries
3927 # @param CreateLibraryCodeFile Flag indicating if or not the code of
3928 # dependent libraries will be created
3930 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
3931 if self
.IsCodeFileCreated
:
3934 # Need to generate PcdDatabase even PcdDriver is binarymodule
3935 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
3936 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3938 if self
.IsBinaryModule
:
3940 self
.CopyBinaryFiles()
3943 if not self
.IsLibrary
and CreateLibraryCodeFile
:
3944 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3945 LibraryAutoGen
.CreateCodeFile()
3951 IgoredAutoGenList
= []
3953 for File
in self
.AutoGenFileList
:
3954 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
3955 #Ignore Edk AutoGen.c
3956 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
3959 AutoGenList
.append(str(File
))
3961 IgoredAutoGenList
.append(str(File
))
3963 # Skip the following code for EDK I inf
3964 if self
.AutoGenVersion
< 0x00010005:
3967 for ModuleType
in self
.DepexList
:
3968 # Ignore empty [depex] section or [depex] section for SUP_MODULE_USER_DEFINED module
3969 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== SUP_MODULE_USER_DEFINED
:
3972 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
3973 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
3975 if len(Dpx
.PostfixNotation
) != 0:
3976 self
.DepexGenerated
= True
3978 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
3979 AutoGenList
.append(str(DpxFile
))
3981 IgoredAutoGenList
.append(str(DpxFile
))
3983 if IgoredAutoGenList
== []:
3984 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
3985 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
3986 elif AutoGenList
== []:
3987 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
3988 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3990 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
3991 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3993 self
.IsCodeFileCreated
= True
3996 ## Summarize the ModuleAutoGen objects of all libraries used by this module
3998 def LibraryAutoGenList(self
):
4000 for Library
in self
.DependentLibraryList
:
4007 self
.PlatformInfo
.MetaFile
4009 if La
not in RetVal
:
4011 for Lib
in La
.CodaTargetList
:
4012 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4015 def GenModuleHash(self
):
4016 if self
.Arch
not in GlobalData
.gModuleHash
:
4017 GlobalData
.gModuleHash
[self
.Arch
] = {}
4019 # Add Platform level hash
4020 m
.update(GlobalData
.gPlatformHash
.encode('utf-8'))
4021 # Add Package level hash
4022 if self
.DependentPackageList
:
4023 for Pkg
in sorted(self
.DependentPackageList
, key
=lambda x
: x
.PackageName
):
4024 if Pkg
.PackageName
in GlobalData
.gPackageHash
[self
.Arch
]:
4025 m
.update(GlobalData
.gPackageHash
[self
.Arch
][Pkg
.PackageName
].encode('utf-8'))
4028 if self
.LibraryAutoGenList
:
4029 for Lib
in sorted(self
.LibraryAutoGenList
, key
=lambda x
: x
.Name
):
4030 if Lib
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4032 m
.update(GlobalData
.gModuleHash
[self
.Arch
][Lib
.Name
].encode('utf-8'))
4035 f
= open(str(self
.MetaFile
), 'rb')
4039 # Add Module's source files
4040 if self
.SourceFileList
:
4041 for File
in sorted(self
.SourceFileList
, key
=lambda x
: str(x
)):
4042 f
= open(str(File
), 'rb')
4047 ModuleHashFile
= path
.join(self
.BuildDir
, self
.Name
+ ".hash")
4048 if self
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4049 GlobalData
.gModuleHash
[self
.Arch
][self
.Name
] = m
.hexdigest()
4050 if GlobalData
.gBinCacheSource
:
4051 if self
.AttemptModuleCacheCopy():
4053 return SaveFileOnChange(ModuleHashFile
, m
.hexdigest(), True)
4055 ## Decide whether we can skip the ModuleAutoGen process
4056 def CanSkipbyHash(self
):
4057 if GlobalData
.gUseHashCache
:
4058 return not self
.GenModuleHash()
4061 ## Decide whether we can skip the ModuleAutoGen process
4062 # If any source file is newer than the module than we cannot skip
4065 if self
.MakeFileDir
in GlobalData
.gSikpAutoGenCache
:
4067 if not os
.path
.exists(self
.TimeStampPath
):
4069 #last creation time of the module
4070 DstTimeStamp
= os
.stat(self
.TimeStampPath
)[8]
4072 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4073 if SrcTimeStamp
> DstTimeStamp
:
4076 with
open(self
.TimeStampPath
,'r') as f
:
4078 source
= source
.rstrip('\n')
4079 if not os
.path
.exists(source
):
4081 if source
not in ModuleAutoGen
.TimeDict
:
4082 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4083 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4085 GlobalData
.gSikpAutoGenCache
.add(self
.MakeFileDir
)
4089 def TimeStampPath(self
):
4090 return os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')