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