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