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
{
139 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, headerFile
.toFileList()
140 + imageOutFile
.toFileList()
141 + mcoFile
.toFileList()
142 + dscFile
.toFileList()
143 + asmIncFile
.toFileList()
145 + " is/are up-to-date!");
149 Project project
= this.getOwningTarget().getProject();
151 // absolute path of efi tools
153 String path
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
158 command
= path
+ File
.separator
+ toolName
;
162 // add substituted input file and output file
164 if (this.inStrFile
!= null && this.outStrFile
!= null
165 && this.inStrFile
.length() > 0 && this.outStrFile
.length() > 0) {
166 strFile
.setPrefix(" -strsub ");
167 strFile
.insValue(this.inStrFile
);
168 strFile
.insValue(this.outStrFile
);
171 String argument
= "" + flashDefFile
+ flashDevice
+ flashDeviceImage
172 + mciFile
+ mcoFile
+ fdImage
+ dscFile
+ asmIncFile
173 + imageOutFile
+ headerFile
+ strFile
+ baseAddr
174 + aligment
+ padValue
+ mciFileArray
;
180 // ProcessBuilder pb = new ProcessBuilder(argList);
181 // pb.directory(new File(outputDir));
184 Commandline cmdline
= new Commandline();
185 cmdline
.setExecutable(command
);
186 cmdline
.createArgument().setLine(argument
);
188 LogStreamHandler streamHandler
= new LogStreamHandler(this,
189 Project
.MSG_INFO
, Project
.MSG_WARN
);
190 Execute runner
= new Execute(streamHandler
, null);
192 runner
.setAntRun(project
);
193 runner
.setCommandline(cmdline
.getCommandline());
195 if (outputDir
!= null) {
196 runner
.setWorkingDirectory(new File(outputDir
));
199 // log command line string.
201 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, Commandline
.toString(cmdline
.getCommandline()));
202 EdkLog
.log(this, flashDefFile
.toFileList()
203 + mciFile
.toFileList()
204 + mciFileArray
.toFileList()
205 + fdImage
.toFileList()
208 + headerFile
.toFileList()
209 + imageOutFile
.toFileList()
210 + mcoFile
.toFileList()
211 + dscFile
.toFileList()
212 + asmIncFile
.toFileList()
215 exitCode
= runner
.execute();
217 EdkLog
.log(this, "ERROR = " + Integer
.toHexString(exitCode
));
219 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "FlashMap succeeded!");
221 } catch (Exception e
) {
222 throw new BuildException(e
.getMessage());
225 throw new BuildException("FlashMap failed!");
233 This function is to get class member "flashDefFile"
235 @return flashDeFile Name of flash definition file.
237 public String
getFlashDefFile() {
238 return this.flashDefFile
.getValue();
244 This function is to set class member "flashDefFile"
247 Name of flash definition file.
249 public void setFlashDefFile(String flashDefFile
) {
250 this.flashDefFile
.setArg(" -fdf ", flashDefFile
);
256 This function is to get class member "aligment"
258 @return aligment String of aligment value.
260 public String
getAligment() {
261 return this.aligment
.getValue();
267 This function is to set class member "aligment"
270 String of aligment value.
272 public void setAligment(String aligment
) {
273 this.aligment
.setArg(" -align ", aligment
);
279 This function is to get class member "asmIncFile"
281 @return asmIncFile String of ASM include file.
283 public String
getAsmIncFile() {
284 return this.asmIncFile
.getValue();
290 This function is to set class member "asmIncFile"
293 String of ASM include file.
295 public void setAsmIncFile(String asmIncFile
) {
296 this.asmIncFile
.setArg(" -asmincfile ", asmIncFile
);
302 This function is to get class member "baseAddr"
304 @return baseAddr String of base address value.
306 public String
getBaseAddr() {
307 return this.baseAddr
.getValue();
313 This function is to set class member "baseAddr"
316 String of base address value.
318 public void setBaseAddr(String baseAddr
) {
319 this.baseAddr
.setArg(" -baseaddr ", baseAddr
);
325 This function is to get class member "dscFile"
327 @return dscFile name of DSC file
329 public String
getDscFile() {
330 return this.dscFile
.getValue();
336 This function is to set class member "dscFile"
341 public void setDscFile(String dscFile
) {
342 this.dscFile
.setArg(" -dsc ", dscFile
);
348 This function is to get class member "fdImage"
350 @return fdImage name of input FDI image file.
352 public String
getFdImage() {
353 return this.fdImage
.getValue();
359 This function is to set class member "fdImage"
362 name of input FDI image file.
364 public void setFdImage(String fdImage
) {
365 this.fdImage
.setArg(" -discover ", fdImage
);
371 This function is to get class member "flashDevice".
373 @return flashDevice name of flash device.
375 public String
getFlashDevice() {
376 return this.flashDevice
.getValue();
382 This function is to set class member "flashDevice"
385 name of flash device.
387 public void setFlashDevice(String flashDevice
) {
388 this.flashDevice
.setArg(" -flashdevice ", flashDevice
);
394 This function is to get class member "flashDeviceImage"
396 @return flashDeviceImage name of flash device image
398 public String
getFlashDeviceImage() {
399 return this.flashDeviceImage
.getValue();
405 This function is to set class member "flashDeviceImage"
407 @param flashDeviceImage
408 name of flash device image
410 public void setFlashDeviceImage(String flashDeviceImage
) {
411 this.flashDeviceImage
.setArg(" -flashdeviceimage ", flashDeviceImage
);
418 This function is to get class member "headerFile"
420 @return headerFile name of include file
422 public String
getHeaderFile() {
423 return this.headerFile
.getValue();
429 This function is to set class member "headerFile"
434 public void setHeaderFile(String headerFile
) {
435 this.headerFile
.setArg(" -hfile ", headerFile
);
441 This function is to get class member "imageOutFile"
443 @return imageOutFile name of output image file
445 public String
getImageOutFile() {
446 return this.imageOutFile
.getValue();
452 This function is to set class member "ImageOutFile"
455 name of output image file
457 public void setImageOutFile(String imageOutFile
) {
458 this.imageOutFile
.setArg(" -imageout ", imageOutFile
);
464 This function is to get class member "inStrFile"
466 @return inStrFile name of input file which used to replace symbol names.
468 public String
getInStrFile() {
469 return this.inStrFile
;
475 This function is to set class member "inStrFile"
478 name of input file which used to replace symbol names.
480 public void setInStrFile(String inStrFile
) {
481 this.inStrFile
= inStrFile
;
487 This function is to get class member "mciFile"
489 @return mciFile name of input microcode file
491 public String
getMciFile() {
492 return this.mciFile
.getValue();
498 This function is to set class member "mciFile"
501 name of input microcode file
503 public void setMciFile(String mciFile
) {
504 this.mciFile
.setArg(" -mci ", mciFile
);
510 This function is to get class member "mcoFile"
512 @return mcoFile name of output binary microcode image
514 public String
getMcoFile() {
515 return this.mcoFile
.getValue();
521 This function is to set class member "mcoFile"
524 name of output binary microcode image
526 public void setMcoFile(String mcoFile
) {
527 this.mcoFile
.setArg(" -mco ", mcoFile
);
533 This function is to get class member "outStrFile"
535 @return outStrFile name of output string substitution file
537 public String
getOutStrFile() {
538 return this.outStrFile
;
544 This function is to set class member "outStrFile"
547 name of output string substitution file
549 public void setOutStrFile(String outStrFile
) {
550 this.outStrFile
= outStrFile
;
556 This function is to get class member "padValue"
558 @return padValue string of byte value to use as padding
560 public String
getPadValue() {
561 return this.padValue
.getValue();
567 This function is to set class member "padValue"
570 string of byte value to use as padding
572 public void setPadValue(String padValue
) {
573 this.padValue
.setArg(" -padvalue ", padValue
);
579 This function is to add Microcode binary file
582 instance of input class
584 public void addConfiguredMciFile(FileArg mciFile
) {
585 this.mciFileArray
.setPrefix(" -mcmerge ");
586 this.mciFileArray
.insert(mciFile
);
592 This function is to get class member "outputDir"
594 @return outputDir string of output directory
596 public String
getOutputDir() {
603 This function is to set class member "outputDir"
606 string of output directory
608 public void setOutputDir(String outputDir
) {
609 this.outputDir
= outputDir
;
615 private boolean isUptodate() {
616 long srcTimeStamp
= 0;
618 long dstTimeStamp
= 0;
622 if (!flashDefFile
.isEmpty()) {
623 srcName
= flashDefFile
.getValue();
624 timeStamp
= new File(srcName
).lastModified();
625 if (timeStamp
> srcTimeStamp
) {
626 srcTimeStamp
= timeStamp
;
630 if (!mciFile
.isEmpty()) {
631 srcName
= mciFile
.getValue();
632 timeStamp
= new File(srcName
).lastModified();
633 if (timeStamp
> srcTimeStamp
) {
634 srcTimeStamp
= timeStamp
;
638 if (!fdImage
.isEmpty()) {
639 srcName
= fdImage
.getValue();
640 timeStamp
= new File(srcName
).lastModified();
641 if (timeStamp
> srcTimeStamp
) {
642 srcTimeStamp
= timeStamp
;
646 if (inStrFile
.length() != 0) {
648 timeStamp
= new File(srcName
).lastModified();
649 if (timeStamp
> srcTimeStamp
) {
650 srcTimeStamp
= timeStamp
;
654 if (!mciFileArray
.isEmpty()) {
655 for (int i
= 0; i
< mciFileArray
.nameList
.size(); ++i
) {
656 srcName
+= mciFileArray
.nameList
.get(i
) + " ";
657 timeStamp
= new File(mciFileArray
.nameList
.get(i
)).lastModified();
658 if (timeStamp
> srcTimeStamp
) {
659 srcTimeStamp
= timeStamp
;
664 if (!headerFile
.isEmpty()) {
665 dstName
= headerFile
.getValue();
666 File dstFile
= new File(dstName
);
667 if (!dstFile
.isAbsolute()) {
668 dstName
= outputDir
+ File
.separator
+ dstName
;
669 dstFile
= new File(dstName
);
672 if (srcTimeStamp
> dstFile
.lastModified()) {
673 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
678 if (!imageOutFile
.isEmpty()) {
679 dstName
= imageOutFile
.getValue();
680 File dstFile
= new File(dstName
);
681 if (!dstFile
.isAbsolute()) {
682 dstName
= outputDir
+ File
.separator
+ dstName
;
683 dstFile
= new File(dstName
);
686 if (srcTimeStamp
> dstFile
.lastModified()) {
687 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
692 if (!mcoFile
.isEmpty()) {
693 dstName
= mcoFile
.getValue();
694 File dstFile
= new File(dstName
);
695 if (!dstFile
.isAbsolute()) {
696 dstName
= outputDir
+ File
.separator
+ dstName
;
697 dstFile
= new File(dstName
);
700 if (srcTimeStamp
> dstFile
.lastModified()) {
701 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
706 if (!dscFile
.isEmpty()) {
707 dstName
= dscFile
.getValue();
708 File dstFile
= new File(dstName
);
709 if (!dstFile
.isAbsolute()) {
710 dstName
= outputDir
+ File
.separator
+ dstName
;
711 dstFile
= new File(dstName
);
714 if (srcTimeStamp
> dstFile
.lastModified()) {
715 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
720 if (!asmIncFile
.isEmpty()) {
721 dstName
= asmIncFile
.getValue();
722 File dstFile
= new File(dstName
);
723 if (!dstFile
.isAbsolute()) {
724 dstName
= outputDir
+ File
.separator
+ dstName
;
725 dstFile
= new File(dstName
);
728 if (srcTimeStamp
> dstFile
.lastModified()) {
729 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");
734 if (outStrFile
.length() != 0) {
735 dstName
= outStrFile
;
736 File dstFile
= new File(dstName
);
737 if (!dstFile
.isAbsolute()) {
738 dstName
= outputDir
+ File
.separator
+ dstName
;
739 dstFile
= new File(dstName
);
742 if (srcTimeStamp
> dstFile
.lastModified()) {
743 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, srcName
+ " has been changed since last build!");