]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Vtf.py
BaseTools: Remove unused logic for EDKI
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Vtf.py
1 ## @file
2 # process VTF 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 from .GenFdsGlobalVariable import GenFdsGlobalVariable
20 import Common.LongFilePathOs as os
21 from Common.LongFilePathSupport import OpenLongFilePath as open
22 from Common.DataType import TAB_LINE_BREAK
23
24 ## generate VTF
25 #
26 #
27 class Vtf (object):
28
29 ## The constructor
30 #
31 # @param self The object pointer
32 #
33 def __init__(self):
34 self.KeyArch = None
35 self.ArchList = None
36 self.UiName = None
37 self.ResetBin = None
38 self.ComponentStatementList = []
39
40 ## GenVtf() method
41 #
42 # Generate VTF
43 #
44 # @param self The object pointer
45 # @param FdAddressDict dictionary contains FV name and its base address
46 # @retval Dict FV and corresponding VTF file name
47 #
48 def GenVtf(self, FdAddressDict) :
49 self.GenBsfInf()
50 BaseAddArg = self.GetBaseAddressArg(FdAddressDict)
51 OutputArg, VtfRawDict = self.GenOutputArg()
52
53 Cmd = (
54 'GenVtf',
55 ) + OutputArg + (
56 '-f', self.BsfInfName,
57 ) + BaseAddArg
58
59 GenFdsGlobalVariable.CallExternalTool(Cmd, "GenFv -Vtf Failed!")
60 GenFdsGlobalVariable.SharpCounter = 0
61
62 return VtfRawDict
63
64 ## GenBsfInf() method
65 #
66 # Generate inf used to generate VTF
67 #
68 # @param self The object pointer
69 #
70 def GenBsfInf (self):
71 FvList = self.GetFvList()
72 self.BsfInfName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.inf')
73 BsfInf = open(self.BsfInfName, 'w+')
74 if self.ResetBin:
75 BsfInf.writelines ("[OPTIONS]" + TAB_LINE_BREAK)
76 BsfInf.writelines ("IA32_RST_BIN" + \
77 " = " + \
78 GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.ResetBin)) + \
79 TAB_LINE_BREAK)
80 BsfInf.writelines (TAB_LINE_BREAK)
81
82 BsfInf.writelines ("[COMPONENTS]" + TAB_LINE_BREAK)
83
84 for ComponentObj in self.ComponentStatementList :
85 BsfInf.writelines ("COMP_NAME" + \
86 " = " + \
87 ComponentObj.CompName + \
88 TAB_LINE_BREAK)
89 if ComponentObj.CompLoc.upper() == 'NONE':
90 BsfInf.writelines ("COMP_LOC" + \
91 " = " + \
92 'N' + \
93 TAB_LINE_BREAK)
94
95 elif ComponentObj.FilePos:
96 BsfInf.writelines ("COMP_LOC" + \
97 " = " + \
98 ComponentObj.FilePos + \
99 TAB_LINE_BREAK)
100 else:
101 Index = FvList.index(ComponentObj.CompLoc.upper())
102 if Index == 0:
103 BsfInf.writelines ("COMP_LOC" + \
104 " = " + \
105 'F' + \
106 TAB_LINE_BREAK)
107 elif Index == 1:
108 BsfInf.writelines ("COMP_LOC" + \
109 " = " + \
110 'S' + \
111 TAB_LINE_BREAK)
112
113 BsfInf.writelines ("COMP_TYPE" + \
114 " = " + \
115 ComponentObj.CompType + \
116 TAB_LINE_BREAK)
117 BsfInf.writelines ("COMP_VER" + \
118 " = " + \
119 ComponentObj.CompVer + \
120 TAB_LINE_BREAK)
121 BsfInf.writelines ("COMP_CS" + \
122 " = " + \
123 ComponentObj.CompCs + \
124 TAB_LINE_BREAK)
125
126 BinPath = ComponentObj.CompBin
127 if BinPath != '-':
128 BinPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(BinPath))
129 BsfInf.writelines ("COMP_BIN" + \
130 " = " + \
131 BinPath + \
132 TAB_LINE_BREAK)
133
134 SymPath = ComponentObj.CompSym
135 if SymPath != '-':
136 SymPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(SymPath))
137 BsfInf.writelines ("COMP_SYM" + \
138 " = " + \
139 SymPath + \
140 TAB_LINE_BREAK)
141 BsfInf.writelines ("COMP_SIZE" + \
142 " = " + \
143 ComponentObj.CompSize + \
144 TAB_LINE_BREAK)
145 BsfInf.writelines (TAB_LINE_BREAK)
146
147 BsfInf.close()
148
149 ## GenFvList() method
150 #
151 # Get FV list referenced by VTF components
152 #
153 # @param self The object pointer
154 #
155 def GetFvList(self):
156 FvList = []
157 for component in self.ComponentStatementList :
158 if component.CompLoc.upper() != 'NONE' and not (component.CompLoc.upper() in FvList):
159 FvList.append(component.CompLoc.upper())
160
161 return FvList
162
163 ## GetBaseAddressArg() method
164 #
165 # Get base address arguments for GenVtf
166 #
167 # @param self The object pointer
168 #
169 def GetBaseAddressArg(self, FdAddressDict):
170 FvList = self.GetFvList()
171 CmdStr = tuple()
172 for i in FvList:
173 (BaseAddress, Size) = FdAddressDict.get(i)
174 CmdStr += (
175 '-r', '0x%x' % BaseAddress,
176 '-s', '0x%x' % Size,
177 )
178 return CmdStr
179
180 ## GenOutputArg() method
181 #
182 # Get output arguments for GenVtf
183 #
184 # @param self The object pointer
185 #
186 def GenOutputArg(self):
187 FvVtfDict = {}
188 OutputFileName = ''
189 FvList = self.GetFvList()
190 Index = 0
191 Arg = tuple()
192 for FvObj in FvList:
193 Index = Index + 1
194 OutputFileName = 'Vtf%d.raw' % Index
195 OutputFileName = os.path.join(GenFdsGlobalVariable.FvDir, OutputFileName)
196 Arg += ('-o', OutputFileName)
197 FvVtfDict[FvObj.upper()] = OutputFileName
198
199 return Arg, FvVtfDict
200