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