• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## @file InfPomAlignmentMisc.py
2# This file contained the routines for InfPomAlignment
3#
4# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
5#
6# This program and the accompanying materials are licensed and made available
7# under the terms and conditions of the BSD License which accompanies this
8# distribution. The full text of the license may be found at
9# http://opensource.org/licenses/bsd-license.php
10#
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13#
14
15'''
16InfPomAlignmentMisc
17'''
18
19##
20# Import modules
21#
22import Logger.Log as Logger
23from Library import DataType as DT
24from Library.Misc import ConvertArchList
25from Object.POM.ModuleObject import BinaryFileObject
26from Object.POM import CommonObject
27from Library.String import FORMAT_INVALID
28from Library.Misc import CheckGuidRegFormat
29from Logger import StringTable as ST
30
31
32## GenModuleHeaderUserExt
33#
34#
35def GenModuleHeaderUserExt(DefineObj, ArchString):
36    DefinesDictNew = {}
37    EdkReleaseVersion = DefineObj.GetEdkReleaseVersion()
38    Shadow = DefineObj.GetShadow()
39    DpxSource = DefineObj.GetDpxSource()
40    PciVendorId = DefineObj.GetPciVendorId()
41    PciDeviceId = DefineObj.GetPciDeviceId()
42    PciClassCode = DefineObj.GetPciClassCode()
43    PciRevision = DefineObj.GetPciRevision()
44    PciCompress = DefineObj.GetPciCompress()
45    CustomMakefile = DefineObj.GetCustomMakefile()
46    UefiHiiResourceSection = DefineObj.GetUefiHiiResourceSection()
47
48    if EdkReleaseVersion != None:
49        Name = DT.TAB_INF_DEFINES_EDK_RELEASE_VERSION
50        Value = EdkReleaseVersion.GetValue()
51        Statement = _GenInfDefineStateMent(EdkReleaseVersion.Comments.GetHeaderComments(),
52                                           Name,
53                                           Value,
54                                           EdkReleaseVersion.Comments.GetTailComments())
55        DefinesDictNew[Statement] = ArchString
56
57    if Shadow != None:
58        Name = DT.TAB_INF_DEFINES_SHADOW
59        Value = Shadow.GetValue()
60        Statement = _GenInfDefineStateMent(Shadow.Comments.GetHeaderComments(),
61                                           Name,
62                                           Value,
63                                           Shadow.Comments.GetTailComments())
64        DefinesDictNew[Statement] = ArchString
65
66    if DpxSource != None:
67        Name = DT.TAB_INF_DEFINES_DPX_SOURCE
68        for DpxSourceItem in DpxSource:
69            Value = DpxSourceItem[0]
70            Statement = _GenInfDefineStateMent(DpxSourceItem[1].GetHeaderComments(),
71                                               Name,
72                                               Value,
73                                               DpxSourceItem[1].GetTailComments())
74            DefinesDictNew[Statement] = ArchString
75
76    if PciVendorId != None:
77        Name = DT.TAB_INF_DEFINES_PCI_VENDOR_ID
78        Value = PciVendorId.GetValue()
79        Statement = _GenInfDefineStateMent(PciVendorId.Comments.GetHeaderComments(),
80                                           Name,
81                                           Value,
82                                           PciVendorId.Comments.GetTailComments())
83        DefinesDictNew[Statement] = ArchString
84
85    if PciDeviceId != None:
86        Name = DT.TAB_INF_DEFINES_PCI_DEVICE_ID
87        Value = PciDeviceId.GetValue()
88        Statement = _GenInfDefineStateMent(PciDeviceId.Comments.GetHeaderComments(),
89                                           Name,
90                                           Value,
91                                           PciDeviceId.Comments.GetTailComments())
92        DefinesDictNew[Statement] = ArchString
93
94    if PciClassCode != None:
95        Name = DT.TAB_INF_DEFINES_PCI_CLASS_CODE
96        Value = PciClassCode.GetValue()
97        Statement = _GenInfDefineStateMent(PciClassCode.Comments.GetHeaderComments(),
98                                           Name,
99                                           Value,
100                                           PciClassCode.Comments.GetTailComments())
101        DefinesDictNew[Statement] = ArchString
102
103    if PciRevision != None:
104        Name = DT.TAB_INF_DEFINES_PCI_REVISION
105        Value = PciRevision.GetValue()
106        Statement = _GenInfDefineStateMent(PciRevision.Comments.GetHeaderComments(),
107                                           Name,
108                                           Value,
109                                           PciRevision.Comments.GetTailComments())
110        DefinesDictNew[Statement] = ArchString
111
112    if PciCompress != None:
113        Name = DT.TAB_INF_DEFINES_PCI_COMPRESS
114        Value = PciCompress.GetValue()
115        Statement = _GenInfDefineStateMent(PciCompress.Comments.GetHeaderComments(),
116                                           Name,
117                                           Value,
118                                           PciCompress.Comments.GetTailComments())
119        DefinesDictNew[Statement] = ArchString
120
121    if len(CustomMakefile) >= 1:
122        for CustomMakefileItem in CustomMakefile:
123            Name = DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE
124            #
125            # Not with Feature Flag Expression
126            #
127            if len(CustomMakefileItem) == 3:
128                if CustomMakefileItem[0] != '':
129                    Value = CustomMakefileItem[0] + ' | ' + CustomMakefileItem[1]
130                else:
131                    Value = CustomMakefileItem[1]
132
133                Comments = CustomMakefileItem[2]
134                Statement = _GenInfDefineStateMent(Comments.GetHeaderComments(),
135                                                   Name,
136                                                   Value,
137                                                   Comments.GetTailComments())
138
139            DefinesDictNew[Statement] = ArchString
140
141    if UefiHiiResourceSection != None:
142        Name = DT.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
143        Value = UefiHiiResourceSection.GetValue()
144        HeaderComment = UefiHiiResourceSection.Comments.GetHeaderComments()
145        TailComment = UefiHiiResourceSection.Comments.GetTailComments()
146        Statement = _GenInfDefineStateMent(HeaderComment,
147                                           Name,
148                                           Value,
149                                           TailComment)
150        DefinesDictNew[Statement] = ""
151
152    return DefinesDictNew
153
154
155## Generate the define statement that will be put into userextension
156#  Not support comments.
157#
158# @param HeaderComment: the original header comment (# not remvoed)
159# @param Name: the definition keyword, should not be empty or none
160# @param Value: the definition keyword value
161# @param TailComment: the original Tail comment (# not remvoed)
162#
163# @return: the regenerated define statement
164#
165def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment):
166    Logger.Debug(5, HeaderComment + TailComment)
167    Statement = '%s = %s' % (Name, Value)
168
169    return Statement
170
171## GenBinaryData
172#
173#
174def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, \
175                  SupArchList, BinaryModule, DecObjList=None):
176    if BinaryModule:
177        pass
178    OriSupArchList = SupArchList
179    for Item in BinaryData:
180        ItemObj = BinaryObj[Item][0][0]
181        if ItemObj.GetType() not in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST:
182            TagName = ItemObj.GetTagName()
183            Family = ItemObj.GetFamily()
184        else:
185            TagName = ''
186            Family = ''
187
188        FFE = ItemObj.GetFeatureFlagExp()
189
190        #
191        # If have architecturie specified, then use the specified architecturie;
192        # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive),
193        # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment
194        # can be used for the attribute.
195        # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty.
196        #
197        SupArchList = ConvertArchList(ItemObj.GetSupArchList())
198        SupArchList.sort()
199        if len(SupArchList) == 1 and SupArchList[0] == 'COMMON':
200            if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'):
201                SupArchList = OriSupArchList
202            else:
203                SupArchList = ['COMMON']
204
205        FileNameObj = CommonObject.FileNameObject()
206        FileNameObj.SetFileType(ItemObj.GetType())
207        FileNameObj.SetFilename(ItemObj.GetFileName())
208        FileNameObj.SetFeatureFlag(FFE)
209        #
210        # Get GUID value of the GUID CName in the DEC file
211        #
212        if ItemObj.GetType() == DT.SUBTYPE_GUID_BINARY_FILE_TYPE:
213            if not CheckGuidRegFormat(ItemObj.GetGuidValue()):
214                if not DecObjList:
215                    if DT.TAB_HORIZON_LINE_SPLIT in ItemObj.GetGuidValue() or \
216                        DT.TAB_COMMA_SPLIT in ItemObj.GetGuidValue():
217                        Logger.Error("\nMkPkg",
218                                 FORMAT_INVALID,
219                                 ST.ERR_DECPARSE_DEFINE_PKGGUID,
220                                 ExtraData=ItemObj.GetGuidValue(),
221                                 RaiseError=True)
222                    else:
223                        Logger.Error("\nMkPkg",
224                                     FORMAT_INVALID,
225                                     ST.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND % \
226                                     (ItemObj.GetGuidValue()),
227                                     RaiseError=True)
228                else:
229                    for DecObj in DecObjList:
230                        for GuidObj in DecObj.GetGuidList():
231                            if GuidObj.GetCName() == ItemObj.GetGuidValue():
232                                FileNameObj.SetGuidValue(GuidObj.GetGuid())
233                                break
234
235                    if not FileNameObj.GetGuidValue():
236                        Logger.Error("\nMkPkg",
237                                         FORMAT_INVALID,
238                                         ST.ERR_DECPARSE_CGUID_NOT_FOUND % \
239                                         (ItemObj.GetGuidValue()),
240                                         RaiseError=True)
241            else:
242                FileNameObj.SetGuidValue(ItemObj.GetGuidValue().strip())
243
244        FileNameObj.SetSupArchList(SupArchList)
245        FileNameList = [FileNameObj]
246
247        BinaryFile = BinaryFileObject()
248        BinaryFile.SetFileNameList(FileNameList)
249        BinaryFile.SetAsBuiltList(AsBuildIns)
250        BinaryFileObjectList.append(BinaryFile)
251
252        SupArchStr = ' '.join(SupArchList)
253        Key = (ItemObj.GetFileName(), ItemObj.GetType(), FFE, SupArchStr)
254        ValueItem = (ItemObj.GetTarget(), Family, TagName, '')
255        if Key in BinariesDict:
256            ValueList = BinariesDict[Key]
257            ValueList.append(ValueItem)
258            BinariesDict[Key] = ValueList
259        else:
260            BinariesDict[Key] = [ValueItem]
261
262    return BinariesDict, AsBuildIns, BinaryFileObjectList
263