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