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