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