]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/OptionRom.py
BaseTools: Clean up source files
[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
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
1be2ed90 18import Common.LongFilePathOs as os\r
30fdf114 19import subprocess\r
30fdf114
LG
20\r
21import OptRomInfStatement\r
22from GenFdsGlobalVariable import GenFdsGlobalVariable\r
23from GenFds import GenFds\r
24from CommonDataClass.FdfClass import OptionRomClassObject\r
25from Common.Misc import SaveFileOnChange\r
26from Common import EdkLogger\r
27from Common.BuildToolError import *\r
28\r
29T_CHAR_LF = '\n'\r
30\r
f7496d71 31##\r
30fdf114
LG
32#\r
33#\r
34class OPTIONROM (OptionRomClassObject):\r
35 ## The constructor\r
36 #\r
37 # @param self The object pointer\r
38 #\r
39 def __init__(self):\r
40 OptionRomClassObject.__init__(self)\r
41\r
42\r
43 ## AddToBuffer()\r
44 #\r
45 # Generate Option ROM\r
46 #\r
47 # @param self The object pointer\r
48 # @param Buffer The buffer generated OptROM data will be put\r
49 # @retval string Generated OptROM file path\r
50 #\r
37de70b7
YZ
51 def AddToBuffer (self, Buffer, Flag=False) :\r
52 if not Flag:\r
53 GenFdsGlobalVariable.InfLogger( "\nGenerating %s Option ROM ..." %self.DriverName)\r
30fdf114
LG
54\r
55 EfiFileList = []\r
56 BinFileList = []\r
57\r
58 # Process Modules in FfsList\r
59 for FfsFile in self.FfsList :\r
f7496d71 60\r
30fdf114 61 if isinstance(FfsFile, OptRomInfStatement.OptRomInfStatement):\r
37de70b7 62 FilePathNameList = FfsFile.GenFfs(IsMakefile=Flag)\r
30fdf114
LG
63 if len(FilePathNameList) == 0:\r
64 EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s not produce .efi files, so NO file could be put into option ROM." % (FfsFile.InfFileName))\r
4231a819 65 if FfsFile.OverrideAttribs is None:\r
30fdf114
LG
66 EfiFileList.extend(FilePathNameList)\r
67 else:\r
68 FileName = os.path.basename(FilePathNameList[0])\r
2a6402d4 69 TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName, FfsFile.CurrentArch)\r
30fdf114
LG
70 if not os.path.exists(TmpOutputDir) :\r
71 os.makedirs(TmpOutputDir)\r
72 TmpOutputFile = os.path.join(TmpOutputDir, FileName+'.tmp')\r
f7496d71
LG
73\r
74 GenFdsGlobalVariable.GenerateOptionRom(TmpOutputFile,\r
75 FilePathNameList,\r
76 [],\r
77 FfsFile.OverrideAttribs.NeedCompress,\r
78 FfsFile.OverrideAttribs.PciClassCode,\r
79 FfsFile.OverrideAttribs.PciRevision,\r
80 FfsFile.OverrideAttribs.PciDeviceId,\r
37de70b7
YZ
81 FfsFile.OverrideAttribs.PciVendorId,\r
82 IsMakefile = Flag)\r
30fdf114
LG
83 BinFileList.append(TmpOutputFile)\r
84 else:\r
37de70b7 85 FilePathName = FfsFile.GenFfs(IsMakefile=Flag)\r
4231a819 86 if FfsFile.OverrideAttribs is not None:\r
30fdf114 87 FileName = os.path.basename(FilePathName)\r
2a6402d4 88 TmpOutputDir = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName, FfsFile.CurrentArch)\r
30fdf114
LG
89 if not os.path.exists(TmpOutputDir) :\r
90 os.makedirs(TmpOutputDir)\r
91 TmpOutputFile = os.path.join(TmpOutputDir, FileName+'.tmp')\r
f7496d71
LG
92\r
93 GenFdsGlobalVariable.GenerateOptionRom(TmpOutputFile,\r
94 [FilePathName],\r
95 [],\r
96 FfsFile.OverrideAttribs.NeedCompress,\r
97 FfsFile.OverrideAttribs.PciClassCode,\r
98 FfsFile.OverrideAttribs.PciRevision,\r
99 FfsFile.OverrideAttribs.PciDeviceId,\r
37de70b7
YZ
100 FfsFile.OverrideAttribs.PciVendorId,\r
101 IsMakefile=Flag)\r
30fdf114
LG
102 BinFileList.append(TmpOutputFile)\r
103 else:\r
104 if FfsFile.FileType == 'EFI':\r
105 EfiFileList.append(FilePathName)\r
106 else:\r
107 BinFileList.append(FilePathName)\r
f7496d71 108\r
30fdf114
LG
109 #\r
110 # Call EfiRom tool\r
111 #\r
112 OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.DriverName)\r
113 OutputFile = OutputFile + '.rom'\r
f7496d71 114\r
30fdf114
LG
115 GenFdsGlobalVariable.GenerateOptionRom(\r
116 OutputFile,\r
117 EfiFileList,\r
37de70b7
YZ
118 BinFileList,\r
119 IsMakefile=Flag)\r
30fdf114 120\r
37de70b7
YZ
121 if not Flag:\r
122 GenFdsGlobalVariable.InfLogger( "\nGenerate %s Option ROM Successfully" %self.DriverName)\r
30fdf114 123 GenFdsGlobalVariable.SharpCounter = 0\r
f7496d71 124\r
30fdf114
LG
125 return OutputFile\r
126\r
127class OverrideAttribs:\r
f7496d71 128\r
30fdf114
LG
129 ## The constructor\r
130 #\r
131 # @param self The object pointer\r
132 #\r
133 def __init__(self):\r
f7496d71 134\r
30fdf114
LG
135 self.PciVendorId = None\r
136 self.PciClassCode = None\r
137 self.PciDeviceId = None\r
138 self.PciRevision = None\r
fd171542 139 self.NeedCompress = None\r