4 FlashMapTask is used to call FlashMap.exe to lay out the flash.
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
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.
17 package org
.tianocore
.framework
.tasks
;
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
;
27 import org
.tianocore
.common
.logger
.EdkLog
;
32 * FlashMapTask is used to call FlashMap.exe to generate flash map defition files and fd files.
34 public class FlashMapTask
extends Task
implements EfiDefine
{
38 private final String toolName
= "FlashMap";
41 // Flash definition file
43 private FileArg flashDefFile
= new FileArg();
48 private ToolArg flashDevice
= new ToolArg();
53 private ToolArg flashDeviceImage
= new ToolArg();
58 private FileArg mciFile
= new FileArg();
63 private FileArg mcoFile
= new FileArg();
68 private ToolArg fdImage
= new ToolArg();
73 private FileArg dscFile
= new FileArg();
78 private FileArg asmIncFile
= new FileArg();
83 private FileArg imageOutFile
= new FileArg();
88 private FileArg headerFile
= new FileArg();
93 private String inStrFile
= "";
98 private String outStrFile
= "";
103 private FileArg strFile
= new FileArg();
107 private ToolArg baseAddr
= new ToolArg();
112 private ToolArg aligment
= new ToolArg();
117 private ToolArg padValue
= new ToolArg();
122 private String outputDir
= ".";
127 FileArg mciFileArray
= new FileArg();
132 FlashMapTask execute function is to assemble tool command line & execute
135 @throws BuidException
137 public void execute() throws BuildException
{
140 EdkLog.log(this, EdkLog.EDK_VERBOSE, headerFile.toFileList()
141 + imageOutFile.toFileList()
142 + mcoFile.toFileList()
143 + dscFile.toFileList()
144 + asmIncFile.toFileList()
146 + " is/are up-to-date!");
151 Project project
= this.getOwningTarget().getProject();
153 // absolute path of efi tools
155 String path
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
160 command
= path
+ File
.separator
+ toolName
;
164 // add substituted input file and output file
166 if (this.inStrFile
!= null && this.outStrFile
!= null
167 && this.inStrFile
.length() > 0 && this.outStrFile
.length() > 0) {
168 strFile
.setPrefix(" -strsub ");
169 strFile
.insValue(this.inStrFile
);
170 strFile
.insValue(this.outStrFile
);
173 String argument
= "" + flashDefFile
+ flashDevice
+ flashDeviceImage
174 + mciFile
+ mcoFile
+ fdImage
+ dscFile
+ asmIncFile
175 + imageOutFile
+ headerFile
+ strFile
+ baseAddr
176 + aligment
+ padValue
+ mciFileArray
;
182 // ProcessBuilder pb = new ProcessBuilder(argList);
183 // pb.directory(new File(outputDir));
186 Commandline cmdline
= new Commandline();
187 cmdline
.setExecutable(command
);
188 cmdline
.createArgument().setLine(argument
);
190 LogStreamHandler streamHandler
= new LogStreamHandler(this,
191 Project
.MSG_INFO
, Project
.MSG_WARN
);
192 Execute runner
= new Execute(streamHandler
, null);
194 runner
.setAntRun(project
);
195 runner
.setCommandline(cmdline
.getCommandline());
197 if (outputDir
!= null) {
198 runner
.setWorkingDirectory(new File(outputDir
));
201 // log command line string.
203 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, Commandline
.toString(cmdline
.getCommandline()));
204 EdkLog
.log(this, flashDefFile
.toFileList()
205 + mciFile
.toFileList()
206 + mciFileArray
.toFileList()
207 + fdImage
.toFileList()
210 + headerFile
.toFileList()
211 + imageOutFile
.toFileList()
212 + mcoFile
.toFileList()
213 + dscFile
.toFileList()
214 + asmIncFile
.toFileList()
217 exitCode
= runner
.execute();
219 EdkLog
.log(this, "ERROR = " + Integer
.toHexString(exitCode
));
221 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "FlashMap succeeded!");
223 } catch (Exception e
) {
224 throw new BuildException(e
.getMessage());
227 throw new BuildException("FlashMap failed!");
235 This function is to get class member "flashDefFile"
237 @return flashDeFile Name of flash definition file.
239 public String
getFlashDefFile() {
240 return this.flashDefFile
.getValue();
246 This function is to set class member "flashDefFile"
249 Name of flash definition file.
251 public void setFlashDefFile(String flashDefFile
) {
252 this.flashDefFile
.setArg(" -fdf ", flashDefFile
);
258 This function is to get class member "aligment"
260 @return aligment String of aligment value.
262 public String
getAligment() {
263 return this.aligment
.getValue();
269 This function is to set class member "aligment"
272 String of aligment value.
274 public void setAligment(String aligment
) {
275 this.aligment
.setArg(" -align ", aligment
);
281 This function is to get class member "asmIncFile"
283 @return asmIncFile String of ASM include file.
285 public String
getAsmIncFile() {
286 return this.asmIncFile
.getValue();
292 This function is to set class member "asmIncFile"
295 String of ASM include file.
297 public void setAsmIncFile(String asmIncFile
) {
298 this.asmIncFile
.setArg(" -asmincfile ", asmIncFile
);
304 This function is to get class member "baseAddr"
306 @return baseAddr String of base address value.
308 public String
getBaseAddr() {
309 return this.baseAddr
.getValue();
315 This function is to set class member "baseAddr"
318 String of base address value.
320 public void setBaseAddr(String baseAddr
) {
321 this.baseAddr
.setArg(" -baseaddr ", baseAddr
);
327 This function is to get class member "dscFile"
329 @return dscFile name of DSC file
331 public String
getDscFile() {
332 return this.dscFile
.getValue();
338 This function is to set class member "dscFile"
343 public void setDscFile(String dscFile
) {
344 this.dscFile
.setArg(" -dsc ", dscFile
);
350 This function is to get class member "fdImage"
352 @return fdImage name of input FDI image file.
354 public String
getFdImage() {
355 return this.fdImage
.getValue();
361 This function is to set class member "fdImage"
364 name of input FDI image file.
366 public void setFdImage(String fdImage
) {
367 this.fdImage
.setArg(" -discover ", fdImage
);
373 This function is to get class member "flashDevice".
375 @return flashDevice name of flash device.
377 public String
getFlashDevice() {
378 return this.flashDevice
.getValue();
384 This function is to set class member "flashDevice"
387 name of flash device.
389 public void setFlashDevice(String flashDevice
) {
390 this.flashDevice
.setArg(" -flashdevice ", flashDevice
);
396 This function is to get class member "flashDeviceImage"
398 @return flashDeviceImage name of flash device image
400 public String
getFlashDeviceImage() {
401 return this.flashDeviceImage
.getValue();
407 This function is to set class member "flashDeviceImage"
409 @param flashDeviceImage
410 name of flash device image
412 public void setFlashDeviceImage(String flashDeviceImage
) {
413 this.flashDeviceImage
.setArg(" -flashdeviceimage ", flashDeviceImage
);
420 This function is to get class member "headerFile"
422 @return headerFile name of include file
424 public String
getHeaderFile() {
425 return this.headerFile
.getValue();
431 This function is to set class member "headerFile"
436 public void setHeaderFile(String headerFile
) {
437 this.headerFile
.setArg(" -hfile ", headerFile
);
443 This function is to get class member "imageOutFile"
445 @return imageOutFile name of output image file
447 public String
getImageOutFile() {
448 return this.imageOutFile
.getValue();
454 This function is to set class member "ImageOutFile"
457 name of output image file
459 public void setImageOutFile(String imageOutFile
) {
460 this.imageOutFile
.setArg(" -imageout ", imageOutFile
);
466 This function is to get class member "inStrFile"
468 @return inStrFile name of input file which used to replace symbol names.
470 public String
getInStrFile() {
471 return this.inStrFile
;
477 This function is to set class member "inStrFile"
480 name of input file which used to replace symbol names.
482 public void setInStrFile(String inStrFile
) {
483 this.inStrFile
= inStrFile
;
489 This function is to get class member "mciFile"
491 @return mciFile name of input microcode file
493 public String
getMciFile() {
494 return this.mciFile
.getValue();
500 This function is to set class member "mciFile"
503 name of input microcode file
505 public void setMciFile(String mciFile
) {
506 this.mciFile
.setArg(" -mci ", mciFile
);
512 This function is to get class member "mcoFile"
514 @return mcoFile name of output binary microcode image
516 public String
getMcoFile() {
517 return this.mcoFile
.getValue();
523 This function is to set class member "mcoFile"
526 name of output binary microcode image
528 public void setMcoFile(String mcoFile
) {
529 this.mcoFile
.setArg(" -mco ", mcoFile
);
535 This function is to get class member "outStrFile"
537 @return outStrFile name of output string substitution file
539 public String
getOutStrFile() {
540 return this.outStrFile
;
546 This function is to set class member "outStrFile"
549 name of output string substitution file
551 public void setOutStrFile(String outStrFile
) {
552 this.outStrFile
= outStrFile
;
558 This function is to get class member "padValue"
560 @return padValue string of byte value to use as padding
562 public String
getPadValue() {
563 return this.padValue
.getValue();
569 This function is to set class member "padValue"
572 string of byte value to use as padding
574 public void setPadValue(String padValue
) {
575 this.padValue
.setArg(" -padvalue ", padValue
);
581 This function is to add Microcode binary file
584 instance of input class
586 public void addConfiguredMciFile(FileArg mciFile
) {
587 this.mciFileArray
.setPrefix(" -mcmerge ");
588 this.mciFileArray
.insert(mciFile
);
594 This function is to get class member "outputDir"
596 @return outputDir string of output directory
598 public String
getOutputDir() {
605 This function is to set class member "outputDir"
608 string of output directory
610 public void setOutputDir(String outputDir
) {
611 this.outputDir
= outputDir
;
617 private boolean isUptodate() {
618 long srcTimeStamp
= 0;
620 long dstTimeStamp
= 0;
624 if (!flashDefFile
.isEmpty()) {
625 srcName
= flashDefFile
.getValue();
626 timeStamp
= new File(srcName
).lastModified();
627 if (timeStamp
> srcTimeStamp
) {
628 srcTimeStamp
= timeStamp
;
632 if (!mciFile
.isEmpty()) {
633 srcName
= mciFile
.getValue();
634 timeStamp
= new File(srcName
).lastModified();
635 if (timeStamp
> srcTimeStamp
) {
636 srcTimeStamp
= timeStamp
;
640 if (!fdImage
.isEmpty()) {
641 srcName
= fdImage
.getValue();
642 timeStamp
= new File(srcName
).lastModified();
643 if (timeStamp
> srcTimeStamp
) {
644 srcTimeStamp
= timeStamp
;
648 if (inStrFile
.length() != 0) {
650 timeStamp
= new File(srcName
).lastModified();
651 if (timeStamp
> srcTimeStamp
) {
652 srcTimeStamp
= timeStamp
;
656 if (!mciFileArray
.isEmpty()) {
657 for (int i
= 0; i
< mciFileArray
.nameList
.size(); ++i
) {
658 srcName
+= mciFileArray
.nameList
.get(i
) + " ";
659 timeStamp
= new File(mciFileArray
.nameList
.get(i
)).lastModified();
660 if (timeStamp
> srcTimeStamp
) {
661 srcTimeStamp
= timeStamp
;
666 if (!headerFile
.isEmpty()) {
667 dstName
= headerFile
.getValue();
668 File dstFile
= new File(dstName
);
669 if (!dstFile
.isAbsolute()) {
670 dstName
= outputDir
+ File
.separator
+ dstName
;
671 dstFile
= new File(dstName
);
674 if (srcTimeStamp
> dstFile
.lastModified()) {
675 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
680 if (!imageOutFile
.isEmpty()) {
681 dstName
= imageOutFile
.getValue();
682 File dstFile
= new File(dstName
);
683 if (!dstFile
.isAbsolute()) {
684 dstName
= outputDir
+ File
.separator
+ dstName
;
685 dstFile
= new File(dstName
);
688 if (srcTimeStamp
> dstFile
.lastModified()) {
689 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
694 if (!mcoFile
.isEmpty()) {
695 dstName
= mcoFile
.getValue();
696 File dstFile
= new File(dstName
);
697 if (!dstFile
.isAbsolute()) {
698 dstName
= outputDir
+ File
.separator
+ dstName
;
699 dstFile
= new File(dstName
);
702 if (srcTimeStamp
> dstFile
.lastModified()) {
703 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
708 if (!dscFile
.isEmpty()) {
709 dstName
= dscFile
.getValue();
710 File dstFile
= new File(dstName
);
711 if (!dstFile
.isAbsolute()) {
712 dstName
= outputDir
+ File
.separator
+ dstName
;
713 dstFile
= new File(dstName
);
716 if (srcTimeStamp
> dstFile
.lastModified()) {
717 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
722 if (!asmIncFile
.isEmpty()) {
723 dstName
= asmIncFile
.getValue();
724 File dstFile
= new File(dstName
);
725 if (!dstFile
.isAbsolute()) {
726 dstName
= outputDir
+ File
.separator
+ dstName
;
727 dstFile
= new File(dstName
);
730 if (srcTimeStamp
> dstFile
.lastModified()) {
731 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
736 if (outStrFile
.length() != 0) {
737 dstName
= outStrFile
;
738 File dstFile
= new File(dstName
);
739 if (!dstFile
.isAbsolute()) {
740 dstName
= outputDir
+ File
.separator
+ dstName
;
741 dstFile
= new File(dstName
);
744 if (srcTimeStamp
> dstFile
.lastModified()) {
745 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");