2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2016, 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
46 ## Regular expression for splitting Dependency Expression string into tokens
47 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
50 # Match name = variable
52 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
54 # The format of guid in efivarstore statement likes following and must be correct:
55 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
57 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
59 ## Mapping Makefile type
60 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
63 ## Build rule configuration file
64 gDefaultBuildRuleFile
= 'Conf/build_rule.txt'
66 ## Build rule default version
67 AutoGenReqBuildRuleVerNum
= "0.1"
69 ## default file name for AutoGen
70 gAutoGenCodeFileName
= "AutoGen.c"
71 gAutoGenHeaderFileName
= "AutoGen.h"
72 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
73 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
74 gAutoGenDepexFileName
= "%(module_name)s.depex"
76 gInfSpecVersion
= "0x00010017"
79 # Template string to generic AsBuilt INF
81 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
87 INF_VERSION = ${module_inf_version}
88 BASE_NAME = ${module_name}
89 FILE_GUID = ${module_guid}
90 MODULE_TYPE = ${module_module_type}${BEGIN}
91 VERSION_STRING = ${module_version_string}${END}${BEGIN}
92 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
93 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
94 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
95 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
96 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
97 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
98 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
99 SHADOW = ${module_shadow}${END}${BEGIN}
100 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
101 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
102 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
103 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
104 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
105 SPEC = ${module_spec}${END}${BEGIN}
106 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
107 MODULE_UNI_FILE = ${module_uni_file}${END}
109 [Packages.${module_arch}]${BEGIN}
110 ${package_item}${END}
112 [Binaries.${module_arch}]${BEGIN}
115 [PatchPcd.${module_arch}]${BEGIN}
119 [Protocols.${module_arch}]${BEGIN}
123 [Ppis.${module_arch}]${BEGIN}
127 [Guids.${module_arch}]${BEGIN}
131 [PcdEx.${module_arch}]${BEGIN}
135 [LibraryClasses.${module_arch}]
136 ## @LIB_INSTANCES${BEGIN}
137 # ${libraryclasses_item}${END}
143 [BuildOptions.${module_arch}]
145 ## ${flags_item}${END}
148 ## Base class for AutoGen
150 # This class just implements the cache mechanism of AutoGen objects.
152 class AutoGen(object):
153 # database to maintain the objects of xxxAutoGen
154 _CACHE_
= {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
158 # @param Class class object of real AutoGen class
159 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
160 # @param Workspace Workspace directory or WorkspaceAutoGen object
161 # @param MetaFile The path of meta file
162 # @param Target Build target
163 # @param Toolchain Tool chain name
164 # @param Arch Target arch
165 # @param *args The specific class related parameters
166 # @param **kwargs The specific class related dict parameters
168 def __new__(Class
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
169 # check if the object has been created
170 Key
= (Target
, Toolchain
)
171 if Key
not in Class
._CACHE
_ or Arch
not in Class
._CACHE
_[Key
] \
172 or MetaFile
not in Class
._CACHE
_[Key
][Arch
]:
173 AutoGenObject
= super(AutoGen
, Class
).__new
__(Class
)
174 # call real constructor
175 if not AutoGenObject
._Init
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
177 if Key
not in Class
._CACHE
_:
178 Class
._CACHE
_[Key
] = {}
179 if Arch
not in Class
._CACHE
_[Key
]:
180 Class
._CACHE
_[Key
][Arch
] = {}
181 Class
._CACHE
_[Key
][Arch
][MetaFile
] = AutoGenObject
183 AutoGenObject
= Class
._CACHE
_[Key
][Arch
][MetaFile
]
189 # The file path of platform file will be used to represent hash value of this object
191 # @retval int Hash value of the file path of platform file
194 return hash(self
.MetaFile
)
198 # The file path of platform file will be used to represent this object
200 # @retval string String of platform file path
203 return str(self
.MetaFile
)
206 def __eq__(self
, Other
):
207 return Other
and self
.MetaFile
== Other
209 ## Workspace AutoGen class
211 # This class is used mainly to control the whole platform build for different
212 # architecture. This class will generate top level makefile.
214 class WorkspaceAutoGen(AutoGen
):
215 ## Real constructor of WorkspaceAutoGen
217 # This method behaves the same as __init__ except that it needs explicit invoke
218 # (in super class's __new__ method)
220 # @param WorkspaceDir Root directory of workspace
221 # @param ActivePlatform Meta-file of active platform
222 # @param Target Build target
223 # @param Toolchain Tool chain name
224 # @param ArchList List of architecture of current build
225 # @param MetaFileDb Database containing meta-files
226 # @param BuildConfig Configuration of build
227 # @param ToolDefinition Tool chain definitions
228 # @param FlashDefinitionFile File of flash definition
229 # @param Fds FD list to be generated
230 # @param Fvs FV list to be generated
231 # @param Caps Capsule list to be generated
232 # @param SkuId SKU id from command line
234 def _Init(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
235 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
236 Progress
=None, BuildModule
=None):
243 self
.BuildDatabase
= MetaFileDb
244 self
.MetaFile
= ActivePlatform
245 self
.WorkspaceDir
= WorkspaceDir
246 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, 'COMMON', Target
, Toolchain
]
247 GlobalData
.gActivePlatform
= self
.Platform
248 self
.BuildTarget
= Target
249 self
.ToolChain
= Toolchain
250 self
.ArchList
= ArchList
252 self
.UniFlag
= UniFlag
254 self
.TargetTxt
= BuildConfig
255 self
.ToolDef
= ToolDefinition
256 self
.FdfFile
= FlashDefinitionFile
257 self
.FdTargetList
= Fds
258 self
.FvTargetList
= Fvs
259 self
.CapTargetList
= Caps
260 self
.AutoGenObjectList
= []
262 # there's many relative directory operations, so ...
263 os
.chdir(self
.WorkspaceDir
)
268 if not self
.ArchList
:
269 ArchList
= set(self
.Platform
.SupArchList
)
271 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
273 EdkLogger
.error("build", PARAMETER_INVALID
,
274 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
275 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
276 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
277 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
278 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
279 self
.ArchList
= tuple(ArchList
)
281 # Validate build target
282 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
283 EdkLogger
.error("build", PARAMETER_INVALID
,
284 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
285 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
288 # parse FDF file to get PCDs in it, if any
290 self
.FdfFile
= self
.Platform
.FlashDefinition
294 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
295 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
296 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
298 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
300 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
303 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
305 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
308 Progress
.Start("\nProcessing meta-data")
312 # Mark now build in AutoGen Phase
314 GlobalData
.gAutoGenPhase
= True
315 Fdf
= FdfParser(self
.FdfFile
.Path
)
317 GlobalData
.gFdfParser
= Fdf
318 GlobalData
.gAutoGenPhase
= False
319 PcdSet
= Fdf
.Profile
.PcdDict
320 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
321 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
322 for FdRegion
in FdDict
.RegionList
:
323 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
324 if int(FdRegion
.Offset
) % 8 != 0:
325 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
326 ModuleList
= Fdf
.Profile
.InfList
327 self
.FdfProfile
= Fdf
.Profile
328 for fvname
in self
.FvTargetList
:
329 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
330 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
331 "No such an FV in FDF file: %s" % fvname
)
335 self
.FdfProfile
= None
336 if self
.FdTargetList
:
337 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
338 self
.FdTargetList
= []
339 if self
.FvTargetList
:
340 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
341 self
.FvTargetList
= []
342 if self
.CapTargetList
:
343 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
344 self
.CapTargetList
= []
346 # apply SKU and inject PCDs from Flash Definition file
347 for Arch
in self
.ArchList
:
348 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
352 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
353 if GlobalData
.BuildOptionPcd
:
354 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
355 if type(pcd
) is tuple:
357 (pcdname
, pcdvalue
) = pcd
.split('=')
359 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
361 (TokenSpaceGuidCName
, TokenCName
) = pcdname
.split('.')
365 TokenSpaceGuidCName
= ''
366 HasTokenSpace
= False
367 TokenSpaceGuidCNameList
= []
371 for package
in PGen
.PackageList
:
372 for key
in package
.Pcds
:
373 PcdItem
= package
.Pcds
[key
]
375 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
376 PcdDatumType
= PcdItem
.DatumType
377 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
380 if PcdItem
.TokenCName
== TokenCName
:
381 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
382 if len (TokenSpaceGuidCNameList
) < 1:
383 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
384 PcdDatumType
= PcdItem
.DatumType
385 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
386 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
392 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
395 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, NewValue
)
399 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
401 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
403 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
404 if BuildData
.Arch
!= Arch
:
406 if BuildData
.MetaFile
.Ext
== '.dec':
408 for key
in BuildData
.Pcds
:
409 PcdItem
= BuildData
.Pcds
[key
]
410 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
):
411 PcdItem
.DefaultValue
= NewValue
413 if (TokenCName
, TokenSpaceGuidCName
) in PcdSet
:
414 PcdSet
[(TokenCName
, TokenSpaceGuidCName
)] = NewValue
416 SourcePcdDict
= {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
417 BinaryPcdDict
= {'DynamicEx':[], 'PatchableInModule':[]}
418 SourcePcdDict_Keys
= SourcePcdDict
.keys()
419 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
421 # generate the SourcePcdDict and BinaryPcdDict
422 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
423 if BuildData
.Arch
!= Arch
:
425 if BuildData
.MetaFile
.Ext
== '.inf':
426 for key
in BuildData
.Pcds
:
427 if BuildData
.Pcds
[key
].Pending
:
428 if key
in Platform
.Pcds
:
429 PcdInPlatform
= Platform
.Pcds
[key
]
430 if PcdInPlatform
.Type
not in [None, '']:
431 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
433 if BuildData
.MetaFile
in Platform
.Modules
:
434 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
435 if key
in PlatformModule
.Pcds
:
436 PcdInPlatform
= PlatformModule
.Pcds
[key
]
437 if PcdInPlatform
.Type
not in [None, '']:
438 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
440 if 'DynamicEx' in BuildData
.Pcds
[key
].Type
:
441 if BuildData
.IsBinaryModule
:
442 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['DynamicEx']:
443 BinaryPcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
445 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['DynamicEx']:
446 SourcePcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
448 elif 'PatchableInModule' in BuildData
.Pcds
[key
].Type
:
449 if BuildData
.MetaFile
.Ext
== '.inf':
450 if BuildData
.IsBinaryModule
:
451 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['PatchableInModule']:
452 BinaryPcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
454 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['PatchableInModule']:
455 SourcePcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
457 elif 'Dynamic' in BuildData
.Pcds
[key
].Type
:
458 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['Dynamic']:
459 SourcePcdDict
['Dynamic'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
460 elif 'FixedAtBuild' in BuildData
.Pcds
[key
].Type
:
461 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['FixedAtBuild']:
462 SourcePcdDict
['FixedAtBuild'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
467 # intersection the BinaryPCD for Mixed PCD
469 for i
in BinaryPcdDict_Keys
:
470 for j
in BinaryPcdDict_Keys
:
472 IntersectionList
= list(set(BinaryPcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
473 for item
in IntersectionList
:
474 NewPcd1
= (item
[0] + '_' + i
, item
[1])
475 NewPcd2
= (item
[0] + '_' + j
, item
[1])
476 if item
not in GlobalData
.MixedPcd
:
477 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
479 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
480 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
481 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
482 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
487 # intersection the SourcePCD and BinaryPCD for Mixed PCD
489 for i
in SourcePcdDict_Keys
:
490 for j
in BinaryPcdDict_Keys
:
492 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
493 for item
in IntersectionList
:
494 NewPcd1
= (item
[0] + '_' + i
, item
[1])
495 NewPcd2
= (item
[0] + '_' + j
, item
[1])
496 if item
not in GlobalData
.MixedPcd
:
497 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
499 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
500 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
501 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
502 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
506 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
507 if BuildData
.Arch
!= Arch
:
509 for key
in BuildData
.Pcds
:
510 for SinglePcd
in GlobalData
.MixedPcd
:
511 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
512 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
513 Pcd_Type
= item
[0].split('_')[-1]
514 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
515 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
516 Value
= BuildData
.Pcds
[key
]
517 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
519 newkey
= (Value
.TokenCName
, key
[1])
521 newkey
= (Value
.TokenCName
, key
[1], key
[2])
522 del BuildData
.Pcds
[key
]
523 BuildData
.Pcds
[newkey
] = Value
531 # handle the mixed pcd in FDF file
533 if key
in GlobalData
.MixedPcd
:
536 for item
in GlobalData
.MixedPcd
[key
]:
539 #Collect package set information from INF of FDF
541 for Inf
in ModuleList
:
542 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
543 if ModuleFile
in Platform
.Modules
:
545 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
546 PkgSet
.update(ModuleData
.Packages
)
547 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
550 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
551 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
553 Platform
.SkuName
= self
.SkuId
554 for Name
, Guid
in PcdSet
:
555 if (Name
, Guid
) not in DecPcds
:
559 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
560 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
561 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
564 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
565 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
566 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
567 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
568 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
570 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
574 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
575 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
576 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
579 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
581 # Explicitly collect platform's dynamic PCDs
583 Pa
.CollectPlatformDynamicPcds()
584 Pa
.CollectFixedAtBuildPcds()
585 self
.AutoGenObjectList
.append(Pa
)
588 # Check PCDs token value conflict in each DEC file.
590 self
._CheckAllPcdsTokenValueConflict
()
593 # Check PCD type and definition between DSC and DEC
595 self
._CheckPcdDefineAndType
()
598 # self._CheckDuplicateInFV(Fdf)
600 self
._BuildDir
= None
602 self
._MakeFileDir
= None
603 self
._BuildCommand
= None
607 def _BuildOptionPcdValueFormat(self
, TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, Value
):
608 if PcdDatumType
== 'VOID*':
609 if Value
.startswith('L'):
611 EdkLogger
.error('build', OPTION_VALUE_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
612 Value
= Value
[0] + '"' + Value
[1:] + '"'
613 elif Value
.startswith('B'):
615 EdkLogger
.error('build', OPTION_VALUE_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
619 EdkLogger
.error('build', OPTION_VALUE_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
620 Value
= '"' + Value
+ '"'
622 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, Value
)
624 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
625 if PcdDatumType
== 'BOOLEAN':
626 Value
= Value
.upper()
627 if Value
== 'TRUE' or Value
== '1':
629 elif Value
== 'FALSE' or Value
== '0':
633 ## _CheckDuplicateInFV() method
635 # Check whether there is duplicate modules/files exist in FV section.
636 # The check base on the file GUID;
638 def _CheckDuplicateInFV(self
, Fdf
):
639 for Fv
in Fdf
.Profile
.FvDict
:
641 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
642 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
647 for Pa
in self
.AutoGenObjectList
:
650 for Module
in Pa
.ModuleAutoGenList
:
651 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
653 if not Module
.Guid
.upper() in _GuidDict
.keys():
654 _GuidDict
[Module
.Guid
.upper()] = FfsFile
657 EdkLogger
.error("build",
659 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
660 FfsFile
.CurrentLineContent
,
661 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
662 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
663 Module
.Guid
.upper()),
664 ExtraData
=self
.FdfFile
)
666 # Some INF files not have entity in DSC file.
669 if FfsFile
.InfFileName
.find('$') == -1:
670 InfPath
= NormPath(FfsFile
.InfFileName
)
671 if not os
.path
.exists(InfPath
):
672 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
674 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
676 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
677 # BuildObject from one of AutoGenObjectList is enough.
679 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
680 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
681 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
683 EdkLogger
.error("build",
685 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
686 FfsFile
.CurrentLineContent
,
687 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
688 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
689 InfObj
.Guid
.upper()),
690 ExtraData
=self
.FdfFile
)
693 if FfsFile
.NameGuid
!= None:
694 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
697 # If the NameGuid reference a PCD name.
698 # The style must match: PCD(xxxx.yyy)
700 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
702 # Replace the PCD value.
704 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
706 for Pa
in self
.AutoGenObjectList
:
708 for PcdItem
in Pa
.AllPcdList
:
709 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
711 # First convert from CFormatGuid to GUID string
713 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
715 if not _PcdGuidString
:
717 # Then try Byte array.
719 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
721 if not _PcdGuidString
:
723 # Not Byte array or CFormat GUID, raise error.
725 EdkLogger
.error("build",
727 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
728 ExtraData
=self
.FdfFile
)
730 if not _PcdGuidString
.upper() in _GuidDict
.keys():
731 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
735 EdkLogger
.error("build",
737 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
738 FfsFile
.CurrentLineContent
,
739 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
740 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
741 FfsFile
.NameGuid
.upper()),
742 ExtraData
=self
.FdfFile
)
744 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
745 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
748 # Two raw file GUID conflict.
750 EdkLogger
.error("build",
752 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
753 FfsFile
.CurrentLineContent
,
754 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
755 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
756 FfsFile
.NameGuid
.upper()),
757 ExtraData
=self
.FdfFile
)
760 def _CheckPcdDefineAndType(self
):
762 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
763 "Dynamic", #"DynamicHii", "DynamicVpd",
764 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
767 # This dict store PCDs which are not used by any modules with specified arches
769 for Pa
in self
.AutoGenObjectList
:
770 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
771 for Pcd
in Pa
.Platform
.Pcds
:
772 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
774 # If no PCD type, this PCD comes from FDF
778 # Try to remove Hii and Vpd suffix
779 if PcdType
.startswith("DynamicEx"):
780 PcdType
= "DynamicEx"
781 elif PcdType
.startswith("Dynamic"):
784 for Package
in Pa
.PackageList
:
785 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
786 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
788 for Type
in PcdTypeList
:
789 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
793 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
794 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
799 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
801 for Pcd
in UnusedPcd
:
804 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
805 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
806 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
811 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
813 ## Return the directory to store FV files
815 if self
._FvDir
== None:
816 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
819 ## Return the directory to store all intermediate and final files built
820 def _GetBuildDir(self
):
821 return self
.AutoGenObjectList
[0].BuildDir
823 ## Return the build output directory platform specifies
824 def _GetOutputDir(self
):
825 return self
.Platform
.OutputDirectory
827 ## Return platform name
829 return self
.Platform
.PlatformName
831 ## Return meta-file GUID
833 return self
.Platform
.Guid
835 ## Return platform version
836 def _GetVersion(self
):
837 return self
.Platform
.Version
839 ## Return paths of tools
840 def _GetToolDefinition(self
):
841 return self
.AutoGenObjectList
[0].ToolDefinition
843 ## Return directory of platform makefile
845 # @retval string Makefile directory
847 def _GetMakeFileDir(self
):
848 if self
._MakeFileDir
== None:
849 self
._MakeFileDir
= self
.BuildDir
850 return self
._MakeFileDir
852 ## Return build command string
854 # @retval string Build command string
856 def _GetBuildCommand(self
):
857 if self
._BuildCommand
== None:
858 # BuildCommand should be all the same. So just get one from platform AutoGen
859 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
860 return self
._BuildCommand
862 ## Check the PCDs token value conflict in each DEC file.
864 # Will cause build break and raise error message while two PCDs conflict.
868 def _CheckAllPcdsTokenValueConflict(self
):
869 for Pa
in self
.AutoGenObjectList
:
870 for Package
in Pa
.PackageList
:
871 PcdList
= Package
.Pcds
.values()
872 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
874 while (Count
< len(PcdList
) - 1) :
875 Item
= PcdList
[Count
]
876 ItemNext
= PcdList
[Count
+ 1]
878 # Make sure in the same token space the TokenValue should be unique
880 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
881 SameTokenValuePcdList
= []
882 SameTokenValuePcdList
.append(Item
)
883 SameTokenValuePcdList
.append(ItemNext
)
884 RemainPcdListLength
= len(PcdList
) - Count
- 2
885 for ValueSameCount
in range(RemainPcdListLength
):
886 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
887 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
891 # Sort same token value PCD list with TokenGuid and TokenCName
893 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
894 SameTokenValuePcdListCount
= 0
895 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
897 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
898 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
900 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
901 for PcdItem
in GlobalData
.MixedPcd
:
902 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
903 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
909 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
910 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
913 SameTokenValuePcdListCount
+= 1
914 Count
+= SameTokenValuePcdListCount
917 PcdList
= Package
.Pcds
.values()
918 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
920 while (Count
< len(PcdList
) - 1) :
921 Item
= PcdList
[Count
]
922 ItemNext
= PcdList
[Count
+ 1]
924 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
926 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
930 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
931 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
935 ## Generate fds command
936 def _GenFdsCommand(self
):
937 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
939 ## Create makefile for the platform and modules in it
941 # @param CreateDepsMakeFile Flag indicating if the makefile for
942 # modules will be created as well
944 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
945 if CreateDepsMakeFile
:
946 for Pa
in self
.AutoGenObjectList
:
947 Pa
.CreateMakeFile(CreateDepsMakeFile
)
949 ## Create autogen code for platform and modules
951 # Since there's no autogen code for platform, this method will do nothing
952 # if CreateModuleCodeFile is set to False.
954 # @param CreateDepsCodeFile Flag indicating if creating module's
955 # autogen code file or not
957 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
958 if not CreateDepsCodeFile
:
960 for Pa
in self
.AutoGenObjectList
:
961 Pa
.CreateCodeFile(CreateDepsCodeFile
)
963 ## Create AsBuilt INF file the platform
965 def CreateAsBuiltInf(self
):
968 Name
= property(_GetName
)
969 Guid
= property(_GetGuid
)
970 Version
= property(_GetVersion
)
971 OutputDir
= property(_GetOutputDir
)
973 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
975 BuildDir
= property(_GetBuildDir
)
976 FvDir
= property(_GetFvDir
)
977 MakeFileDir
= property(_GetMakeFileDir
)
978 BuildCommand
= property(_GetBuildCommand
)
979 GenFdsCommand
= property(_GenFdsCommand
)
981 ## AutoGen class for platform
983 # PlatformAutoGen class will process the original information in platform
984 # file in order to generate makefile for platform.
986 class PlatformAutoGen(AutoGen
):
988 # Used to store all PCDs for both PEI and DXE phase, in order to generate
989 # correct PCD database
992 _NonDynaPcdList_
= []
996 # The priority list while override build option
998 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
999 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1000 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1001 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1002 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1003 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1004 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1005 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1006 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1007 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1008 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1009 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1010 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1011 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1012 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1013 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1015 ## The real constructor of PlatformAutoGen
1017 # This method is not supposed to be called by users of PlatformAutoGen. It's
1018 # only used by factory method __new__() to do real initialization work for an
1019 # object of PlatformAutoGen
1021 # @param Workspace WorkspaceAutoGen object
1022 # @param PlatformFile Platform file (DSC file)
1023 # @param Target Build target (DEBUG, RELEASE)
1024 # @param Toolchain Name of tool chain
1025 # @param Arch arch of the platform supports
1027 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1028 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1029 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1031 self
.MetaFile
= PlatformFile
1032 self
.Workspace
= Workspace
1033 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1034 self
.ToolChain
= Toolchain
1035 self
.BuildTarget
= Target
1037 self
.SourceDir
= PlatformFile
.SubDir
1038 self
.SourceOverrideDir
= None
1039 self
.FdTargetList
= self
.Workspace
.FdTargetList
1040 self
.FvTargetList
= self
.Workspace
.FvTargetList
1041 self
.AllPcdList
= []
1042 # get the original module/package/platform objects
1043 self
.BuildDatabase
= Workspace
.BuildDatabase
1045 # flag indicating if the makefile/C-code file has been created or not
1046 self
.IsMakeFileCreated
= False
1047 self
.IsCodeFileCreated
= False
1049 self
._Platform
= None
1052 self
._Version
= None
1054 self
._BuildRule
= None
1055 self
._SourceDir
= None
1056 self
._BuildDir
= None
1057 self
._OutputDir
= None
1059 self
._MakeFileDir
= None
1060 self
._FdfFile
= None
1062 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1063 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1064 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1065 self
._NonDynamicPcdDict
= {}
1067 self
._ToolDefinitions
= None
1068 self
._ToolDefFile
= None # toolcode : tool path
1069 self
._ToolChainFamily
= None
1070 self
._BuildRuleFamily
= None
1071 self
._BuildOption
= None # toolcode : option
1072 self
._EdkBuildOption
= None # edktoolcode : option
1073 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1074 self
._PackageList
= None
1075 self
._ModuleAutoGenList
= None
1076 self
._LibraryAutoGenList
= None
1077 self
._BuildCommand
= None
1078 self
._AsBuildInfList
= []
1079 self
._AsBuildModuleList
= []
1080 if GlobalData
.gFdfParser
!= None:
1081 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1082 for Inf
in self
._AsBuildInfList
:
1083 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1084 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1085 if not M
.IsSupportedArch
:
1087 self
._AsBuildModuleList
.append(InfClass
)
1088 # get library/modules for build
1089 self
.LibraryBuildDirectoryList
= []
1090 self
.ModuleBuildDirectoryList
= []
1094 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1096 ## Create autogen code for platform and modules
1098 # Since there's no autogen code for platform, this method will do nothing
1099 # if CreateModuleCodeFile is set to False.
1101 # @param CreateModuleCodeFile Flag indicating if creating module's
1102 # autogen code file or not
1104 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1105 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1106 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1109 for Ma
in self
.ModuleAutoGenList
:
1110 Ma
.CreateCodeFile(True)
1112 # don't do this twice
1113 self
.IsCodeFileCreated
= True
1115 ## Generate Fds Command
1116 def _GenFdsCommand(self
):
1117 return self
.Workspace
.GenFdsCommand
1119 ## Create makefile for the platform and mdoules in it
1121 # @param CreateModuleMakeFile Flag indicating if the makefile for
1122 # modules will be created as well
1124 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
1125 if CreateModuleMakeFile
:
1126 for ModuleFile
in self
.Platform
.Modules
:
1127 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1128 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1129 Ma
.CreateMakeFile(True)
1130 #Ma.CreateAsBuiltInf()
1132 # no need to create makefile for the platform more than once
1133 if self
.IsMakeFileCreated
:
1136 # create library/module build dirs for platform
1137 Makefile
= GenMake
.PlatformMakefile(self
)
1138 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1139 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1141 self
.IsMakeFileCreated
= True
1143 ## Deal with Shared FixedAtBuild Pcds
1145 def CollectFixedAtBuildPcds(self
):
1146 for LibAuto
in self
.LibraryAutoGenList
:
1147 FixedAtBuildPcds
= {}
1148 ShareFixedAtBuildPcdsSameValue
= {}
1149 for Module
in LibAuto
._ReferenceModules
:
1150 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1151 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1152 if key
not in FixedAtBuildPcds
:
1153 ShareFixedAtBuildPcdsSameValue
[key
] = True
1154 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1156 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1157 ShareFixedAtBuildPcdsSameValue
[key
] = False
1158 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1159 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1160 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1163 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1164 if DscPcd
.Type
!= "FixedAtBuild":
1166 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1167 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1169 ## Collect dynamic PCDs
1171 # Gather dynamic PCDs list from each module and their settings from platform
1172 # This interface should be invoked explicitly when platform action is created.
1174 def CollectPlatformDynamicPcds(self
):
1175 # Override the platform Pcd's value by build option
1176 if GlobalData
.BuildOptionPcd
:
1177 for key
in self
.Platform
.Pcds
:
1178 PlatformPcd
= self
.Platform
.Pcds
[key
]
1179 for PcdItem
in GlobalData
.BuildOptionPcd
:
1180 if (PlatformPcd
.TokenSpaceGuidCName
, PlatformPcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1181 PlatformPcd
.DefaultValue
= PcdItem
[2]
1182 if PlatformPcd
.SkuInfoList
:
1183 Sku
= PlatformPcd
.SkuInfoList
[PlatformPcd
.SkuInfoList
.keys()[0]]
1184 Sku
.DefaultValue
= PcdItem
[2]
1187 for key
in self
.Platform
.Pcds
:
1188 for SinglePcd
in GlobalData
.MixedPcd
:
1189 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1190 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1191 Pcd_Type
= item
[0].split('_')[-1]
1192 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 \
1193 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
1194 Value
= self
.Platform
.Pcds
[key
]
1195 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1197 newkey
= (Value
.TokenCName
, key
[1])
1199 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1200 del self
.Platform
.Pcds
[key
]
1201 self
.Platform
.Pcds
[newkey
] = Value
1209 # for gathering error information
1210 NoDatumTypePcdList
= set()
1212 self
._GuidValue
= {}
1214 for InfName
in self
._AsBuildInfList
:
1215 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1216 FdfModuleList
.append(os
.path
.normpath(InfName
))
1217 for F
in self
.Platform
.Modules
.keys():
1218 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1219 #GuidValue.update(M.Guids)
1221 self
.Platform
.Modules
[F
].M
= M
1223 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1224 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1225 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1226 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1228 # Check the PCD from Binary INF or Source INF
1229 if M
.IsBinaryModule
== True:
1230 PcdFromModule
.IsFromBinaryInf
= True
1232 # Check the PCD from DSC or not
1233 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1234 PcdFromModule
.IsFromDsc
= True
1236 PcdFromModule
.IsFromDsc
= False
1237 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1238 if F
.Path
not in FdfModuleList
:
1239 # If one of the Source built modules listed in the DSC is not listed
1240 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1241 # access method (it is only listed in the DEC file that declares the
1242 # PCD as PcdsDynamic), then build tool will report warning message
1243 # notify the PI that they are attempting to build a module that must
1244 # be included in a flash image in order to be functional. These Dynamic
1245 # PCD will not be added into the Database unless it is used by other
1246 # modules that are included in the FDF file.
1247 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1248 PcdFromModule
.IsFromBinaryInf
== False:
1249 # Print warning message to let the developer make a determine.
1250 if PcdFromModule
not in PcdNotInDb
:
1251 PcdNotInDb
.append(PcdFromModule
)
1253 # If one of the Source built modules listed in the DSC is not listed in
1254 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1255 # access method (it is only listed in the DEC file that declares the
1256 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1257 # PCD to the Platform's PCD Database.
1258 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1259 if PcdFromModule
not in PcdNotInDb
:
1260 PcdNotInDb
.append(PcdFromModule
)
1263 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1264 # it should be stored in Pcd PEI database, If a dynamic only
1265 # used by DXE module, it should be stored in DXE PCD database.
1266 # The default Phase is DXE
1268 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1269 PcdFromModule
.Phase
= "PEI"
1270 if PcdFromModule
not in self
._DynaPcdList
_:
1271 self
._DynaPcdList
_.append(PcdFromModule
)
1272 elif PcdFromModule
.Phase
== 'PEI':
1273 # overwrite any the same PCD existing, if Phase is PEI
1274 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1275 self
._DynaPcdList
_[Index
] = PcdFromModule
1276 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1277 self
._NonDynaPcdList
_.append(PcdFromModule
)
1278 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1279 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1280 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1281 #The PCD from Binary INF will override the same one from source INF
1282 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1283 PcdFromModule
.Pending
= False
1284 self
._NonDynaPcdList
_.append (PcdFromModule
)
1285 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1287 for ModuleInf
in self
.Platform
.Modules
.keys():
1288 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1289 # add the PCD from modules that listed in FDF but not in DSC to Database
1290 for InfName
in FdfModuleList
:
1291 if InfName
not in DscModuleList
:
1292 InfClass
= PathClass(InfName
)
1293 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1294 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1295 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1296 # For binary module, if in current arch, we need to list the PCDs into database.
1297 if not M
.IsSupportedArch
:
1299 # Override the module PCD setting by platform setting
1300 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1301 for PcdFromModule
in ModulePcdList
:
1302 PcdFromModule
.IsFromBinaryInf
= True
1303 PcdFromModule
.IsFromDsc
= False
1304 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1305 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1306 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1308 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1309 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1310 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1311 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1312 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1313 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1314 PcdFromModule
.Phase
= "PEI"
1315 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1316 self
._DynaPcdList
_.append(PcdFromModule
)
1317 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1318 self
._NonDynaPcdList
_.append(PcdFromModule
)
1319 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1320 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1321 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1322 # module & DXE module at a same time.
1323 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1324 # INF file as DynamicEx.
1325 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1326 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1327 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1328 for PcdFromModule
in self
._NonDynaPcdList
_:
1329 # If a PCD is not listed in the DSC file, but binary INF files used by
1330 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1331 # section, AND all source INF files used by this platform the build
1332 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1333 # section, then the tools must NOT add the PCD to the Platform's PCD
1334 # Database; the build must assign the access method for this PCD as
1335 # PcdsPatchableInModule.
1336 if PcdFromModule
not in self
._DynaPcdList
_:
1338 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1339 if PcdFromModule
.IsFromDsc
== False and \
1340 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1341 PcdFromModule
.IsFromBinaryInf
== True and \
1342 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1343 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1344 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1346 # print out error information and break the build, if error found
1347 if len(NoDatumTypePcdList
) > 0:
1348 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1349 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1351 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1352 % NoDatumTypePcdListString
)
1353 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1354 self
._DynamicPcdList
= self
._DynaPcdList
_
1356 # Sort dynamic PCD list to:
1357 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1358 # try to be put header of dynamicd List
1359 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1361 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1363 UnicodePcdArray
= []
1367 VpdFile
= VpdInfoFile
.VpdInfoFile()
1368 NeedProcessVpdMapFile
= False
1370 for pcd
in self
.Platform
.Pcds
.keys():
1371 if pcd
not in self
._PlatformPcds
.keys():
1372 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1374 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1375 for Pcd
in self
._DynamicPcdList
:
1376 # just pick the a value to determine whether is unicode string type
1377 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1378 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1380 PcdValue
= Sku
.DefaultValue
1381 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1382 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1383 UnicodePcdArray
.append(Pcd
)
1384 elif len(Sku
.VariableName
) > 0:
1385 # if found HII type PCD then insert to right of UnicodeIndex
1386 HiiPcdArray
.append(Pcd
)
1388 OtherPcdArray
.append(Pcd
)
1389 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1390 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1392 PlatformPcds
= self
._PlatformPcds
.keys()
1395 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1397 for PcdKey
in PlatformPcds
:
1398 Pcd
= self
._PlatformPcds
[PcdKey
]
1399 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1400 PcdKey
in VpdPcdDict
:
1401 Pcd
= VpdPcdDict
[PcdKey
]
1402 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1403 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1404 PcdValue
= Sku
.DefaultValue
1406 PcdValue
= Pcd
.DefaultValue
1407 if Sku
.VpdOffset
!= '*':
1408 if PcdValue
.startswith("{"):
1410 elif PcdValue
.startswith("L"):
1415 VpdOffset
= int(Sku
.VpdOffset
)
1418 VpdOffset
= int(Sku
.VpdOffset
, 16)
1420 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1421 if VpdOffset
% Alignment
!= 0:
1422 if PcdValue
.startswith("{"):
1423 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1425 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1426 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1427 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1428 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1429 NeedProcessVpdMapFile
= True
1430 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1431 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1432 "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.")
1436 # Fix the PCDs define in VPD PCD section that never referenced by module.
1437 # An example is PCD for signature usage.
1439 for DscPcd
in PlatformPcds
:
1440 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1441 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1442 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1444 for VpdPcd
in VpdFile
._VpdArray
.keys():
1445 # This PCD has been referenced by module
1446 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1447 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1450 # Not found, it should be signature
1452 # just pick the a value to determine whether is unicode string type
1453 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1454 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1456 # Need to iterate DEC pcd information to get the value & datumtype
1457 for eachDec
in self
.PackageList
:
1458 for DecPcd
in eachDec
.Pcds
:
1459 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1460 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1461 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1462 # Print warning message to let the developer make a determine.
1463 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1464 File
=self
.MetaFile
, \
1465 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1466 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1468 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1469 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1470 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1471 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1472 # Only fix the value while no value provided in DSC file.
1473 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1474 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1476 if DscPcdEntry
not in self
._DynamicPcdList
:
1477 self
._DynamicPcdList
.append(DscPcdEntry
)
1478 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1479 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1480 PcdValue
= Sku
.DefaultValue
1482 PcdValue
= DscPcdEntry
.DefaultValue
1483 if Sku
.VpdOffset
!= '*':
1484 if PcdValue
.startswith("{"):
1486 elif PcdValue
.startswith("L"):
1491 VpdOffset
= int(Sku
.VpdOffset
)
1494 VpdOffset
= int(Sku
.VpdOffset
, 16)
1496 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1497 if VpdOffset
% Alignment
!= 0:
1498 if PcdValue
.startswith("{"):
1499 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1501 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1502 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1503 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1504 NeedProcessVpdMapFile
= True
1505 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1506 UnicodePcdArray
.append(DscPcdEntry
)
1507 elif len(Sku
.VariableName
) > 0:
1508 HiiPcdArray
.append(DscPcdEntry
)
1510 OtherPcdArray
.append(DscPcdEntry
)
1512 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1516 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1517 VpdFile
.GetCount() != 0:
1518 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1519 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1521 if VpdFile
.GetCount() != 0:
1522 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1523 if not os
.path
.exists(FvPath
):
1527 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1529 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1531 if VpdFile
.Write(VpdFilePath
):
1532 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1534 for ToolDef
in self
.ToolDefinition
.values():
1535 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1536 if not ToolDef
.has_key("PATH"):
1537 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1538 BPDGToolName
= ToolDef
["PATH"]
1540 # Call third party GUID BPDG tool.
1541 if BPDGToolName
!= None:
1542 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1544 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.")
1546 # Process VPD map file generated by third party BPDG tool
1547 if NeedProcessVpdMapFile
:
1548 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1549 if os
.path
.exists(VpdMapFilePath
):
1550 VpdFile
.Read(VpdMapFilePath
)
1553 for Pcd
in self
._DynamicPcdList
:
1554 # just pick the a value to determine whether is unicode string type
1556 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1557 if Sku
.VpdOffset
== "*":
1558 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1561 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1563 # Delete the DynamicPcdList At the last time enter into this function
1564 del self
._DynamicPcdList
[:]
1565 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1566 self
._DynamicPcdList
.extend(HiiPcdArray
)
1567 self
._DynamicPcdList
.extend(OtherPcdArray
)
1568 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1570 ## Return the platform build data object
1571 def _GetPlatform(self
):
1572 if self
._Platform
== None:
1573 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1574 return self
._Platform
1576 ## Return platform name
1578 return self
.Platform
.PlatformName
1580 ## Return the meta file GUID
1582 return self
.Platform
.Guid
1584 ## Return the platform version
1585 def _GetVersion(self
):
1586 return self
.Platform
.Version
1588 ## Return the FDF file name
1589 def _GetFdfFile(self
):
1590 if self
._FdfFile
== None:
1591 if self
.Workspace
.FdfFile
!= "":
1592 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1595 return self
._FdfFile
1597 ## Return the build output directory platform specifies
1598 def _GetOutputDir(self
):
1599 return self
.Platform
.OutputDirectory
1601 ## Return the directory to store all intermediate and final files built
1602 def _GetBuildDir(self
):
1603 if self
._BuildDir
== None:
1604 if os
.path
.isabs(self
.OutputDir
):
1605 self
._BuildDir
= path
.join(
1606 path
.abspath(self
.OutputDir
),
1607 self
.BuildTarget
+ "_" + self
.ToolChain
,
1610 self
._BuildDir
= path
.join(
1613 self
.BuildTarget
+ "_" + self
.ToolChain
,
1615 return self
._BuildDir
1617 ## Return directory of platform makefile
1619 # @retval string Makefile directory
1621 def _GetMakeFileDir(self
):
1622 if self
._MakeFileDir
== None:
1623 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1624 return self
._MakeFileDir
1626 ## Return build command string
1628 # @retval string Build command string
1630 def _GetBuildCommand(self
):
1631 if self
._BuildCommand
== None:
1632 self
._BuildCommand
= []
1633 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1634 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1635 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1636 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1638 self
._BuildCommand
+= SplitOption(NewOption
)
1639 return self
._BuildCommand
1641 ## Get tool chain definition
1643 # Get each tool defition for given tool chain from tools_def.txt and platform
1645 def _GetToolDefinition(self
):
1646 if self
._ToolDefinitions
== None:
1647 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1648 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1649 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1650 ExtraData
="[%s]" % self
.MetaFile
)
1651 self
._ToolDefinitions
= {}
1653 for Def
in ToolDefinition
:
1654 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1655 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1658 Value
= ToolDefinition
[Def
]
1659 # don't record the DLL
1661 DllPathList
.add(Value
)
1664 if Tool
not in self
._ToolDefinitions
:
1665 self
._ToolDefinitions
[Tool
] = {}
1666 self
._ToolDefinitions
[Tool
][Attr
] = Value
1670 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1671 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1672 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1673 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1675 for Tool
in self
._ToolDefinitions
:
1676 for Attr
in self
._ToolDefinitions
[Tool
]:
1677 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1678 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1679 # check if override is indicated
1680 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1681 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1683 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1686 # Don't put MAKE definition in the file
1690 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1692 # Don't put MAKE definition in the file
1697 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1700 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1701 for DllPath
in DllPathList
:
1702 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1703 os
.environ
["MAKE_FLAGS"] = MakeFlags
1705 return self
._ToolDefinitions
1707 ## Return the paths of tools
1708 def _GetToolDefFile(self
):
1709 if self
._ToolDefFile
== None:
1710 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1711 return self
._ToolDefFile
1713 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1714 def _GetToolChainFamily(self
):
1715 if self
._ToolChainFamily
== None:
1716 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1717 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1718 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1719 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1720 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1722 self
._ToolChainFamily
= "MSFT"
1724 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1725 return self
._ToolChainFamily
1727 def _GetBuildRuleFamily(self
):
1728 if self
._BuildRuleFamily
== None:
1729 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1730 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1731 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1732 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1733 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1735 self
._BuildRuleFamily
= "MSFT"
1737 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1738 return self
._BuildRuleFamily
1740 ## Return the build options specific for all modules in this platform
1741 def _GetBuildOptions(self
):
1742 if self
._BuildOption
== None:
1743 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1744 return self
._BuildOption
1746 ## Return the build options specific for EDK modules in this platform
1747 def _GetEdkBuildOptions(self
):
1748 if self
._EdkBuildOption
== None:
1749 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1750 return self
._EdkBuildOption
1752 ## Return the build options specific for EDKII modules in this platform
1753 def _GetEdkIIBuildOptions(self
):
1754 if self
._EdkIIBuildOption
== None:
1755 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1756 return self
._EdkIIBuildOption
1758 ## Parse build_rule.txt in Conf Directory.
1760 # @retval BuildRule object
1762 def _GetBuildRule(self
):
1763 if self
._BuildRule
== None:
1764 BuildRuleFile
= None
1765 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1766 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1767 if BuildRuleFile
in [None, '']:
1768 BuildRuleFile
= gDefaultBuildRuleFile
1769 self
._BuildRule
= BuildRule(BuildRuleFile
)
1770 if self
._BuildRule
._FileVersion
== "":
1771 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1773 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1774 # If Build Rule's version is less than the version number required by the tools, halting the build.
1775 EdkLogger
.error("build", AUTOGEN_ERROR
,
1776 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])"\
1777 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1779 return self
._BuildRule
1781 ## Summarize the packages used by modules in this platform
1782 def _GetPackageList(self
):
1783 if self
._PackageList
== None:
1784 self
._PackageList
= set()
1785 for La
in self
.LibraryAutoGenList
:
1786 self
._PackageList
.update(La
.DependentPackageList
)
1787 for Ma
in self
.ModuleAutoGenList
:
1788 self
._PackageList
.update(Ma
.DependentPackageList
)
1789 #Collect package set information from INF of FDF
1791 for ModuleFile
in self
._AsBuildModuleList
:
1792 if ModuleFile
in self
.Platform
.Modules
:
1794 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1795 PkgSet
.update(ModuleData
.Packages
)
1796 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1797 return self
._PackageList
1799 def _GetNonDynamicPcdDict(self
):
1800 if self
._NonDynamicPcdDict
:
1801 return self
._NonDynamicPcdDict
1802 for Pcd
in self
.NonDynamicPcdList
:
1803 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1804 return self
._NonDynamicPcdDict
1806 ## Get list of non-dynamic PCDs
1807 def _GetNonDynamicPcdList(self
):
1808 if self
._NonDynamicPcdList
== None:
1809 self
.CollectPlatformDynamicPcds()
1810 return self
._NonDynamicPcdList
1812 ## Get list of dynamic PCDs
1813 def _GetDynamicPcdList(self
):
1814 if self
._DynamicPcdList
== None:
1815 self
.CollectPlatformDynamicPcds()
1816 return self
._DynamicPcdList
1818 ## Generate Token Number for all PCD
1819 def _GetPcdTokenNumbers(self
):
1820 if self
._PcdTokenNumber
== None:
1821 self
._PcdTokenNumber
= sdict()
1824 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1828 # TokenNumber 0 ~ 10
1830 # TokeNumber 11 ~ 20
1832 for Pcd
in self
.DynamicPcdList
:
1833 if Pcd
.Phase
== "PEI":
1834 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1835 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1836 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1839 for Pcd
in self
.DynamicPcdList
:
1840 if Pcd
.Phase
== "PEI":
1841 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1842 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1843 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1846 for Pcd
in self
.DynamicPcdList
:
1847 if Pcd
.Phase
== "DXE":
1848 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1849 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1850 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1853 for Pcd
in self
.DynamicPcdList
:
1854 if Pcd
.Phase
== "DXE":
1855 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1856 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1857 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1860 for Pcd
in self
.NonDynamicPcdList
:
1861 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1863 return self
._PcdTokenNumber
1865 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1866 def _GetAutoGenObjectList(self
):
1867 self
._ModuleAutoGenList
= []
1868 self
._LibraryAutoGenList
= []
1869 for ModuleFile
in self
.Platform
.Modules
:
1878 if Ma
not in self
._ModuleAutoGenList
:
1879 self
._ModuleAutoGenList
.append(Ma
)
1880 for La
in Ma
.LibraryAutoGenList
:
1881 if La
not in self
._LibraryAutoGenList
:
1882 self
._LibraryAutoGenList
.append(La
)
1883 if Ma
not in La
._ReferenceModules
:
1884 La
._ReferenceModules
.append(Ma
)
1886 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
1887 def _GetModuleAutoGenList(self
):
1888 if self
._ModuleAutoGenList
== None:
1889 self
._GetAutoGenObjectList
()
1890 return self
._ModuleAutoGenList
1892 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
1893 def _GetLibraryAutoGenList(self
):
1894 if self
._LibraryAutoGenList
== None:
1895 self
._GetAutoGenObjectList
()
1896 return self
._LibraryAutoGenList
1898 ## Test if a module is supported by the platform
1900 # An error will be raised directly if the module or its arch is not supported
1901 # by the platform or current configuration
1903 def ValidModule(self
, Module
):
1904 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
1905 or Module
in self
._AsBuildModuleList
1907 ## Resolve the library classes in a module to library instances
1909 # This method will not only resolve library classes but also sort the library
1910 # instances according to the dependency-ship.
1912 # @param Module The module from which the library classes will be resolved
1914 # @retval library_list List of library instances sorted
1916 def ApplyLibraryInstance(self
, Module
):
1917 ModuleType
= Module
.ModuleType
1919 # for overridding library instances with module specific setting
1920 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1922 # add forced library instances (specified under LibraryClasses sections)
1924 # If a module has a MODULE_TYPE of USER_DEFINED,
1925 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
1927 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
1928 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
1929 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
1930 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
1932 # add forced library instances (specified in module overrides)
1933 for LibraryClass
in PlatformModule
.LibraryClasses
:
1934 if LibraryClass
.startswith("NULL"):
1935 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
1938 LibraryConsumerList
= [Module
]
1940 ConsumedByList
= sdict()
1941 LibraryInstance
= sdict()
1943 EdkLogger
.verbose("")
1944 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
1945 while len(LibraryConsumerList
) > 0:
1946 M
= LibraryConsumerList
.pop()
1947 for LibraryClassName
in M
.LibraryClasses
:
1948 if LibraryClassName
not in LibraryInstance
:
1949 # override library instance for this module
1950 if LibraryClassName
in PlatformModule
.LibraryClasses
:
1951 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
1953 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
1954 if LibraryPath
== None or LibraryPath
== "":
1955 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
1956 if LibraryPath
== None or LibraryPath
== "":
1957 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
1958 "Instance of library class [%s] is not found" % LibraryClassName
,
1960 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
1962 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1963 # for those forced library instance (NULL library), add a fake library class
1964 if LibraryClassName
.startswith("NULL"):
1965 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
1966 elif LibraryModule
.LibraryClass
== None \
1967 or len(LibraryModule
.LibraryClass
) == 0 \
1968 or (ModuleType
!= 'USER_DEFINED'
1969 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
1970 # only USER_DEFINED can link against any library instance despite of its SupModList
1971 EdkLogger
.error("build", OPTION_MISSING
,
1972 "Module type [%s] is not supported by library instance [%s]" \
1973 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
1974 ExtraData
="consumed by [%s]" % str(Module
))
1976 LibraryInstance
[LibraryClassName
] = LibraryModule
1977 LibraryConsumerList
.append(LibraryModule
)
1978 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
1980 LibraryModule
= LibraryInstance
[LibraryClassName
]
1982 if LibraryModule
== None:
1985 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
1986 Constructor
.append(LibraryModule
)
1988 if LibraryModule
not in ConsumedByList
:
1989 ConsumedByList
[LibraryModule
] = []
1990 # don't add current module itself to consumer list
1992 if M
in ConsumedByList
[LibraryModule
]:
1994 ConsumedByList
[LibraryModule
].append(M
)
1996 # Initialize the sorted output list to the empty set
1998 SortedLibraryList
= []
2000 # Q <- Set of all nodes with no incoming edges
2002 LibraryList
= [] #LibraryInstance.values()
2004 for LibraryClassName
in LibraryInstance
:
2005 M
= LibraryInstance
[LibraryClassName
]
2006 LibraryList
.append(M
)
2007 if ConsumedByList
[M
] == []:
2011 # start the DAG algorithm
2015 while Q
== [] and EdgeRemoved
:
2017 # for each node Item with a Constructor
2018 for Item
in LibraryList
:
2019 if Item
not in Constructor
:
2021 # for each Node without a constructor with an edge e from Item to Node
2022 for Node
in ConsumedByList
[Item
]:
2023 if Node
in Constructor
:
2025 # remove edge e from the graph if Node has no constructor
2026 ConsumedByList
[Item
].remove(Node
)
2028 if ConsumedByList
[Item
] == []:
2029 # insert Item into Q
2034 # DAG is done if there's no more incoming edge for all nodes
2038 # remove node from Q
2041 SortedLibraryList
.append(Node
)
2043 # for each node Item with an edge e from Node to Item do
2044 for Item
in LibraryList
:
2045 if Node
not in ConsumedByList
[Item
]:
2047 # remove edge e from the graph
2048 ConsumedByList
[Item
].remove(Node
)
2050 if ConsumedByList
[Item
] != []:
2052 # insert Item into Q, if Item has no other incoming edges
2056 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
2058 for Item
in LibraryList
:
2059 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
2060 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
2061 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
2062 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
2063 if Item
not in SortedLibraryList
:
2064 SortedLibraryList
.append(Item
)
2067 # Build the list of constructor and destructir names
2068 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
2070 SortedLibraryList
.reverse()
2071 return SortedLibraryList
2074 ## Override PCD setting (type, value, ...)
2076 # @param ToPcd The PCD to be overrided
2077 # @param FromPcd The PCD overrideing from
2079 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
2081 # in case there's PCDs coming from FDF file, which have no type given.
2082 # at this point, ToPcd.Type has the type found from dependent
2085 TokenCName
= ToPcd
.TokenCName
2086 for PcdItem
in GlobalData
.MixedPcd
:
2087 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2088 TokenCName
= PcdItem
[0]
2091 if GlobalData
.BuildOptionPcd
:
2092 for pcd
in GlobalData
.BuildOptionPcd
:
2093 if (FromPcd
.TokenSpaceGuidCName
, FromPcd
.TokenCName
) == (pcd
[0], pcd
[1]):
2094 FromPcd
.DefaultValue
= pcd
[2]
2096 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
2097 ToPcd
.Type
= FromPcd
.Type
2098 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
2099 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
2100 if ToPcd
.Type
.strip() == "DynamicEx":
2101 ToPcd
.Type
= FromPcd
.Type
2102 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
2103 and ToPcd
.Type
!= FromPcd
.Type
:
2104 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2105 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
2106 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2107 ToPcd
.Type
, Module
, FromPcd
.Type
),
2110 if FromPcd
.MaxDatumSize
not in [None, '']:
2111 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2112 if FromPcd
.DefaultValue
not in [None, '']:
2113 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2114 if FromPcd
.TokenValue
not in [None, '']:
2115 ToPcd
.TokenValue
= FromPcd
.TokenValue
2116 if FromPcd
.MaxDatumSize
not in [None, '']:
2117 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2118 if FromPcd
.DatumType
not in [None, '']:
2119 ToPcd
.DatumType
= FromPcd
.DatumType
2120 if FromPcd
.SkuInfoList
not in [None, '', []]:
2121 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2123 # check the validation of datum
2124 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2126 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2127 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2128 ToPcd
.validateranges
= FromPcd
.validateranges
2129 ToPcd
.validlists
= FromPcd
.validlists
2130 ToPcd
.expressions
= FromPcd
.expressions
2132 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
2133 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2134 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2135 Value
= ToPcd
.DefaultValue
2136 if Value
in [None, '']:
2137 ToPcd
.MaxDatumSize
= '1'
2138 elif Value
[0] == 'L':
2139 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2140 elif Value
[0] == '{':
2141 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2143 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2145 # apply default SKU for dynamic PCDS if specified one is not available
2146 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
2147 and ToPcd
.SkuInfoList
in [None, {}, '']:
2148 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2149 SkuName
= self
.Platform
.SkuName
2152 ToPcd
.SkuInfoList
= {
2153 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
2156 ## Apply PCD setting defined platform to a module
2158 # @param Module The module from which the PCD setting will be overrided
2160 # @retval PCD_list The list PCDs with settings from platform
2162 def ApplyPcdSetting(self
, Module
, Pcds
):
2163 # for each PCD in module
2164 for Name
, Guid
in Pcds
:
2165 PcdInModule
= Pcds
[Name
, Guid
]
2166 # find out the PCD setting in platform
2167 if (Name
, Guid
) in self
.Platform
.Pcds
:
2168 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2170 PcdInPlatform
= None
2171 # then override the settings if any
2172 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2173 # resolve the VariableGuid value
2174 for SkuId
in PcdInModule
.SkuInfoList
:
2175 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2176 if Sku
.VariableGuid
== '': continue
2177 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
)
2178 if Sku
.VariableGuidValue
== None:
2179 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2182 RESOURCE_NOT_AVAILABLE
,
2183 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2184 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2185 % (Guid
, Name
, str(Module
)),
2189 # override PCD settings with module specific setting
2190 if Module
in self
.Platform
.Modules
:
2191 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2192 for Key
in PlatformModule
.Pcds
:
2194 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
2195 return Pcds
.values()
2197 ## Resolve library names to library modules
2199 # (for Edk.x modules)
2201 # @param Module The module from which the library names will be resolved
2203 # @retval library_list The list of library modules
2205 def ResolveLibraryReference(self
, Module
):
2206 EdkLogger
.verbose("")
2207 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2208 LibraryConsumerList
= [Module
]
2210 # "CompilerStub" is a must for Edk modules
2211 if Module
.Libraries
:
2212 Module
.Libraries
.append("CompilerStub")
2214 while len(LibraryConsumerList
) > 0:
2215 M
= LibraryConsumerList
.pop()
2216 for LibraryName
in M
.Libraries
:
2217 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2219 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2220 if LibraryName
.upper() == Key
.upper():
2221 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2224 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2225 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2228 if Library
not in LibraryList
:
2229 LibraryList
.append(Library
)
2230 LibraryConsumerList
.append(Library
)
2231 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2234 ## Calculate the priority value of the build option
2236 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2238 # @retval Value Priority value based on the priority list.
2240 def CalculatePriorityValue(self
, Key
):
2241 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2242 PriorityValue
= 0x11111
2244 PriorityValue
&= 0x01111
2245 if ToolChain
== "*":
2246 PriorityValue
&= 0x10111
2248 PriorityValue
&= 0x11011
2249 if CommandType
== "*":
2250 PriorityValue
&= 0x11101
2252 PriorityValue
&= 0x11110
2254 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2257 ## Expand * in build option key
2259 # @param Options Options to be expanded
2261 # @retval options Options expanded
2263 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2270 # Construct a list contain the build options which need override.
2274 # Key[0] -- tool family
2275 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2277 if (Key
[0] == self
.BuildRuleFamily
and
2278 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2279 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2280 if Target
== self
.BuildTarget
or Target
== "*":
2281 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2282 if Arch
== self
.Arch
or Arch
== "*":
2283 if Options
[Key
].startswith("="):
2284 if OverrideList
.get(Key
[1]) != None:
2285 OverrideList
.pop(Key
[1])
2286 OverrideList
[Key
[1]] = Options
[Key
]
2289 # Use the highest priority value.
2291 if (len(OverrideList
) >= 2):
2292 KeyList
= OverrideList
.keys()
2293 for Index
in range(len(KeyList
)):
2294 NowKey
= KeyList
[Index
]
2295 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2296 for Index1
in range(len(KeyList
) - Index
- 1):
2297 NextKey
= KeyList
[Index1
+ Index
+ 1]
2299 # Compare two Key, if one is included by another, choose the higher priority one
2301 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2302 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2303 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2304 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2305 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2306 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2307 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2308 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2309 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2311 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2312 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2315 if ModuleStyle
!= None and len (Key
) > 2:
2316 # Check Module style is EDK or EDKII.
2317 # Only append build option for the matched style module.
2318 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2320 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2323 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2324 # if tool chain family doesn't match, skip it
2325 if Tool
in self
.ToolDefinition
and Family
!= "":
2326 FamilyIsNull
= False
2327 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2328 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2330 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2333 # expand any wildcard
2334 if Target
== "*" or Target
== self
.BuildTarget
:
2335 if Tag
== "*" or Tag
== self
.ToolChain
:
2336 if Arch
== "*" or Arch
== self
.Arch
:
2337 if Tool
not in BuildOptions
:
2338 BuildOptions
[Tool
] = {}
2339 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2340 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2342 # append options for the same tool
2343 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2344 # Build Option Family has been checked, which need't to be checked again for family.
2345 if FamilyMatch
or FamilyIsNull
:
2349 if ModuleStyle
!= None and len (Key
) > 2:
2350 # Check Module style is EDK or EDKII.
2351 # Only append build option for the matched style module.
2352 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2354 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2357 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2358 # if tool chain family doesn't match, skip it
2359 if Tool
not in self
.ToolDefinition
or Family
== "":
2361 # option has been added before
2362 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2365 # expand any wildcard
2366 if Target
== "*" or Target
== self
.BuildTarget
:
2367 if Tag
== "*" or Tag
== self
.ToolChain
:
2368 if Arch
== "*" or Arch
== self
.Arch
:
2369 if Tool
not in BuildOptions
:
2370 BuildOptions
[Tool
] = {}
2371 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2372 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2374 # append options for the same tool
2375 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2378 ## Append build options in platform to a module
2380 # @param Module The module to which the build options will be appened
2382 # @retval options The options appended with build options in platform
2384 def ApplyBuildOption(self
, Module
):
2385 # Get the different options for the different style module
2386 if Module
.AutoGenVersion
< 0x00010005:
2387 PlatformOptions
= self
.EdkBuildOption
2388 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2390 PlatformOptions
= self
.EdkIIBuildOption
2391 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2392 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2393 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2394 if Module
in self
.Platform
.Modules
:
2395 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2396 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2398 PlatformModuleOptions
= {}
2400 BuildRuleOrder
= None
2401 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2402 for Tool
in Options
:
2403 for Attr
in Options
[Tool
]:
2404 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2405 BuildRuleOrder
= Options
[Tool
][Attr
]
2407 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2408 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2409 self
.ToolDefinition
.keys())
2411 for Tool
in AllTools
:
2412 if Tool
not in BuildOptions
:
2413 BuildOptions
[Tool
] = {}
2415 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2416 if Tool
not in Options
:
2418 for Attr
in Options
[Tool
]:
2419 Value
= Options
[Tool
][Attr
]
2421 # Do not generate it in Makefile
2423 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2425 if Attr
not in BuildOptions
[Tool
]:
2426 BuildOptions
[Tool
][Attr
] = ""
2427 # check if override is indicated
2428 if Value
.startswith('='):
2429 ToolPath
= Value
[1:]
2430 ToolPath
= mws
.handleWsMacro(ToolPath
)
2431 BuildOptions
[Tool
][Attr
] = ToolPath
2433 Value
= mws
.handleWsMacro(Value
)
2434 BuildOptions
[Tool
][Attr
] += " " + Value
2435 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2437 # Override UNI flag only for EDK module.
2439 if 'BUILD' not in BuildOptions
:
2440 BuildOptions
['BUILD'] = {}
2441 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2442 return BuildOptions
, BuildRuleOrder
2444 Platform
= property(_GetPlatform
)
2445 Name
= property(_GetName
)
2446 Guid
= property(_GetGuid
)
2447 Version
= property(_GetVersion
)
2449 OutputDir
= property(_GetOutputDir
)
2450 BuildDir
= property(_GetBuildDir
)
2451 MakeFileDir
= property(_GetMakeFileDir
)
2452 FdfFile
= property(_GetFdfFile
)
2454 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2455 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2456 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2457 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2458 PackageList
= property(_GetPackageList
)
2460 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2461 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2462 ToolChainFamily
= property(_GetToolChainFamily
)
2463 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2464 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2465 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2466 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2468 BuildCommand
= property(_GetBuildCommand
)
2469 BuildRule
= property(_GetBuildRule
)
2470 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2471 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2472 GenFdsCommand
= property(_GenFdsCommand
)
2474 ## ModuleAutoGen class
2476 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2477 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2478 # to the [depex] section in module's inf file.
2480 class ModuleAutoGen(AutoGen
):
2481 ## The real constructor of ModuleAutoGen
2483 # This method is not supposed to be called by users of ModuleAutoGen. It's
2484 # only used by factory method __new__() to do real initialization work for an
2485 # object of ModuleAutoGen
2487 # @param Workspace EdkIIWorkspaceBuild object
2488 # @param ModuleFile The path of module file
2489 # @param Target Build target (DEBUG, RELEASE)
2490 # @param Toolchain Name of tool chain
2491 # @param Arch The arch the module supports
2492 # @param PlatformFile Platform meta-file
2494 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2495 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2496 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2498 self
.Workspace
= Workspace
2499 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2501 self
.MetaFile
= ModuleFile
2502 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2503 # check if this module is employed by active platform
2504 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2505 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2506 % (self
.MetaFile
, Arch
))
2509 self
.SourceDir
= self
.MetaFile
.SubDir
2510 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2512 self
.SourceOverrideDir
= None
2513 # use overrided path defined in DSC file
2514 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2515 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2517 self
.ToolChain
= Toolchain
2518 self
.BuildTarget
= Target
2520 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2521 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2523 self
.IsMakeFileCreated
= False
2524 self
.IsCodeFileCreated
= False
2525 self
.IsAsBuiltInfCreated
= False
2526 self
.DepexGenerated
= False
2528 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2529 self
.BuildRuleOrder
= None
2534 self
._Version
= None
2535 self
._ModuleType
= None
2536 self
._ComponentType
= None
2537 self
._PcdIsDriver
= None
2538 self
._AutoGenVersion
= None
2539 self
._LibraryFlag
= None
2540 self
._CustomMakefile
= None
2543 self
._BuildDir
= None
2544 self
._OutputDir
= None
2545 self
._DebugDir
= None
2546 self
._MakeFileDir
= None
2548 self
._IncludePathList
= None
2549 self
._IncludePathLength
= 0
2550 self
._AutoGenFileList
= None
2551 self
._UnicodeFileList
= None
2552 self
._SourceFileList
= None
2553 self
._ObjectFileList
= None
2554 self
._BinaryFileList
= None
2556 self
._DependentPackageList
= None
2557 self
._DependentLibraryList
= None
2558 self
._LibraryAutoGenList
= None
2559 self
._DerivedPackageList
= None
2560 self
._ModulePcdList
= None
2561 self
._LibraryPcdList
= None
2562 self
._PcdComments
= sdict()
2563 self
._GuidList
= None
2564 self
._GuidsUsedByPcd
= None
2565 self
._GuidComments
= sdict()
2566 self
._ProtocolList
= None
2567 self
._ProtocolComments
= sdict()
2568 self
._PpiList
= None
2569 self
._PpiComments
= sdict()
2570 self
._DepexList
= None
2571 self
._DepexExpressionList
= None
2572 self
._BuildOption
= None
2573 self
._BuildOptionIncPathList
= None
2574 self
._BuildTargets
= None
2575 self
._IntroBuildTargetList
= None
2576 self
._FinalBuildTargetList
= None
2577 self
._FileTypes
= None
2578 self
._BuildRules
= None
2580 ## The Modules referenced to this Library
2581 # Only Library has this attribute
2582 self
._ReferenceModules
= []
2584 ## Store the FixedAtBuild Pcds
2586 self
._FixedAtBuildPcds
= []
2591 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2593 # Get FixedAtBuild Pcds of this Module
2594 def _GetFixedAtBuildPcds(self
):
2595 if self
._FixedAtBuildPcds
:
2596 return self
._FixedAtBuildPcds
2597 for Pcd
in self
.ModulePcdList
:
2599 if not (Pcd
.Pending
== False and Pcd
.Type
== "FixedAtBuild"):
2601 elif Pcd
.Type
!= "FixedAtBuild":
2603 if Pcd
not in self
._FixedAtBuildPcds
:
2604 self
._FixedAtBuildPcds
.append(Pcd
)
2606 return self
._FixedAtBuildPcds
2608 def _GetUniqueBaseName(self
):
2609 BaseName
= self
.Name
2610 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2611 if Module
.MetaFile
== self
.MetaFile
:
2613 if Module
.Name
== self
.Name
:
2614 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2615 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2616 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2617 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2620 # Macros could be used in build_rule.txt (also Makefile)
2621 def _GetMacros(self
):
2622 if self
._Macro
== None:
2623 self
._Macro
= sdict()
2624 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2625 self
._Macro
["MODULE_NAME" ] = self
.Name
2626 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2627 self
._Macro
["MODULE_GUID" ] = self
.Guid
2628 self
._Macro
["MODULE_VERSION" ] = self
.Version
2629 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2630 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2631 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2632 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2633 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2635 self
._Macro
["BASE_NAME" ] = self
.Name
2637 self
._Macro
["ARCH" ] = self
.Arch
2638 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2639 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2640 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2641 self
._Macro
["TARGET" ] = self
.BuildTarget
2643 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2644 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2645 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2646 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2647 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2648 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2649 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2650 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2651 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2652 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2653 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2654 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2655 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2656 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2659 ## Return the module build data object
2660 def _GetModule(self
):
2661 if self
._Module
== None:
2662 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2665 ## Return the module name
2666 def _GetBaseName(self
):
2667 return self
.Module
.BaseName
2669 ## Return the module DxsFile if exist
2670 def _GetDxsFile(self
):
2671 return self
.Module
.DxsFile
2673 ## Return the module SourceOverridePath
2674 def _GetSourceOverridePath(self
):
2675 return self
.Module
.SourceOverridePath
2677 ## Return the module meta-file GUID
2680 # To build same module more than once, the module path with FILE_GUID overridden has
2681 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2682 # in DSC. The overridden GUID can be retrieved from file name
2684 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2686 # Length of GUID is 36
2688 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2689 return self
.Module
.Guid
2691 ## Return the module version
2692 def _GetVersion(self
):
2693 return self
.Module
.Version
2695 ## Return the module type
2696 def _GetModuleType(self
):
2697 return self
.Module
.ModuleType
2699 ## Return the component type (for Edk.x style of module)
2700 def _GetComponentType(self
):
2701 return self
.Module
.ComponentType
2703 ## Return the build type
2704 def _GetBuildType(self
):
2705 return self
.Module
.BuildType
2707 ## Return the PCD_IS_DRIVER setting
2708 def _GetPcdIsDriver(self
):
2709 return self
.Module
.PcdIsDriver
2711 ## Return the autogen version, i.e. module meta-file version
2712 def _GetAutoGenVersion(self
):
2713 return self
.Module
.AutoGenVersion
2715 ## Check if the module is library or not
2716 def _IsLibrary(self
):
2717 if self
._LibraryFlag
== None:
2718 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2719 self
._LibraryFlag
= True
2721 self
._LibraryFlag
= False
2722 return self
._LibraryFlag
2724 ## Check if the module is binary module or not
2725 def _IsBinaryModule(self
):
2726 return self
.Module
.IsBinaryModule
2728 ## Return the directory to store intermediate files of the module
2729 def _GetBuildDir(self
):
2730 if self
._BuildDir
== None:
2731 self
._BuildDir
= path
.join(
2732 self
.PlatformInfo
.BuildDir
,
2735 self
.MetaFile
.BaseName
2737 CreateDirectory(self
._BuildDir
)
2738 return self
._BuildDir
2740 ## Return the directory to store the intermediate object files of the mdoule
2741 def _GetOutputDir(self
):
2742 if self
._OutputDir
== None:
2743 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2744 CreateDirectory(self
._OutputDir
)
2745 return self
._OutputDir
2747 ## Return the directory to store auto-gened source files of the mdoule
2748 def _GetDebugDir(self
):
2749 if self
._DebugDir
== None:
2750 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2751 CreateDirectory(self
._DebugDir
)
2752 return self
._DebugDir
2754 ## Return the path of custom file
2755 def _GetCustomMakefile(self
):
2756 if self
._CustomMakefile
== None:
2757 self
._CustomMakefile
= {}
2758 for Type
in self
.Module
.CustomMakefile
:
2759 if Type
in gMakeTypeMap
:
2760 MakeType
= gMakeTypeMap
[Type
]
2763 if self
.SourceOverrideDir
!= None:
2764 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2765 if not os
.path
.exists(File
):
2766 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2768 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2769 self
._CustomMakefile
[MakeType
] = File
2770 return self
._CustomMakefile
2772 ## Return the directory of the makefile
2774 # @retval string The directory string of module's makefile
2776 def _GetMakeFileDir(self
):
2777 return self
.BuildDir
2779 ## Return build command string
2781 # @retval string Build command string
2783 def _GetBuildCommand(self
):
2784 return self
.PlatformInfo
.BuildCommand
2786 ## Get object list of all packages the module and its dependent libraries belong to
2788 # @retval list The list of package object
2790 def _GetDerivedPackageList(self
):
2792 for M
in [self
.Module
] + self
.DependentLibraryList
:
2793 for Package
in M
.Packages
:
2794 if Package
in PackageList
:
2796 PackageList
.append(Package
)
2799 ## Get the depex string
2801 # @return : a string contain all depex expresion.
2802 def _GetDepexExpresionString(self
):
2805 ## DPX_SOURCE IN Define section.
2806 if self
.Module
.DxsFile
:
2808 for M
in [self
.Module
] + self
.DependentLibraryList
:
2809 Filename
= M
.MetaFile
.Path
2810 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2811 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2812 for DepexExpresion
in DepexExpresionList
:
2813 for key
in DepexExpresion
.keys():
2814 Arch
, ModuleType
= key
2815 # the type of build module is USER_DEFINED.
2816 # All different DEPEX section tags would be copied into the As Built INF file
2817 # and there would be separate DEPEX section tags
2818 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2819 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2820 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2822 if Arch
.upper() == TAB_ARCH_COMMON
or \
2823 (Arch
.upper() == self
.Arch
.upper() and \
2824 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2825 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2827 #the type of build module is USER_DEFINED.
2828 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2829 for Depex
in DepexList
:
2830 for key
in Depex
.keys():
2831 DepexStr
+= '[Depex.%s.%s]\n' % key
2832 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2835 return '[Depex.%s]\n' % self
.Arch
2838 #the type of build module not is USER_DEFINED.
2840 for Depex
in DepexList
:
2845 for D
in Depex
.values():
2846 DepexStr
+= ' '.join([val
for val
in D
])
2847 Index
= DepexStr
.find('END')
2848 if Index
> -1 and Index
== len(DepexStr
) - 3:
2849 DepexStr
= DepexStr
[:-3]
2850 DepexStr
= DepexStr
.strip()
2853 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2855 return '[Depex.%s]\n' % self
.Arch
2856 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2858 ## Merge dependency expression
2860 # @retval list The token list of the dependency expression after parsed
2862 def _GetDepexTokenList(self
):
2863 if self
._DepexList
== None:
2864 self
._DepexList
= {}
2865 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2866 return self
._DepexList
2868 self
._DepexList
[self
.ModuleType
] = []
2870 for ModuleType
in self
._DepexList
:
2871 DepexList
= self
._DepexList
[ModuleType
]
2873 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2875 for M
in [self
.Module
] + self
.DependentLibraryList
:
2877 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
2879 DepexList
.append('AND')
2880 DepexList
.append('(')
2882 if DepexList
[-1] == 'END': # no need of a END at this time
2884 DepexList
.append(')')
2887 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2888 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2890 if len(DepexList
) > 0:
2891 EdkLogger
.verbose('')
2892 return self
._DepexList
2894 ## Merge dependency expression
2896 # @retval list The token list of the dependency expression after parsed
2898 def _GetDepexExpressionTokenList(self
):
2899 if self
._DepexExpressionList
== None:
2900 self
._DepexExpressionList
= {}
2901 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2902 return self
._DepexExpressionList
2904 self
._DepexExpressionList
[self
.ModuleType
] = ''
2906 for ModuleType
in self
._DepexExpressionList
:
2907 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
2909 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2911 for M
in [self
.Module
] + self
.DependentLibraryList
:
2913 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
2914 if DepexExpressionList
!= '':
2915 DepexExpressionList
+= ' AND '
2916 DepexExpressionList
+= '('
2917 DepexExpressionList
+= D
2918 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
2919 DepexExpressionList
+= ')'
2922 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
2923 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
2925 if len(DepexExpressionList
) > 0:
2926 EdkLogger
.verbose('')
2927 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
2928 return self
._DepexExpressionList
2930 ## Return the list of specification version required for the module
2932 # @retval list The list of specification defined in module file
2934 def _GetSpecification(self
):
2935 return self
.Module
.Specification
2937 ## Tool option for the module build
2939 # @param PlatformInfo The object of PlatformBuildInfo
2940 # @retval dict The dict containing valid options
2942 def _GetModuleBuildOption(self
):
2943 if self
._BuildOption
== None:
2944 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2945 if self
.BuildRuleOrder
:
2946 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
2947 return self
._BuildOption
2949 ## Get include path list from tool option for the module build
2951 # @retval list The include path list
2953 def _GetBuildOptionIncPathList(self
):
2954 if self
._BuildOptionIncPathList
== None:
2956 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2957 # is the former use /I , the Latter used -I to specify include directories
2959 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
2960 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2961 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
2962 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2965 # New ToolChainFamily, don't known whether there is option to specify include directories
2967 self
._BuildOptionIncPathList
= []
2968 return self
._BuildOptionIncPathList
2970 BuildOptionIncPathList
= []
2971 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2974 FlagOption
= self
.BuildOption
[Tool
][Attr
]
2978 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
2979 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
2982 # RVCT may specify a list of directory seperated by commas
2985 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
2986 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
2987 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
2990 # EDK II modules must not reference header files outside of the packages they depend on or
2991 # within the module's directory tree. Report error if violation.
2993 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
2994 for Path
in IncPathList
:
2995 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
2996 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
2997 EdkLogger
.error("build",
3000 File
=str(self
.MetaFile
))
3003 BuildOptionIncPathList
+= IncPathList
3005 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3007 return self
._BuildOptionIncPathList
3009 ## Return a list of files which can be built from source
3011 # What kind of files can be built is determined by build rules in
3012 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3014 def _GetSourceFileList(self
):
3015 if self
._SourceFileList
== None:
3016 self
._SourceFileList
= []
3017 for F
in self
.Module
.Sources
:
3019 if F
.TagName
not in ("", "*", self
.ToolChain
):
3020 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3021 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3023 # match tool chain family
3024 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
3027 "The file [%s] must be built by tools of [%s], " \
3028 "but current toolchain family is [%s]" \
3029 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
3032 # add the file path into search path list for file including
3033 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3034 self
.IncludePathList
.insert(0, F
.Dir
)
3035 self
._SourceFileList
.append(F
)
3037 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3039 for F
in self
._SourceFileList
:
3040 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3041 return self
._SourceFileList
3043 def _MatchBuildRuleOrder(self
, FileList
):
3045 self
._GetModuleBuildOption
()
3046 for SingleFile
in FileList
:
3047 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3048 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3049 if key
in Order_Dict
:
3050 Order_Dict
[key
].append(SingleFile
.Ext
)
3052 Order_Dict
[key
] = [SingleFile
.Ext
]
3055 for F
in Order_Dict
:
3056 if len(Order_Dict
[F
]) > 1:
3057 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3058 for Ext
in Order_Dict
[F
][1:]:
3059 RemoveList
.append(F
+ Ext
)
3061 for item
in RemoveList
:
3062 FileList
.remove(item
)
3066 ## Return the list of unicode files
3067 def _GetUnicodeFileList(self
):
3068 if self
._UnicodeFileList
== None:
3069 if TAB_UNICODE_FILE
in self
.FileTypes
:
3070 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3072 self
._UnicodeFileList
= []
3073 return self
._UnicodeFileList
3075 ## Return a list of files which can be built from binary
3077 # "Build" binary files are just to copy them to build directory.
3079 # @retval list The list of files which can be built later
3081 def _GetBinaryFiles(self
):
3082 if self
._BinaryFileList
== None:
3083 self
._BinaryFileList
= []
3084 for F
in self
.Module
.Binaries
:
3085 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3087 self
._BinaryFileList
.append(F
)
3088 self
._ApplyBuildRule
(F
, F
.Type
)
3089 return self
._BinaryFileList
3091 def _GetBuildRules(self
):
3092 if self
._BuildRules
== None:
3094 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3095 for Type
in BuildRuleDatabase
.FileTypeList
:
3096 #first try getting build rule by BuildRuleFamily
3097 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3099 # build type is always module type, but ...
3100 if self
.ModuleType
!= self
.BuildType
:
3101 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3102 #second try getting build rule by ToolChainFamily
3104 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3106 # build type is always module type, but ...
3107 if self
.ModuleType
!= self
.BuildType
:
3108 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3111 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3112 BuildRules
[Type
] = RuleObject
3113 for Ext
in RuleObject
.SourceFileExtList
:
3114 BuildRules
[Ext
] = RuleObject
3115 self
._BuildRules
= BuildRules
3116 return self
._BuildRules
3118 def _ApplyBuildRule(self
, File
, FileType
):
3119 if self
._BuildTargets
== None:
3120 self
._IntroBuildTargetList
= set()
3121 self
._FinalBuildTargetList
= set()
3122 self
._BuildTargets
= {}
3123 self
._FileTypes
= {}
3125 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3126 if not os
.path
.exists(SubDirectory
):
3127 CreateDirectory(SubDirectory
)
3133 # Make sure to get build rule order value
3135 self
._GetModuleBuildOption
()
3137 while Index
< len(SourceList
):
3138 Source
= SourceList
[Index
]
3142 CreateDirectory(Source
.Dir
)
3144 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
3145 # Skip all files that are not binary libraries
3146 if not self
.IsLibrary
:
3148 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3149 elif FileType
in self
.BuildRules
:
3150 RuleObject
= self
.BuildRules
[FileType
]
3151 elif Source
.Ext
in self
.BuildRules
:
3152 RuleObject
= self
.BuildRules
[Source
.Ext
]
3154 # stop at no more rules
3156 self
._FinalBuildTargetList
.add(LastTarget
)
3159 FileType
= RuleObject
.SourceFileType
3160 if FileType
not in self
._FileTypes
:
3161 self
._FileTypes
[FileType
] = set()
3162 self
._FileTypes
[FileType
].add(Source
)
3164 # stop at STATIC_LIBRARY for library
3165 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3167 self
._FinalBuildTargetList
.add(LastTarget
)
3170 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3173 self
._FinalBuildTargetList
.add(LastTarget
)
3175 elif not Target
.Outputs
:
3176 # Only do build for target with outputs
3177 self
._FinalBuildTargetList
.add(Target
)
3179 if FileType
not in self
._BuildTargets
:
3180 self
._BuildTargets
[FileType
] = set()
3181 self
._BuildTargets
[FileType
].add(Target
)
3183 if not Source
.IsBinary
and Source
== File
:
3184 self
._IntroBuildTargetList
.add(Target
)
3186 # to avoid cyclic rule
3187 if FileType
in RuleChain
:
3190 RuleChain
.append(FileType
)
3191 SourceList
.extend(Target
.Outputs
)
3193 FileType
= TAB_UNKNOWN_FILE
3195 def _GetTargets(self
):
3196 if self
._BuildTargets
== None:
3197 self
._IntroBuildTargetList
= set()
3198 self
._FinalBuildTargetList
= set()
3199 self
._BuildTargets
= {}
3200 self
._FileTypes
= {}
3202 #TRICK: call _GetSourceFileList to apply build rule for source files
3203 if self
.SourceFileList
:
3206 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3207 if self
.BinaryFileList
:
3210 return self
._BuildTargets
3212 def _GetIntroTargetList(self
):
3214 return self
._IntroBuildTargetList
3216 def _GetFinalTargetList(self
):
3218 return self
._FinalBuildTargetList
3220 def _GetFileTypes(self
):
3222 return self
._FileTypes
3224 ## Get the list of package object the module depends on
3226 # @retval list The package object list
3228 def _GetDependentPackageList(self
):
3229 return self
.Module
.Packages
3231 ## Return the list of auto-generated code file
3233 # @retval list The list of auto-generated file
3235 def _GetAutoGenFileList(self
):
3236 UniStringAutoGenC
= True
3237 UniStringBinBuffer
= StringIO()
3238 if self
.BuildType
== 'UEFI_HII':
3239 UniStringAutoGenC
= False
3240 if self
._AutoGenFileList
== None:
3241 self
._AutoGenFileList
= {}
3242 AutoGenC
= TemplateString()
3243 AutoGenH
= TemplateString()
3244 StringH
= TemplateString()
3245 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
)
3247 # AutoGen.c is generated if there are library classes in inf, or there are object files
3249 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3250 or TAB_OBJECT_FILE
in self
.FileTypes
):
3251 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3252 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3253 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3254 if str(AutoGenH
) != "":
3255 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3256 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3257 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3258 if str(StringH
) != "":
3259 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3260 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3261 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3262 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3263 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3264 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3265 AutoFile
.IsBinary
= True
3266 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3267 if UniStringBinBuffer
!= None:
3268 UniStringBinBuffer
.close()
3269 return self
._AutoGenFileList
3271 ## Return the list of library modules explicitly or implicityly used by this module
3272 def _GetLibraryList(self
):
3273 if self
._DependentLibraryList
== None:
3274 # only merge library classes and PCD for non-library module
3276 self
._DependentLibraryList
= []
3278 if self
.AutoGenVersion
< 0x00010005:
3279 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3281 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3282 return self
._DependentLibraryList
3285 def UpdateComments(Recver
, Src
):
3287 if Key
not in Recver
:
3289 Recver
[Key
].extend(Src
[Key
])
3290 ## Get the list of PCDs from current module
3292 # @retval list The list of PCD
3294 def _GetModulePcdList(self
):
3295 if self
._ModulePcdList
== None:
3296 # apply PCD settings from platform
3297 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3298 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3299 return self
._ModulePcdList
3301 ## Get the list of PCDs from dependent libraries
3303 # @retval list The list of PCD
3305 def _GetLibraryPcdList(self
):
3306 if self
._LibraryPcdList
== None:
3308 if not self
.IsLibrary
:
3309 # get PCDs from dependent libraries
3310 for Library
in self
.DependentLibraryList
:
3311 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3312 for Key
in Library
.Pcds
:
3313 # skip duplicated PCDs
3314 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3316 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3317 # apply PCD settings from platform
3318 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3320 self
._LibraryPcdList
= []
3321 return self
._LibraryPcdList
3323 ## Get the GUID value mapping
3325 # @retval dict The mapping between GUID cname and its value
3327 def _GetGuidList(self
):
3328 if self
._GuidList
== None:
3329 self
._GuidList
= sdict()
3330 self
._GuidList
.update(self
.Module
.Guids
)
3331 for Library
in self
.DependentLibraryList
:
3332 self
._GuidList
.update(Library
.Guids
)
3333 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3334 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3335 return self
._GuidList
3337 def GetGuidsUsedByPcd(self
):
3338 if self
._GuidsUsedByPcd
== None:
3339 self
._GuidsUsedByPcd
= sdict()
3340 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3341 for Library
in self
.DependentLibraryList
:
3342 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3343 return self
._GuidsUsedByPcd
3344 ## Get the protocol value mapping
3346 # @retval dict The mapping between protocol cname and its value
3348 def _GetProtocolList(self
):
3349 if self
._ProtocolList
== None:
3350 self
._ProtocolList
= sdict()
3351 self
._ProtocolList
.update(self
.Module
.Protocols
)
3352 for Library
in self
.DependentLibraryList
:
3353 self
._ProtocolList
.update(Library
.Protocols
)
3354 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3355 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3356 return self
._ProtocolList
3358 ## Get the PPI value mapping
3360 # @retval dict The mapping between PPI cname and its value
3362 def _GetPpiList(self
):
3363 if self
._PpiList
== None:
3364 self
._PpiList
= sdict()
3365 self
._PpiList
.update(self
.Module
.Ppis
)
3366 for Library
in self
.DependentLibraryList
:
3367 self
._PpiList
.update(Library
.Ppis
)
3368 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3369 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3370 return self
._PpiList
3372 ## Get the list of include search path
3374 # @retval list The list path
3376 def _GetIncludePathList(self
):
3377 if self
._IncludePathList
== None:
3378 self
._IncludePathList
= []
3379 if self
.AutoGenVersion
< 0x00010005:
3380 for Inc
in self
.Module
.Includes
:
3381 if Inc
not in self
._IncludePathList
:
3382 self
._IncludePathList
.append(Inc
)
3384 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3385 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3386 self
._IncludePathList
.append(Inc
)
3387 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3388 self
._IncludePathList
.append(self
.DebugDir
)
3390 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3391 self
._IncludePathList
.append(self
.DebugDir
)
3393 for Package
in self
.Module
.Packages
:
3394 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3395 if PackageDir
not in self
._IncludePathList
:
3396 self
._IncludePathList
.append(PackageDir
)
3397 for Inc
in Package
.Includes
:
3398 if Inc
not in self
._IncludePathList
:
3399 self
._IncludePathList
.append(str(Inc
))
3400 return self
._IncludePathList
3402 def _GetIncludePathLength(self
):
3403 self
._IncludePathLength
= 0
3404 if self
._IncludePathList
:
3405 for inc
in self
._IncludePathList
:
3406 self
._IncludePathLength
+= len(' ' + inc
)
3407 return self
._IncludePathLength
3409 ## Get HII EX PCDs which maybe used by VFR
3411 # efivarstore used by VFR may relate with HII EX PCDs
3412 # Get the variable name and GUID from efivarstore and HII EX PCD
3413 # List the HII EX PCDs in As Built INF if both name and GUID match.
3415 # @retval list HII EX PCDs
3417 def _GetPcdsMaybeUsedByVfr(self
):
3418 if not self
.SourceFileList
:
3422 for SrcFile
in self
.SourceFileList
:
3423 if SrcFile
.Ext
.lower() != '.vfr':
3425 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3426 if not os
.path
.exists(Vfri
):
3428 VfriFile
= open(Vfri
, 'r')
3429 Content
= VfriFile
.read()
3431 Pos
= Content
.find('efivarstore')
3434 # Make sure 'efivarstore' is the start of efivarstore statement
3435 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3438 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3440 if Index
>= 0 and Content
[Index
] != ';':
3441 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3444 # 'efivarstore' must be followed by name and guid
3446 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3449 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3452 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3453 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3454 Pos
= Content
.find('efivarstore', Name
.end())
3458 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3459 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3461 for SkuName
in Pcd
.SkuInfoList
:
3462 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3463 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3464 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
)
3467 Guid
= GuidStructureStringToGuidString(Value
)
3468 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3469 HiiExPcds
.append(Pcd
)
3474 def _GenOffsetBin(self
):
3476 for SourceFile
in self
.Module
.Sources
:
3477 if SourceFile
.Type
.upper() == ".VFR" :
3479 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3481 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3482 if SourceFile
.Type
.upper() == ".UNI" :
3484 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3486 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3488 if len(VfrUniBaseName
) == 0:
3490 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3491 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3492 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3493 if not VfrUniOffsetList
:
3496 OutputName
= '%sOffset.bin' % self
.Name
3497 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3500 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3502 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3504 # Use a instance of StringIO to cache data
3505 fStringIO
= StringIO('')
3507 for Item
in VfrUniOffsetList
:
3508 if (Item
[0].find("Strings") != -1):
3510 # UNI offset in image.
3512 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3514 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3515 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3516 fStringIO
.write(''.join(UniGuid
))
3517 UniValue
= pack ('Q', int (Item
[1], 16))
3518 fStringIO
.write (UniValue
)
3521 # VFR binary offset in image.
3523 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3525 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3526 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3527 fStringIO
.write(''.join(VfrGuid
))
3529 VfrValue
= pack ('Q', int (Item
[1], 16))
3530 fStringIO
.write (VfrValue
)
3532 # write data into file.
3535 fInputfile
.write (fStringIO
.getvalue())
3537 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3538 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3544 ## Create AsBuilt INF file the module
3546 def CreateAsBuiltInf(self
):
3547 if self
.IsAsBuiltInfCreated
:
3550 # Skip the following code for EDK I inf
3551 if self
.AutoGenVersion
< 0x00010005:
3554 # Skip the following code for libraries
3558 # Skip the following code for modules with no source files
3559 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3562 # Skip the following code for modules without any binary files
3563 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3566 ### TODO: How to handles mixed source and binary modules
3568 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3569 # Also find all packages that the DynamicEx PCDs depend on
3574 PcdTokenSpaceList
= []
3575 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3576 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3577 PatchablePcds
[Pcd
.TokenCName
] = Pcd
3578 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3579 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3582 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3583 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3584 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3586 GuidList
.update(self
.GuidList
)
3587 for TokenSpace
in self
.GetGuidsUsedByPcd():
3588 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3589 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3590 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3591 GuidList
.pop(TokenSpace
)
3592 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3593 for Package
in self
.DerivedPackageList
:
3594 if Package
in Packages
:
3596 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3598 for Index
in range(len(BeChecked
)):
3599 for Item
in CheckList
[Index
]:
3600 if Item
in BeChecked
[Index
]:
3601 Packages
+= [Package
]
3606 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3607 for Pkg
in self
.PlatformInfo
.PackageList
:
3610 for VfrPcd
in VfrPcds
:
3611 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3612 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3616 ModuleType
= self
.ModuleType
3617 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3618 ModuleType
= 'DXE_DRIVER'
3621 if self
.PcdIsDriver
!= '':
3622 DriverType
= self
.PcdIsDriver
3625 MDefs
= self
.Module
.Defines
3628 'module_name' : self
.Name
,
3629 'module_guid' : Guid
,
3630 'module_module_type' : ModuleType
,
3631 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3632 'pcd_is_driver_string' : [],
3633 'module_uefi_specification_version' : [],
3634 'module_pi_specification_version' : [],
3635 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3636 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3637 'module_constructor' : self
.Module
.ConstructorList
,
3638 'module_destructor' : self
.Module
.DestructorList
,
3639 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3640 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3641 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3642 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3643 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3644 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3645 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3646 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3647 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3648 'module_arch' : self
.Arch
,
3649 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3651 'patchablepcd_item' : [],
3653 'protocol_item' : [],
3657 'libraryclasses_item' : []
3660 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3661 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3663 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3666 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3668 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3669 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3670 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3671 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3673 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3675 for Item
in self
.CodaTargetList
:
3676 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3677 if Item
.Target
.Ext
.lower() == '.aml':
3678 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3679 elif Item
.Target
.Ext
.lower() == '.acpi':
3680 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3681 elif Item
.Target
.Ext
.lower() == '.efi':
3682 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3684 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3685 if self
.DepexGenerated
:
3686 if self
.ModuleType
in ['PEIM']:
3687 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3688 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3689 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3690 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3691 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3693 Bin
= self
._GenOffsetBin
()
3695 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3697 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3699 if File
.lower().endswith('.pdb'):
3700 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3701 HeaderComments
= self
.Module
.HeaderComments
3703 for Index
in range(len(HeaderComments
)):
3704 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3705 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3708 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3709 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3712 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3713 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3714 (GuidList
, self
._GuidComments
, 'guid_item')
3716 for Item
in GenList
:
3717 for CName
in Item
[0]:
3719 if CName
in Item
[1]:
3720 Comments
= '\n '.join(Item
[1][CName
])
3723 Entry
= Comments
+ '\n ' + CName
3724 AsBuiltInfDict
[Item
[2]].append(Entry
)
3725 PatchList
= parsePcdInfoFromMapFile(
3726 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3727 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3730 for PatchPcd
in PatchList
:
3731 if PatchPcd
[0] in PatchablePcds
:
3733 elif PatchPcd
[0] + '_PatchableInModule' in PatchablePcds
:
3734 key
= PatchPcd
[0] + '_PatchableInModule'
3737 Pcd
= PatchablePcds
[key
]
3738 TokenCName
= PatchPcd
[0]
3740 if Pcd
.DatumType
!= 'VOID*':
3741 HexFormat
= '0x%02x'
3742 if Pcd
.DatumType
== 'UINT16':
3743 HexFormat
= '0x%04x'
3744 elif Pcd
.DatumType
== 'UINT32':
3745 HexFormat
= '0x%08x'
3746 elif Pcd
.DatumType
== 'UINT64':
3747 HexFormat
= '0x%016x'
3748 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3750 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3751 EdkLogger
.error("build", AUTOGEN_ERROR
,
3752 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3754 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3755 PcdValue
= Pcd
.DefaultValue
3756 if PcdValue
[0] != '{':
3758 if PcdValue
[0] == 'L':
3760 PcdValue
= PcdValue
.lstrip('L')
3761 PcdValue
= eval(PcdValue
)
3763 for Index
in range(0, len(PcdValue
)):
3765 CharVal
= ord(PcdValue
[Index
])
3766 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3767 + '0x%02x' % (CharVal
>> 8) + ', '
3769 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3772 Padding
= Padding
* 2
3773 ArraySize
= ArraySize
/ 2
3774 if ArraySize
< (len(PcdValue
) + 1):
3775 EdkLogger
.error("build", AUTOGEN_ERROR
,
3776 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3778 if ArraySize
> len(PcdValue
) + 1:
3779 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3780 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3781 elif len(PcdValue
.split(',')) <= ArraySize
:
3782 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3785 EdkLogger
.error("build", AUTOGEN_ERROR
,
3786 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3788 PcdItem
= '%s.%s|%s|0x%X' % \
3789 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
3791 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3792 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3794 PcdItem
= PcdComments
+ '\n ' + PcdItem
3795 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3798 for Pcd
in Pcds
+ VfrPcds
:
3803 TokenCName
= Pcd
.TokenCName
3804 for PcdItem
in GlobalData
.MixedPcd
:
3805 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3806 TokenCName
= PcdItem
[0]
3808 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3809 for SkuName
in Pcd
.SkuInfoList
:
3810 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3811 SkuId
= SkuInfo
.SkuId
3812 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3816 # Don't generate duplicated HII PCD
3818 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
3821 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
3822 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3823 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3827 for Index
, Comment
in enumerate(PcdCommentList
):
3828 for Usage
in UsageList
:
3829 if Comment
.find(Usage
) != -1:
3833 if UsageIndex
!= -1:
3834 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3836 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3837 PcdComments
= '\n '.join(PcdCommentList
)
3838 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
3840 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3841 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
3842 for Item
in self
.BuildOption
:
3843 if 'FLAGS' in self
.BuildOption
[Item
]:
3844 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
3846 # Generated LibraryClasses section in comments.
3847 for Library
in self
.LibraryAutoGenList
:
3848 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
3850 # Generated depex expression section in comments.
3851 AsBuiltInfDict
['depexsection_item'] = ''
3852 DepexExpresion
= self
._GetDepexExpresionString
()
3854 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
3856 AsBuiltInf
= TemplateString()
3857 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3859 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3861 self
.IsAsBuiltInfCreated
= True
3863 ## Create makefile for the module and its dependent libraries
3865 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3866 # dependent libraries will be created
3868 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
3869 # Ignore generating makefile when it is a binary module
3870 if self
.IsBinaryModule
:
3873 if self
.IsMakeFileCreated
:
3876 if not self
.IsLibrary
and CreateLibraryMakeFile
:
3877 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3878 LibraryAutoGen
.CreateMakeFile()
3880 if len(self
.CustomMakefile
) == 0:
3881 Makefile
= GenMake
.ModuleMakefile(self
)
3883 Makefile
= GenMake
.CustomMakefile(self
)
3884 if Makefile
.Generate():
3885 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
3886 (self
.Name
, self
.Arch
))
3888 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
3889 (self
.Name
, self
.Arch
))
3891 self
.IsMakeFileCreated
= True
3893 def CopyBinaryFiles(self
):
3894 for File
in self
.Module
.Binaries
:
3896 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
3897 CopyLongFilePath(SrcPath
, DstPath
)
3898 ## Create autogen code for the module and its dependent libraries
3900 # @param CreateLibraryCodeFile Flag indicating if or not the code of
3901 # dependent libraries will be created
3903 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
3904 if self
.IsCodeFileCreated
:
3907 # Need to generate PcdDatabase even PcdDriver is binarymodule
3908 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
3909 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3911 if self
.IsBinaryModule
:
3913 self
.CopyBinaryFiles()
3916 if not self
.IsLibrary
and CreateLibraryCodeFile
:
3917 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3918 LibraryAutoGen
.CreateCodeFile()
3921 IgoredAutoGenList
= []
3923 for File
in self
.AutoGenFileList
:
3924 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
3925 #Ignore Edk AutoGen.c
3926 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
3929 AutoGenList
.append(str(File
))
3931 IgoredAutoGenList
.append(str(File
))
3933 # Skip the following code for EDK I inf
3934 if self
.AutoGenVersion
< 0x00010005:
3937 for ModuleType
in self
.DepexList
:
3938 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
3939 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
3942 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
3943 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
3945 if len(Dpx
.PostfixNotation
) <> 0:
3946 self
.DepexGenerated
= True
3948 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
3949 AutoGenList
.append(str(DpxFile
))
3951 IgoredAutoGenList
.append(str(DpxFile
))
3953 if IgoredAutoGenList
== []:
3954 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
3955 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
3956 elif AutoGenList
== []:
3957 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
3958 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3960 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
3961 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3963 self
.IsCodeFileCreated
= True
3966 ## Summarize the ModuleAutoGen objects of all libraries used by this module
3967 def _GetLibraryAutoGenList(self
):
3968 if self
._LibraryAutoGenList
== None:
3969 self
._LibraryAutoGenList
= []
3970 for Library
in self
.DependentLibraryList
:
3977 self
.PlatformInfo
.MetaFile
3979 if La
not in self
._LibraryAutoGenList
:
3980 self
._LibraryAutoGenList
.append(La
)
3981 for Lib
in La
.CodaTargetList
:
3982 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
3983 return self
._LibraryAutoGenList
3985 Module
= property(_GetModule
)
3986 Name
= property(_GetBaseName
)
3987 Guid
= property(_GetGuid
)
3988 Version
= property(_GetVersion
)
3989 ModuleType
= property(_GetModuleType
)
3990 ComponentType
= property(_GetComponentType
)
3991 BuildType
= property(_GetBuildType
)
3992 PcdIsDriver
= property(_GetPcdIsDriver
)
3993 AutoGenVersion
= property(_GetAutoGenVersion
)
3994 Macros
= property(_GetMacros
)
3995 Specification
= property(_GetSpecification
)
3997 IsLibrary
= property(_IsLibrary
)
3998 IsBinaryModule
= property(_IsBinaryModule
)
3999 BuildDir
= property(_GetBuildDir
)
4000 OutputDir
= property(_GetOutputDir
)
4001 DebugDir
= property(_GetDebugDir
)
4002 MakeFileDir
= property(_GetMakeFileDir
)
4003 CustomMakefile
= property(_GetCustomMakefile
)
4005 IncludePathList
= property(_GetIncludePathList
)
4006 IncludePathLength
= property(_GetIncludePathLength
)
4007 AutoGenFileList
= property(_GetAutoGenFileList
)
4008 UnicodeFileList
= property(_GetUnicodeFileList
)
4009 SourceFileList
= property(_GetSourceFileList
)
4010 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4011 Targets
= property(_GetTargets
)
4012 IntroTargetList
= property(_GetIntroTargetList
)
4013 CodaTargetList
= property(_GetFinalTargetList
)
4014 FileTypes
= property(_GetFileTypes
)
4015 BuildRules
= property(_GetBuildRules
)
4017 DependentPackageList
= property(_GetDependentPackageList
)
4018 DependentLibraryList
= property(_GetLibraryList
)
4019 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4020 DerivedPackageList
= property(_GetDerivedPackageList
)
4022 ModulePcdList
= property(_GetModulePcdList
)
4023 LibraryPcdList
= property(_GetLibraryPcdList
)
4024 GuidList
= property(_GetGuidList
)
4025 ProtocolList
= property(_GetProtocolList
)
4026 PpiList
= property(_GetPpiList
)
4027 DepexList
= property(_GetDepexTokenList
)
4028 DxsFile
= property(_GetDxsFile
)
4029 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4030 BuildOption
= property(_GetModuleBuildOption
)
4031 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4032 BuildCommand
= property(_GetBuildCommand
)
4034 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4036 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4037 if __name__
== '__main__':