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