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