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