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