1## @file
2# process OptionROM generation
3#
4#  Copyright (c) 2007 - 2016, 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#
18import Common.LongFilePathOs as os
19import subprocess
20import StringIO
21
22import OptRomInfStatement
23from GenFdsGlobalVariable import GenFdsGlobalVariable
24from GenFds import GenFds
25from CommonDataClass.FdfClass import OptionRomClassObject
26from Common.Misc import SaveFileOnChange
27from Common import EdkLogger
28from Common.BuildToolError import *
29
30T_CHAR_LF = '\n'
31
32##
33#
34#
35class OPTIONROM (OptionRomClassObject):
36    ## The constructor
37    #
38    #   @param  self        The object pointer
39    #
40    def __init__(self):
41        OptionRomClassObject.__init__(self)
42
43
44    ## AddToBuffer()
45    #
46    #   Generate Option ROM
47    #
48    #   @param  self        The object pointer
49    #   @param  Buffer      The buffer generated OptROM data will be put
50    #   @retval string      Generated OptROM file path
51    #
52    def AddToBuffer (self, Buffer) :
53
54        GenFdsGlobalVariable.InfLogger( "\nGenerating %s Option ROM ..." %self.DriverName)
55
56        EfiFileList = []
57        BinFileList = []
58
59        # Process Modules in FfsList
60        for FfsFile in self.FfsList :
61
62            if isinstance(FfsFile, OptRomInfStatement.OptRomInfStatement):
63                FilePathNameList = FfsFile.GenFfs()
64                if len(FilePathNameList) == 0:
65                    EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s not produce .efi files, so NO file could be put into option ROM." % (FfsFile.InfFileName))
66                if FfsFile.OverrideAttribs == None:
67                    EfiFileList.extend(FilePathNameList)
68                else:
69                    FileName = os.path.basename(FilePathNameList[0])
70                    TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName, FfsFile.CurrentArch)
71                    if not os.path.exists(TmpOutputDir) :
72                        os.makedirs(TmpOutputDir)
73                    TmpOutputFile = os.path.join(TmpOutputDir, FileName+'.tmp')
74
75                    GenFdsGlobalVariable.GenerateOptionRom(TmpOutputFile,
76                                                           FilePathNameList,
77                                                           [],
78                                                           FfsFile.OverrideAttribs.NeedCompress,
79                                                           FfsFile.OverrideAttribs.PciClassCode,
80                                                           FfsFile.OverrideAttribs.PciRevision,
81                                                           FfsFile.OverrideAttribs.PciDeviceId,
82                                                           FfsFile.OverrideAttribs.PciVendorId)
83                    BinFileList.append(TmpOutputFile)
84            else:
85                FilePathName = FfsFile.GenFfs()
86                if FfsFile.OverrideAttribs != None:
87                    FileName = os.path.basename(FilePathName)
88                    TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName, FfsFile.CurrentArch)
89                    if not os.path.exists(TmpOutputDir) :
90                        os.makedirs(TmpOutputDir)
91                    TmpOutputFile = os.path.join(TmpOutputDir, FileName+'.tmp')
92
93                    GenFdsGlobalVariable.GenerateOptionRom(TmpOutputFile,
94                                                           [FilePathName],
95                                                           [],
96                                                           FfsFile.OverrideAttribs.NeedCompress,
97                                                           FfsFile.OverrideAttribs.PciClassCode,
98                                                           FfsFile.OverrideAttribs.PciRevision,
99                                                           FfsFile.OverrideAttribs.PciDeviceId,
100                                                           FfsFile.OverrideAttribs.PciVendorId)
101                    BinFileList.append(TmpOutputFile)
102                else:
103                    if FfsFile.FileType == 'EFI':
104                        EfiFileList.append(FilePathName)
105                    else:
106                        BinFileList.append(FilePathName)
107
108        #
109        # Call EfiRom tool
110        #
111        OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName)
112        OutputFile = OutputFile + '.rom'
113
114        GenFdsGlobalVariable.GenerateOptionRom(
115                                OutputFile,
116                                EfiFileList,
117                                BinFileList
118                                )
119
120        GenFdsGlobalVariable.InfLogger( "\nGenerate %s Option ROM Successfully" %self.DriverName)
121        GenFdsGlobalVariable.SharpCounter = 0
122
123        return OutputFile
124
125class OverrideAttribs:
126
127    ## The constructor
128    #
129    #   @param  self        The object pointer
130    #
131    def __init__(self):
132
133        self.PciVendorId = None
134        self.PciClassCode = None
135        self.PciDeviceId = None
136        self.PciRevision = None
137        self.NeedCompress = None
138
139