Sync basetools' source and binary files with r1707 of the basetools project.
[edk2.git] / BaseTools / Source / Python / GenFds / OptRomInfStatement.py
blob8cd7429d58a44c794b66ffd364f4e7a8cbca8c1e
1 ## @file
2 # process OptionROM generation from INF statement
4 # Copyright (c) 2007, Intel Corporation
6 # All rights reserved. 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
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.
16 # Import Modules
18 import RuleSimpleFile
19 import RuleComplexFile
20 import Section
21 import OptionRom
22 import Common.GlobalData as GlobalData
24 from Common.DataType import *
25 from Common.String import *
26 from FfsInfStatement import FfsInfStatement
27 from GenFdsGlobalVariable import GenFdsGlobalVariable
29 ##
32 class OptRomInfStatement (FfsInfStatement):
33 ## The constructor
35 # @param self The object pointer
37 def __init__(self):
38 FfsInfStatement.__init__(self)
39 self.OverrideAttribs = None
41 ## __GetOptRomParams() method
43 # Parse inf file to get option ROM related parameters
45 # @param self The object pointer
47 def __GetOptRomParams(self):
49 if self.OverrideAttribs == None:
50 self.OverrideAttribs = OptionRom.OverrideAttribs()
52 if self.OverrideAttribs.NeedCompress == None:
53 self.OverrideAttribs.NeedCompress = self.OptRomDefs.get ('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 COMPRESS: %s" %self.InfFileName)
57 self.OverrideAttribs.NeedCompress = \
58 self.OverrideAttribs.NeedCompress.upper() == 'TRUE'
60 if self.OverrideAttribs.PciVendorId == None:
61 self.OverrideAttribs.PciVendorId = self.OptRomDefs.get ('PCI_VENDOR_ID')
63 if self.OverrideAttribs.PciClassCode == None:
64 self.OverrideAttribs.PciClassCode = self.OptRomDefs.get ('PCI_CLASS_CODE')
66 if self.OverrideAttribs.PciDeviceId == None:
67 self.OverrideAttribs.PciDeviceId = self.OptRomDefs.get ('PCI_DEVICE_ID')
69 if self.OverrideAttribs.PciRevision == None:
70 self.OverrideAttribs.PciRevision = self.OptRomDefs.get ('PCI_REVISION')
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
79 # Generate FFS
81 # @param self The object pointer
82 # @retval string Generated .efi file name
84 def GenFfs(self):
86 # Parse Inf file get Module related information
89 self.__InfParse__()
90 self.__GetOptRomParams()
92 # Get the rule of how to generate Ffs file
94 Rule = self.__GetRule__()
95 GenFdsGlobalVariable.VerboseLogger( "Packing binaries from inf file : %s" %self.InfFileName)
96 #FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]
98 # For the rule only has simpleFile
100 if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :
101 EfiOutputList = self.__GenSimpleFileSection__(Rule)
102 return EfiOutputList
104 # For Rule has ComplexFile
106 elif isinstance(Rule, RuleComplexFile.RuleComplexFile):
107 EfiOutputList = self.__GenComplexFileSection__(Rule)
108 return EfiOutputList
110 ## __GenSimpleFileSection__() method
112 # Get .efi files according to simple rule.
114 # @param self The object pointer
115 # @param Rule The rule object used to generate section
116 # @retval string File name of the generated section file
118 def __GenSimpleFileSection__(self, Rule):
120 # Prepare the parameter of GenSection
123 OutputFileList = []
124 if Rule.FileName != None:
125 GenSecInputFile = self.__ExtendMacro__(Rule.FileName)
126 OutputFileList.append(GenSecInputFile)
127 else:
128 OutputFileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension)
130 return OutputFileList
133 ## __GenComplexFileSection__() method
135 # Get .efi by sections in complex Rule
137 # @param self The object pointer
138 # @param Rule The rule object used to generate section
139 # @retval string File name of the generated section file
141 def __GenComplexFileSection__(self, Rule):
143 OutputFileList = []
144 for Sect in Rule.SectionList:
145 if Sect.SectionType == 'PE32':
146 if Sect.FileName != None:
147 GenSecInputFile = self.__ExtendMacro__(Sect.FileName)
148 OutputFileList.append(GenSecInputFile)
149 else:
150 FileList, IsSect = Section.Section.GetFileList(self, '', Sect.FileExtension)
151 OutputFileList.extend(FileList)
153 return OutputFileList