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