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