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