]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Vtf.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Vtf.py
1 ## @file
2 # process VTF generation
3 #
4 # Copyright (c) 2007, Intel Corporation
5 #
6 # All rights reserved. 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 BsfInf.writelines ("[COMPONENTS]" + T_CHAR_LF)
71
72 for ComponentObj in self.ComponentStatementList :
73 BsfInf.writelines ("COMP_NAME" + \
74 " = " + \
75 ComponentObj.CompName + \
76 T_CHAR_LF )
77 if ComponentObj.CompLoc.upper() == 'NONE':
78 BsfInf.writelines ("COMP_LOC" + \
79 " = " + \
80 'N' + \
81 T_CHAR_LF )
82
83 elif ComponentObj.FilePos != None:
84 BsfInf.writelines ("COMP_LOC" + \
85 " = " + \
86 ComponentObj.FilePos + \
87 T_CHAR_LF )
88 else:
89 Index = FvList.index(ComponentObj.CompLoc.upper())
90 if Index == 0:
91 BsfInf.writelines ("COMP_LOC" + \
92 " = " + \
93 'F' + \
94 T_CHAR_LF )
95 elif Index == 1:
96 BsfInf.writelines ("COMP_LOC" + \
97 " = " + \
98 'S' + \
99 T_CHAR_LF )
100
101 BsfInf.writelines ("COMP_TYPE" + \
102 " = " + \
103 ComponentObj.CompType + \
104 T_CHAR_LF )
105 BsfInf.writelines ("COMP_VER" + \
106 " = " + \
107 ComponentObj.CompVer + \
108 T_CHAR_LF )
109 BsfInf.writelines ("COMP_CS" + \
110 " = " + \
111 ComponentObj.CompCs + \
112 T_CHAR_LF )
113
114 BinPath = ComponentObj.CompBin
115 if BinPath != '-':
116 BinPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(BinPath))
117 BsfInf.writelines ("COMP_BIN" + \
118 " = " + \
119 BinPath + \
120 T_CHAR_LF )
121
122 SymPath = ComponentObj.CompSym
123 if SymPath != '-':
124 SymPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(SymPath))
125 BsfInf.writelines ("COMP_SYM" + \
126 " = " + \
127 SymPath + \
128 T_CHAR_LF )
129 BsfInf.writelines ("COMP_SIZE" + \
130 " = " + \
131 ComponentObj.CompSize + \
132 T_CHAR_LF )
133 BsfInf.writelines (T_CHAR_LF )
134
135 BsfInf.close()
136
137 ## GenFvList() method
138 #
139 # Get FV list referenced by VTF components
140 #
141 # @param self The object pointer
142 #
143 def GetFvList(self):
144 FvList = []
145 for component in self.ComponentStatementList :
146 if component.CompLoc.upper() != 'NONE' and not (component.CompLoc.upper() in FvList):
147 FvList.append(component.CompLoc.upper())
148
149 return FvList
150
151 ## GetBaseAddressArg() method
152 #
153 # Get base address arguments for GenVtf
154 #
155 # @param self The object pointer
156 #
157 def GetBaseAddressArg(self, FdAddressDict):
158 FvList = self.GetFvList()
159 CmdStr = tuple()
160 for i in FvList:
161 (BaseAddress, Size) = FdAddressDict.get(i)
162 CmdStr += (
163 '-r', '0x%x' % BaseAddress,
164 '-s', '0x%x' %Size,
165 )
166 return CmdStr
167
168 ## GenOutputArg() method
169 #
170 # Get output arguments for GenVtf
171 #
172 # @param self The object pointer
173 #
174 def GenOutputArg(self):
175 FvVtfDict = {}
176 OutputFileName = ''
177 FvList = self.GetFvList()
178 Index = 0
179 Arg = tuple()
180 for FvObj in FvList:
181 Index = Index + 1
182 OutputFileName = 'Vtf%d.raw' % Index
183 OutputFileName = os.path.join(GenFdsGlobalVariable.FvDir, OutputFileName)
184 Arg += ('-o', OutputFileName)
185 FvVtfDict[FvObj.upper()] = OutputFileName
186
187 return Arg, FvVtfDict
188