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