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