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