]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
1) Added dependency check for flashmap, genfvimage, peirebase tasks
[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 if (isUptodate()) {
139 EdkLog.log(this, EdkLog.EDK_VERBOSE, headerFile.toFileList()
140 + imageOutFile.toFileList()
141 + mcoFile.toFileList()
142 + dscFile.toFileList()
143 + asmIncFile.toFileList()
144 + outStrFile
145 + " is/are up-to-date!");
146 return;
147 }
148
149 Project project = this.getOwningTarget().getProject();
150 //
151 // absolute path of efi tools
152 //
153 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
154 String command;
155 if (path == null) {
156 command = toolName;
157 } else {
158 command = path + File.separator + toolName;
159 }
160
161 //
162 // add substituted input file and output file
163 //
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);
169 }
170
171 String argument = "" + flashDefFile + flashDevice + flashDeviceImage
172 + mciFile + mcoFile + fdImage + dscFile + asmIncFile
173 + imageOutFile + headerFile + strFile + baseAddr
174 + aligment + padValue + mciFileArray;
175
176
177 //
178 // lauch the program
179 //
180 // ProcessBuilder pb = new ProcessBuilder(argList);
181 // pb.directory(new File(outputDir));
182 int exitCode = 0;
183 try {
184 Commandline cmdline = new Commandline();
185 cmdline.setExecutable(command);
186 cmdline.createArgument().setLine(argument);
187
188 LogStreamHandler streamHandler = new LogStreamHandler(this,
189 Project.MSG_INFO, Project.MSG_WARN);
190 Execute runner = new Execute(streamHandler, null);
191
192 runner.setAntRun(project);
193 runner.setCommandline(cmdline.getCommandline());
194
195 if (outputDir != null) {
196 runner.setWorkingDirectory(new File(outputDir));
197 }
198 //
199 // log command line string.
200 //
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()
206 + inStrFile
207 + " => "
208 + headerFile.toFileList()
209 + imageOutFile.toFileList()
210 + mcoFile.toFileList()
211 + dscFile.toFileList()
212 + asmIncFile.toFileList()
213 + outStrFile);
214
215 exitCode = runner.execute();
216 if (exitCode != 0) {
217 EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));
218 } else {
219 EdkLog.log(this, EdkLog.EDK_VERBOSE, "FlashMap succeeded!");
220 }
221 } catch (Exception e) {
222 throw new BuildException(e.getMessage());
223 } finally {
224 if (exitCode != 0) {
225 throw new BuildException("FlashMap failed!");
226 }
227 }
228 }
229
230 /**
231 getFlashDefFile
232
233 This function is to get class member "flashDefFile"
234
235 @return flashDeFile Name of flash definition file.
236 **/
237 public String getFlashDefFile() {
238 return this.flashDefFile.getValue();
239 }
240
241 /**
242 setFlashDefFile
243
244 This function is to set class member "flashDefFile"
245
246 @param flashDefFile
247 Name of flash definition file.
248 **/
249 public void setFlashDefFile(String flashDefFile) {
250 this.flashDefFile.setArg(" -fdf ", flashDefFile);
251 }
252
253 /**
254 getAligment
255
256 This function is to get class member "aligment"
257
258 @return aligment String of aligment value.
259 **/
260 public String getAligment() {
261 return this.aligment.getValue();
262 }
263
264 /**
265 setAligment
266
267 This function is to set class member "aligment"
268
269 @param aligment
270 String of aligment value.
271 **/
272 public void setAligment(String aligment) {
273 this.aligment.setArg(" -align ", aligment);
274 }
275
276 /**
277 getAsmIncFile
278
279 This function is to get class member "asmIncFile"
280
281 @return asmIncFile String of ASM include file.
282 **/
283 public String getAsmIncFile() {
284 return this.asmIncFile.getValue();
285 }
286
287 /**
288 setAsmIncFile
289
290 This function is to set class member "asmIncFile"
291
292 @param asmIncFile
293 String of ASM include file.
294 **/
295 public void setAsmIncFile(String asmIncFile) {
296 this.asmIncFile.setArg(" -asmincfile ", asmIncFile);
297 }
298
299 /**
300 getBaseAddr
301
302 This function is to get class member "baseAddr"
303
304 @return baseAddr String of base address value.
305 **/
306 public String getBaseAddr() {
307 return this.baseAddr.getValue();
308 }
309
310 /**
311 setBaseAddr
312
313 This function is to set class member "baseAddr"
314
315 @param baseAddr
316 String of base address value.
317 **/
318 public void setBaseAddr(String baseAddr) {
319 this.baseAddr.setArg(" -baseaddr ", baseAddr);
320 }
321
322 /**
323 getDscFile
324
325 This function is to get class member "dscFile"
326
327 @return dscFile name of DSC file
328 **/
329 public String getDscFile() {
330 return this.dscFile.getValue();
331 }
332
333 /**
334 setDscFile
335
336 This function is to set class member "dscFile"
337
338 @param dscFile
339 name of DSC file
340 **/
341 public void setDscFile(String dscFile) {
342 this.dscFile.setArg(" -dsc ", dscFile);
343 }
344
345 /**
346 getFdImage
347
348 This function is to get class member "fdImage"
349
350 @return fdImage name of input FDI image file.
351 **/
352 public String getFdImage() {
353 return this.fdImage.getValue();
354 }
355
356 /**
357 setFdImage
358
359 This function is to set class member "fdImage"
360
361 @param fdImage
362 name of input FDI image file.
363 **/
364 public void setFdImage(String fdImage) {
365 this.fdImage.setArg(" -discover ", fdImage);
366 }
367
368 /**
369 getFlashDevice
370
371 This function is to get class member "flashDevice".
372
373 @return flashDevice name of flash device.
374 **/
375 public String getFlashDevice() {
376 return this.flashDevice.getValue();
377 }
378
379 /**
380 setFlashDevice
381
382 This function is to set class member "flashDevice"
383
384 @param flashDevice
385 name of flash device.
386 **/
387 public void setFlashDevice(String flashDevice) {
388 this.flashDevice.setArg(" -flashdevice ", flashDevice);
389 }
390
391 /**
392 getFlashDeviceImage
393
394 This function is to get class member "flashDeviceImage"
395
396 @return flashDeviceImage name of flash device image
397 **/
398 public String getFlashDeviceImage() {
399 return this.flashDeviceImage.getValue();
400 }
401
402 /**
403 setFlashDeviceImage
404
405 This function is to set class member "flashDeviceImage"
406
407 @param flashDeviceImage
408 name of flash device image
409 **/
410 public void setFlashDeviceImage(String flashDeviceImage) {
411 this.flashDeviceImage.setArg(" -flashdeviceimage ", flashDeviceImage);
412
413 }
414
415 /**
416 getHeaderFile
417
418 This function is to get class member "headerFile"
419
420 @return headerFile name of include file
421 **/
422 public String getHeaderFile() {
423 return this.headerFile.getValue();
424 }
425
426 /**
427 setHeaderFile
428
429 This function is to set class member "headerFile"
430
431 @param headerFile
432 name of include file
433 **/
434 public void setHeaderFile(String headerFile) {
435 this.headerFile.setArg(" -hfile ", headerFile);
436 }
437
438 /**
439 getImageOutFile
440
441 This function is to get class member "imageOutFile"
442
443 @return imageOutFile name of output image file
444 **/
445 public String getImageOutFile() {
446 return this.imageOutFile.getValue();
447 }
448
449 /**
450 setImageOutFile
451
452 This function is to set class member "ImageOutFile"
453
454 @param imageOutFile
455 name of output image file
456 **/
457 public void setImageOutFile(String imageOutFile) {
458 this.imageOutFile.setArg(" -imageout ", imageOutFile);
459 }
460
461 /**
462 getInStrFile
463
464 This function is to get class member "inStrFile"
465
466 @return inStrFile name of input file which used to replace symbol names.
467 **/
468 public String getInStrFile() {
469 return this.inStrFile;
470 }
471
472 /**
473 setInStrFile
474
475 This function is to set class member "inStrFile"
476
477 @param inStrFile
478 name of input file which used to replace symbol names.
479 **/
480 public void setInStrFile(String inStrFile) {
481 this.inStrFile = inStrFile;
482 }
483
484 /**
485 getMciFile
486
487 This function is to get class member "mciFile"
488
489 @return mciFile name of input microcode file
490 **/
491 public String getMciFile() {
492 return this.mciFile.getValue();
493 }
494
495 /**
496 setMciFile
497
498 This function is to set class member "mciFile"
499
500 @param mciFile
501 name of input microcode file
502 **/
503 public void setMciFile(String mciFile) {
504 this.mciFile.setArg(" -mci ", mciFile);
505 }
506
507 /**
508 getMcoFile
509
510 This function is to get class member "mcoFile"
511
512 @return mcoFile name of output binary microcode image
513 **/
514 public String getMcoFile() {
515 return this.mcoFile.getValue();
516 }
517
518 /**
519 setMcoFile
520
521 This function is to set class member "mcoFile"
522
523 @param mcoFile
524 name of output binary microcode image
525 **/
526 public void setMcoFile(String mcoFile) {
527 this.mcoFile.setArg(" -mco ", mcoFile);
528 }
529
530 /**
531 getOutStrFile
532
533 This function is to get class member "outStrFile"
534
535 @return outStrFile name of output string substitution file
536 **/
537 public String getOutStrFile() {
538 return this.outStrFile;
539 }
540
541 /**
542 setOutStrFile
543
544 This function is to set class member "outStrFile"
545
546 @param outStrFile
547 name of output string substitution file
548 **/
549 public void setOutStrFile(String outStrFile) {
550 this.outStrFile = outStrFile;
551 }
552
553 /**
554 getPadValue
555
556 This function is to get class member "padValue"
557
558 @return padValue string of byte value to use as padding
559 **/
560 public String getPadValue() {
561 return this.padValue.getValue();
562 }
563
564 /**
565 setPadValue
566
567 This function is to set class member "padValue"
568
569 @param padValue
570 string of byte value to use as padding
571 **/
572 public void setPadValue(String padValue) {
573 this.padValue.setArg(" -padvalue ", padValue);
574 }
575
576 /**
577 addMciFile
578
579 This function is to add Microcode binary file
580
581 @param mciFile
582 instance of input class
583 **/
584 public void addConfiguredMciFile(FileArg mciFile) {
585 this.mciFileArray.setPrefix(" -mcmerge ");
586 this.mciFileArray.insert(mciFile);
587 }
588
589 /**
590 getOutputDir
591
592 This function is to get class member "outputDir"
593
594 @return outputDir string of output directory
595 **/
596 public String getOutputDir() {
597 return outputDir;
598 }
599
600 /**
601 setOutputDir
602
603 This function is to set class member "outputDir"
604
605 @param outputDir
606 string of output directory
607 **/
608 public void setOutputDir(String outputDir) {
609 this.outputDir = outputDir;
610 }
611
612 //
613 // Dependency check
614 //
615 private boolean isUptodate() {
616 long srcTimeStamp = 0;
617 String srcName = "";
618 long dstTimeStamp = 0;
619 String dstName = "";
620 long timeStamp = 0;
621
622 if (!flashDefFile.isEmpty()) {
623 srcName = flashDefFile.getValue();
624 timeStamp = new File(srcName).lastModified();
625 if (timeStamp > srcTimeStamp) {
626 srcTimeStamp = timeStamp;
627 }
628 }
629
630 if (!mciFile.isEmpty()) {
631 srcName = mciFile.getValue();
632 timeStamp = new File(srcName).lastModified();
633 if (timeStamp > srcTimeStamp) {
634 srcTimeStamp = timeStamp;
635 }
636 }
637
638 if (!fdImage.isEmpty()) {
639 srcName = fdImage.getValue();
640 timeStamp = new File(srcName).lastModified();
641 if (timeStamp > srcTimeStamp) {
642 srcTimeStamp = timeStamp;
643 }
644 }
645
646 if (inStrFile.length() != 0) {
647 srcName = inStrFile;
648 timeStamp = new File(srcName).lastModified();
649 if (timeStamp > srcTimeStamp) {
650 srcTimeStamp = timeStamp;
651 }
652 }
653
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;
660 }
661 }
662 }
663
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);
670 }
671
672 if (srcTimeStamp > dstFile.lastModified()) {
673 EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");
674 return false;
675 }
676 }
677
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);
684 }
685
686 if (srcTimeStamp > dstFile.lastModified()) {
687 EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");
688 return false;
689 }
690 }
691
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);
698 }
699
700 if (srcTimeStamp > dstFile.lastModified()) {
701 EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");
702 return false;
703 }
704 }
705
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);
712 }
713
714 if (srcTimeStamp > dstFile.lastModified()) {
715 EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");
716 return false;
717 }
718 }
719
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);
726 }
727
728 if (srcTimeStamp > dstFile.lastModified()) {
729 EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");
730 return false;
731 }
732 }
733
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);
740 }
741
742 if (srcTimeStamp > dstFile.lastModified()) {
743 EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");
744 return false;
745 }
746 }
747
748 return true;
749 }
750 }