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