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