]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/OptionRom.py
BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / OptionRom.py
1 ## @file
2 # process OptionROM generation
3 #
4 # Copyright (c) 2007 - 2017, 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 Common.LongFilePathOs as os
19 import subprocess
20 import StringIO
21
22 import OptRomInfStatement
23 from GenFdsGlobalVariable import GenFdsGlobalVariable
24 from GenFds import GenFds
25 from CommonDataClass.FdfClass import OptionRomClassObject
26 from Common.Misc import SaveFileOnChange
27 from Common import EdkLogger
28 from Common.BuildToolError import *
29
30 T_CHAR_LF = '\n'
31
32 ##
33 #
34 #
35 class 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, Flag=False) :
53 if not Flag:
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(IsMakefile=Flag)
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 is 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 IsMakefile = Flag)
84 BinFileList.append(TmpOutputFile)
85 else:
86 FilePathName = FfsFile.GenFfs(IsMakefile=Flag)
87 if FfsFile.OverrideAttribs is not None:
88 FileName = os.path.basename(FilePathName)
89 TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName, FfsFile.CurrentArch)
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 IsMakefile=Flag)
103 BinFileList.append(TmpOutputFile)
104 else:
105 if FfsFile.FileType == 'EFI':
106 EfiFileList.append(FilePathName)
107 else:
108 BinFileList.append(FilePathName)
109
110 #
111 # Call EfiRom tool
112 #
113 OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName)
114 OutputFile = OutputFile + '.rom'
115
116 GenFdsGlobalVariable.GenerateOptionRom(
117 OutputFile,
118 EfiFileList,
119 BinFileList,
120 IsMakefile=Flag)
121
122 if not Flag:
123 GenFdsGlobalVariable.InfLogger( "\nGenerate %s Option ROM Successfully" %self.DriverName)
124 GenFdsGlobalVariable.SharpCounter = 0
125
126 return OutputFile
127
128 class OverrideAttribs:
129
130 ## The constructor
131 #
132 # @param self The object pointer
133 #
134 def __init__(self):
135
136 self.PciVendorId = None
137 self.PciClassCode = None
138 self.PciDeviceId = None
139 self.PciRevision = None
140 self.NeedCompress = None
141
142