]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
be6c21a292631620a5975c6e460c586c65001d69
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / FlashMapTask.java
1 /** @file
2 FlashMapTask class.
3
4 FlashMapTask 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 org.apache.tools.ant.Task;
21 import org.apache.tools.ant.Project;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.taskdefs.Execute;
24 import org.apache.tools.ant.taskdefs.LogStreamHandler;
25 import org.apache.tools.ant.types.Commandline;
26
27 import org.tianocore.common.logger.EdkLog;
28
29 /**
30 * FlashMapTask class.
31 *
32 * FlashMapTask is used to call FlashMap.exe to generate flash map defition files and fd files.
33 */
34 public class FlashMapTask extends Task implements EfiDefine {
35 //
36 // tool name
37 //
38 private final String toolName = "FlashMap";
39
40 //
41 // Flash definition file
42 //
43 private FileArg flashDefFile = new FileArg();
44
45 //
46 // Flash device
47 //
48 private ToolArg flashDevice = new ToolArg();
49
50 //
51 // Flash device Image
52 //
53 private ToolArg flashDeviceImage = new ToolArg();
54
55 //
56 // MCI file
57 //
58 private FileArg mciFile = new FileArg();
59
60 //
61 // MCO file
62 //
63 private FileArg mcoFile = new FileArg();
64
65 //
66 // Discover FD image
67 //
68 private ToolArg fdImage = new ToolArg();
69
70 //
71 // Dsc file
72 //
73 private FileArg dscFile = new FileArg();
74
75 //
76 // Asm INC file
77 //
78 private FileArg asmIncFile = new FileArg();
79
80 //
81 // Image out file
82 //
83 private FileArg imageOutFile = new FileArg();
84
85 //
86 // Header file
87 //
88 private FileArg headerFile = new FileArg();
89
90 //
91 // Input string file
92 //
93 private String inStrFile = "";
94
95 //
96 // Output string file
97 //
98 private String outStrFile = "";
99
100 //
101 //
102 //
103 private FileArg strFile = new FileArg();
104 //
105 // Base address
106 //
107 private ToolArg baseAddr = new ToolArg();
108
109 //
110 // Aligment
111 //
112 private ToolArg aligment = new ToolArg();
113
114 //
115 // Padding value
116 //
117 private ToolArg padValue = new ToolArg();
118
119 //
120 // output directory
121 //
122 private String outputDir = ".";
123
124 //
125 // MCI file array
126 //
127 FileArg mciFileArray = new FileArg();
128
129 /**
130 execute
131
132 FlashMapTask execute function is to assemble tool command line & execute
133 tool command line
134
135 @throws BuidException
136 **/
137 public void execute() throws BuildException {
138
139 Project project = this.getOwningTarget().getProject();
140 //
141 // absolute path of efi tools
142 //
143 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
144 String command;
145 if (path == null) {
146 command = toolName;
147 } else {
148 command = path + File.separator + toolName;
149 }
150
151 //
152 // add substituted input file and output file
153 //
154 if (this.inStrFile != null && this.outStrFile != null
155 && this.inStrFile.length() > 0 && this.outStrFile.length() > 0) {
156 strFile.setPrefix(" -strsub ");
157 strFile.insValue(this.inStrFile);
158 strFile.insValue(this.outStrFile);
159 }
160
161 String argument = "" + flashDefFile + flashDevice + flashDeviceImage
162 + mciFile + mcoFile + fdImage + dscFile + asmIncFile
163 + imageOutFile + headerFile + strFile + baseAddr
164 + aligment + padValue + mciFileArray;
165
166
167 //
168 // lauch the program
169 //
170 // ProcessBuilder pb = new ProcessBuilder(argList);
171 // pb.directory(new File(outputDir));
172 int exitCode = 0;
173 try {
174 Commandline cmdline = new Commandline();
175 cmdline.setExecutable(command);
176 cmdline.createArgument().setLine(argument);
177
178 LogStreamHandler streamHandler = new LogStreamHandler(this,
179 Project.MSG_INFO, Project.MSG_WARN);
180 Execute runner = new Execute(streamHandler, null);
181
182 runner.setAntRun(project);
183 runner.setCommandline(cmdline.getCommandline());
184
185 if (outputDir != null) {
186 runner.setWorkingDirectory(new File(outputDir));
187 }
188 //
189 // log command line string.
190 //
191 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
192 EdkLog.log(this, flashDefFile.toFileList()
193 + mciFile.toFileList()
194 + mciFileArray.toFileList()
195 + fdImage.toFileList()
196 + inStrFile
197 + " => "
198 + headerFile.toFileList()
199 + imageOutFile.toFileList()
200 + mcoFile.toFileList()
201 + dscFile.toFileList()
202 + asmIncFile.toFileList()
203 + outStrFile);
204
205 exitCode = runner.execute();
206 if (exitCode != 0) {
207 EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));
208 } else {
209 EdkLog.log(this, EdkLog.EDK_VERBOSE, "FlashMap succeeded!");
210 }
211 } catch (Exception e) {
212 throw new BuildException(e.getMessage());
213 } finally {
214 if (exitCode != 0) {
215 throw new BuildException("FlashMap failed!");
216 }
217 }
218 }
219
220 /**
221 getFlashDefFile
222
223 This function is to get class member "flashDefFile"
224
225 @return flashDeFile Name of flash definition file.
226 **/
227 public String getFlashDefFile() {
228 return this.flashDefFile.getValue();
229 }
230
231 /**
232 setFlashDefFile
233
234 This function is to set class member "flashDefFile"
235
236 @param flashDefFile
237 Name of flash definition file.
238 **/
239 public void setFlashDefFile(String flashDefFile) {
240 this.flashDefFile.setArg(" -fdf ", flashDefFile);
241 }
242
243 /**
244 getAligment
245
246 This function is to get class member "aligment"
247
248 @return aligment String of aligment value.
249 **/
250 public String getAligment() {
251 return this.aligment.getValue();
252 }
253
254 /**
255 setAligment
256
257 This function is to set class member "aligment"
258
259 @param aligment
260 String of aligment value.
261 **/
262 public void setAligment(String aligment) {
263 this.aligment.setArg(" -align ", aligment);
264 }
265
266 /**
267 getAsmIncFile
268
269 This function is to get class member "asmIncFile"
270
271 @return asmIncFile String of ASM include file.
272 **/
273 public String getAsmIncFile() {
274 return this.asmIncFile.getValue();
275 }
276
277 /**
278 setAsmIncFile
279
280 This function is to set class member "asmIncFile"
281
282 @param asmIncFile
283 String of ASM include file.
284 **/
285 public void setAsmIncFile(String asmIncFile) {
286 this.asmIncFile.setArg(" -asmincfile ", asmIncFile);
287 }
288
289 /**
290 getBaseAddr
291
292 This function is to get class member "baseAddr"
293
294 @return baseAddr String of base address value.
295 **/
296 public String getBaseAddr() {
297 return this.baseAddr.getValue();
298 }
299
300 /**
301 setBaseAddr
302
303 This function is to set class member "baseAddr"
304
305 @param baseAddr
306 String of base address value.
307 **/
308 public void setBaseAddr(String baseAddr) {
309 this.baseAddr.setArg(" -baseaddr ", baseAddr);
310 }
311
312 /**
313 getDscFile
314
315 This function is to get class member "dscFile"
316
317 @return dscFile name of DSC file
318 **/
319 public String getDscFile() {
320 return this.dscFile.getValue();
321 }
322
323 /**
324 setDscFile
325
326 This function is to set class member "dscFile"
327
328 @param dscFile
329 name of DSC file
330 **/
331 public void setDscFile(String dscFile) {
332 this.dscFile.setArg(" -dsc ", dscFile);
333 }
334
335 /**
336 getFdImage
337
338 This function is to get class member "fdImage"
339
340 @return fdImage name of input FDI image file.
341 **/
342 public String getFdImage() {
343 return this.fdImage.getValue();
344 }
345
346 /**
347 setFdImage
348
349 This function is to set class member "fdImage"
350
351 @param fdImage
352 name of input FDI image file.
353 **/
354 public void setFdImage(String fdImage) {
355 this.fdImage.setArg(" -discover ", fdImage);
356 }
357
358 /**
359 getFlashDevice
360
361 This function is to get class member "flashDevice".
362
363 @return flashDevice name of flash device.
364 **/
365 public String getFlashDevice() {
366 return this.flashDevice.getValue();
367 }
368
369 /**
370 setFlashDevice
371
372 This function is to set class member "flashDevice"
373
374 @param flashDevice
375 name of flash device.
376 **/
377 public void setFlashDevice(String flashDevice) {
378 this.flashDevice.setArg(" -flashdevice ", flashDevice);
379 }
380
381 /**
382 getFlashDeviceImage
383
384 This function is to get class member "flashDeviceImage"
385
386 @return flashDeviceImage name of flash device image
387 **/
388 public String getFlashDeviceImage() {
389 return this.flashDeviceImage.getValue();
390 }
391
392 /**
393 setFlashDeviceImage
394
395 This function is to set class member "flashDeviceImage"
396
397 @param flashDeviceImage
398 name of flash device image
399 **/
400 public void setFlashDeviceImage(String flashDeviceImage) {
401 this.flashDeviceImage.setArg(" -flashdeviceimage ", flashDeviceImage);
402
403 }
404
405 /**
406 getHeaderFile
407
408 This function is to get class member "headerFile"
409
410 @return headerFile name of include file
411 **/
412 public String getHeaderFile() {
413 return this.headerFile.getValue();
414 }
415
416 /**
417 setHeaderFile
418
419 This function is to set class member "headerFile"
420
421 @param headerFile
422 name of include file
423 **/
424 public void setHeaderFile(String headerFile) {
425 this.headerFile.setArg(" -hfile ", headerFile);
426 }
427
428 /**
429 getImageOutFile
430
431 This function is to get class member "imageOutFile"
432
433 @return imageOutFile name of output image file
434 **/
435 public String getImageOutFile() {
436 return this.imageOutFile.getValue();
437 }
438
439 /**
440 setImageOutFile
441
442 This function is to set class member "ImageOutFile"
443
444 @param imageOutFile
445 name of output image file
446 **/
447 public void setImageOutFile(String imageOutFile) {
448 this.imageOutFile.setArg(" -imageout ", imageOutFile);
449 }
450
451 /**
452 getInStrFile
453
454 This function is to get class member "inStrFile"
455
456 @return inStrFile name of input file which used to replace symbol names.
457 **/
458 public String getInStrFile() {
459 return this.inStrFile;
460 }
461
462 /**
463 setInStrFile
464
465 This function is to set class member "inStrFile"
466
467 @param inStrFile
468 name of input file which used to replace symbol names.
469 **/
470 public void setInStrFile(String inStrFile) {
471 this.inStrFile = inStrFile;
472 }
473
474 /**
475 getMciFile
476
477 This function is to get class member "mciFile"
478
479 @return mciFile name of input microcode file
480 **/
481 public String getMciFile() {
482 return this.mciFile.getValue();
483 }
484
485 /**
486 setMciFile
487
488 This function is to set class member "mciFile"
489
490 @param mciFile
491 name of input microcode file
492 **/
493 public void setMciFile(String mciFile) {
494 this.mciFile.setArg(" -mci ", mciFile);
495 }
496
497 /**
498 getMcoFile
499
500 This function is to get class member "mcoFile"
501
502 @return mcoFile name of output binary microcode image
503 **/
504 public String getMcoFile() {
505 return this.mcoFile.getValue();
506 }
507
508 /**
509 setMcoFile
510
511 This function is to set class member "mcoFile"
512
513 @param mcoFile
514 name of output binary microcode image
515 **/
516 public void setMcoFile(String mcoFile) {
517 this.mcoFile.setArg(" -mco ", mcoFile);
518 }
519
520 /**
521 getOutStrFile
522
523 This function is to get class member "outStrFile"
524
525 @return outStrFile name of output string substitution file
526 **/
527 public String getOutStrFile() {
528 return this.outStrFile;
529 }
530
531 /**
532 setOutStrFile
533
534 This function is to set class member "outStrFile"
535
536 @param outStrFile
537 name of output string substitution file
538 **/
539 public void setOutStrFile(String outStrFile) {
540 this.outStrFile = outStrFile;
541 }
542
543 /**
544 getPadValue
545
546 This function is to get class member "padValue"
547
548 @return padValue string of byte value to use as padding
549 **/
550 public String getPadValue() {
551 return this.padValue.getValue();
552 }
553
554 /**
555 setPadValue
556
557 This function is to set class member "padValue"
558
559 @param padValue
560 string of byte value to use as padding
561 **/
562 public void setPadValue(String padValue) {
563 this.padValue.setArg(" -padvalue ", padValue);
564 }
565
566 /**
567 addMciFile
568
569 This function is to add Microcode binary file
570
571 @param mciFile
572 instance of input class
573 **/
574 public void addConfiguredMciFile(FileArg mciFile) {
575 this.mciFileArray.setPrefix(" -mcmerge ");
576 this.mciFileArray.insert(mciFile);
577 }
578
579 /**
580 getOutputDir
581
582 This function is to get class member "outputDir"
583
584 @return outputDir string of output directory
585 **/
586 public String getOutputDir() {
587 return outputDir;
588 }
589
590 /**
591 setOutputDir
592
593 This function is to set class member "outputDir"
594
595 @param outputDir
596 string of output directory
597 **/
598 public void setOutputDir(String outputDir) {
599 this.outputDir = outputDir;
600 }
601 }