BaseTools: Move OverrideAttribs to OptRomInfStatement.py
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / OptRomInfStatement.py
1 ## @file
2 # process OptionROM generation from INF statement
3 #
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this 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 ##
16 # Import Modules
17 #
18 from __future__ import absolute_import
19 from . import RuleSimpleFile
20 from . import RuleComplexFile
21 from . import Section
22 import Common.GlobalData as GlobalData
23
24 from Common.DataType import *
25 from Common.StringUtils import *
26 from .FfsInfStatement import FfsInfStatement
27 from .GenFdsGlobalVariable import GenFdsGlobalVariable
28
29 ##
30 #
31 #
32 class OptRomInfStatement (FfsInfStatement):
33 ## The constructor
34 #
35 # @param self The object pointer
36 #
37 def __init__(self):
38 FfsInfStatement.__init__(self)
39 self.OverrideAttribs = None
40
41 ## __GetOptRomParams() method
42 #
43 # Parse inf file to get option ROM related parameters
44 #
45 # @param self The object pointer
46 #
47 def __GetOptRomParams(self):
48 if self.OverrideAttribs is None:
49 self.OverrideAttribs = OverrideAttribs()
50
51 if self.OverrideAttribs.NeedCompress is None:
52 self.OverrideAttribs.NeedCompress = self.OptRomDefs.get ('PCI_COMPRESS')
53 if self.OverrideAttribs.NeedCompress is not None:
54 if self.OverrideAttribs.NeedCompress.upper() not in ('TRUE', 'FALSE'):
55 GenFdsGlobalVariable.ErrorLogger( "Expected TRUE/FALSE for PCI_COMPRESS: %s" %self.InfFileName)
56 self.OverrideAttribs.NeedCompress = \
57 self.OverrideAttribs.NeedCompress.upper() == 'TRUE'
58
59 if self.OverrideAttribs.PciVendorId is None:
60 self.OverrideAttribs.PciVendorId = self.OptRomDefs.get ('PCI_VENDOR_ID')
61
62 if self.OverrideAttribs.PciClassCode is None:
63 self.OverrideAttribs.PciClassCode = self.OptRomDefs.get ('PCI_CLASS_CODE')
64
65 if self.OverrideAttribs.PciDeviceId is None:
66 self.OverrideAttribs.PciDeviceId = self.OptRomDefs.get ('PCI_DEVICE_ID')
67
68 if self.OverrideAttribs.PciRevision is None:
69 self.OverrideAttribs.PciRevision = self.OptRomDefs.get ('PCI_REVISION')
70
71 # InfObj = GenFdsGlobalVariable.WorkSpace.BuildObject[self.PathClassObj, self.CurrentArch]
72 # RecordList = InfObj._RawData[MODEL_META_DATA_HEADER, InfObj._Arch, InfObj._Platform]
73 # for Record in RecordList:
74 # Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
75 # Name = Record[0]
76 ## GenFfs() method
77 #
78 # Generate FFS
79 #
80 # @param self The object pointer
81 # @retval string Generated .efi file name
82 #
83 def GenFfs(self, IsMakefile=False):
84 #
85 # Parse Inf file get Module related information
86 #
87
88 self.__InfParse__()
89 self.__GetOptRomParams()
90 #
91 # Get the rule of how to generate Ffs file
92 #
93 Rule = self.__GetRule__()
94 GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName)
95 #
96 # For the rule only has simpleFile
97 #
98 if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :
99 EfiOutputList = self.__GenSimpleFileSection__(Rule, IsMakefile=IsMakefile)
100 return EfiOutputList
101 #
102 # For Rule has ComplexFile
103 #
104 elif isinstance(Rule, RuleComplexFile.RuleComplexFile):
105 EfiOutputList = self.__GenComplexFileSection__(Rule, IsMakefile=IsMakefile)
106 return EfiOutputList
107
108 ## __GenSimpleFileSection__() method
109 #
110 # Get .efi files according to simple rule.
111 #
112 # @param self The object pointer
113 # @param Rule The rule object used to generate section
114 # @retval string File name of the generated section file
115 #
116 def __GenSimpleFileSection__(self, Rule, IsMakefile = False):
117 #
118 # Prepare the parameter of GenSection
119 #
120
121 OutputFileList = []
122 if Rule.FileName is not None:
123 GenSecInputFile = self.__ExtendMacro__(Rule.FileName)
124 OutputFileList.append(GenSecInputFile)
125 else:
126 OutputFileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)
127
128 return OutputFileList
129
130
131 ## __GenComplexFileSection__() method
132 #
133 # Get .efi by sections in complex Rule
134 #
135 # @param self The object pointer
136 # @param Rule The rule object used to generate section
137 # @retval string File name of the generated section file
138 #
139 def __GenComplexFileSection__(self, Rule, IsMakefile=False):
140
141 OutputFileList = []
142 for Sect in Rule.SectionList:
143 if Sect.SectionType == BINARY_FILE_TYPE_PE32:
144 if Sect.FileName is not None:
145 GenSecInputFile = self.__ExtendMacro__(Sect.FileName)
146 OutputFileList.append(GenSecInputFile)
147 else:
148 FileList, IsSect = Section.Section.GetFileList(self, '', Sect.FileExtension)
149 OutputFileList.extend(FileList)
150
151 return OutputFileList
152
153 class OverrideAttribs:
154
155 ## The constructor
156 #
157 # @param self The object pointer
158 #
159 def __init__(self):
160
161 self.PciVendorId = None
162 self.PciClassCode = None
163 self.PciDeviceId = None
164 self.PciRevision = None
165 self.NeedCompress = None