]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/OptionRom.py
BaseTools: Replace StringIO.StringIO with io.BytesIO
[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
21 import OptRomInfStatement
22 from GenFdsGlobalVariable import GenFdsGlobalVariable
23 from GenFds import GenFds
24 from CommonDataClass.FdfClass import OptionRomClassObject
25 from Common.Misc import SaveFileOnChange
26 from Common import EdkLogger
27 from Common.BuildToolError import *
28
29 T_CHAR_LF = '\n'
30
31 ##
32 #
33 #
34 class OPTIONROM (OptionRomClassObject):
35 ## The constructor
36 #
37 # @param self The object pointer
38 #
39 def __init__(self):
40 OptionRomClassObject.__init__(self)
41
42
43 ## AddToBuffer()
44 #
45 # Generate Option ROM
46 #
47 # @param self The object pointer
48 # @param Buffer The buffer generated OptROM data will be put
49 # @retval string Generated OptROM file path
50 #
51 def AddToBuffer (self, Buffer, Flag=False) :
52 if not Flag:
53 GenFdsGlobalVariable.InfLogger( "\nGenerating %s Option ROM ..." %self.DriverName)
54
55 EfiFileList = []
56 BinFileList = []
57
58 # Process Modules in FfsList
59 for FfsFile in self.FfsList :
60
61 if isinstance(FfsFile, OptRomInfStatement.OptRomInfStatement):
62 FilePathNameList = FfsFile.GenFfs(IsMakefile=Flag)
63 if len(FilePathNameList) == 0:
64 EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s not produce .efi files, so NO file could be put into option ROM." % (FfsFile.InfFileName))
65 if FfsFile.OverrideAttribs is None:
66 EfiFileList.extend(FilePathNameList)
67 else:
68 FileName = os.path.basename(FilePathNameList[0])
69 TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName, FfsFile.CurrentArch)
70 if not os.path.exists(TmpOutputDir) :
71 os.makedirs(TmpOutputDir)
72 TmpOutputFile = os.path.join(TmpOutputDir, FileName+'.tmp')
73
74 GenFdsGlobalVariable.GenerateOptionRom(TmpOutputFile,
75 FilePathNameList,
76 [],
77 FfsFile.OverrideAttribs.NeedCompress,
78 FfsFile.OverrideAttribs.PciClassCode,
79 FfsFile.OverrideAttribs.PciRevision,
80 FfsFile.OverrideAttribs.PciDeviceId,
81 FfsFile.OverrideAttribs.PciVendorId,
82 IsMakefile = Flag)
83 BinFileList.append(TmpOutputFile)
84 else:
85 FilePathName = FfsFile.GenFfs(IsMakefile=Flag)
86 if FfsFile.OverrideAttribs is not 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 IsMakefile=Flag)
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 IsMakefile=Flag)
120
121 if not Flag:
122 GenFdsGlobalVariable.InfLogger( "\nGenerate %s Option ROM Successfully" %self.DriverName)
123 GenFdsGlobalVariable.SharpCounter = 0
124
125 return OutputFile
126
127 class OverrideAttribs:
128
129 ## The constructor
130 #
131 # @param self The object pointer
132 #
133 def __init__(self):
134
135 self.PciVendorId = None
136 self.PciClassCode = None
137 self.PciDeviceId = None
138 self.PciRevision = None
139 self.NeedCompress = None