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