]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
Remove FrameworkLogger in FrameworkTasks and EdkException in GenBuild. Update EdkLog...
[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 //
117 // absolute path of efi tools
118 //
119 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
120 String command;
121 if (path == null) {
122 command = toolName;
123 } else {
124 command = path + File.separatorChar + toolName;
125 }
126 argList.addFirst(command);
127
128 //
129 // add microcode binary files
130 //
131 if (this.binaryFileList.size() > 0){
132 argList.add("-b");
133 Iterator binList = this.binaryFileList.iterator();
134 while (binList.hasNext()){
135 argList.addAll(((Input)binList.next()).getNameList());
136 }
137 }
138
139 //
140 // add pe32 file
141 //
142 if (this.pe32FileList.size() > 0){
143 argList.add("-e");
144 Iterator pe32List = this.pe32FileList.iterator();
145 while (pe32List.hasNext()){
146 argList.addAll(((Input)pe32List.next()).getNameList());
147 }
148 }
149
150 //
151 // add compressed pe32 file
152 //
153 if (this.pe32ComprFileList.size() > 0){
154 argList.add("-ec");
155 Iterator pe32ComprList = this.pe32ComprFileList.iterator();
156 while (pe32ComprList.hasNext()){
157 argList.addAll(((Input)pe32ComprList.next()).getNameList());
158 }
159 }
160
161 EdkLog.log(this, EdkLog.EDK_VERBOSE, argList.toString().replaceAll(",",""));
162 EdkLog.log(this, EdkLog.EDK_INFO, " ");
163
164 //
165 // lauch the program
166 //
167 ProcessBuilder pb = new ProcessBuilder(argList);
168 pb.directory(new File(outputDir));
169 int exitCode = 0;
170 try {
171 Process cmdProc = pb.start();
172 InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream());
173 char[] buf = new char[1024];
174
175 exitCode = cmdProc.waitFor();
176 if (exitCode != 0) {
177 int len = cmdOut.read(buf, 0, 1024);
178 EdkLog.log(EdkLog.EDK_INFO, new String(buf, 0, len));
179 } else {
180 EdkLog.log(EdkLog.EDK_VERBOSE, "EfiRom succeeded!");
181 }
182 } catch (Exception e) {
183 throw new BuildException(e.getMessage());
184 } finally {
185 if (exitCode != 0) {
186 throw new BuildException("EfiRom failed!");
187 }
188 }
189 }
190
191 /**
192 * getVerbose
193 *
194 * This function is to get class member "verbose"
195 *
196 * @return verbose for verbose output.
197 */
198 public String getVerbose() {
199 return verbose;
200 }
201
202 /**
203 * setVerbose
204 *
205 * This function is to set class member "verbose"
206 *
207 * @param verbose for verbose output.
208 */
209 public void setVerbose(boolean verbose) {
210 if (verbose){
211 this.verbose = "-p";
212 argList.add(this.verbose);
213 }
214 }
215
216 /**
217 * getVenderId
218 *
219 * This function is to get class member "venderId"
220 *
221 * @return venderId String of venderId.
222 */
223 public String getVenderId() {
224 return venderId;
225 }
226
227 /**
228 * setVenderId
229 *
230 * This function is to set class member "venderId"
231 *
232 * @param venderId String of venderId.
233 */
234 public void setVenderId(String VenderId) {
235 this.venderId = VenderId;
236 argList.add("-v");
237 argList.add(this.venderId);
238 }
239
240 /**
241 * getDeviceId
242 *
243 * This function is to get class member "deviceId"
244 *
245 * @return deviceId String of device ID.
246 */
247 public String getDeviceId() {
248 return this.deviceId;
249 }
250
251 /**
252 * setDeviceId
253 *
254 * This function is to set class member "deviceId"
255 *
256 * @param deviceId String of device ID.
257 */
258 public void setDeviceId(String deviceId) {
259 this.deviceId = deviceId;
260 argList.add("-d");
261 argList.add(this.deviceId);
262 }
263
264
265 /**
266 * getOutputFile
267 *
268 * This function is to get class member "outputFile"
269 *
270 * @return outputFile name of output directory.
271 */
272 public String getOutputFile() {
273 return outputFile;
274 }
275
276 /**
277 * setOutputFile
278 *
279 * This function is to set class member "dscFile"
280 *
281 * @param outputFile name of DSC file
282 */
283 public void setOutputFile(String outputFile) {
284 this.outputFile = outputFile;
285
286 }
287
288 /**
289 * getClassCode
290 *
291 * This function is to get class member "classCode"
292 *
293 * @return fdImage name of class code file.
294 */
295 public String getClassCode() {
296 return classCode;
297 }
298
299 /**
300 * setclassCode
301 *
302 * This function is to set class member "classCode"
303 *
304 * @param fdImage name of class code file.
305 */
306 public void setclassCode(String classCode) {
307 this.classCode = classCode;
308 argList.add("-cc");
309 argList.add(this.classCode);
310 }
311
312 /**
313 * getRevision
314 *
315 * This function is to get class member "revision".
316 *
317 * @return revision hex revision in the PDI data header.
318 */
319 public String getRevision() {
320 return revision;
321 }
322
323 /**
324 * setRevision
325 *
326 * This function is to set class member "revision"
327 *
328 * @param revision hex revision in the PDI data header.
329 */
330 public void setRevision(String revision) {
331 this.revision = revision;
332 argList.add("-rev");
333 argList.add(this.revision);
334 }
335
336 /**
337 * getFlashDeviceImage
338 *
339 * This function is to get class member "dump"
340 *
341 * @return flashDeviceImage name of flash device image
342 */
343 public String getDump() {
344 return dump;
345 }
346
347 /**
348 * setFlashDeviceImage
349 *
350 * This function is to set class member "dump"
351 *
352 * @param flashDeviceImage name of flash device image
353 */
354 public void setDump(boolean dump) {
355 if (dump){
356 this.dump = "-dump";
357 argList.add(this.dump);
358 }
359 }
360
361 /**
362 * getOutputDir
363 *
364 * This function is to get class member "outputDir"
365 *
366 * @return outputDir string of output directory
367 */
368 public String getOutputDir() {
369 return outputDir;
370 }
371
372 /**
373 * setOutputDir
374 *
375 * This function is to set class member "outputDir"
376 *
377 * @param outputDir string of output directory
378 */
379 public void setOutputDir(String outputDir) {
380 this.outputDir = outputDir;
381 }
382 /**
383 * addBinaryFile
384 *
385 * This function is to add binary file to binaryFile list.
386 *
387 * @param binaryFile name of binary file.
388 */
389 public void addBinaryFile(Input binaryFile){
390 this.binaryFileList.add(binaryFile);
391 }
392
393 /**
394 * addPe32File
395 *
396 * This function is to add pe32 file to pe32File list.
397 *
398 * @param pe32File name of pe32 file.
399 */
400 public void addPe32File(Input pe32File){
401 this.pe32FileList.add(pe32File);
402 }
403
404 /**
405 * addPe32ComprFile
406 *
407 * This function os to add compressed pe32 file to pe32ComprFile list.
408 *
409 * @param pe32ComprFile name of compressed pe32 file.
410 */
411 public void addPe32ComprFile(Input pe32ComprFile){
412 this.pe32ComprFileList.add(pe32ComprFile);
413 }
414 }