]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | EfiRomTask class.\r | |
3 | \r | |
4 | EfiRomTask is used to call FlashMap.exe to lay out the flash.\r | |
5 | \r | |
6 | \r | |
7 | Copyright (c) 2006, Intel Corporation\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | package org.tianocore.framework.tasks;\r | |
18 | \r | |
19 | import java.io.File;\r | |
20 | import java.io.InputStreamReader;\r | |
21 | import java.util.ArrayList;\r | |
22 | import java.util.Iterator;\r | |
23 | import java.util.LinkedList;\r | |
24 | import java.util.List;\r | |
25 | \r | |
26 | import org.apache.tools.ant.BuildException;\r | |
27 | import org.apache.tools.ant.Project;\r | |
28 | import org.apache.tools.ant.Task;\r | |
29 | import org.tianocore.common.logger.EdkLog;\r | |
30 | import org.apache.tools.ant.taskdefs.Execute;\r | |
31 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
32 | import org.apache.tools.ant.types.Commandline;\r | |
33 | \r | |
34 | import com.sun.org.apache.bcel.internal.generic.NEW;\r | |
35 | \r | |
36 | /**\r | |
37 | SecFixupTask class.\r | |
38 | \r | |
39 | SecFixupTask is used to call SecFixup.exe to fix up sec image.\r | |
40 | **/\r | |
41 | public class EfiRomTask extends Task implements EfiDefine {\r | |
42 | //\r | |
43 | // tool name\r | |
44 | //\r | |
45 | private final static String toolName = "EfiRom";\r | |
46 | \r | |
47 | //\r | |
48 | // Flash default file\r | |
49 | //\r | |
50 | private ToolArg verbose = new ToolArg();\r | |
51 | \r | |
52 | //\r | |
53 | // Flash device\r | |
54 | //\r | |
55 | private ToolArg venderId = new ToolArg();\r | |
56 | \r | |
57 | //\r | |
58 | // Flash device Image\r | |
59 | //\r | |
60 | private ToolArg deviceId = new ToolArg();\r | |
61 | \r | |
62 | //\r | |
63 | // output file\r | |
64 | //\r | |
65 | private FileArg outputFile = new FileArg();\r | |
66 | \r | |
67 | //\r | |
68 | // binary file\r | |
69 | //\r | |
70 | private Input binaryFileList = new Input();\r | |
71 | \r | |
72 | //\r | |
73 | // Efi PE32 image file\r | |
74 | //\r | |
75 | private Input pe32FileList = new Input();\r | |
76 | \r | |
77 | //\r | |
78 | // Compress efi PE32 image file\r | |
79 | //\r | |
80 | private Input pe32ComprFileList = new Input();\r | |
81 | \r | |
82 | //\r | |
83 | // Hex class code in the PCI data strutor header\r | |
84 | //\r | |
85 | private ToolArg classCode = new ToolArg();\r | |
86 | \r | |
87 | //\r | |
88 | // Hex revision in the PCI data header.\r | |
89 | //\r | |
90 | private ToolArg revision = new ToolArg();\r | |
91 | \r | |
92 | //\r | |
93 | // Dump the headers of an existing option rom image.\r | |
94 | //\r | |
95 | private ToolArg dump = new ToolArg();\r | |
96 | \r | |
97 | //\r | |
98 | // output directory\r | |
99 | //\r | |
100 | private String outputDir = ".";\r | |
101 | \r | |
102 | //\r | |
103 | // command and argument list\r | |
104 | //\r | |
105 | LinkedList<String> argList = new LinkedList<String>();\r | |
106 | \r | |
107 | /**\r | |
108 | execute\r | |
109 | \r | |
110 | EfiRomTask execute function is to assemble tool command line & execute\r | |
111 | tool command line\r | |
112 | \r | |
113 | @throws BuidException\r | |
114 | **/\r | |
115 | public void execute() throws BuildException {\r | |
116 | \r | |
117 | Project project = this.getOwningTarget().getProject();\r | |
118 | \r | |
119 | //\r | |
120 | // absolute path of efi tools\r | |
121 | //\r | |
122 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
123 | String command;\r | |
124 | if (path == null) {\r | |
125 | command = toolName;\r | |
126 | } else {\r | |
127 | command = path + File.separator + toolName;\r | |
128 | }\r | |
129 | \r | |
130 | String argument = "" + verbose + venderId + deviceId + dump + revision + classCode \r | |
131 | + binaryFileList.toStringWithSinglepPrefix(" -b ")\r | |
132 | + pe32FileList.toStringWithSinglepPrefix(" -e ")\r | |
133 | + pe32ComprFileList.toStringWithSinglepPrefix(" -ec ")\r | |
134 | + outputFile;\r | |
135 | \r | |
136 | try {\r | |
137 | Commandline cmdline = new Commandline();\r | |
138 | cmdline.setExecutable(command);\r | |
139 | cmdline.createArgument().setLine(argument);\r | |
140 | \r | |
141 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
142 | Project.MSG_INFO, Project.MSG_WARN);\r | |
143 | Execute runner = new Execute(streamHandler, null);\r | |
144 | \r | |
145 | runner.setAntRun(project);\r | |
146 | runner.setCommandline(cmdline.getCommandline());\r | |
147 | runner.setWorkingDirectory(new File(outputDir));\r | |
148 | \r | |
149 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r | |
150 | EdkLog.log(this, EdkLog.EDK_INFO, binaryFileList.toFileList() \r | |
151 | + pe32FileList.toFileList() + pe32ComprFileList.toFileList()\r | |
152 | + " => " + outputFile.toFileList());\r | |
153 | \r | |
154 | int exitCode = runner.execute();\r | |
155 | if (exitCode != 0) {\r | |
156 | //\r | |
157 | // command execution fail\r | |
158 | //\r | |
159 | EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));\r | |
160 | throw new BuildException(toolName + " failed!");\r | |
161 | } else {\r | |
162 | EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");\r | |
163 | }\r | |
164 | } catch (Exception e) {\r | |
165 | throw new BuildException(e.getMessage());\r | |
166 | }\r | |
167 | }\r | |
168 | \r | |
169 | /**\r | |
170 | getVerbose\r | |
171 | \r | |
172 | This function is to get class member "verbose"\r | |
173 | \r | |
174 | @return verbose for verbose output.\r | |
175 | **/\r | |
176 | public String getVerbose() {\r | |
177 | return verbose.getValue();\r | |
178 | }\r | |
179 | \r | |
180 | /**\r | |
181 | setVerbose\r | |
182 | \r | |
183 | This function is to set class member "verbose"\r | |
184 | \r | |
185 | @param verbose for verbose output.\r | |
186 | **/\r | |
187 | public void setVerbose(boolean verbose) {\r | |
188 | if (verbose){\r | |
189 | this.verbose.setArg(" -", "p");\r | |
190 | }\r | |
191 | }\r | |
192 | \r | |
193 | /**\r | |
194 | getVenderId\r | |
195 | \r | |
196 | This function is to get class member "venderId"\r | |
197 | \r | |
198 | @return venderId String of venderId.\r | |
199 | **/\r | |
200 | public String getVenderId() {\r | |
201 | return venderId.getValue();\r | |
202 | }\r | |
203 | \r | |
204 | /**\r | |
205 | setVenderId\r | |
206 | \r | |
207 | This function is to set class member "venderId"\r | |
208 | \r | |
209 | @param venderId String of venderId.\r | |
210 | **/\r | |
211 | public void setVenderId(String venderId) {\r | |
212 | this.venderId.setArg(" -v ", venderId);\r | |
213 | }\r | |
214 | \r | |
215 | /**\r | |
216 | getDeviceId\r | |
217 | \r | |
218 | This function is to get class member "deviceId"\r | |
219 | \r | |
220 | @return deviceId String of device ID.\r | |
221 | **/\r | |
222 | public String getDeviceId() {\r | |
223 | return this.deviceId.getValue();\r | |
224 | }\r | |
225 | \r | |
226 | /**\r | |
227 | setDeviceId\r | |
228 | \r | |
229 | This function is to set class member "deviceId"\r | |
230 | \r | |
231 | @param deviceId String of device ID.\r | |
232 | **/\r | |
233 | public void setDeviceId(String deviceId) {\r | |
234 | this.deviceId.setArg(" -d ", deviceId);\r | |
235 | }\r | |
236 | \r | |
237 | \r | |
238 | /**\r | |
239 | getOutputFile\r | |
240 | \r | |
241 | This function is to get class member "outputFile"\r | |
242 | \r | |
243 | @return outputFile name of output directory.\r | |
244 | **/\r | |
245 | public String getOutputFile() {\r | |
246 | return outputFile.getValue();\r | |
247 | }\r | |
248 | \r | |
249 | /**\r | |
250 | setOutputFile\r | |
251 | \r | |
252 | This function is to set class member "dscFile"\r | |
253 | \r | |
254 | @param outputFile name of DSC file\r | |
255 | **/\r | |
256 | public void setOutputFile(String outputFile) {\r | |
257 | this.outputFile.setArg(" -o ", outputFile);\r | |
258 | }\r | |
259 | \r | |
260 | /**\r | |
261 | getClassCode\r | |
262 | \r | |
263 | This function is to get class member "classCode"\r | |
264 | \r | |
265 | @return fdImage name of class code file.\r | |
266 | **/\r | |
267 | public String getClassCode() {\r | |
268 | return classCode.getValue();\r | |
269 | }\r | |
270 | \r | |
271 | /**\r | |
272 | setclassCode\r | |
273 | \r | |
274 | This function is to set class member "classCode"\r | |
275 | \r | |
276 | @param fdImage name of class code file.\r | |
277 | **/\r | |
278 | public void setclassCode(String classCode) {\r | |
279 | this.classCode.setArg(" -cc ", classCode);\r | |
280 | }\r | |
281 | \r | |
282 | /**\r | |
283 | getRevision\r | |
284 | \r | |
285 | This function is to get class member "revision".\r | |
286 | \r | |
287 | @return revision hex revision in the PDI data header.\r | |
288 | **/\r | |
289 | public String getRevision() {\r | |
290 | return revision.getValue();\r | |
291 | }\r | |
292 | \r | |
293 | /**\r | |
294 | setRevision\r | |
295 | \r | |
296 | This function is to set class member "revision"\r | |
297 | \r | |
298 | @param revision hex revision in the PDI data header.\r | |
299 | **/\r | |
300 | public void setRevision(String revision) {\r | |
301 | this.revision.setArg(" -rev ", revision);\r | |
302 | }\r | |
303 | \r | |
304 | /**\r | |
305 | getFlashDeviceImage\r | |
306 | \r | |
307 | This function is to get class member "dump"\r | |
308 | \r | |
309 | @return flashDeviceImage name of flash device image\r | |
310 | **/\r | |
311 | public String getDump() {\r | |
312 | return dump.getValue();\r | |
313 | }\r | |
314 | \r | |
315 | /**\r | |
316 | setFlashDeviceImage\r | |
317 | \r | |
318 | This function is to set class member "dump"\r | |
319 | \r | |
320 | @param flashDeviceImage name of flash device image\r | |
321 | **/\r | |
322 | public void setDump(boolean dump) {\r | |
323 | if (dump) {\r | |
324 | this.dump.setArg(" -", "dump");\r | |
325 | }\r | |
326 | }\r | |
327 | \r | |
328 | /**\r | |
329 | getOutputDir\r | |
330 | \r | |
331 | This function is to get class member "outputDir"\r | |
332 | \r | |
333 | @return outputDir string of output directory\r | |
334 | **/\r | |
335 | public String getOutputDir() {\r | |
336 | return outputDir;\r | |
337 | }\r | |
338 | \r | |
339 | /**\r | |
340 | setOutputDir\r | |
341 | \r | |
342 | This function is to set class member "outputDir"\r | |
343 | \r | |
344 | @param outputDir string of output directory\r | |
345 | **/\r | |
346 | public void setOutputDir(String outputDir) {\r | |
347 | this.outputDir = outputDir;\r | |
348 | }\r | |
349 | \r | |
350 | /**\r | |
351 | addBinaryFile\r | |
352 | \r | |
353 | This function is to add binary file to binaryFile list.\r | |
354 | \r | |
355 | @param binaryFile name of binary file.\r | |
356 | **/\r | |
357 | public void addConfiguredBinaryFile(Input binaryFile){\r | |
358 | this.binaryFileList.insert(binaryFile);\r | |
359 | }\r | |
360 | \r | |
361 | /**\r | |
362 | addPe32File\r | |
363 | \r | |
364 | This function is to add pe32 file to pe32File list.\r | |
365 | \r | |
366 | @param pe32File name of pe32 file.\r | |
367 | **/\r | |
368 | public void addConfiguredPe32File(Input pe32File){\r | |
369 | this.pe32FileList.insert(pe32File);\r | |
370 | }\r | |
371 | \r | |
372 | /**\r | |
373 | addPe32ComprFile\r | |
374 | \r | |
375 | This function os to add compressed pe32 file to pe32ComprFile list.\r | |
376 | \r | |
377 | @param pe32ComprFile name of compressed pe32 file.\r | |
378 | **/\r | |
379 | public void addConfiguredPe32ComprFile(Input pe32ComprFile){\r | |
380 | this.pe32ComprFileList.insert(pe32ComprFile);\r | |
381 | }\r | |
382 | }\r |