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