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