2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 import Common
.LongFilePathOs
as os
18 import os
.path
as path
25 from StringIO
import StringIO
27 from StrGather
import *
28 from BuildEngine
import BuildRule
30 from Common
.LongFilePathSupport
import CopyLongFilePath
31 from Common
.BuildToolError
import *
32 from Common
.DataType
import *
33 from Common
.Misc
import *
34 from Common
.String
import *
35 import Common
.GlobalData
as GlobalData
36 from GenFds
.FdfParser
import *
37 from CommonDataClass
.CommonClass
import SkuInfoClass
38 from Workspace
.BuildClassObject
import *
39 from GenPatchPcdTable
.GenPatchPcdTable
import parsePcdInfoFromMapFile
40 import Common
.VpdInfoFile
as VpdInfoFile
41 from GenPcdDb
import CreatePcdDatabaseCode
42 from Workspace
.MetaFileCommentParser
import UsageList
43 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
44 import InfSectionParser
47 from GenVar
import VariableMgr
,var_info
48 from collections
import OrderedDict
50 ## Regular expression for splitting Dependency Expression string into tokens
51 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
54 # Match name = variable
56 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
58 # The format of guid in efivarstore statement likes following and must be correct:
59 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
61 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
63 ## Mapping Makefile type
64 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
67 ## Build rule configuration file
68 gDefaultBuildRuleFile
= 'build_rule.txt'
70 ## Tools definition configuration file
71 gDefaultToolsDefFile
= 'tools_def.txt'
73 ## Build rule default version
74 AutoGenReqBuildRuleVerNum
= "0.1"
76 ## default file name for AutoGen
77 gAutoGenCodeFileName
= "AutoGen.c"
78 gAutoGenHeaderFileName
= "AutoGen.h"
79 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
80 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
81 gAutoGenDepexFileName
= "%(module_name)s.depex"
82 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
83 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
84 gInfSpecVersion
= "0x00010017"
87 # Template string to generic AsBuilt INF
89 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
95 INF_VERSION = ${module_inf_version}
96 BASE_NAME = ${module_name}
97 FILE_GUID = ${module_guid}
98 MODULE_TYPE = ${module_module_type}${BEGIN}
99 VERSION_STRING = ${module_version_string}${END}${BEGIN}
100 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
101 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
102 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
103 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
104 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
105 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
106 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
107 SHADOW = ${module_shadow}${END}${BEGIN}
108 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
109 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
110 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
111 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
112 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
113 SPEC = ${module_spec}${END}${BEGIN}
114 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
115 MODULE_UNI_FILE = ${module_uni_file}${END}
117 [Packages.${module_arch}]${BEGIN}
118 ${package_item}${END}
120 [Binaries.${module_arch}]${BEGIN}
123 [PatchPcd.${module_arch}]${BEGIN}
127 [Protocols.${module_arch}]${BEGIN}
131 [Ppis.${module_arch}]${BEGIN}
135 [Guids.${module_arch}]${BEGIN}
139 [PcdEx.${module_arch}]${BEGIN}
143 [LibraryClasses.${module_arch}]
144 ## @LIB_INSTANCES${BEGIN}
145 # ${libraryclasses_item}${END}
149 ${userextension_tianocore_item}
153 [BuildOptions.${module_arch}]
155 ## ${flags_item}${END}
158 ## Base class for AutoGen
160 # This class just implements the cache mechanism of AutoGen objects.
162 class AutoGen(object):
163 # database to maintain the objects in each child class
164 __ObjectCache
= {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object
168 # @param Class class object of real AutoGen class
169 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
170 # @param Workspace Workspace directory or WorkspaceAutoGen object
171 # @param MetaFile The path of meta file
172 # @param Target Build target
173 # @param Toolchain Tool chain name
174 # @param Arch Target arch
175 # @param *args The specific class related parameters
176 # @param **kwargs The specific class related dict parameters
178 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
179 # check if the object has been created
180 Key
= (Target
, Toolchain
, Arch
, MetaFile
)
182 # if it exists, just return it directly
183 return cls
.__ObjectCache
[Key
]
185 # it didnt exist. create it, cache it, then return it
186 cls
.__ObjectCache
[Key
] = super(AutoGen
, cls
).__new
__(cls
)
187 return cls
.__ObjectCache
[Key
]
189 def __init__ (self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
190 super(AutoGen
, self
).__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
194 # The file path of platform file will be used to represent hash value of this object
196 # @retval int Hash value of the file path of platform file
199 return hash(self
.MetaFile
)
203 # The file path of platform file will be used to represent this object
205 # @retval string String of platform file path
208 return str(self
.MetaFile
)
211 def __eq__(self
, Other
):
212 return Other
and self
.MetaFile
== Other
214 ## Workspace AutoGen class
216 # This class is used mainly to control the whole platform build for different
217 # architecture. This class will generate top level makefile.
219 class WorkspaceAutoGen(AutoGen
):
220 # call super().__init__ then call the worker function with different parameter count
221 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
225 super(WorkspaceAutoGen
, self
).__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
226 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
229 ## Initialize WorkspaceAutoGen
231 # @param WorkspaceDir Root directory of workspace
232 # @param ActivePlatform Meta-file of active platform
233 # @param Target Build target
234 # @param Toolchain Tool chain name
235 # @param ArchList List of architecture of current build
236 # @param MetaFileDb Database containing meta-files
237 # @param BuildConfig Configuration of build
238 # @param ToolDefinition Tool chain definitions
239 # @param FlashDefinitionFile File of flash definition
240 # @param Fds FD list to be generated
241 # @param Fvs FV list to be generated
242 # @param Caps Capsule list to be generated
243 # @param SkuId SKU id from command line
245 def _InitWorker(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
246 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
247 Progress
=None, BuildModule
=None):
254 self
.BuildDatabase
= MetaFileDb
255 self
.MetaFile
= ActivePlatform
256 self
.WorkspaceDir
= WorkspaceDir
257 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, 'COMMON', Target
, Toolchain
]
258 GlobalData
.gActivePlatform
= self
.Platform
259 self
.BuildTarget
= Target
260 self
.ToolChain
= Toolchain
261 self
.ArchList
= ArchList
263 self
.UniFlag
= UniFlag
265 self
.TargetTxt
= BuildConfig
266 self
.ToolDef
= ToolDefinition
267 self
.FdfFile
= FlashDefinitionFile
268 self
.FdTargetList
= Fds
269 self
.FvTargetList
= Fvs
270 self
.CapTargetList
= Caps
271 self
.AutoGenObjectList
= []
272 self
._BuildDir
= None
274 self
._MakeFileDir
= None
275 self
._BuildCommand
= None
278 # there's many relative directory operations, so ...
279 os
.chdir(self
.WorkspaceDir
)
284 if not self
.ArchList
:
285 ArchList
= set(self
.Platform
.SupArchList
)
287 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
289 EdkLogger
.error("build", PARAMETER_INVALID
,
290 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
291 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
292 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
293 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
294 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
295 self
.ArchList
= tuple(ArchList
)
297 # Validate build target
298 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
299 EdkLogger
.error("build", PARAMETER_INVALID
,
300 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
301 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
304 # parse FDF file to get PCDs in it, if any
306 self
.FdfFile
= self
.Platform
.FlashDefinition
310 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
311 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
312 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
314 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
316 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
319 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
321 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
324 Progress
.Start("\nProcessing meta-data")
328 # Mark now build in AutoGen Phase
330 GlobalData
.gAutoGenPhase
= True
331 Fdf
= FdfParser(self
.FdfFile
.Path
)
333 GlobalData
.gFdfParser
= Fdf
334 GlobalData
.gAutoGenPhase
= False
335 PcdSet
= Fdf
.Profile
.PcdDict
336 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
337 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
338 for FdRegion
in FdDict
.RegionList
:
339 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
340 if int(FdRegion
.Offset
) % 8 != 0:
341 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
342 ModuleList
= Fdf
.Profile
.InfList
343 self
.FdfProfile
= Fdf
.Profile
344 for fvname
in self
.FvTargetList
:
345 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
346 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
347 "No such an FV in FDF file: %s" % fvname
)
349 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
350 # but the path (self.MetaFile.Path) is the real path
351 for key
in self
.FdfProfile
.InfDict
:
355 for Arch
in self
.ArchList
:
356 Platform_cache
[Arch
] = self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
357 MetaFile_cache
[Arch
] = []
358 for Pkey
in Platform_cache
[Arch
].Modules
.keys():
359 MetaFile_cache
[Arch
].append(Platform_cache
[Arch
].Modules
[Pkey
].MetaFile
)
360 for Inf
in self
.FdfProfile
.InfDict
[key
]:
361 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
362 for Arch
in self
.ArchList
:
363 if ModuleFile
in MetaFile_cache
[Arch
]:
366 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
367 if not ModuleData
.IsBinaryModule
:
368 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
371 for Arch
in self
.ArchList
:
373 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
375 for Pkey
in Platform
.Modules
.keys():
376 MetaFileList
.append(Platform
.Modules
[Pkey
].MetaFile
)
377 for Inf
in self
.FdfProfile
.InfDict
[key
]:
378 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
379 if ModuleFile
in MetaFileList
:
381 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
382 if not ModuleData
.IsBinaryModule
:
383 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
388 self
.FdfProfile
= None
389 if self
.FdTargetList
:
390 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
391 self
.FdTargetList
= []
392 if self
.FvTargetList
:
393 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
394 self
.FvTargetList
= []
395 if self
.CapTargetList
:
396 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
397 self
.CapTargetList
= []
399 # apply SKU and inject PCDs from Flash Definition file
400 for Arch
in self
.ArchList
:
401 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
408 SourcePcdDict
= {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
409 BinaryPcdDict
= {'DynamicEx':[], 'PatchableInModule':[]}
410 SourcePcdDict_Keys
= SourcePcdDict
.keys()
411 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
413 # generate the SourcePcdDict and BinaryPcdDict
414 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
415 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
416 if BuildData
.Arch
!= Arch
:
418 if BuildData
.MetaFile
.Ext
== '.inf':
419 for key
in BuildData
.Pcds
:
420 if BuildData
.Pcds
[key
].Pending
:
421 if key
in Platform
.Pcds
:
422 PcdInPlatform
= Platform
.Pcds
[key
]
423 if PcdInPlatform
.Type
not in [None, '']:
424 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
426 if BuildData
.MetaFile
in Platform
.Modules
:
427 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
428 if key
in PlatformModule
.Pcds
:
429 PcdInPlatform
= PlatformModule
.Pcds
[key
]
430 if PcdInPlatform
.Type
not in [None, '']:
431 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
433 if 'DynamicEx' in BuildData
.Pcds
[key
].Type
:
434 if BuildData
.IsBinaryModule
:
435 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['DynamicEx']:
436 BinaryPcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
438 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['DynamicEx']:
439 SourcePcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
441 elif 'PatchableInModule' in BuildData
.Pcds
[key
].Type
:
442 if BuildData
.MetaFile
.Ext
== '.inf':
443 if BuildData
.IsBinaryModule
:
444 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['PatchableInModule']:
445 BinaryPcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
447 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['PatchableInModule']:
448 SourcePcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
450 elif 'Dynamic' in BuildData
.Pcds
[key
].Type
:
451 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['Dynamic']:
452 SourcePcdDict
['Dynamic'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
453 elif 'FixedAtBuild' in BuildData
.Pcds
[key
].Type
:
454 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['FixedAtBuild']:
455 SourcePcdDict
['FixedAtBuild'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
459 # A PCD can only use one type for all source modules
461 for i
in SourcePcdDict_Keys
:
462 for j
in SourcePcdDict_Keys
:
464 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(SourcePcdDict
[j
])))
465 if len(IntersectionList
) > 0:
469 "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
),
470 ExtraData
="%s" % '\n\t'.join([str(P
[1]+'.'+P
[0]) for P
in IntersectionList
])
476 # intersection the BinaryPCD for Mixed PCD
478 for i
in BinaryPcdDict_Keys
:
479 for j
in BinaryPcdDict_Keys
:
481 IntersectionList
= list(set(BinaryPcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
482 for item
in IntersectionList
:
483 NewPcd1
= (item
[0] + '_' + i
, item
[1])
484 NewPcd2
= (item
[0] + '_' + j
, item
[1])
485 if item
not in GlobalData
.MixedPcd
:
486 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
488 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
489 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
490 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
491 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
496 # intersection the SourcePCD and BinaryPCD for Mixed PCD
498 for i
in SourcePcdDict_Keys
:
499 for j
in BinaryPcdDict_Keys
:
501 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
502 for item
in IntersectionList
:
503 NewPcd1
= (item
[0] + '_' + i
, item
[1])
504 NewPcd2
= (item
[0] + '_' + j
, item
[1])
505 if item
not in GlobalData
.MixedPcd
:
506 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
508 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
509 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
510 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
511 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
515 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
516 if BuildData
.Arch
!= Arch
:
518 for key
in BuildData
.Pcds
:
519 for SinglePcd
in GlobalData
.MixedPcd
:
520 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
521 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
522 Pcd_Type
= item
[0].split('_')[-1]
523 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
524 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
525 Value
= BuildData
.Pcds
[key
]
526 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
528 newkey
= (Value
.TokenCName
, key
[1])
530 newkey
= (Value
.TokenCName
, key
[1], key
[2])
531 del BuildData
.Pcds
[key
]
532 BuildData
.Pcds
[newkey
] = Value
540 # handle the mixed pcd in FDF file
542 if key
in GlobalData
.MixedPcd
:
545 for item
in GlobalData
.MixedPcd
[key
]:
548 #Collect package set information from INF of FDF
550 for Inf
in ModuleList
:
551 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
552 if ModuleFile
in Platform
.Modules
:
554 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
555 PkgSet
.update(ModuleData
.Packages
)
556 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
561 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
562 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
564 Platform
.SkuName
= self
.SkuId
565 for Name
, Guid
in PcdSet
:
566 if (Name
, Guid
) not in DecPcds
:
570 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
571 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
572 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
575 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
576 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
577 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
578 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
579 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
581 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
585 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
586 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
587 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
590 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
592 # Explicitly collect platform's dynamic PCDs
594 Pa
.CollectPlatformDynamicPcds()
595 Pa
.CollectFixedAtBuildPcds()
596 self
.AutoGenObjectList
.append(Pa
)
599 # Generate Package level hash value
601 GlobalData
.gPackageHash
[Arch
] = {}
602 if GlobalData
.gUseHashCache
:
604 self
._GenPkgLevelHash
(Pkg
)
607 # Check PCDs token value conflict in each DEC file.
609 self
._CheckAllPcdsTokenValueConflict
()
612 # Check PCD type and definition between DSC and DEC
614 self
._CheckPcdDefineAndType
()
617 # self._CheckDuplicateInFV(Fdf)
620 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.
622 content
= 'gCommandLineDefines: '
623 content
+= str(GlobalData
.gCommandLineDefines
)
624 content
+= os
.linesep
625 content
+= 'BuildOptionPcd: '
626 content
+= str(GlobalData
.BuildOptionPcd
)
627 content
+= os
.linesep
628 content
+= 'Active Platform: '
629 content
+= str(self
.Platform
)
630 content
+= os
.linesep
632 content
+= 'Flash Image Definition: '
633 content
+= str(self
.FdfFile
)
634 content
+= os
.linesep
635 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
638 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
640 PcdTokenNumber
= 'PcdTokenNumber: '
641 if Pa
.PcdTokenNumber
:
642 if Pa
.DynamicPcdList
:
643 for Pcd
in Pa
.DynamicPcdList
:
644 PcdTokenNumber
+= os
.linesep
645 PcdTokenNumber
+= str((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
))
646 PcdTokenNumber
+= ' : '
647 PcdTokenNumber
+= str(Pa
.PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
])
648 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'), PcdTokenNumber
, False)
651 # Get set of workspace metafiles
653 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
656 # Retrieve latest modified time of all metafiles
659 for f
in AllWorkSpaceMetaFiles
:
660 if os
.stat(f
)[8] > SrcTimeStamp
:
661 SrcTimeStamp
= os
.stat(f
)[8]
662 self
._SrcTimeStamp
= SrcTimeStamp
664 if GlobalData
.gUseHashCache
:
666 for files
in AllWorkSpaceMetaFiles
:
667 if files
.endswith('.dec'):
673 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'AutoGen.hash'), m
.hexdigest(), True)
674 GlobalData
.gPlatformHash
= m
.hexdigest()
677 # Write metafile list to build directory
679 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
680 if os
.path
.exists (AutoGenFilePath
):
681 os
.remove(AutoGenFilePath
)
682 if not os
.path
.exists(self
.BuildDir
):
683 os
.makedirs(self
.BuildDir
)
684 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
685 for f
in AllWorkSpaceMetaFiles
:
689 def _GenPkgLevelHash(self
, Pkg
):
690 PkgDir
= os
.path
.join(self
.BuildDir
, Pkg
.Arch
, Pkg
.PackageName
)
691 CreateDirectory(PkgDir
)
692 HashFile
= os
.path
.join(PkgDir
, Pkg
.PackageName
+ '.hash')
694 # Get .dec file's hash value
695 f
= open(Pkg
.MetaFile
.Path
, 'r')
699 # Get include files hash value
701 for inc
in Pkg
.Includes
:
702 for Root
, Dirs
, Files
in os
.walk(str(inc
)):
704 File_Path
= os
.path
.join(Root
, File
)
705 f
= open(File_Path
, 'r')
709 SaveFileOnChange(HashFile
, m
.hexdigest(), True)
710 if Pkg
.PackageName
not in GlobalData
.gPackageHash
[Pkg
.Arch
]:
711 GlobalData
.gPackageHash
[Pkg
.Arch
][Pkg
.PackageName
] = m
.hexdigest()
713 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
714 AllWorkSpaceMetaFiles
= set()
719 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
721 FdfFiles
= GlobalData
.gFdfParser
.GetAllIncludedFile()
723 AllWorkSpaceMetaFiles
.add (f
.FileName
)
727 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
730 # add build_rule.txt & tools_def.txt
732 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
733 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
735 # add BuildOption metafile
737 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
739 # add PcdToken Number file for Dynamic/DynamicEx Pcd
741 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'))
743 for Arch
in self
.ArchList
:
744 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
745 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
750 for Package
in PGen
.PackageList
:
751 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
756 for filePath
in Platform
._RawData
.IncludedFiles
:
757 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
759 return AllWorkSpaceMetaFiles
761 ## _CheckDuplicateInFV() method
763 # Check whether there is duplicate modules/files exist in FV section.
764 # The check base on the file GUID;
766 def _CheckDuplicateInFV(self
, Fdf
):
767 for Fv
in Fdf
.Profile
.FvDict
:
769 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
770 if FfsFile
.InfFileName
and FfsFile
.NameGuid
is None:
775 for Pa
in self
.AutoGenObjectList
:
778 for Module
in Pa
.ModuleAutoGenList
:
779 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
781 if not Module
.Guid
.upper() in _GuidDict
.keys():
782 _GuidDict
[Module
.Guid
.upper()] = FfsFile
785 EdkLogger
.error("build",
787 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
788 FfsFile
.CurrentLineContent
,
789 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
790 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
791 Module
.Guid
.upper()),
792 ExtraData
=self
.FdfFile
)
794 # Some INF files not have entity in DSC file.
797 if FfsFile
.InfFileName
.find('$') == -1:
798 InfPath
= NormPath(FfsFile
.InfFileName
)
799 if not os
.path
.exists(InfPath
):
800 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
802 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
804 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
805 # BuildObject from one of AutoGenObjectList is enough.
807 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
808 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
809 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
811 EdkLogger
.error("build",
813 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
814 FfsFile
.CurrentLineContent
,
815 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
816 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
817 InfObj
.Guid
.upper()),
818 ExtraData
=self
.FdfFile
)
821 if FfsFile
.NameGuid
is not None:
822 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
825 # If the NameGuid reference a PCD name.
826 # The style must match: PCD(xxxx.yyy)
828 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
830 # Replace the PCD value.
832 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
834 for Pa
in self
.AutoGenObjectList
:
836 for PcdItem
in Pa
.AllPcdList
:
837 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
839 # First convert from CFormatGuid to GUID string
841 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
843 if not _PcdGuidString
:
845 # Then try Byte array.
847 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
849 if not _PcdGuidString
:
851 # Not Byte array or CFormat GUID, raise error.
853 EdkLogger
.error("build",
855 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
856 ExtraData
=self
.FdfFile
)
858 if not _PcdGuidString
.upper() in _GuidDict
.keys():
859 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
863 EdkLogger
.error("build",
865 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
866 FfsFile
.CurrentLineContent
,
867 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
868 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
869 FfsFile
.NameGuid
.upper()),
870 ExtraData
=self
.FdfFile
)
872 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
873 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
876 # Two raw file GUID conflict.
878 EdkLogger
.error("build",
880 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
881 FfsFile
.CurrentLineContent
,
882 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
883 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
884 FfsFile
.NameGuid
.upper()),
885 ExtraData
=self
.FdfFile
)
888 def _CheckPcdDefineAndType(self
):
890 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
891 "Dynamic", #"DynamicHii", "DynamicVpd",
892 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
895 # This dict store PCDs which are not used by any modules with specified arches
896 UnusedPcd
= OrderedDict()
897 for Pa
in self
.AutoGenObjectList
:
898 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
899 for Pcd
in Pa
.Platform
.Pcds
:
900 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
902 # If no PCD type, this PCD comes from FDF
906 # Try to remove Hii and Vpd suffix
907 if PcdType
.startswith("DynamicEx"):
908 PcdType
= "DynamicEx"
909 elif PcdType
.startswith("Dynamic"):
912 for Package
in Pa
.PackageList
:
913 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
914 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
916 for Type
in PcdTypeList
:
917 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
921 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
922 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
927 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
929 for Pcd
in UnusedPcd
:
932 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
933 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
934 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
939 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
941 ## Return the directory to store FV files
943 if self
._FvDir
is None:
944 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
947 ## Return the directory to store all intermediate and final files built
948 def _GetBuildDir(self
):
949 if self
._BuildDir
is None:
950 return self
.AutoGenObjectList
[0].BuildDir
952 ## Return the build output directory platform specifies
953 def _GetOutputDir(self
):
954 return self
.Platform
.OutputDirectory
956 ## Return platform name
958 return self
.Platform
.PlatformName
960 ## Return meta-file GUID
962 return self
.Platform
.Guid
964 ## Return platform version
965 def _GetVersion(self
):
966 return self
.Platform
.Version
968 ## Return paths of tools
969 def _GetToolDefinition(self
):
970 return self
.AutoGenObjectList
[0].ToolDefinition
972 ## Return directory of platform makefile
974 # @retval string Makefile directory
976 def _GetMakeFileDir(self
):
977 if self
._MakeFileDir
is None:
978 self
._MakeFileDir
= self
.BuildDir
979 return self
._MakeFileDir
981 ## Return build command string
983 # @retval string Build command string
985 def _GetBuildCommand(self
):
986 if self
._BuildCommand
is None:
987 # BuildCommand should be all the same. So just get one from platform AutoGen
988 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
989 return self
._BuildCommand
991 ## Check the PCDs token value conflict in each DEC file.
993 # Will cause build break and raise error message while two PCDs conflict.
997 def _CheckAllPcdsTokenValueConflict(self
):
998 for Pa
in self
.AutoGenObjectList
:
999 for Package
in Pa
.PackageList
:
1000 PcdList
= Package
.Pcds
.values()
1001 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
1003 while (Count
< len(PcdList
) - 1) :
1004 Item
= PcdList
[Count
]
1005 ItemNext
= PcdList
[Count
+ 1]
1007 # Make sure in the same token space the TokenValue should be unique
1009 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
1010 SameTokenValuePcdList
= []
1011 SameTokenValuePcdList
.append(Item
)
1012 SameTokenValuePcdList
.append(ItemNext
)
1013 RemainPcdListLength
= len(PcdList
) - Count
- 2
1014 for ValueSameCount
in range(RemainPcdListLength
):
1015 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
1016 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
1020 # Sort same token value PCD list with TokenGuid and TokenCName
1022 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1023 SameTokenValuePcdListCount
= 0
1024 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
1026 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
1027 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
1029 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
1030 for PcdItem
in GlobalData
.MixedPcd
:
1031 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
1032 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1038 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
1039 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
1042 SameTokenValuePcdListCount
+= 1
1043 Count
+= SameTokenValuePcdListCount
1046 PcdList
= Package
.Pcds
.values()
1047 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1049 while (Count
< len(PcdList
) - 1) :
1050 Item
= PcdList
[Count
]
1051 ItemNext
= PcdList
[Count
+ 1]
1053 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
1055 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
1059 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
1060 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
1064 ## Generate fds command
1065 def _GenFdsCommand(self
):
1066 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
1068 ## Create makefile for the platform and modules in it
1070 # @param CreateDepsMakeFile Flag indicating if the makefile for
1071 # modules will be created as well
1073 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
1074 if CreateDepsMakeFile
:
1075 for Pa
in self
.AutoGenObjectList
:
1076 Pa
.CreateMakeFile(CreateDepsMakeFile
)
1078 ## Create autogen code for platform and modules
1080 # Since there's no autogen code for platform, this method will do nothing
1081 # if CreateModuleCodeFile is set to False.
1083 # @param CreateDepsCodeFile Flag indicating if creating module's
1084 # autogen code file or not
1086 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
1087 if not CreateDepsCodeFile
:
1089 for Pa
in self
.AutoGenObjectList
:
1090 Pa
.CreateCodeFile(CreateDepsCodeFile
)
1092 ## Create AsBuilt INF file the platform
1094 def CreateAsBuiltInf(self
):
1097 Name
= property(_GetName
)
1098 Guid
= property(_GetGuid
)
1099 Version
= property(_GetVersion
)
1100 OutputDir
= property(_GetOutputDir
)
1102 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
1104 BuildDir
= property(_GetBuildDir
)
1105 FvDir
= property(_GetFvDir
)
1106 MakeFileDir
= property(_GetMakeFileDir
)
1107 BuildCommand
= property(_GetBuildCommand
)
1108 GenFdsCommand
= property(_GenFdsCommand
)
1110 ## AutoGen class for platform
1112 # PlatformAutoGen class will process the original information in platform
1113 # file in order to generate makefile for platform.
1115 class PlatformAutoGen(AutoGen
):
1116 # call super().__init__ then call the worker function with different parameter count
1117 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
1121 super(PlatformAutoGen
, self
).__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
1122 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
)
1125 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1126 # correct PCD database
1129 _NonDynaPcdList_
= []
1133 # The priority list while override build option
1135 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1136 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1137 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1138 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1139 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1140 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1141 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1142 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1143 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1144 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1145 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1146 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1147 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1148 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1149 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1150 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1152 ## Initialize PlatformAutoGen
1155 # @param Workspace WorkspaceAutoGen object
1156 # @param PlatformFile Platform file (DSC file)
1157 # @param Target Build target (DEBUG, RELEASE)
1158 # @param Toolchain Name of tool chain
1159 # @param Arch arch of the platform supports
1161 def _InitWorker(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1162 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1163 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1165 self
.MetaFile
= PlatformFile
1166 self
.Workspace
= Workspace
1167 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1168 self
.ToolChain
= Toolchain
1169 self
.BuildTarget
= Target
1171 self
.SourceDir
= PlatformFile
.SubDir
1172 self
.SourceOverrideDir
= None
1173 self
.FdTargetList
= self
.Workspace
.FdTargetList
1174 self
.FvTargetList
= self
.Workspace
.FvTargetList
1175 self
.AllPcdList
= []
1176 # get the original module/package/platform objects
1177 self
.BuildDatabase
= Workspace
.BuildDatabase
1178 self
.DscBuildDataObj
= Workspace
.Platform
1179 self
._GuidDict
= Workspace
._GuidDict
1181 # flag indicating if the makefile/C-code file has been created or not
1182 self
.IsMakeFileCreated
= False
1183 self
.IsCodeFileCreated
= False
1185 self
._Platform
= None
1188 self
._Version
= None
1190 self
._BuildRule
= None
1191 self
._SourceDir
= None
1192 self
._BuildDir
= None
1193 self
._OutputDir
= None
1195 self
._MakeFileDir
= None
1196 self
._FdfFile
= None
1198 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1199 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1200 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1201 self
._NonDynamicPcdDict
= {}
1203 self
._ToolDefinitions
= None
1204 self
._ToolDefFile
= None # toolcode : tool path
1205 self
._ToolChainFamily
= None
1206 self
._BuildRuleFamily
= None
1207 self
._BuildOption
= None # toolcode : option
1208 self
._EdkBuildOption
= None # edktoolcode : option
1209 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1210 self
._PackageList
= None
1211 self
._ModuleAutoGenList
= None
1212 self
._LibraryAutoGenList
= None
1213 self
._BuildCommand
= None
1214 self
._AsBuildInfList
= []
1215 self
._AsBuildModuleList
= []
1217 self
.VariableInfo
= None
1219 if GlobalData
.gFdfParser
is not None:
1220 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1221 for Inf
in self
._AsBuildInfList
:
1222 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1223 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1224 if not M
.IsSupportedArch
:
1226 self
._AsBuildModuleList
.append(InfClass
)
1227 # get library/modules for build
1228 self
.LibraryBuildDirectoryList
= []
1229 self
.ModuleBuildDirectoryList
= []
1234 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1236 ## Create autogen code for platform and modules
1238 # Since there's no autogen code for platform, this method will do nothing
1239 # if CreateModuleCodeFile is set to False.
1241 # @param CreateModuleCodeFile Flag indicating if creating module's
1242 # autogen code file or not
1244 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1245 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1246 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1249 for Ma
in self
.ModuleAutoGenList
:
1250 Ma
.CreateCodeFile(True)
1252 # don't do this twice
1253 self
.IsCodeFileCreated
= True
1255 ## Generate Fds Command
1256 def _GenFdsCommand(self
):
1257 return self
.Workspace
.GenFdsCommand
1259 ## Create makefile for the platform and mdoules in it
1261 # @param CreateModuleMakeFile Flag indicating if the makefile for
1262 # modules will be created as well
1264 def CreateMakeFile(self
, CreateModuleMakeFile
=False, FfsCommand
= {}):
1265 if CreateModuleMakeFile
:
1266 for ModuleFile
in self
.Platform
.Modules
:
1267 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1268 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1269 if (ModuleFile
.File
, self
.Arch
) in FfsCommand
:
1270 Ma
.CreateMakeFile(True, FfsCommand
[ModuleFile
.File
, self
.Arch
])
1272 Ma
.CreateMakeFile(True)
1273 #Ma.CreateAsBuiltInf()
1275 # no need to create makefile for the platform more than once
1276 if self
.IsMakeFileCreated
:
1279 # create library/module build dirs for platform
1280 Makefile
= GenMake
.PlatformMakefile(self
)
1281 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1282 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1284 self
.IsMakeFileCreated
= True
1286 ## Deal with Shared FixedAtBuild Pcds
1288 def CollectFixedAtBuildPcds(self
):
1289 for LibAuto
in self
.LibraryAutoGenList
:
1290 FixedAtBuildPcds
= {}
1291 ShareFixedAtBuildPcdsSameValue
= {}
1292 for Module
in LibAuto
._ReferenceModules
:
1293 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1294 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1295 if key
not in FixedAtBuildPcds
:
1296 ShareFixedAtBuildPcdsSameValue
[key
] = True
1297 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1299 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1300 ShareFixedAtBuildPcdsSameValue
[key
] = False
1301 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1302 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1303 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1306 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1307 if DscPcd
.Type
!= "FixedAtBuild":
1309 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1310 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1312 def CollectVariables(self
, DynamicPcdSet
):
1316 if self
.Workspace
.FdfFile
:
1317 FdDict
= self
.Workspace
.FdfProfile
.FdDict
[GlobalData
.gFdfParser
.CurrentFdName
]
1318 for FdRegion
in FdDict
.RegionList
:
1319 for item
in FdRegion
.RegionDataList
:
1320 if self
.Platform
.VpdToolGuid
.strip() and self
.Platform
.VpdToolGuid
in item
:
1321 VpdRegionSize
= FdRegion
.Size
1322 VpdRegionBase
= FdRegion
.Offset
1326 VariableInfo
= VariableMgr(self
.DscBuildDataObj
._GetDefaultStores
(),self
.DscBuildDataObj
._GetSkuIds
())
1327 VariableInfo
.SetVpdRegionMaxSize(VpdRegionSize
)
1328 VariableInfo
.SetVpdRegionOffset(VpdRegionBase
)
1330 for Pcd
in DynamicPcdSet
:
1331 pcdname
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1332 for SkuName
in Pcd
.SkuInfoList
:
1333 Sku
= Pcd
.SkuInfoList
[SkuName
]
1335 if SkuId
is None or SkuId
== '':
1337 if len(Sku
.VariableName
) > 0:
1338 VariableGuidStructure
= Sku
.VariableGuidValue
1339 VariableGuid
= GuidStructureStringToGuidString(VariableGuidStructure
)
1340 for StorageName
in Sku
.DefaultStoreDict
:
1341 VariableInfo
.append_variable(var_info(Index
,pcdname
,StorageName
,SkuName
, StringToArray(Sku
.VariableName
),VariableGuid
, Sku
.VariableOffset
, Sku
.VariableAttribute
, Sku
.HiiDefaultValue
,Sku
.DefaultStoreDict
[StorageName
],Pcd
.DatumType
))
1345 def UpdateNVStoreMaxSize(self
,OrgVpdFile
):
1346 if self
.VariableInfo
:
1347 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1348 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
1350 if PcdNvStoreDfBuffer
:
1351 if os
.path
.exists(VpdMapFilePath
):
1352 OrgVpdFile
.Read(VpdMapFilePath
)
1353 PcdItems
= OrgVpdFile
.GetOffset(PcdNvStoreDfBuffer
[0])
1354 NvStoreOffset
= PcdItems
.values()[0].strip() if PcdItems
else '0'
1356 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1358 NvStoreOffset
= int(NvStoreOffset
,16) if NvStoreOffset
.upper().startswith("0X") else int(NvStoreOffset
)
1359 default_skuobj
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get("DEFAULT")
1360 maxsize
= self
.VariableInfo
.VpdRegionSize
- NvStoreOffset
if self
.VariableInfo
.VpdRegionSize
else len(default_skuobj
.DefaultValue
.split(","))
1361 var_data
= self
.VariableInfo
.PatchNVStoreDefaultMaxSize(maxsize
)
1363 if var_data
and default_skuobj
:
1364 default_skuobj
.DefaultValue
= var_data
1365 PcdNvStoreDfBuffer
[0].DefaultValue
= var_data
1366 PcdNvStoreDfBuffer
[0].SkuInfoList
.clear()
1367 PcdNvStoreDfBuffer
[0].SkuInfoList
['DEFAULT'] = default_skuobj
1368 PcdNvStoreDfBuffer
[0].MaxDatumSize
= str(len(default_skuobj
.DefaultValue
.split(",")))
1372 ## Collect dynamic PCDs
1374 # Gather dynamic PCDs list from each module and their settings from platform
1375 # This interface should be invoked explicitly when platform action is created.
1377 def CollectPlatformDynamicPcds(self
):
1379 for key
in self
.Platform
.Pcds
:
1380 for SinglePcd
in GlobalData
.MixedPcd
:
1381 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1382 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1383 Pcd_Type
= item
[0].split('_')[-1]
1384 if (Pcd_Type
== self
.Platform
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
1385 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
1386 Value
= self
.Platform
.Pcds
[key
]
1387 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1389 newkey
= (Value
.TokenCName
, key
[1])
1391 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1392 del self
.Platform
.Pcds
[key
]
1393 self
.Platform
.Pcds
[newkey
] = Value
1401 # for gathering error information
1402 NoDatumTypePcdList
= set()
1404 self
._GuidValue
= {}
1406 for InfName
in self
._AsBuildInfList
:
1407 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1408 FdfModuleList
.append(os
.path
.normpath(InfName
))
1409 for F
in self
.Platform
.Modules
.keys():
1410 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1411 #GuidValue.update(M.Guids)
1413 self
.Platform
.Modules
[F
].M
= M
1415 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1416 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1417 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1418 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1420 # Check the PCD from Binary INF or Source INF
1421 if M
.IsBinaryModule
== True:
1422 PcdFromModule
.IsFromBinaryInf
= True
1424 # Check the PCD from DSC or not
1425 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1426 PcdFromModule
.IsFromDsc
= True
1428 PcdFromModule
.IsFromDsc
= False
1429 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1430 if F
.Path
not in FdfModuleList
:
1431 # If one of the Source built modules listed in the DSC is not listed
1432 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1433 # access method (it is only listed in the DEC file that declares the
1434 # PCD as PcdsDynamic), then build tool will report warning message
1435 # notify the PI that they are attempting to build a module that must
1436 # be included in a flash image in order to be functional. These Dynamic
1437 # PCD will not be added into the Database unless it is used by other
1438 # modules that are included in the FDF file.
1439 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1440 PcdFromModule
.IsFromBinaryInf
== False:
1441 # Print warning message to let the developer make a determine.
1442 if PcdFromModule
not in PcdNotInDb
:
1443 PcdNotInDb
.append(PcdFromModule
)
1445 # If one of the Source built modules listed in the DSC is not listed in
1446 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1447 # access method (it is only listed in the DEC file that declares the
1448 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1449 # PCD to the Platform's PCD Database.
1450 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1451 if PcdFromModule
not in PcdNotInDb
:
1452 PcdNotInDb
.append(PcdFromModule
)
1455 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1456 # it should be stored in Pcd PEI database, If a dynamic only
1457 # used by DXE module, it should be stored in DXE PCD database.
1458 # The default Phase is DXE
1460 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1461 PcdFromModule
.Phase
= "PEI"
1462 if PcdFromModule
not in self
._DynaPcdList
_:
1463 self
._DynaPcdList
_.append(PcdFromModule
)
1464 elif PcdFromModule
.Phase
== 'PEI':
1465 # overwrite any the same PCD existing, if Phase is PEI
1466 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1467 self
._DynaPcdList
_[Index
] = PcdFromModule
1468 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1469 self
._NonDynaPcdList
_.append(PcdFromModule
)
1470 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1471 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1472 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1473 #The PCD from Binary INF will override the same one from source INF
1474 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1475 PcdFromModule
.Pending
= False
1476 self
._NonDynaPcdList
_.append (PcdFromModule
)
1477 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1479 for ModuleInf
in self
.Platform
.Modules
.keys():
1480 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1481 # add the PCD from modules that listed in FDF but not in DSC to Database
1482 for InfName
in FdfModuleList
:
1483 if InfName
not in DscModuleList
:
1484 InfClass
= PathClass(InfName
)
1485 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1486 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1487 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1488 # For binary module, if in current arch, we need to list the PCDs into database.
1489 if not M
.IsSupportedArch
:
1491 # Override the module PCD setting by platform setting
1492 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1493 for PcdFromModule
in ModulePcdList
:
1494 PcdFromModule
.IsFromBinaryInf
= True
1495 PcdFromModule
.IsFromDsc
= False
1496 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1497 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1498 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1500 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1501 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1502 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1503 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1504 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1505 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1506 PcdFromModule
.Phase
= "PEI"
1507 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1508 self
._DynaPcdList
_.append(PcdFromModule
)
1509 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1510 self
._NonDynaPcdList
_.append(PcdFromModule
)
1511 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1512 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1513 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1514 # module & DXE module at a same time.
1515 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1516 # INF file as DynamicEx.
1517 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1518 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1519 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1520 for PcdFromModule
in self
._NonDynaPcdList
_:
1521 # If a PCD is not listed in the DSC file, but binary INF files used by
1522 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1523 # section, AND all source INF files used by this platform the build
1524 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1525 # section, then the tools must NOT add the PCD to the Platform's PCD
1526 # Database; the build must assign the access method for this PCD as
1527 # PcdsPatchableInModule.
1528 if PcdFromModule
not in self
._DynaPcdList
_:
1530 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1531 if PcdFromModule
.IsFromDsc
== False and \
1532 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1533 PcdFromModule
.IsFromBinaryInf
== True and \
1534 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1535 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1536 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1538 # print out error information and break the build, if error found
1539 if len(NoDatumTypePcdList
) > 0:
1540 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1541 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1543 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1544 % NoDatumTypePcdListString
)
1545 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1546 self
._DynamicPcdList
= self
._DynaPcdList
_
1548 # Sort dynamic PCD list to:
1549 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1550 # try to be put header of dynamicd List
1551 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1553 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1555 UnicodePcdArray
= set()
1557 OtherPcdArray
= set()
1559 VpdFile
= VpdInfoFile
.VpdInfoFile()
1560 NeedProcessVpdMapFile
= False
1562 for pcd
in self
.Platform
.Pcds
.keys():
1563 if pcd
not in self
._PlatformPcds
.keys():
1564 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1566 for item
in self
._PlatformPcds
:
1567 if self
._PlatformPcds
[item
].DatumType
and self
._PlatformPcds
[item
].DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1568 self
._PlatformPcds
[item
].DatumType
= "VOID*"
1570 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1571 for Pcd
in self
._DynamicPcdList
:
1572 # just pick the a value to determine whether is unicode string type
1573 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1574 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1576 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1577 Pcd
.DatumType
= "VOID*"
1579 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1580 # if found HII type PCD then insert to right of UnicodeIndex
1581 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1582 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1584 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer
1585 PcdNvStoreDfBuffer
= VpdPcdDict
.get(("PcdNvStoreDefaultValueBuffer","gEfiMdeModulePkgTokenSpaceGuid"))
1586 if PcdNvStoreDfBuffer
:
1587 self
.VariableInfo
= self
.CollectVariables(self
._DynamicPcdList
)
1588 vardump
= self
.VariableInfo
.dump()
1590 PcdNvStoreDfBuffer
.DefaultValue
= vardump
1591 for skuname
in PcdNvStoreDfBuffer
.SkuInfoList
:
1592 PcdNvStoreDfBuffer
.SkuInfoList
[skuname
].DefaultValue
= vardump
1593 PcdNvStoreDfBuffer
.MaxDatumSize
= str(len(vardump
.split(",")))
1595 PlatformPcds
= self
._PlatformPcds
.keys()
1598 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1601 for PcdKey
in PlatformPcds
:
1602 Pcd
= self
._PlatformPcds
[PcdKey
]
1603 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1604 PcdKey
in VpdPcdDict
:
1605 Pcd
= VpdPcdDict
[PcdKey
]
1607 DefaultSku
= Pcd
.SkuInfoList
.get('DEFAULT')
1609 PcdValue
= DefaultSku
.DefaultValue
1610 if PcdValue
not in SkuValueMap
:
1611 SkuValueMap
[PcdValue
] = []
1612 VpdFile
.Add(Pcd
, 'DEFAULT',DefaultSku
.VpdOffset
)
1613 SkuValueMap
[PcdValue
].append(DefaultSku
)
1615 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1616 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1617 PcdValue
= Sku
.DefaultValue
1619 PcdValue
= Pcd
.DefaultValue
1620 if Sku
.VpdOffset
!= '*':
1621 if PcdValue
.startswith("{"):
1623 elif PcdValue
.startswith("L"):
1628 VpdOffset
= int(Sku
.VpdOffset
)
1631 VpdOffset
= int(Sku
.VpdOffset
, 16)
1633 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1634 if VpdOffset
% Alignment
!= 0:
1635 if PcdValue
.startswith("{"):
1636 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1638 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1639 if PcdValue
not in SkuValueMap
:
1640 SkuValueMap
[PcdValue
] = []
1641 VpdFile
.Add(Pcd
, SkuName
,Sku
.VpdOffset
)
1642 SkuValueMap
[PcdValue
].append(Sku
)
1643 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1644 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1645 NeedProcessVpdMapFile
= True
1646 if self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== '':
1647 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1648 "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.")
1650 VpdSkuMap
[PcdKey
] = SkuValueMap
1652 # Fix the PCDs define in VPD PCD section that never referenced by module.
1653 # An example is PCD for signature usage.
1655 for DscPcd
in PlatformPcds
:
1656 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1657 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1658 if not (self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== ''):
1660 for VpdPcd
in VpdFile
._VpdArray
.keys():
1661 # This PCD has been referenced by module
1662 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1663 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1666 # Not found, it should be signature
1668 # just pick the a value to determine whether is unicode string type
1670 SkuObjList
= DscPcdEntry
.SkuInfoList
.items()
1671 DefaultSku
= DscPcdEntry
.SkuInfoList
.get('DEFAULT')
1673 defaultindex
= SkuObjList
.index(('DEFAULT',DefaultSku
))
1674 SkuObjList
[0],SkuObjList
[defaultindex
] = SkuObjList
[defaultindex
],SkuObjList
[0]
1675 for (SkuName
,Sku
) in SkuObjList
:
1676 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1678 # Need to iterate DEC pcd information to get the value & datumtype
1679 for eachDec
in self
.PackageList
:
1680 for DecPcd
in eachDec
.Pcds
:
1681 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1682 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1683 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1684 # Print warning message to let the developer make a determine.
1685 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1686 File
=self
.MetaFile
, \
1687 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1688 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1690 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1691 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1692 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1693 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1694 # Only fix the value while no value provided in DSC file.
1695 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1696 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1698 if DscPcdEntry
not in self
._DynamicPcdList
:
1699 self
._DynamicPcdList
.append(DscPcdEntry
)
1700 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1701 PcdValue
= Sku
.DefaultValue
1703 PcdValue
= DscPcdEntry
.DefaultValue
1704 if Sku
.VpdOffset
!= '*':
1705 if PcdValue
.startswith("{"):
1707 elif PcdValue
.startswith("L"):
1712 VpdOffset
= int(Sku
.VpdOffset
)
1715 VpdOffset
= int(Sku
.VpdOffset
, 16)
1717 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1718 if VpdOffset
% Alignment
!= 0:
1719 if PcdValue
.startswith("{"):
1720 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1722 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1723 if PcdValue
not in SkuValueMap
:
1724 SkuValueMap
[PcdValue
] = []
1725 VpdFile
.Add(DscPcdEntry
, SkuName
,Sku
.VpdOffset
)
1726 SkuValueMap
[PcdValue
].append(Sku
)
1727 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1728 NeedProcessVpdMapFile
= True
1729 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1730 UnicodePcdArray
.add(DscPcdEntry
)
1731 elif len(Sku
.VariableName
) > 0:
1732 HiiPcdArray
.add(DscPcdEntry
)
1734 OtherPcdArray
.add(DscPcdEntry
)
1736 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1737 VpdSkuMap
[DscPcd
] = SkuValueMap
1738 if (self
.Platform
.FlashDefinition
is None or self
.Platform
.FlashDefinition
== '') and \
1739 VpdFile
.GetCount() != 0:
1740 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1741 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1743 if VpdFile
.GetCount() != 0:
1745 self
.FixVpdOffset(VpdFile
)
1747 self
.FixVpdOffset(self
.UpdateNVStoreMaxSize(VpdFile
))
1749 # Process VPD map file generated by third party BPDG tool
1750 if NeedProcessVpdMapFile
:
1751 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1752 if os
.path
.exists(VpdMapFilePath
):
1753 VpdFile
.Read(VpdMapFilePath
)
1756 for pcd
in VpdSkuMap
:
1757 vpdinfo
= VpdFile
.GetVpdInfo(pcd
)
1759 # just pick the a value to determine whether is unicode string type
1761 for pcdvalue
in VpdSkuMap
[pcd
]:
1762 for sku
in VpdSkuMap
[pcd
][pcdvalue
]:
1763 for item
in vpdinfo
:
1764 if item
[2] == pcdvalue
:
1765 sku
.VpdOffset
= item
[1]
1767 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1769 # Delete the DynamicPcdList At the last time enter into this function
1770 for Pcd
in self
._DynamicPcdList
:
1771 # just pick the a value to determine whether is unicode string type
1772 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1773 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1775 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1776 Pcd
.DatumType
= "VOID*"
1778 PcdValue
= Sku
.DefaultValue
1779 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1780 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1781 UnicodePcdArray
.add(Pcd
)
1782 elif len(Sku
.VariableName
) > 0:
1783 # if found HII type PCD then insert to right of UnicodeIndex
1784 HiiPcdArray
.add(Pcd
)
1786 OtherPcdArray
.add(Pcd
)
1787 del self
._DynamicPcdList
[:]
1788 self
._DynamicPcdList
.extend(list(UnicodePcdArray
))
1789 self
._DynamicPcdList
.extend(list(HiiPcdArray
))
1790 self
._DynamicPcdList
.extend(list(OtherPcdArray
))
1791 allskuset
= [(SkuName
,Sku
.SkuId
) for pcd
in self
._DynamicPcdList
for (SkuName
,Sku
) in pcd
.SkuInfoList
.items()]
1792 for pcd
in self
._DynamicPcdList
:
1793 if len(pcd
.SkuInfoList
) == 1:
1794 for (SkuName
,SkuId
) in allskuset
:
1795 if type(SkuId
) in (str,unicode) and eval(SkuId
) == 0 or SkuId
== 0:
1797 pcd
.SkuInfoList
[SkuName
] = copy
.deepcopy(pcd
.SkuInfoList
['DEFAULT'])
1798 pcd
.SkuInfoList
[SkuName
].SkuId
= SkuId
1799 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1801 def FixVpdOffset(self
,VpdFile
):
1802 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1803 if not os
.path
.exists(FvPath
):
1807 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1809 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1811 if VpdFile
.Write(VpdFilePath
):
1812 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1814 for ToolDef
in self
.ToolDefinition
.values():
1815 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1816 if not ToolDef
.has_key("PATH"):
1817 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1818 BPDGToolName
= ToolDef
["PATH"]
1820 # Call third party GUID BPDG tool.
1821 if BPDGToolName
is not None:
1822 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1824 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.")
1826 ## Return the platform build data object
1827 def _GetPlatform(self
):
1828 if self
._Platform
is None:
1829 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1830 return self
._Platform
1832 ## Return platform name
1834 return self
.Platform
.PlatformName
1836 ## Return the meta file GUID
1838 return self
.Platform
.Guid
1840 ## Return the platform version
1841 def _GetVersion(self
):
1842 return self
.Platform
.Version
1844 ## Return the FDF file name
1845 def _GetFdfFile(self
):
1846 if self
._FdfFile
is None:
1847 if self
.Workspace
.FdfFile
!= "":
1848 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1851 return self
._FdfFile
1853 ## Return the build output directory platform specifies
1854 def _GetOutputDir(self
):
1855 return self
.Platform
.OutputDirectory
1857 ## Return the directory to store all intermediate and final files built
1858 def _GetBuildDir(self
):
1859 if self
._BuildDir
is None:
1860 if os
.path
.isabs(self
.OutputDir
):
1861 self
._BuildDir
= path
.join(
1862 path
.abspath(self
.OutputDir
),
1863 self
.BuildTarget
+ "_" + self
.ToolChain
,
1866 self
._BuildDir
= path
.join(
1869 self
.BuildTarget
+ "_" + self
.ToolChain
,
1871 GlobalData
.gBuildDirectory
= self
._BuildDir
1872 return self
._BuildDir
1874 ## Return directory of platform makefile
1876 # @retval string Makefile directory
1878 def _GetMakeFileDir(self
):
1879 if self
._MakeFileDir
is None:
1880 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1881 return self
._MakeFileDir
1883 ## Return build command string
1885 # @retval string Build command string
1887 def _GetBuildCommand(self
):
1888 if self
._BuildCommand
is None:
1889 self
._BuildCommand
= []
1890 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1891 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1892 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1893 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1895 self
._BuildCommand
+= SplitOption(NewOption
)
1896 if "MAKE" in self
.EdkIIBuildOption
:
1897 if "FLAGS" in self
.EdkIIBuildOption
["MAKE"]:
1898 Flags
= self
.EdkIIBuildOption
["MAKE"]["FLAGS"]
1899 if Flags
.startswith('='):
1900 self
._BuildCommand
= [self
._BuildCommand
[0]] + [Flags
[1:]]
1902 self
._BuildCommand
+= [Flags
]
1903 return self
._BuildCommand
1905 ## Get tool chain definition
1907 # Get each tool defition for given tool chain from tools_def.txt and platform
1909 def _GetToolDefinition(self
):
1910 if self
._ToolDefinitions
is None:
1911 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1912 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1913 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1914 ExtraData
="[%s]" % self
.MetaFile
)
1915 self
._ToolDefinitions
= {}
1917 for Def
in ToolDefinition
:
1918 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1919 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1922 Value
= ToolDefinition
[Def
]
1923 # don't record the DLL
1925 DllPathList
.add(Value
)
1928 if Tool
not in self
._ToolDefinitions
:
1929 self
._ToolDefinitions
[Tool
] = {}
1930 self
._ToolDefinitions
[Tool
][Attr
] = Value
1934 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1935 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1936 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1937 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1939 for Tool
in self
._ToolDefinitions
:
1940 for Attr
in self
._ToolDefinitions
[Tool
]:
1941 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1942 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1943 # check if override is indicated
1944 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1945 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1948 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1950 Value
= self
.BuildOption
[Tool
][Attr
]
1953 # Don't put MAKE definition in the file
1957 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1959 # Don't put MAKE definition in the file
1964 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1967 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1968 for DllPath
in DllPathList
:
1969 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1970 os
.environ
["MAKE_FLAGS"] = MakeFlags
1972 return self
._ToolDefinitions
1974 ## Return the paths of tools
1975 def _GetToolDefFile(self
):
1976 if self
._ToolDefFile
is None:
1977 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1978 return self
._ToolDefFile
1980 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1981 def _GetToolChainFamily(self
):
1982 if self
._ToolChainFamily
is None:
1983 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1984 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1985 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1986 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1987 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1989 self
._ToolChainFamily
= "MSFT"
1991 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1992 return self
._ToolChainFamily
1994 def _GetBuildRuleFamily(self
):
1995 if self
._BuildRuleFamily
is None:
1996 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1997 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1998 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1999 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
2000 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
2002 self
._BuildRuleFamily
= "MSFT"
2004 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
2005 return self
._BuildRuleFamily
2007 ## Return the build options specific for all modules in this platform
2008 def _GetBuildOptions(self
):
2009 if self
._BuildOption
is None:
2010 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
2011 return self
._BuildOption
2013 ## Return the build options specific for EDK modules in this platform
2014 def _GetEdkBuildOptions(self
):
2015 if self
._EdkBuildOption
is None:
2016 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
2017 return self
._EdkBuildOption
2019 ## Return the build options specific for EDKII modules in this platform
2020 def _GetEdkIIBuildOptions(self
):
2021 if self
._EdkIIBuildOption
is None:
2022 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
2023 return self
._EdkIIBuildOption
2025 ## Parse build_rule.txt in Conf Directory.
2027 # @retval BuildRule object
2029 def _GetBuildRule(self
):
2030 if self
._BuildRule
is None:
2031 BuildRuleFile
= None
2032 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
2033 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
2034 if BuildRuleFile
in [None, '']:
2035 BuildRuleFile
= gDefaultBuildRuleFile
2036 self
._BuildRule
= BuildRule(BuildRuleFile
)
2037 if self
._BuildRule
._FileVersion
== "":
2038 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
2040 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
2041 # If Build Rule's version is less than the version number required by the tools, halting the build.
2042 EdkLogger
.error("build", AUTOGEN_ERROR
,
2043 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])"\
2044 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
2046 return self
._BuildRule
2048 ## Summarize the packages used by modules in this platform
2049 def _GetPackageList(self
):
2050 if self
._PackageList
is None:
2051 self
._PackageList
= set()
2052 for La
in self
.LibraryAutoGenList
:
2053 self
._PackageList
.update(La
.DependentPackageList
)
2054 for Ma
in self
.ModuleAutoGenList
:
2055 self
._PackageList
.update(Ma
.DependentPackageList
)
2056 #Collect package set information from INF of FDF
2058 for ModuleFile
in self
._AsBuildModuleList
:
2059 if ModuleFile
in self
.Platform
.Modules
:
2061 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2062 PkgSet
.update(ModuleData
.Packages
)
2063 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
2064 return self
._PackageList
2066 def _GetNonDynamicPcdDict(self
):
2067 if self
._NonDynamicPcdDict
:
2068 return self
._NonDynamicPcdDict
2069 for Pcd
in self
.NonDynamicPcdList
:
2070 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
2071 return self
._NonDynamicPcdDict
2073 ## Get list of non-dynamic PCDs
2074 def _GetNonDynamicPcdList(self
):
2075 if self
._NonDynamicPcdList
is None:
2076 self
.CollectPlatformDynamicPcds()
2077 return self
._NonDynamicPcdList
2079 ## Get list of dynamic PCDs
2080 def _GetDynamicPcdList(self
):
2081 if self
._DynamicPcdList
is None:
2082 self
.CollectPlatformDynamicPcds()
2083 return self
._DynamicPcdList
2085 ## Generate Token Number for all PCD
2086 def _GetPcdTokenNumbers(self
):
2087 if self
._PcdTokenNumber
is None:
2088 self
._PcdTokenNumber
= OrderedDict()
2091 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
2095 # TokenNumber 0 ~ 10
2097 # TokeNumber 11 ~ 20
2099 for Pcd
in self
.DynamicPcdList
:
2100 if Pcd
.Phase
== "PEI":
2101 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
2102 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2103 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2106 for Pcd
in self
.DynamicPcdList
:
2107 if Pcd
.Phase
== "PEI":
2108 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
2109 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2110 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2113 for Pcd
in self
.DynamicPcdList
:
2114 if Pcd
.Phase
== "DXE":
2115 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
2116 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2117 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2120 for Pcd
in self
.DynamicPcdList
:
2121 if Pcd
.Phase
== "DXE":
2122 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
2123 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2124 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2127 for Pcd
in self
.NonDynamicPcdList
:
2128 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2130 return self
._PcdTokenNumber
2132 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
2133 def _GetAutoGenObjectList(self
):
2134 self
._ModuleAutoGenList
= []
2135 self
._LibraryAutoGenList
= []
2136 for ModuleFile
in self
.Platform
.Modules
:
2145 if Ma
not in self
._ModuleAutoGenList
:
2146 self
._ModuleAutoGenList
.append(Ma
)
2147 for La
in Ma
.LibraryAutoGenList
:
2148 if La
not in self
._LibraryAutoGenList
:
2149 self
._LibraryAutoGenList
.append(La
)
2150 if Ma
not in La
._ReferenceModules
:
2151 La
._ReferenceModules
.append(Ma
)
2153 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2154 def _GetModuleAutoGenList(self
):
2155 if self
._ModuleAutoGenList
is None:
2156 self
._GetAutoGenObjectList
()
2157 return self
._ModuleAutoGenList
2159 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2160 def _GetLibraryAutoGenList(self
):
2161 if self
._LibraryAutoGenList
is None:
2162 self
._GetAutoGenObjectList
()
2163 return self
._LibraryAutoGenList
2165 ## Test if a module is supported by the platform
2167 # An error will be raised directly if the module or its arch is not supported
2168 # by the platform or current configuration
2170 def ValidModule(self
, Module
):
2171 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2172 or Module
in self
._AsBuildModuleList
2174 ## Resolve the library classes in a module to library instances
2176 # This method will not only resolve library classes but also sort the library
2177 # instances according to the dependency-ship.
2179 # @param Module The module from which the library classes will be resolved
2181 # @retval library_list List of library instances sorted
2183 def ApplyLibraryInstance(self
, Module
):
2184 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2185 if str(Module
) not in self
.Platform
.Modules
:
2188 ModuleType
= Module
.ModuleType
2190 # for overridding library instances with module specific setting
2191 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2193 # add forced library instances (specified under LibraryClasses sections)
2195 # If a module has a MODULE_TYPE of USER_DEFINED,
2196 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
2198 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
2199 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
2200 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
2201 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
2203 # add forced library instances (specified in module overrides)
2204 for LibraryClass
in PlatformModule
.LibraryClasses
:
2205 if LibraryClass
.startswith("NULL"):
2206 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
2209 LibraryConsumerList
= [Module
]
2211 ConsumedByList
= OrderedDict()
2212 LibraryInstance
= OrderedDict()
2214 EdkLogger
.verbose("")
2215 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2216 while len(LibraryConsumerList
) > 0:
2217 M
= LibraryConsumerList
.pop()
2218 for LibraryClassName
in M
.LibraryClasses
:
2219 if LibraryClassName
not in LibraryInstance
:
2220 # override library instance for this module
2221 if LibraryClassName
in PlatformModule
.LibraryClasses
:
2222 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
2224 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
2225 if LibraryPath
is None or LibraryPath
== "":
2226 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
2227 if LibraryPath
is None or LibraryPath
== "":
2228 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
2229 "Instance of library class [%s] is not found" % LibraryClassName
,
2231 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
2233 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2234 # for those forced library instance (NULL library), add a fake library class
2235 if LibraryClassName
.startswith("NULL"):
2236 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
2237 elif LibraryModule
.LibraryClass
is None \
2238 or len(LibraryModule
.LibraryClass
) == 0 \
2239 or (ModuleType
!= 'USER_DEFINED'
2240 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
2241 # only USER_DEFINED can link against any library instance despite of its SupModList
2242 EdkLogger
.error("build", OPTION_MISSING
,
2243 "Module type [%s] is not supported by library instance [%s]" \
2244 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
2245 ExtraData
="consumed by [%s]" % str(Module
))
2247 LibraryInstance
[LibraryClassName
] = LibraryModule
2248 LibraryConsumerList
.append(LibraryModule
)
2249 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
2251 LibraryModule
= LibraryInstance
[LibraryClassName
]
2253 if LibraryModule
is None:
2256 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
2257 Constructor
.append(LibraryModule
)
2259 if LibraryModule
not in ConsumedByList
:
2260 ConsumedByList
[LibraryModule
] = []
2261 # don't add current module itself to consumer list
2263 if M
in ConsumedByList
[LibraryModule
]:
2265 ConsumedByList
[LibraryModule
].append(M
)
2267 # Initialize the sorted output list to the empty set
2269 SortedLibraryList
= []
2271 # Q <- Set of all nodes with no incoming edges
2273 LibraryList
= [] #LibraryInstance.values()
2275 for LibraryClassName
in LibraryInstance
:
2276 M
= LibraryInstance
[LibraryClassName
]
2277 LibraryList
.append(M
)
2278 if ConsumedByList
[M
] == []:
2282 # start the DAG algorithm
2286 while Q
== [] and EdgeRemoved
:
2288 # for each node Item with a Constructor
2289 for Item
in LibraryList
:
2290 if Item
not in Constructor
:
2292 # for each Node without a constructor with an edge e from Item to Node
2293 for Node
in ConsumedByList
[Item
]:
2294 if Node
in Constructor
:
2296 # remove edge e from the graph if Node has no constructor
2297 ConsumedByList
[Item
].remove(Node
)
2299 if ConsumedByList
[Item
] == []:
2300 # insert Item into Q
2305 # DAG is done if there's no more incoming edge for all nodes
2309 # remove node from Q
2312 SortedLibraryList
.append(Node
)
2314 # for each node Item with an edge e from Node to Item do
2315 for Item
in LibraryList
:
2316 if Node
not in ConsumedByList
[Item
]:
2318 # remove edge e from the graph
2319 ConsumedByList
[Item
].remove(Node
)
2321 if ConsumedByList
[Item
] != []:
2323 # insert Item into Q, if Item has no other incoming edges
2327 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
2329 for Item
in LibraryList
:
2330 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
2331 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
2332 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
2333 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
2334 if Item
not in SortedLibraryList
:
2335 SortedLibraryList
.append(Item
)
2338 # Build the list of constructor and destructir names
2339 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
2341 SortedLibraryList
.reverse()
2342 return SortedLibraryList
2345 ## Override PCD setting (type, value, ...)
2347 # @param ToPcd The PCD to be overrided
2348 # @param FromPcd The PCD overrideing from
2350 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
2352 # in case there's PCDs coming from FDF file, which have no type given.
2353 # at this point, ToPcd.Type has the type found from dependent
2356 TokenCName
= ToPcd
.TokenCName
2357 for PcdItem
in GlobalData
.MixedPcd
:
2358 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2359 TokenCName
= PcdItem
[0]
2361 if FromPcd
is not None:
2362 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
2363 ToPcd
.Type
= FromPcd
.Type
2364 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
2365 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
2366 if ToPcd
.Type
.strip() == "DynamicEx":
2367 ToPcd
.Type
= FromPcd
.Type
2368 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
2369 and ToPcd
.Type
!= FromPcd
.Type
:
2370 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2371 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
2372 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2373 ToPcd
.Type
, Module
, FromPcd
.Type
),
2376 if FromPcd
.MaxDatumSize
not in [None, '']:
2377 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2378 if FromPcd
.DefaultValue
not in [None, '']:
2379 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2380 if FromPcd
.TokenValue
not in [None, '']:
2381 ToPcd
.TokenValue
= FromPcd
.TokenValue
2382 if FromPcd
.MaxDatumSize
not in [None, '']:
2383 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2384 if FromPcd
.DatumType
not in [None, '']:
2385 ToPcd
.DatumType
= FromPcd
.DatumType
2386 if FromPcd
.SkuInfoList
not in [None, '', []]:
2387 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2388 # Add Flexible PCD format parse
2389 if ToPcd
.DefaultValue
:
2391 ToPcd
.DefaultValue
= ValueExpressionEx(ToPcd
.DefaultValue
, ToPcd
.DatumType
, self
._GuidDict
)(True)
2392 except BadExpression
, Value
:
2393 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
, ToPcd
.DefaultValue
, Value
),
2396 # check the validation of datum
2397 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2399 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2400 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2401 ToPcd
.validateranges
= FromPcd
.validateranges
2402 ToPcd
.validlists
= FromPcd
.validlists
2403 ToPcd
.expressions
= FromPcd
.expressions
2405 if FromPcd
is not None and ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
2406 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2407 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2408 Value
= ToPcd
.DefaultValue
2409 if Value
in [None, '']:
2410 ToPcd
.MaxDatumSize
= '1'
2411 elif Value
[0] == 'L':
2412 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2413 elif Value
[0] == '{':
2414 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2416 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2418 # apply default SKU for dynamic PCDS if specified one is not available
2419 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
2420 and ToPcd
.SkuInfoList
in [None, {}, '']:
2421 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2422 SkuName
= self
.Platform
.SkuName
2425 ToPcd
.SkuInfoList
= {
2426 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
][0], '', '', '', '', '', ToPcd
.DefaultValue
)
2429 ## Apply PCD setting defined platform to a module
2431 # @param Module The module from which the PCD setting will be overrided
2433 # @retval PCD_list The list PCDs with settings from platform
2435 def ApplyPcdSetting(self
, Module
, Pcds
):
2436 # for each PCD in module
2437 for Name
, Guid
in Pcds
:
2438 PcdInModule
= Pcds
[Name
, Guid
]
2439 # find out the PCD setting in platform
2440 if (Name
, Guid
) in self
.Platform
.Pcds
:
2441 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2443 PcdInPlatform
= None
2444 # then override the settings if any
2445 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2446 # resolve the VariableGuid value
2447 for SkuId
in PcdInModule
.SkuInfoList
:
2448 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2449 if Sku
.VariableGuid
== '': continue
2450 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2451 if Sku
.VariableGuidValue
is None:
2452 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2455 RESOURCE_NOT_AVAILABLE
,
2456 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2457 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2458 % (Guid
, Name
, str(Module
)),
2462 # override PCD settings with module specific setting
2463 if Module
in self
.Platform
.Modules
:
2464 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2465 for Key
in PlatformModule
.Pcds
:
2470 elif Key
in GlobalData
.MixedPcd
:
2471 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
2473 ToPcd
= Pcds
[PcdItem
]
2477 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
)
2478 # use PCD value to calculate the MaxDatumSize when it is not specified
2479 for Name
, Guid
in Pcds
:
2480 Pcd
= Pcds
[Name
, Guid
]
2481 if Pcd
.DatumType
== "VOID*" and Pcd
.MaxDatumSize
in ['', None]:
2482 Value
= Pcd
.DefaultValue
2483 if Value
in [None, '']:
2484 Pcd
.MaxDatumSize
= '1'
2485 elif Value
[0] == 'L':
2486 Pcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2487 elif Value
[0] == '{':
2488 Pcd
.MaxDatumSize
= str(len(Value
.split(',')))
2490 Pcd
.MaxDatumSize
= str(len(Value
) - 1)
2491 return Pcds
.values()
2493 ## Resolve library names to library modules
2495 # (for Edk.x modules)
2497 # @param Module The module from which the library names will be resolved
2499 # @retval library_list The list of library modules
2501 def ResolveLibraryReference(self
, Module
):
2502 EdkLogger
.verbose("")
2503 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2504 LibraryConsumerList
= [Module
]
2506 # "CompilerStub" is a must for Edk modules
2507 if Module
.Libraries
:
2508 Module
.Libraries
.append("CompilerStub")
2510 while len(LibraryConsumerList
) > 0:
2511 M
= LibraryConsumerList
.pop()
2512 for LibraryName
in M
.Libraries
:
2513 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2515 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2516 if LibraryName
.upper() == Key
.upper():
2517 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2520 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2521 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2524 if Library
not in LibraryList
:
2525 LibraryList
.append(Library
)
2526 LibraryConsumerList
.append(Library
)
2527 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2530 ## Calculate the priority value of the build option
2532 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2534 # @retval Value Priority value based on the priority list.
2536 def CalculatePriorityValue(self
, Key
):
2537 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2538 PriorityValue
= 0x11111
2540 PriorityValue
&= 0x01111
2541 if ToolChain
== "*":
2542 PriorityValue
&= 0x10111
2544 PriorityValue
&= 0x11011
2545 if CommandType
== "*":
2546 PriorityValue
&= 0x11101
2548 PriorityValue
&= 0x11110
2550 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2553 ## Expand * in build option key
2555 # @param Options Options to be expanded
2557 # @retval options Options expanded
2559 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2566 # Construct a list contain the build options which need override.
2570 # Key[0] -- tool family
2571 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2573 if (Key
[0] == self
.BuildRuleFamily
and
2574 (ModuleStyle
is None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2575 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2576 if Target
== self
.BuildTarget
or Target
== "*":
2577 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2578 if Arch
== self
.Arch
or Arch
== "*":
2579 if Options
[Key
].startswith("="):
2580 if OverrideList
.get(Key
[1]) is not None:
2581 OverrideList
.pop(Key
[1])
2582 OverrideList
[Key
[1]] = Options
[Key
]
2585 # Use the highest priority value.
2587 if (len(OverrideList
) >= 2):
2588 KeyList
= OverrideList
.keys()
2589 for Index
in range(len(KeyList
)):
2590 NowKey
= KeyList
[Index
]
2591 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2592 for Index1
in range(len(KeyList
) - Index
- 1):
2593 NextKey
= KeyList
[Index1
+ Index
+ 1]
2595 # Compare two Key, if one is included by another, choose the higher priority one
2597 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2598 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2599 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2600 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2601 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2602 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2603 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2604 if Options
.get((self
.BuildRuleFamily
, NextKey
)) is not None:
2605 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2607 if Options
.get((self
.BuildRuleFamily
, NowKey
)) is not None:
2608 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2611 if ModuleStyle
is not None and len (Key
) > 2:
2612 # Check Module style is EDK or EDKII.
2613 # Only append build option for the matched style module.
2614 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2616 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2619 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2620 # if tool chain family doesn't match, skip it
2621 if Tool
in self
.ToolDefinition
and Family
!= "":
2622 FamilyIsNull
= False
2623 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2624 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2626 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2629 # expand any wildcard
2630 if Target
== "*" or Target
== self
.BuildTarget
:
2631 if Tag
== "*" or Tag
== self
.ToolChain
:
2632 if Arch
== "*" or Arch
== self
.Arch
:
2633 if Tool
not in BuildOptions
:
2634 BuildOptions
[Tool
] = {}
2635 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2636 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2638 # append options for the same tool except PATH
2640 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2642 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2643 # Build Option Family has been checked, which need't to be checked again for family.
2644 if FamilyMatch
or FamilyIsNull
:
2648 if ModuleStyle
is not None and len (Key
) > 2:
2649 # Check Module style is EDK or EDKII.
2650 # Only append build option for the matched style module.
2651 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2653 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2656 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2657 # if tool chain family doesn't match, skip it
2658 if Tool
not in self
.ToolDefinition
or Family
== "":
2660 # option has been added before
2661 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2664 # expand any wildcard
2665 if Target
== "*" or Target
== self
.BuildTarget
:
2666 if Tag
== "*" or Tag
== self
.ToolChain
:
2667 if Arch
== "*" or Arch
== self
.Arch
:
2668 if Tool
not in BuildOptions
:
2669 BuildOptions
[Tool
] = {}
2670 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2671 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2673 # append options for the same tool except PATH
2675 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2677 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2680 ## Append build options in platform to a module
2682 # @param Module The module to which the build options will be appened
2684 # @retval options The options appended with build options in platform
2686 def ApplyBuildOption(self
, Module
):
2687 # Get the different options for the different style module
2688 if Module
.AutoGenVersion
< 0x00010005:
2689 PlatformOptions
= self
.EdkBuildOption
2690 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2692 PlatformOptions
= self
.EdkIIBuildOption
2693 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2694 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2695 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2696 if Module
in self
.Platform
.Modules
:
2697 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2698 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2700 PlatformModuleOptions
= {}
2702 BuildRuleOrder
= None
2703 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2704 for Tool
in Options
:
2705 for Attr
in Options
[Tool
]:
2706 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2707 BuildRuleOrder
= Options
[Tool
][Attr
]
2709 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2710 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2711 self
.ToolDefinition
.keys())
2713 for Tool
in AllTools
:
2714 if Tool
not in BuildOptions
:
2715 BuildOptions
[Tool
] = {}
2717 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2718 if Tool
not in Options
:
2720 for Attr
in Options
[Tool
]:
2721 Value
= Options
[Tool
][Attr
]
2723 # Do not generate it in Makefile
2725 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2727 if Attr
not in BuildOptions
[Tool
]:
2728 BuildOptions
[Tool
][Attr
] = ""
2729 # check if override is indicated
2730 if Value
.startswith('='):
2731 ToolPath
= Value
[1:]
2732 ToolPath
= mws
.handleWsMacro(ToolPath
)
2733 BuildOptions
[Tool
][Attr
] = ToolPath
2735 Value
= mws
.handleWsMacro(Value
)
2737 BuildOptions
[Tool
][Attr
] += " " + Value
2739 BuildOptions
[Tool
][Attr
] = Value
2740 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
is not None:
2742 # Override UNI flag only for EDK module.
2744 if 'BUILD' not in BuildOptions
:
2745 BuildOptions
['BUILD'] = {}
2746 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2747 return BuildOptions
, BuildRuleOrder
2749 Platform
= property(_GetPlatform
)
2750 Name
= property(_GetName
)
2751 Guid
= property(_GetGuid
)
2752 Version
= property(_GetVersion
)
2754 OutputDir
= property(_GetOutputDir
)
2755 BuildDir
= property(_GetBuildDir
)
2756 MakeFileDir
= property(_GetMakeFileDir
)
2757 FdfFile
= property(_GetFdfFile
)
2759 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2760 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2761 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2762 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2763 PackageList
= property(_GetPackageList
)
2765 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2766 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2767 ToolChainFamily
= property(_GetToolChainFamily
)
2768 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2769 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2770 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2771 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2773 BuildCommand
= property(_GetBuildCommand
)
2774 BuildRule
= property(_GetBuildRule
)
2775 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2776 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2777 GenFdsCommand
= property(_GenFdsCommand
)
2779 ## ModuleAutoGen class
2781 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2782 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2783 # to the [depex] section in module's inf file.
2785 class ModuleAutoGen(AutoGen
):
2786 # call super().__init__ then call the worker function with different parameter count
2787 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2791 super(ModuleAutoGen
, self
).__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2792 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
)
2795 ## Cache the timestamps of metafiles of every module in a class variable
2799 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2800 obj
= super(ModuleAutoGen
, cls
).__new
__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2801 # check if this module is employed by active platform
2802 if not PlatformAutoGen(Workspace
, args
[0], Target
, Toolchain
, Arch
).ValidModule(MetaFile
):
2803 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2808 ## Initialize ModuleAutoGen
2810 # @param Workspace EdkIIWorkspaceBuild object
2811 # @param ModuleFile The path of module file
2812 # @param Target Build target (DEBUG, RELEASE)
2813 # @param Toolchain Name of tool chain
2814 # @param Arch The arch the module supports
2815 # @param PlatformFile Platform meta-file
2817 def _InitWorker(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2818 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2819 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2821 self
.Workspace
= Workspace
2822 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2824 self
.MetaFile
= ModuleFile
2825 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2827 self
.SourceDir
= self
.MetaFile
.SubDir
2828 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2830 self
.SourceOverrideDir
= None
2831 # use overrided path defined in DSC file
2832 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2833 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2835 self
.ToolChain
= Toolchain
2836 self
.BuildTarget
= Target
2838 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2839 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2841 self
.IsMakeFileCreated
= False
2842 self
.IsCodeFileCreated
= False
2843 self
.IsAsBuiltInfCreated
= False
2844 self
.DepexGenerated
= False
2846 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2847 self
.BuildRuleOrder
= None
2853 self
._Version
= None
2854 self
._ModuleType
= None
2855 self
._ComponentType
= None
2856 self
._PcdIsDriver
= None
2857 self
._AutoGenVersion
= None
2858 self
._LibraryFlag
= None
2859 self
._CustomMakefile
= None
2862 self
._BuildDir
= None
2863 self
._OutputDir
= None
2864 self
._FfsOutputDir
= None
2865 self
._DebugDir
= None
2866 self
._MakeFileDir
= None
2868 self
._IncludePathList
= None
2869 self
._IncludePathLength
= 0
2870 self
._AutoGenFileList
= None
2871 self
._UnicodeFileList
= None
2872 self
._VfrFileList
= None
2873 self
._IdfFileList
= None
2874 self
._SourceFileList
= None
2875 self
._ObjectFileList
= None
2876 self
._BinaryFileList
= None
2878 self
._DependentPackageList
= None
2879 self
._DependentLibraryList
= None
2880 self
._LibraryAutoGenList
= None
2881 self
._DerivedPackageList
= None
2882 self
._ModulePcdList
= None
2883 self
._LibraryPcdList
= None
2884 self
._PcdComments
= OrderedDict()
2885 self
._GuidList
= None
2886 self
._GuidsUsedByPcd
= None
2887 self
._GuidComments
= OrderedDict()
2888 self
._ProtocolList
= None
2889 self
._ProtocolComments
= OrderedDict()
2890 self
._PpiList
= None
2891 self
._PpiComments
= OrderedDict()
2892 self
._DepexList
= None
2893 self
._DepexExpressionList
= None
2894 self
._BuildOption
= None
2895 self
._BuildOptionIncPathList
= None
2896 self
._BuildTargets
= None
2897 self
._IntroBuildTargetList
= None
2898 self
._FinalBuildTargetList
= None
2899 self
._FileTypes
= None
2900 self
._BuildRules
= None
2902 self
._TimeStampPath
= None
2904 self
.AutoGenDepSet
= set()
2907 ## The Modules referenced to this Library
2908 # Only Library has this attribute
2909 self
._ReferenceModules
= []
2911 ## Store the FixedAtBuild Pcds
2913 self
._FixedAtBuildPcds
= []
2918 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2920 # Get FixedAtBuild Pcds of this Module
2921 def _GetFixedAtBuildPcds(self
):
2922 if self
._FixedAtBuildPcds
:
2923 return self
._FixedAtBuildPcds
2924 for Pcd
in self
.ModulePcdList
:
2925 if Pcd
.Type
!= "FixedAtBuild":
2927 if Pcd
not in self
._FixedAtBuildPcds
:
2928 self
._FixedAtBuildPcds
.append(Pcd
)
2930 return self
._FixedAtBuildPcds
2932 def _GetUniqueBaseName(self
):
2933 BaseName
= self
.Name
2934 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2935 if Module
.MetaFile
== self
.MetaFile
:
2937 if Module
.Name
== self
.Name
:
2938 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2939 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2940 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2941 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2944 # Macros could be used in build_rule.txt (also Makefile)
2945 def _GetMacros(self
):
2946 if self
._Macro
is None:
2947 self
._Macro
= OrderedDict()
2948 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2949 self
._Macro
["MODULE_NAME" ] = self
.Name
2950 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2951 self
._Macro
["MODULE_GUID" ] = self
.Guid
2952 self
._Macro
["MODULE_VERSION" ] = self
.Version
2953 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2954 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2955 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2956 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2957 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2959 self
._Macro
["BASE_NAME" ] = self
.Name
2961 self
._Macro
["ARCH" ] = self
.Arch
2962 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2963 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2964 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2965 self
._Macro
["TARGET" ] = self
.BuildTarget
2967 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2968 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2969 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2970 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2971 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2972 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2973 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2974 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2975 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2976 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2977 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2978 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2979 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2980 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2981 self
._Macro
["FFS_OUTPUT_DIR" ] = self
.FfsOutputDir
2984 ## Return the module build data object
2985 def _GetModule(self
):
2986 if self
._Module
is None:
2987 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2990 ## Return the module name
2991 def _GetBaseName(self
):
2992 return self
.Module
.BaseName
2994 ## Return the module DxsFile if exist
2995 def _GetDxsFile(self
):
2996 return self
.Module
.DxsFile
2998 ## Return the module SourceOverridePath
2999 def _GetSourceOverridePath(self
):
3000 return self
.Module
.SourceOverridePath
3002 ## Return the module meta-file GUID
3005 # To build same module more than once, the module path with FILE_GUID overridden has
3006 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
3007 # in DSC. The overridden GUID can be retrieved from file name
3009 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
3011 # Length of GUID is 36
3013 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
3014 return self
.Module
.Guid
3016 ## Return the module version
3017 def _GetVersion(self
):
3018 return self
.Module
.Version
3020 ## Return the module type
3021 def _GetModuleType(self
):
3022 return self
.Module
.ModuleType
3024 ## Return the component type (for Edk.x style of module)
3025 def _GetComponentType(self
):
3026 return self
.Module
.ComponentType
3028 ## Return the build type
3029 def _GetBuildType(self
):
3030 return self
.Module
.BuildType
3032 ## Return the PCD_IS_DRIVER setting
3033 def _GetPcdIsDriver(self
):
3034 return self
.Module
.PcdIsDriver
3036 ## Return the autogen version, i.e. module meta-file version
3037 def _GetAutoGenVersion(self
):
3038 return self
.Module
.AutoGenVersion
3040 ## Check if the module is library or not
3041 def _IsLibrary(self
):
3042 if self
._LibraryFlag
is None:
3043 if self
.Module
.LibraryClass
is not None and self
.Module
.LibraryClass
!= []:
3044 self
._LibraryFlag
= True
3046 self
._LibraryFlag
= False
3047 return self
._LibraryFlag
3049 ## Check if the module is binary module or not
3050 def _IsBinaryModule(self
):
3051 return self
.Module
.IsBinaryModule
3053 ## Return the directory to store intermediate files of the module
3054 def _GetBuildDir(self
):
3055 if self
._BuildDir
is None:
3056 self
._BuildDir
= path
.join(
3057 self
.PlatformInfo
.BuildDir
,
3060 self
.MetaFile
.BaseName
3062 CreateDirectory(self
._BuildDir
)
3063 return self
._BuildDir
3065 ## Return the directory to store the intermediate object files of the mdoule
3066 def _GetOutputDir(self
):
3067 if self
._OutputDir
is None:
3068 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
3069 CreateDirectory(self
._OutputDir
)
3070 return self
._OutputDir
3072 ## Return the directory to store ffs file
3073 def _GetFfsOutputDir(self
):
3074 if self
._FfsOutputDir
is None:
3075 if GlobalData
.gFdfParser
is not None:
3076 self
._FfsOutputDir
= path
.join(self
.PlatformInfo
.BuildDir
, "FV", "Ffs", self
.Guid
+ self
.Name
)
3078 self
._FfsOutputDir
= ''
3079 return self
._FfsOutputDir
3081 ## Return the directory to store auto-gened source files of the mdoule
3082 def _GetDebugDir(self
):
3083 if self
._DebugDir
is None:
3084 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
3085 CreateDirectory(self
._DebugDir
)
3086 return self
._DebugDir
3088 ## Return the path of custom file
3089 def _GetCustomMakefile(self
):
3090 if self
._CustomMakefile
is None:
3091 self
._CustomMakefile
= {}
3092 for Type
in self
.Module
.CustomMakefile
:
3093 if Type
in gMakeTypeMap
:
3094 MakeType
= gMakeTypeMap
[Type
]
3097 if self
.SourceOverrideDir
is not None:
3098 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
3099 if not os
.path
.exists(File
):
3100 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
3102 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
3103 self
._CustomMakefile
[MakeType
] = File
3104 return self
._CustomMakefile
3106 ## Return the directory of the makefile
3108 # @retval string The directory string of module's makefile
3110 def _GetMakeFileDir(self
):
3111 return self
.BuildDir
3113 ## Return build command string
3115 # @retval string Build command string
3117 def _GetBuildCommand(self
):
3118 return self
.PlatformInfo
.BuildCommand
3120 ## Get object list of all packages the module and its dependent libraries belong to
3122 # @retval list The list of package object
3124 def _GetDerivedPackageList(self
):
3126 for M
in [self
.Module
] + self
.DependentLibraryList
:
3127 for Package
in M
.Packages
:
3128 if Package
in PackageList
:
3130 PackageList
.append(Package
)
3133 ## Get the depex string
3135 # @return : a string contain all depex expresion.
3136 def _GetDepexExpresionString(self
):
3139 ## DPX_SOURCE IN Define section.
3140 if self
.Module
.DxsFile
:
3142 for M
in [self
.Module
] + self
.DependentLibraryList
:
3143 Filename
= M
.MetaFile
.Path
3144 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
3145 DepexExpresionList
= InfObj
.GetDepexExpresionList()
3146 for DepexExpresion
in DepexExpresionList
:
3147 for key
in DepexExpresion
.keys():
3148 Arch
, ModuleType
= key
3149 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
3150 # the type of build module is USER_DEFINED.
3151 # All different DEPEX section tags would be copied into the As Built INF file
3152 # and there would be separate DEPEX section tags
3153 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
3154 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
3155 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
3157 if Arch
.upper() == TAB_ARCH_COMMON
or \
3158 (Arch
.upper() == self
.Arch
.upper() and \
3159 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
3160 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
3162 #the type of build module is USER_DEFINED.
3163 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
3164 for Depex
in DepexList
:
3165 for key
in Depex
.keys():
3166 DepexStr
+= '[Depex.%s.%s]\n' % key
3167 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
3170 return '[Depex.%s]\n' % self
.Arch
3173 #the type of build module not is USER_DEFINED.
3175 for Depex
in DepexList
:
3180 for D
in Depex
.values():
3181 DepexStr
+= ' '.join([val
for val
in D
])
3182 Index
= DepexStr
.find('END')
3183 if Index
> -1 and Index
== len(DepexStr
) - 3:
3184 DepexStr
= DepexStr
[:-3]
3185 DepexStr
= DepexStr
.strip()
3188 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
3190 return '[Depex.%s]\n' % self
.Arch
3191 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
3193 ## Merge dependency expression
3195 # @retval list The token list of the dependency expression after parsed
3197 def _GetDepexTokenList(self
):
3198 if self
._DepexList
is None:
3199 self
._DepexList
= {}
3200 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3201 return self
._DepexList
3203 self
._DepexList
[self
.ModuleType
] = []
3205 for ModuleType
in self
._DepexList
:
3206 DepexList
= self
._DepexList
[ModuleType
]
3208 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3210 for M
in [self
.Module
] + self
.DependentLibraryList
:
3212 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3214 DepexList
.append('AND')
3215 DepexList
.append('(')
3217 if DepexList
[-1] == 'END': # no need of a END at this time
3219 DepexList
.append(')')
3222 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3223 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3225 if len(DepexList
) > 0:
3226 EdkLogger
.verbose('')
3227 return self
._DepexList
3229 ## Merge dependency expression
3231 # @retval list The token list of the dependency expression after parsed
3233 def _GetDepexExpressionTokenList(self
):
3234 if self
._DepexExpressionList
is None:
3235 self
._DepexExpressionList
= {}
3236 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3237 return self
._DepexExpressionList
3239 self
._DepexExpressionList
[self
.ModuleType
] = ''
3241 for ModuleType
in self
._DepexExpressionList
:
3242 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
3244 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3246 for M
in [self
.Module
] + self
.DependentLibraryList
:
3248 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3249 if DepexExpressionList
!= '':
3250 DepexExpressionList
+= ' AND '
3251 DepexExpressionList
+= '('
3252 DepexExpressionList
+= D
3253 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
3254 DepexExpressionList
+= ')'
3257 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
3258 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
3260 if len(DepexExpressionList
) > 0:
3261 EdkLogger
.verbose('')
3262 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
3263 return self
._DepexExpressionList
3265 # Get the tiano core user extension, it is contain dependent library.
3266 # @retval: a list contain tiano core userextension.
3268 def _GetTianoCoreUserExtensionList(self
):
3269 TianoCoreUserExtentionList
= []
3270 for M
in [self
.Module
] + self
.DependentLibraryList
:
3271 Filename
= M
.MetaFile
.Path
3272 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
3273 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
3274 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
3275 for Section
in TianoCoreUserExtent
.keys():
3276 ItemList
= Section
.split(TAB_SPLIT
)
3278 if len(ItemList
) == 4:
3280 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
3282 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
3283 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
3284 TianoCoreList
.append('\n')
3285 TianoCoreUserExtentionList
.append(TianoCoreList
)
3287 return TianoCoreUserExtentionList
3289 ## Return the list of specification version required for the module
3291 # @retval list The list of specification defined in module file
3293 def _GetSpecification(self
):
3294 return self
.Module
.Specification
3296 ## Tool option for the module build
3298 # @param PlatformInfo The object of PlatformBuildInfo
3299 # @retval dict The dict containing valid options
3301 def _GetModuleBuildOption(self
):
3302 if self
._BuildOption
is None:
3303 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3304 if self
.BuildRuleOrder
:
3305 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3306 return self
._BuildOption
3308 ## Get include path list from tool option for the module build
3310 # @retval list The include path list
3312 def _GetBuildOptionIncPathList(self
):
3313 if self
._BuildOptionIncPathList
is None:
3315 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3316 # is the former use /I , the Latter used -I to specify include directories
3318 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3319 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3320 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3321 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3324 # New ToolChainFamily, don't known whether there is option to specify include directories
3326 self
._BuildOptionIncPathList
= []
3327 return self
._BuildOptionIncPathList
3329 BuildOptionIncPathList
= []
3330 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3333 FlagOption
= self
.BuildOption
[Tool
][Attr
]
3337 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3338 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
3341 # RVCT may specify a list of directory seperated by commas
3344 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
3345 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3346 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
3349 # EDK II modules must not reference header files outside of the packages they depend on or
3350 # within the module's directory tree. Report error if violation.
3352 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
3353 for Path
in IncPathList
:
3354 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3355 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3356 EdkLogger
.error("build",
3359 File
=str(self
.MetaFile
))
3362 BuildOptionIncPathList
+= IncPathList
3364 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3366 return self
._BuildOptionIncPathList
3368 ## Return a list of files which can be built from source
3370 # What kind of files can be built is determined by build rules in
3371 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3373 def _GetSourceFileList(self
):
3374 if self
._SourceFileList
is None:
3375 self
._SourceFileList
= []
3376 for F
in self
.Module
.Sources
:
3378 if F
.TagName
not in ("", "*", self
.ToolChain
):
3379 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3380 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3382 # match tool chain family or build rule family
3383 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
, self
.BuildRuleFamily
):
3386 "The file [%s] must be built by tools of [%s], " \
3387 "but current toolchain family is [%s], buildrule family is [%s]" \
3388 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
, self
.BuildRuleFamily
))
3391 # add the file path into search path list for file including
3392 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3393 self
.IncludePathList
.insert(0, F
.Dir
)
3394 self
._SourceFileList
.append(F
)
3396 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3398 for F
in self
._SourceFileList
:
3399 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3400 return self
._SourceFileList
3402 def _MatchBuildRuleOrder(self
, FileList
):
3404 self
._GetModuleBuildOption
()
3405 for SingleFile
in FileList
:
3406 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3407 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3408 if key
in Order_Dict
:
3409 Order_Dict
[key
].append(SingleFile
.Ext
)
3411 Order_Dict
[key
] = [SingleFile
.Ext
]
3414 for F
in Order_Dict
:
3415 if len(Order_Dict
[F
]) > 1:
3416 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3417 for Ext
in Order_Dict
[F
][1:]:
3418 RemoveList
.append(F
+ Ext
)
3420 for item
in RemoveList
:
3421 FileList
.remove(item
)
3425 ## Return the list of unicode files
3426 def _GetUnicodeFileList(self
):
3427 if self
._UnicodeFileList
is None:
3428 if TAB_UNICODE_FILE
in self
.FileTypes
:
3429 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3431 self
._UnicodeFileList
= []
3432 return self
._UnicodeFileList
3434 ## Return the list of vfr files
3435 def _GetVfrFileList(self
):
3436 if self
._VfrFileList
is None:
3437 if TAB_VFR_FILE
in self
.FileTypes
:
3438 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3440 self
._VfrFileList
= []
3441 return self
._VfrFileList
3443 ## Return the list of Image Definition files
3444 def _GetIdfFileList(self
):
3445 if self
._IdfFileList
is None:
3446 if TAB_IMAGE_FILE
in self
.FileTypes
:
3447 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3449 self
._IdfFileList
= []
3450 return self
._IdfFileList
3452 ## Return a list of files which can be built from binary
3454 # "Build" binary files are just to copy them to build directory.
3456 # @retval list The list of files which can be built later
3458 def _GetBinaryFiles(self
):
3459 if self
._BinaryFileList
is None:
3460 self
._BinaryFileList
= []
3461 for F
in self
.Module
.Binaries
:
3462 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3464 self
._BinaryFileList
.append(F
)
3465 self
._ApplyBuildRule
(F
, F
.Type
)
3466 return self
._BinaryFileList
3468 def _GetBuildRules(self
):
3469 if self
._BuildRules
is None:
3471 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3472 for Type
in BuildRuleDatabase
.FileTypeList
:
3473 #first try getting build rule by BuildRuleFamily
3474 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3476 # build type is always module type, but ...
3477 if self
.ModuleType
!= self
.BuildType
:
3478 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3479 #second try getting build rule by ToolChainFamily
3481 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3483 # build type is always module type, but ...
3484 if self
.ModuleType
!= self
.BuildType
:
3485 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3488 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3489 BuildRules
[Type
] = RuleObject
3490 for Ext
in RuleObject
.SourceFileExtList
:
3491 BuildRules
[Ext
] = RuleObject
3492 self
._BuildRules
= BuildRules
3493 return self
._BuildRules
3495 def _ApplyBuildRule(self
, File
, FileType
):
3496 if self
._BuildTargets
is None:
3497 self
._IntroBuildTargetList
= set()
3498 self
._FinalBuildTargetList
= set()
3499 self
._BuildTargets
= {}
3500 self
._FileTypes
= {}
3502 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3503 if not os
.path
.exists(SubDirectory
):
3504 CreateDirectory(SubDirectory
)
3510 # Make sure to get build rule order value
3512 self
._GetModuleBuildOption
()
3514 while Index
< len(SourceList
):
3515 Source
= SourceList
[Index
]
3519 CreateDirectory(Source
.Dir
)
3521 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
is not None and File
in self
._BinaryFileList
:
3522 # Skip all files that are not binary libraries
3523 if not self
.IsLibrary
:
3525 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3526 elif FileType
in self
.BuildRules
:
3527 RuleObject
= self
.BuildRules
[FileType
]
3528 elif Source
.Ext
in self
.BuildRules
:
3529 RuleObject
= self
.BuildRules
[Source
.Ext
]
3531 # stop at no more rules
3533 self
._FinalBuildTargetList
.add(LastTarget
)
3536 FileType
= RuleObject
.SourceFileType
3537 if FileType
not in self
._FileTypes
:
3538 self
._FileTypes
[FileType
] = set()
3539 self
._FileTypes
[FileType
].add(Source
)
3541 # stop at STATIC_LIBRARY for library
3542 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3544 self
._FinalBuildTargetList
.add(LastTarget
)
3547 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3550 self
._FinalBuildTargetList
.add(LastTarget
)
3552 elif not Target
.Outputs
:
3553 # Only do build for target with outputs
3554 self
._FinalBuildTargetList
.add(Target
)
3556 if FileType
not in self
._BuildTargets
:
3557 self
._BuildTargets
[FileType
] = set()
3558 self
._BuildTargets
[FileType
].add(Target
)
3560 if not Source
.IsBinary
and Source
== File
:
3561 self
._IntroBuildTargetList
.add(Target
)
3563 # to avoid cyclic rule
3564 if FileType
in RuleChain
:
3567 RuleChain
.append(FileType
)
3568 SourceList
.extend(Target
.Outputs
)
3570 FileType
= TAB_UNKNOWN_FILE
3572 def _GetTargets(self
):
3573 if self
._BuildTargets
is None:
3574 self
._IntroBuildTargetList
= set()
3575 self
._FinalBuildTargetList
= set()
3576 self
._BuildTargets
= {}
3577 self
._FileTypes
= {}
3579 #TRICK: call _GetSourceFileList to apply build rule for source files
3580 if self
.SourceFileList
:
3583 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3584 if self
.BinaryFileList
:
3587 return self
._BuildTargets
3589 def _GetIntroTargetList(self
):
3591 return self
._IntroBuildTargetList
3593 def _GetFinalTargetList(self
):
3595 return self
._FinalBuildTargetList
3597 def _GetFileTypes(self
):
3599 return self
._FileTypes
3601 ## Get the list of package object the module depends on
3603 # @retval list The package object list
3605 def _GetDependentPackageList(self
):
3606 return self
.Module
.Packages
3608 ## Return the list of auto-generated code file
3610 # @retval list The list of auto-generated file
3612 def _GetAutoGenFileList(self
):
3613 UniStringAutoGenC
= True
3614 IdfStringAutoGenC
= True
3615 UniStringBinBuffer
= StringIO()
3616 IdfGenBinBuffer
= StringIO()
3617 if self
.BuildType
== 'UEFI_HII':
3618 UniStringAutoGenC
= False
3619 IdfStringAutoGenC
= False
3620 if self
._AutoGenFileList
is None:
3621 self
._AutoGenFileList
= {}
3622 AutoGenC
= TemplateString()
3623 AutoGenH
= TemplateString()
3624 StringH
= TemplateString()
3625 StringIdf
= TemplateString()
3626 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3628 # AutoGen.c is generated if there are library classes in inf, or there are object files
3630 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3631 or TAB_OBJECT_FILE
in self
.FileTypes
):
3632 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3633 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3634 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3635 if str(AutoGenH
) != "":
3636 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3637 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3638 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3639 if str(StringH
) != "":
3640 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3641 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3642 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3643 if UniStringBinBuffer
is not None and UniStringBinBuffer
.getvalue() != "":
3644 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3645 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3646 AutoFile
.IsBinary
= True
3647 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3648 if UniStringBinBuffer
is not None:
3649 UniStringBinBuffer
.close()
3650 if str(StringIdf
) != "":
3651 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3652 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3653 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3654 if IdfGenBinBuffer
is not None and IdfGenBinBuffer
.getvalue() != "":
3655 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3656 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3657 AutoFile
.IsBinary
= True
3658 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3659 if IdfGenBinBuffer
is not None:
3660 IdfGenBinBuffer
.close()
3661 return self
._AutoGenFileList
3663 ## Return the list of library modules explicitly or implicityly used by this module
3664 def _GetLibraryList(self
):
3665 if self
._DependentLibraryList
is None:
3666 # only merge library classes and PCD for non-library module
3668 self
._DependentLibraryList
= []
3670 if self
.AutoGenVersion
< 0x00010005:
3671 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3673 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3674 return self
._DependentLibraryList
3677 def UpdateComments(Recver
, Src
):
3679 if Key
not in Recver
:
3681 Recver
[Key
].extend(Src
[Key
])
3682 ## Get the list of PCDs from current module
3684 # @retval list The list of PCD
3686 def _GetModulePcdList(self
):
3687 if self
._ModulePcdList
is None:
3688 # apply PCD settings from platform
3689 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3690 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3691 return self
._ModulePcdList
3693 ## Get the list of PCDs from dependent libraries
3695 # @retval list The list of PCD
3697 def _GetLibraryPcdList(self
):
3698 if self
._LibraryPcdList
is None:
3699 Pcds
= OrderedDict()
3700 if not self
.IsLibrary
:
3701 # get PCDs from dependent libraries
3702 for Library
in self
.DependentLibraryList
:
3703 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3704 for Key
in Library
.Pcds
:
3705 # skip duplicated PCDs
3706 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3708 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3709 # apply PCD settings from platform
3710 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3712 self
._LibraryPcdList
= []
3713 return self
._LibraryPcdList
3715 ## Get the GUID value mapping
3717 # @retval dict The mapping between GUID cname and its value
3719 def _GetGuidList(self
):
3720 if self
._GuidList
is None:
3721 self
._GuidList
= OrderedDict()
3722 self
._GuidList
.update(self
.Module
.Guids
)
3723 for Library
in self
.DependentLibraryList
:
3724 self
._GuidList
.update(Library
.Guids
)
3725 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3726 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3727 return self
._GuidList
3729 def GetGuidsUsedByPcd(self
):
3730 if self
._GuidsUsedByPcd
is None:
3731 self
._GuidsUsedByPcd
= OrderedDict()
3732 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3733 for Library
in self
.DependentLibraryList
:
3734 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3735 return self
._GuidsUsedByPcd
3736 ## Get the protocol value mapping
3738 # @retval dict The mapping between protocol cname and its value
3740 def _GetProtocolList(self
):
3741 if self
._ProtocolList
is None:
3742 self
._ProtocolList
= OrderedDict()
3743 self
._ProtocolList
.update(self
.Module
.Protocols
)
3744 for Library
in self
.DependentLibraryList
:
3745 self
._ProtocolList
.update(Library
.Protocols
)
3746 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3747 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3748 return self
._ProtocolList
3750 ## Get the PPI value mapping
3752 # @retval dict The mapping between PPI cname and its value
3754 def _GetPpiList(self
):
3755 if self
._PpiList
is None:
3756 self
._PpiList
= OrderedDict()
3757 self
._PpiList
.update(self
.Module
.Ppis
)
3758 for Library
in self
.DependentLibraryList
:
3759 self
._PpiList
.update(Library
.Ppis
)
3760 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3761 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3762 return self
._PpiList
3764 ## Get the list of include search path
3766 # @retval list The list path
3768 def _GetIncludePathList(self
):
3769 if self
._IncludePathList
is None:
3770 self
._IncludePathList
= []
3771 if self
.AutoGenVersion
< 0x00010005:
3772 for Inc
in self
.Module
.Includes
:
3773 if Inc
not in self
._IncludePathList
:
3774 self
._IncludePathList
.append(Inc
)
3776 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3777 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3778 self
._IncludePathList
.append(Inc
)
3779 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3780 self
._IncludePathList
.append(self
.DebugDir
)
3782 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3783 self
._IncludePathList
.append(self
.DebugDir
)
3785 for Package
in self
.Module
.Packages
:
3786 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3787 if PackageDir
not in self
._IncludePathList
:
3788 self
._IncludePathList
.append(PackageDir
)
3789 IncludesList
= Package
.Includes
3790 if Package
._PrivateIncludes
:
3791 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3792 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3793 for Inc
in IncludesList
:
3794 if Inc
not in self
._IncludePathList
:
3795 self
._IncludePathList
.append(str(Inc
))
3796 return self
._IncludePathList
3798 def _GetIncludePathLength(self
):
3799 self
._IncludePathLength
= 0
3800 if self
._IncludePathList
:
3801 for inc
in self
._IncludePathList
:
3802 self
._IncludePathLength
+= len(' ' + inc
)
3803 return self
._IncludePathLength
3805 ## Get HII EX PCDs which maybe used by VFR
3807 # efivarstore used by VFR may relate with HII EX PCDs
3808 # Get the variable name and GUID from efivarstore and HII EX PCD
3809 # List the HII EX PCDs in As Built INF if both name and GUID match.
3811 # @retval list HII EX PCDs
3813 def _GetPcdsMaybeUsedByVfr(self
):
3814 if not self
.SourceFileList
:
3818 for SrcFile
in self
.SourceFileList
:
3819 if SrcFile
.Ext
.lower() != '.vfr':
3821 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3822 if not os
.path
.exists(Vfri
):
3824 VfriFile
= open(Vfri
, 'r')
3825 Content
= VfriFile
.read()
3827 Pos
= Content
.find('efivarstore')
3830 # Make sure 'efivarstore' is the start of efivarstore statement
3831 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3834 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3836 if Index
>= 0 and Content
[Index
] != ';':
3837 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3840 # 'efivarstore' must be followed by name and guid
3842 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3845 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3848 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3849 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3850 Pos
= Content
.find('efivarstore', Name
.end())
3854 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3855 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3857 for SkuName
in Pcd
.SkuInfoList
:
3858 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3859 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3860 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3863 Guid
= GuidStructureStringToGuidString(Value
)
3864 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3865 HiiExPcds
.append(Pcd
)
3870 def _GenOffsetBin(self
):
3872 for SourceFile
in self
.Module
.Sources
:
3873 if SourceFile
.Type
.upper() == ".VFR" :
3875 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3877 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3878 if SourceFile
.Type
.upper() == ".UNI" :
3880 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3882 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3884 if len(VfrUniBaseName
) == 0:
3886 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3887 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3888 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3889 if not VfrUniOffsetList
:
3892 OutputName
= '%sOffset.bin' % self
.Name
3893 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3896 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3898 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3900 # Use a instance of StringIO to cache data
3901 fStringIO
= StringIO('')
3903 for Item
in VfrUniOffsetList
:
3904 if (Item
[0].find("Strings") != -1):
3906 # UNI offset in image.
3908 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3910 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3911 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3912 fStringIO
.write(''.join(UniGuid
))
3913 UniValue
= pack ('Q', int (Item
[1], 16))
3914 fStringIO
.write (UniValue
)
3917 # VFR binary offset in image.
3919 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3921 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3922 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3923 fStringIO
.write(''.join(VfrGuid
))
3925 VfrValue
= pack ('Q', int (Item
[1], 16))
3926 fStringIO
.write (VfrValue
)
3928 # write data into file.
3931 fInputfile
.write (fStringIO
.getvalue())
3933 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3934 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3940 ## Create AsBuilt INF file the module
3942 def CreateAsBuiltInf(self
, IsOnlyCopy
= False):
3943 self
.OutputFile
= []
3945 if GlobalData
.gBinCacheDest
:
3946 self
.CopyModuleToCache()
3949 if self
.IsAsBuiltInfCreated
:
3952 # Skip the following code for EDK I inf
3953 if self
.AutoGenVersion
< 0x00010005:
3956 # Skip the following code for libraries
3960 # Skip the following code for modules with no source files
3961 if self
.SourceFileList
is None or self
.SourceFileList
== []:
3964 # Skip the following code for modules without any binary files
3965 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3968 ### TODO: How to handles mixed source and binary modules
3970 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3971 # Also find all packages that the DynamicEx PCDs depend on
3976 PcdTokenSpaceList
= []
3977 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3978 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3979 PatchablePcds
+= [Pcd
]
3980 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3981 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3984 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3985 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3986 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3987 GuidList
= OrderedDict()
3988 GuidList
.update(self
.GuidList
)
3989 for TokenSpace
in self
.GetGuidsUsedByPcd():
3990 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3991 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3992 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3993 GuidList
.pop(TokenSpace
)
3994 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3995 for Package
in self
.DerivedPackageList
:
3996 if Package
in Packages
:
3998 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
4000 for Index
in range(len(BeChecked
)):
4001 for Item
in CheckList
[Index
]:
4002 if Item
in BeChecked
[Index
]:
4003 Packages
+= [Package
]
4008 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
4009 for Pkg
in self
.PlatformInfo
.PackageList
:
4012 for VfrPcd
in VfrPcds
:
4013 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
4014 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
4018 ModuleType
= self
.ModuleType
4019 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
4020 ModuleType
= 'DXE_DRIVER'
4023 if self
.PcdIsDriver
!= '':
4024 DriverType
= self
.PcdIsDriver
4027 MDefs
= self
.Module
.Defines
4030 'module_name' : self
.Name
,
4031 'module_guid' : Guid
,
4032 'module_module_type' : ModuleType
,
4033 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
4034 'pcd_is_driver_string' : [],
4035 'module_uefi_specification_version' : [],
4036 'module_pi_specification_version' : [],
4037 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
4038 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
4039 'module_constructor' : self
.Module
.ConstructorList
,
4040 'module_destructor' : self
.Module
.DestructorList
,
4041 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
4042 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
4043 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
4044 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
4045 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
4046 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
4047 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
4048 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
4049 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
4050 'module_arch' : self
.Arch
,
4051 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
4053 'patchablepcd_item' : [],
4055 'protocol_item' : [],
4059 'libraryclasses_item' : []
4062 if 'MODULE_UNI_FILE' in MDefs
:
4063 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
4064 if os
.path
.isfile(UNIFile
):
4065 shutil
.copy2(UNIFile
, self
.OutputDir
)
4067 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
4068 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
4070 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
4073 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
4075 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
4076 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
4077 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
4078 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
4080 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
4081 DebugDir
= self
.DebugDir
.replace('\\', '/').strip('/')
4082 for Item
in self
.CodaTargetList
:
4083 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(DebugDir
, '').replace(OutputDir
, '').strip('/')
4084 if File
not in self
.OutputFile
:
4085 self
.OutputFile
.append(File
)
4086 if os
.path
.isabs(File
):
4087 File
= File
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
4088 if Item
.Target
.Ext
.lower() == '.aml':
4089 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
4090 elif Item
.Target
.Ext
.lower() == '.acpi':
4091 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
4092 elif Item
.Target
.Ext
.lower() == '.efi':
4093 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
4095 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
4096 if self
.DepexGenerated
:
4097 if self
.Name
+ '.depex' not in self
.OutputFile
:
4098 self
.OutputFile
.append(self
.Name
+ '.depex')
4099 if self
.ModuleType
in ['PEIM']:
4100 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
4101 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
4102 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
4103 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
4104 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
4106 Bin
= self
._GenOffsetBin
()
4108 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
4109 if Bin
not in self
.OutputFile
:
4110 self
.OutputFile
.append(Bin
)
4112 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
4114 if File
.lower().endswith('.pdb'):
4115 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
4116 if File
not in self
.OutputFile
:
4117 self
.OutputFile
.append(File
)
4118 HeaderComments
= self
.Module
.HeaderComments
4120 for Index
in range(len(HeaderComments
)):
4121 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
4122 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
4125 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
4126 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
4129 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
4130 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
4131 (GuidList
, self
._GuidComments
, 'guid_item')
4133 for Item
in GenList
:
4134 for CName
in Item
[0]:
4136 if CName
in Item
[1]:
4137 Comments
= '\n '.join(Item
[1][CName
])
4140 Entry
= Comments
+ '\n ' + CName
4141 AsBuiltInfDict
[Item
[2]].append(Entry
)
4142 PatchList
= parsePcdInfoFromMapFile(
4143 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
4144 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
4147 for Pcd
in PatchablePcds
:
4148 TokenCName
= Pcd
.TokenCName
4149 for PcdItem
in GlobalData
.MixedPcd
:
4150 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4151 TokenCName
= PcdItem
[0]
4153 for PatchPcd
in PatchList
:
4154 if TokenCName
== PatchPcd
[0]:
4159 if Pcd
.DatumType
== 'BOOLEAN':
4160 BoolValue
= Pcd
.DefaultValue
.upper()
4161 if BoolValue
== 'TRUE':
4162 Pcd
.DefaultValue
= '1'
4163 elif BoolValue
== 'FALSE':
4164 Pcd
.DefaultValue
= '0'
4166 if Pcd
.DatumType
in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
4167 HexFormat
= '0x%02x'
4168 if Pcd
.DatumType
== 'UINT16':
4169 HexFormat
= '0x%04x'
4170 elif Pcd
.DatumType
== 'UINT32':
4171 HexFormat
= '0x%08x'
4172 elif Pcd
.DatumType
== 'UINT64':
4173 HexFormat
= '0x%016x'
4174 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
4176 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
4177 EdkLogger
.error("build", AUTOGEN_ERROR
,
4178 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4180 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
4181 PcdValue
= Pcd
.DefaultValue
4182 if PcdValue
[0] != '{':
4184 if PcdValue
[0] == 'L':
4186 PcdValue
= PcdValue
.lstrip('L')
4187 PcdValue
= eval(PcdValue
)
4189 for Index
in range(0, len(PcdValue
)):
4191 CharVal
= ord(PcdValue
[Index
])
4192 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
4193 + '0x%02x' % (CharVal
>> 8) + ', '
4195 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
4198 Padding
= Padding
* 2
4199 ArraySize
= ArraySize
/ 2
4200 if ArraySize
< (len(PcdValue
) + 1):
4201 EdkLogger
.error("build", AUTOGEN_ERROR
,
4202 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4204 if ArraySize
> len(PcdValue
) + 1:
4205 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
4206 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
4207 elif len(PcdValue
.split(',')) <= ArraySize
:
4208 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
4211 EdkLogger
.error("build", AUTOGEN_ERROR
,
4212 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4214 PcdItem
= '%s.%s|%s|0x%X' % \
4215 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
4217 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4218 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
4220 PcdItem
= PcdComments
+ '\n ' + PcdItem
4221 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
4224 for Pcd
in Pcds
+ VfrPcds
:
4229 TokenCName
= Pcd
.TokenCName
4230 for PcdItem
in GlobalData
.MixedPcd
:
4231 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4232 TokenCName
= PcdItem
[0]
4234 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
4235 for SkuName
in Pcd
.SkuInfoList
:
4236 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
4237 SkuId
= SkuInfo
.SkuId
4238 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
4242 # Don't generate duplicated HII PCD
4244 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4247 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4248 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4249 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4253 for Index
, Comment
in enumerate(PcdCommentList
):
4254 for Usage
in UsageList
:
4255 if Comment
.find(Usage
) != -1:
4259 if UsageIndex
!= -1:
4260 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4262 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4263 PcdComments
= '\n '.join(PcdCommentList
)
4264 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4266 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4267 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
4268 for Item
in self
.BuildOption
:
4269 if 'FLAGS' in self
.BuildOption
[Item
]:
4270 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
4272 # Generated LibraryClasses section in comments.
4273 for Library
in self
.LibraryAutoGenList
:
4274 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
4276 # Generated UserExtensions TianoCore section.
4277 # All tianocore user extensions are copied.
4279 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
4280 UserExtStr
+= '\n'.join(TianoCore
)
4281 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
4282 if os
.path
.isfile(ExtensionFile
):
4283 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
4284 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
4286 # Generated depex expression section in comments.
4287 AsBuiltInfDict
['depexsection_item'] = ''
4288 DepexExpresion
= self
._GetDepexExpresionString
()
4290 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
4292 AsBuiltInf
= TemplateString()
4293 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4295 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4297 self
.IsAsBuiltInfCreated
= True
4298 if GlobalData
.gBinCacheDest
:
4299 self
.CopyModuleToCache()
4301 def CopyModuleToCache(self
):
4302 FileDir
= path
.join(GlobalData
.gBinCacheDest
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
4303 CreateDirectory (FileDir
)
4304 HashFile
= path
.join(self
.BuildDir
, self
.Name
+ '.hash')
4305 ModuleFile
= path
.join(self
.OutputDir
, self
.Name
+ '.inf')
4306 if os
.path
.exists(HashFile
):
4307 shutil
.copy2(HashFile
, FileDir
)
4308 if os
.path
.exists(ModuleFile
):
4309 shutil
.copy2(ModuleFile
, FileDir
)
4310 if not self
.OutputFile
:
4311 Ma
= self
.Workspace
.BuildDatabase
[PathClass(ModuleFile
), self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
4312 self
.OutputFile
= Ma
.Binaries
4314 for File
in self
.OutputFile
:
4316 if not os
.path
.isabs(File
):
4317 File
= os
.path
.join(self
.OutputDir
, File
)
4318 if os
.path
.exists(File
):
4319 shutil
.copy2(File
, FileDir
)
4321 def AttemptModuleCacheCopy(self
):
4322 if self
.IsBinaryModule
:
4324 FileDir
= path
.join(GlobalData
.gBinCacheSource
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
4325 HashFile
= path
.join(FileDir
, self
.Name
+ '.hash')
4326 if os
.path
.exists(HashFile
):
4327 f
= open(HashFile
, 'r')
4328 CacheHash
= f
.read()
4330 if GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
4331 if CacheHash
== GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
4332 for root
, dir, files
in os
.walk(FileDir
):
4334 if self
.Name
+ '.hash' in f
:
4335 shutil
.copy2(HashFile
, self
.BuildDir
)
4337 File
= path
.join(root
, f
)
4338 shutil
.copy2(File
, self
.OutputDir
)
4339 if self
.Name
== "PcdPeim" or self
.Name
== "PcdDxe":
4340 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4344 ## Create makefile for the module and its dependent libraries
4346 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4347 # dependent libraries will be created
4349 def CreateMakeFile(self
, CreateLibraryMakeFile
=True, GenFfsList
= []):
4350 # Ignore generating makefile when it is a binary module
4351 if self
.IsBinaryModule
:
4354 if self
.IsMakeFileCreated
:
4356 self
.GenFfsList
= GenFfsList
4357 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4358 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4359 LibraryAutoGen
.CreateMakeFile()
4364 if len(self
.CustomMakefile
) == 0:
4365 Makefile
= GenMake
.ModuleMakefile(self
)
4367 Makefile
= GenMake
.CustomMakefile(self
)
4368 if Makefile
.Generate():
4369 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4370 (self
.Name
, self
.Arch
))
4372 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4373 (self
.Name
, self
.Arch
))
4375 self
.CreateTimeStamp(Makefile
)
4376 self
.IsMakeFileCreated
= True
4378 def CopyBinaryFiles(self
):
4379 for File
in self
.Module
.Binaries
:
4381 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4382 CopyLongFilePath(SrcPath
, DstPath
)
4383 ## Create autogen code for the module and its dependent libraries
4385 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4386 # dependent libraries will be created
4388 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4389 if self
.IsCodeFileCreated
:
4392 # Need to generate PcdDatabase even PcdDriver is binarymodule
4393 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4394 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4396 if self
.IsBinaryModule
:
4398 self
.CopyBinaryFiles()
4401 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4402 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4403 LibraryAutoGen
.CreateCodeFile()
4409 IgoredAutoGenList
= []
4411 for File
in self
.AutoGenFileList
:
4412 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4413 #Ignore Edk AutoGen.c
4414 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4417 AutoGenList
.append(str(File
))
4419 IgoredAutoGenList
.append(str(File
))
4421 # Skip the following code for EDK I inf
4422 if self
.AutoGenVersion
< 0x00010005:
4425 for ModuleType
in self
.DepexList
:
4426 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4427 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
4430 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4431 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4433 if len(Dpx
.PostfixNotation
) <> 0:
4434 self
.DepexGenerated
= True
4436 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4437 AutoGenList
.append(str(DpxFile
))
4439 IgoredAutoGenList
.append(str(DpxFile
))
4441 if IgoredAutoGenList
== []:
4442 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4443 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4444 elif AutoGenList
== []:
4445 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4446 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4448 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4449 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4451 self
.IsCodeFileCreated
= True
4454 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4455 def _GetLibraryAutoGenList(self
):
4456 if self
._LibraryAutoGenList
is None:
4457 self
._LibraryAutoGenList
= []
4458 for Library
in self
.DependentLibraryList
:
4465 self
.PlatformInfo
.MetaFile
4467 if La
not in self
._LibraryAutoGenList
:
4468 self
._LibraryAutoGenList
.append(La
)
4469 for Lib
in La
.CodaTargetList
:
4470 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4471 return self
._LibraryAutoGenList
4473 def GenModuleHash(self
):
4474 if self
.Arch
not in GlobalData
.gModuleHash
:
4475 GlobalData
.gModuleHash
[self
.Arch
] = {}
4477 # Add Platform level hash
4478 m
.update(GlobalData
.gPlatformHash
)
4479 # Add Package level hash
4480 if self
.DependentPackageList
:
4481 for Pkg
in self
.DependentPackageList
:
4482 if Pkg
.PackageName
in GlobalData
.gPackageHash
[self
.Arch
]:
4483 m
.update(GlobalData
.gPackageHash
[self
.Arch
][Pkg
.PackageName
])
4486 if self
.LibraryAutoGenList
:
4487 for Lib
in self
.LibraryAutoGenList
:
4488 if Lib
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4490 m
.update(GlobalData
.gModuleHash
[self
.Arch
][Lib
.Name
])
4493 f
= open(str(self
.MetaFile
), 'r')
4497 # Add Module's source files
4498 if self
.SourceFileList
:
4499 for File
in self
.SourceFileList
:
4500 f
= open(str(File
), 'r')
4505 ModuleHashFile
= path
.join(self
.BuildDir
, self
.Name
+ ".hash")
4506 if self
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4507 GlobalData
.gModuleHash
[self
.Arch
][self
.Name
] = m
.hexdigest()
4508 if GlobalData
.gBinCacheSource
:
4509 CacheValid
= self
.AttemptModuleCacheCopy()
4512 return SaveFileOnChange(ModuleHashFile
, m
.hexdigest(), True)
4514 ## Decide whether we can skip the ModuleAutoGen process
4515 def CanSkipbyHash(self
):
4516 if GlobalData
.gUseHashCache
:
4517 return not self
.GenModuleHash()
4519 ## Decide whether we can skip the ModuleAutoGen process
4520 # If any source file is newer than the module than we cannot skip
4523 if not os
.path
.exists(self
.GetTimeStampPath()):
4525 #last creation time of the module
4526 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4528 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4529 if SrcTimeStamp
> DstTimeStamp
:
4532 with
open(self
.GetTimeStampPath(),'r') as f
:
4534 source
= source
.rstrip('\n')
4535 if not os
.path
.exists(source
):
4537 if source
not in ModuleAutoGen
.TimeDict
:
4538 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4539 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4543 def GetTimeStampPath(self
):
4544 if self
._TimeStampPath
is None:
4545 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4546 return self
._TimeStampPath
4547 def CreateTimeStamp(self
, Makefile
):
4551 FileSet
.add (self
.MetaFile
.Path
)
4553 for SourceFile
in self
.Module
.Sources
:
4554 FileSet
.add (SourceFile
.Path
)
4556 for Lib
in self
.DependentLibraryList
:
4557 FileSet
.add (Lib
.MetaFile
.Path
)
4559 for f
in self
.AutoGenDepSet
:
4560 FileSet
.add (f
.Path
)
4562 if os
.path
.exists (self
.GetTimeStampPath()):
4563 os
.remove (self
.GetTimeStampPath())
4564 with
open(self
.GetTimeStampPath(), 'w+') as file:
4568 Module
= property(_GetModule
)
4569 Name
= property(_GetBaseName
)
4570 Guid
= property(_GetGuid
)
4571 Version
= property(_GetVersion
)
4572 ModuleType
= property(_GetModuleType
)
4573 ComponentType
= property(_GetComponentType
)
4574 BuildType
= property(_GetBuildType
)
4575 PcdIsDriver
= property(_GetPcdIsDriver
)
4576 AutoGenVersion
= property(_GetAutoGenVersion
)
4577 Macros
= property(_GetMacros
)
4578 Specification
= property(_GetSpecification
)
4580 IsLibrary
= property(_IsLibrary
)
4581 IsBinaryModule
= property(_IsBinaryModule
)
4582 BuildDir
= property(_GetBuildDir
)
4583 OutputDir
= property(_GetOutputDir
)
4584 FfsOutputDir
= property(_GetFfsOutputDir
)
4585 DebugDir
= property(_GetDebugDir
)
4586 MakeFileDir
= property(_GetMakeFileDir
)
4587 CustomMakefile
= property(_GetCustomMakefile
)
4589 IncludePathList
= property(_GetIncludePathList
)
4590 IncludePathLength
= property(_GetIncludePathLength
)
4591 AutoGenFileList
= property(_GetAutoGenFileList
)
4592 UnicodeFileList
= property(_GetUnicodeFileList
)
4593 VfrFileList
= property(_GetVfrFileList
)
4594 SourceFileList
= property(_GetSourceFileList
)
4595 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4596 Targets
= property(_GetTargets
)
4597 IntroTargetList
= property(_GetIntroTargetList
)
4598 CodaTargetList
= property(_GetFinalTargetList
)
4599 FileTypes
= property(_GetFileTypes
)
4600 BuildRules
= property(_GetBuildRules
)
4601 IdfFileList
= property(_GetIdfFileList
)
4603 DependentPackageList
= property(_GetDependentPackageList
)
4604 DependentLibraryList
= property(_GetLibraryList
)
4605 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4606 DerivedPackageList
= property(_GetDerivedPackageList
)
4608 ModulePcdList
= property(_GetModulePcdList
)
4609 LibraryPcdList
= property(_GetLibraryPcdList
)
4610 GuidList
= property(_GetGuidList
)
4611 ProtocolList
= property(_GetProtocolList
)
4612 PpiList
= property(_GetPpiList
)
4613 DepexList
= property(_GetDepexTokenList
)
4614 DxsFile
= property(_GetDxsFile
)
4615 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4616 BuildOption
= property(_GetModuleBuildOption
)
4617 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4618 BuildCommand
= property(_GetBuildCommand
)
4620 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4622 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4623 if __name__
== '__main__':