1 ## @file InfPomAlignmentMisc.py
2 # This file contained the routines for InfPomAlignment
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
16 import Logger
.Log
as Logger
17 from Library
import DataType
as DT
18 from Library
.Misc
import ConvertArchList
19 from Object
.POM
.ModuleObject
import BinaryFileObject
20 from Object
.POM
import CommonObject
21 from Library
.StringUtils
import FORMAT_INVALID
22 from Library
.Misc
import CheckGuidRegFormat
23 from Logger
import StringTable
as ST
26 ## GenModuleHeaderUserExt
29 def GenModuleHeaderUserExt(DefineObj
, ArchString
):
31 EdkReleaseVersion
= DefineObj
.GetEdkReleaseVersion()
32 Shadow
= DefineObj
.GetShadow()
33 DpxSource
= DefineObj
.GetDpxSource()
34 PciVendorId
= DefineObj
.GetPciVendorId()
35 PciDeviceId
= DefineObj
.GetPciDeviceId()
36 PciClassCode
= DefineObj
.GetPciClassCode()
37 PciRevision
= DefineObj
.GetPciRevision()
38 PciCompress
= DefineObj
.GetPciCompress()
39 CustomMakefile
= DefineObj
.GetCustomMakefile()
40 UefiHiiResourceSection
= DefineObj
.GetUefiHiiResourceSection()
42 if EdkReleaseVersion
is not None:
43 Name
= DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
44 Value
= EdkReleaseVersion
.GetValue()
45 Statement
= _GenInfDefineStateMent(EdkReleaseVersion
.Comments
.GetHeaderComments(),
48 EdkReleaseVersion
.Comments
.GetTailComments())
49 DefinesDictNew
[Statement
] = ArchString
51 if Shadow
is not None:
52 Name
= DT
.TAB_INF_DEFINES_SHADOW
53 Value
= Shadow
.GetValue()
54 Statement
= _GenInfDefineStateMent(Shadow
.Comments
.GetHeaderComments(),
57 Shadow
.Comments
.GetTailComments())
58 DefinesDictNew
[Statement
] = ArchString
60 if DpxSource
is not None:
61 Name
= DT
.TAB_INF_DEFINES_DPX_SOURCE
62 for DpxSourceItem
in DpxSource
:
63 Value
= DpxSourceItem
[0]
64 Statement
= _GenInfDefineStateMent(DpxSourceItem
[1].GetHeaderComments(),
67 DpxSourceItem
[1].GetTailComments())
68 DefinesDictNew
[Statement
] = ArchString
70 if PciVendorId
is not None:
71 Name
= DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
72 Value
= PciVendorId
.GetValue()
73 Statement
= _GenInfDefineStateMent(PciVendorId
.Comments
.GetHeaderComments(),
76 PciVendorId
.Comments
.GetTailComments())
77 DefinesDictNew
[Statement
] = ArchString
79 if PciDeviceId
is not None:
80 Name
= DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
81 Value
= PciDeviceId
.GetValue()
82 Statement
= _GenInfDefineStateMent(PciDeviceId
.Comments
.GetHeaderComments(),
85 PciDeviceId
.Comments
.GetTailComments())
86 DefinesDictNew
[Statement
] = ArchString
88 if PciClassCode
is not None:
89 Name
= DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
90 Value
= PciClassCode
.GetValue()
91 Statement
= _GenInfDefineStateMent(PciClassCode
.Comments
.GetHeaderComments(),
94 PciClassCode
.Comments
.GetTailComments())
95 DefinesDictNew
[Statement
] = ArchString
97 if PciRevision
is not None:
98 Name
= DT
.TAB_INF_DEFINES_PCI_REVISION
99 Value
= PciRevision
.GetValue()
100 Statement
= _GenInfDefineStateMent(PciRevision
.Comments
.GetHeaderComments(),
103 PciRevision
.Comments
.GetTailComments())
104 DefinesDictNew
[Statement
] = ArchString
106 if PciCompress
is not None:
107 Name
= DT
.TAB_INF_DEFINES_PCI_COMPRESS
108 Value
= PciCompress
.GetValue()
109 Statement
= _GenInfDefineStateMent(PciCompress
.Comments
.GetHeaderComments(),
112 PciCompress
.Comments
.GetTailComments())
113 DefinesDictNew
[Statement
] = ArchString
115 if len(CustomMakefile
) >= 1:
116 for CustomMakefileItem
in CustomMakefile
:
117 Name
= DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
119 # Not with Feature Flag Expression
121 if len(CustomMakefileItem
) == 3:
122 if CustomMakefileItem
[0] != '':
123 Value
= CustomMakefileItem
[0] + ' | ' + CustomMakefileItem
[1]
125 Value
= CustomMakefileItem
[1]
127 Comments
= CustomMakefileItem
[2]
128 Statement
= _GenInfDefineStateMent(Comments
.GetHeaderComments(),
131 Comments
.GetTailComments())
133 DefinesDictNew
[Statement
] = ArchString
135 if UefiHiiResourceSection
is not None:
136 Name
= DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
137 Value
= UefiHiiResourceSection
.GetValue()
138 HeaderComment
= UefiHiiResourceSection
.Comments
.GetHeaderComments()
139 TailComment
= UefiHiiResourceSection
.Comments
.GetTailComments()
140 Statement
= _GenInfDefineStateMent(HeaderComment
,
144 DefinesDictNew
[Statement
] = ""
146 return DefinesDictNew
149 ## Generate the define statement that will be put into userextension
150 # Not support comments.
152 # @param HeaderComment: the original header comment (# not removed)
153 # @param Name: the definition keyword, should not be empty or none
154 # @param Value: the definition keyword value
155 # @param TailComment: the original Tail comment (# not removed)
157 # @return: the regenerated define statement
159 def _GenInfDefineStateMent(HeaderComment
, Name
, Value
, TailComment
):
160 Logger
.Debug(5, HeaderComment
+ TailComment
)
161 Statement
= '%s = %s' % (Name
, Value
)
168 def GenBinaryData(BinaryData
, BinaryObj
, BinariesDict
, AsBuildIns
, BinaryFileObjectList
, \
169 SupArchList
, BinaryModule
, DecObjList
=None):
172 OriSupArchList
= SupArchList
173 for Item
in BinaryData
:
174 ItemObj
= BinaryObj
[Item
][0][0]
175 if ItemObj
.GetType() not in DT
.BINARY_FILE_TYPE_UI_LIST
+ DT
.BINARY_FILE_TYPE_VER_LIST
:
176 TagName
= ItemObj
.GetTagName()
177 Family
= ItemObj
.GetFamily()
182 FFE
= ItemObj
.GetFeatureFlagExp()
185 # If have architecturie specified, then use the specified architecturie;
186 # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive),
187 # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment
188 # can be used for the attribute.
189 # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty.
191 SupArchList
= sorted(ConvertArchList(ItemObj
.GetSupArchList()))
192 if len(SupArchList
) == 1 and SupArchList
[0] == 'COMMON':
193 if not (len(OriSupArchList
) == 1 or OriSupArchList
[0] == 'COMMON'):
194 SupArchList
= OriSupArchList
196 SupArchList
= ['COMMON']
198 FileNameObj
= CommonObject
.FileNameObject()
199 FileNameObj
.SetFileType(ItemObj
.GetType())
200 FileNameObj
.SetFilename(ItemObj
.GetFileName())
201 FileNameObj
.SetFeatureFlag(FFE
)
203 # Get GUID value of the GUID CName in the DEC file
205 if ItemObj
.GetType() == DT
.SUBTYPE_GUID_BINARY_FILE_TYPE
:
206 if not CheckGuidRegFormat(ItemObj
.GetGuidValue()):
208 if DT
.TAB_HORIZON_LINE_SPLIT
in ItemObj
.GetGuidValue() or \
209 DT
.TAB_COMMA_SPLIT
in ItemObj
.GetGuidValue():
210 Logger
.Error("\nMkPkg",
212 ST
.ERR_DECPARSE_DEFINE_PKGGUID
,
213 ExtraData
=ItemObj
.GetGuidValue(),
216 Logger
.Error("\nMkPkg",
218 ST
.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND
% \
219 (ItemObj
.GetGuidValue()),
222 for DecObj
in DecObjList
:
223 for GuidObj
in DecObj
.GetGuidList():
224 if GuidObj
.GetCName() == ItemObj
.GetGuidValue():
225 FileNameObj
.SetGuidValue(GuidObj
.GetGuid())
228 if not FileNameObj
.GetGuidValue():
229 Logger
.Error("\nMkPkg",
231 ST
.ERR_DECPARSE_CGUID_NOT_FOUND
% \
232 (ItemObj
.GetGuidValue()),
235 FileNameObj
.SetGuidValue(ItemObj
.GetGuidValue().strip())
237 FileNameObj
.SetSupArchList(SupArchList
)
238 FileNameList
= [FileNameObj
]
240 BinaryFile
= BinaryFileObject()
241 BinaryFile
.SetFileNameList(FileNameList
)
242 BinaryFile
.SetAsBuiltList(AsBuildIns
)
243 BinaryFileObjectList
.append(BinaryFile
)
245 SupArchStr
= ' '.join(SupArchList
)
246 Key
= (ItemObj
.GetFileName(), ItemObj
.GetType(), FFE
, SupArchStr
)
247 ValueItem
= (ItemObj
.GetTarget(), Family
, TagName
, '')
248 if Key
in BinariesDict
:
249 ValueList
= BinariesDict
[Key
]
250 ValueList
.append(ValueItem
)
251 BinariesDict
[Key
] = ValueList
253 BinariesDict
[Key
] = [ValueItem
]
255 return BinariesDict
, AsBuildIns
, BinaryFileObjectList