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