]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
9b6268903d59d0d3bc6e585f976f1d9f0b1c7734
[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 java.io.InputStreamReader;
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25
26 import org.apache.tools.ant.Task;
27 import org.apache.tools.ant.Project;
28 import org.apache.tools.ant.BuildException;
29
30 import org.tianocore.common.logger.EdkLog;
31
32 /**
33 * FlashMapTask class.
34 *
35 * FlashMapTask is used to call FlashMap.exe to generate flash map defition files and fd files.
36 */
37 public class FlashMapTask extends Task implements EfiDefine {
38 // /
39 // / tool name
40 // /
41 private final String toolName = "FlashMap";
42
43 // /
44 // / Flash definition file
45 // /
46 private String flashDefFile = "";
47
48 // /
49 // / Flash device
50 // /
51 private String flashDevice = "";
52
53 // /
54 // / Flash device Image
55 // /
56 private String flashDeviceImage = "";
57
58 // /
59 // / MCI file
60 // /
61 private String mciFile = "";
62
63 // /
64 // / MCO file
65 // /
66 private String mcoFile = "";
67
68 // /
69 // / Discover FD image
70 // /
71 private String fdImage = "";
72
73 // /
74 // / Dsc file
75 // /
76 private String dscFile = "";
77
78 // /
79 // / Asm INC file
80 // /
81 private String asmIncFile = "";
82
83 // /
84 // / Image out file
85 // /
86 private String imageOutFile = "";
87
88 // /
89 // / Header file
90 // /
91 private String headerFile = "";
92
93 // /
94 // / Input string file
95 // /
96 private String inStrFile = "";
97
98 // /
99 // / Output string file
100 // /
101 private String outStrFile = "";
102
103 // /
104 // / Base address
105 // /
106 private String baseAddr = "";
107
108 // /
109 // / Aligment
110 // /
111 private String aligment = "";
112
113 // /
114 // / Padding value
115 // /
116 private String padValue = "";
117
118 // /
119 // / output directory
120 // /
121 private String outputDir = ".";
122
123 // /
124 // / MCI file array
125 // /
126 List<Input> mciFileArray = new ArrayList<Input>();
127
128 // /
129 // / command and argument list
130 // /
131 LinkedList<String> argList = new LinkedList<String>();
132
133 /**
134 * execute
135 *
136 * FlashMapTask execute function is to assemble tool command line & execute
137 * tool command line
138 *
139 * @throws BuidException
140 */
141 public void execute() throws BuildException {
142
143 Project project = this.getOwningTarget().getProject();
144 //
145 // set Logger
146 //
147 FrameworkLogger logger = new FrameworkLogger(project, "flashmap");
148 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
149 EdkLog.setLogger(logger);
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.separatorChar + toolName;
159 }
160 argList.addFirst(command);
161
162 //
163 // add substituted input file and output file
164 //
165 if (this.inStrFile != null && this.outStrFile != null
166 && !this.inStrFile.equalsIgnoreCase("")
167 && !this.inStrFile.equalsIgnoreCase("")) {
168 argList.add("-strsub");
169 argList.add(this.inStrFile);
170 argList.add(this.outStrFile);
171 }
172
173
174 //
175 // add microcode binary files
176 //
177 if (mciFileArray.size() > 0) {
178 argList.add("-mcmerge");
179 Iterator mciList = mciFileArray.iterator();
180 while (mciList.hasNext()) {
181 argList.add(((Input) mciList.next()).getFile());
182 }
183 }
184
185 //
186 // lauch the program
187 //
188 ProcessBuilder pb = new ProcessBuilder(argList);
189 pb.directory(new File(outputDir));
190 int exitCode = 0;
191 try {
192 Process cmdProc = pb.start();
193 InputStreamReader cmdOut = new InputStreamReader(cmdProc
194 .getInputStream());
195 char[] buf = new char[1024];
196
197 exitCode = cmdProc.waitFor();
198 //
199 // log command line string.
200 //
201 EdkLog.log(EdkLog.EDK_VERBOSE, cmdProc.getOutputStream().toString());
202 EdkLog.log(EdkLog.EDK_INFO, (new File(this.flashDefFile)).getName());
203 if (exitCode != 0) {
204 int len = cmdOut.read(buf, 0, 1024);
205 EdkLog.log(EdkLog.EDK_INFO, new String(buf, 0, len));
206 } else {
207 EdkLog.log(EdkLog.EDK_VERBOSE, "FlashMap succeeded!");
208 }
209 } catch (Exception e) {
210 throw new BuildException(e.getMessage());
211 } finally {
212 if (exitCode != 0) {
213 throw new BuildException("FlashMap failed!");
214 }
215 }
216 }
217
218 /**
219 * getFlashDefFile
220 *
221 * This function is to get class member "flashDefFile"
222 *
223 * @return flashDeFile Name of flash definition file.
224 */
225 public String getFlashDefFile() {
226 return flashDefFile;
227 }
228
229 /**
230 * setFlashDefFile
231 *
232 * This function is to set class member "flashDefFile"
233 *
234 * @param flashDefFile
235 * Name of flash definition file.
236 */
237 public void setFlashDefFile(String flashDefFile) {
238 this.flashDefFile = flashDefFile;
239 argList.add("-fdf");
240 argList.add(this.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 aligment;
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 = aligment;
264 argList.add("-align");
265 argList.add(this.aligment);
266 }
267
268 /**
269 * getAsmIncFile
270 *
271 * This function is to get class member "asmIncFile"
272 *
273 * @return asmIncFile String of ASM include file.
274 */
275 public String getAsmIncFile() {
276 return asmIncFile;
277 }
278
279 /**
280 * setAsmIncFile
281 *
282 * This function is to set class member "asmIncFile"
283 *
284 * @param asmIncFile
285 * String of ASM include file.
286 */
287 public void setAsmIncFile(String asmIncFile) {
288 this.asmIncFile = asmIncFile;
289 argList.add("-asmincfile");
290 argList.add(this.asmIncFile);
291 }
292
293 /**
294 * getBaseAddr
295 *
296 * This function is to get class member "baseAddr"
297 *
298 * @return baseAddr String of base address value.
299 */
300 public String getBaseAddr() {
301 return baseAddr;
302 }
303
304 /**
305 * setBaseAddr
306 *
307 * This function is to set class member "baseAddr"
308 *
309 * @param baseAddr
310 * String of base address value.
311 */
312 public void setBaseAddr(String baseAddr) {
313 this.baseAddr = baseAddr;
314 argList.add("-baseaddr");
315 argList.add(this.baseAddr);
316 }
317
318 /**
319 * getDscFile
320 *
321 * This function is to get class member "dscFile"
322 *
323 * @return dscFile name of DSC file
324 */
325 public String getDscFile() {
326 return dscFile;
327 }
328
329 /**
330 * setDscFile
331 *
332 * This function is to set class member "dscFile"
333 *
334 * @param dscFile
335 * name of DSC file
336 */
337 public void setDscFile(String dscFile) {
338 this.dscFile = dscFile;
339 argList.add("-dsc");
340 argList.add(this.dscFile);
341 }
342
343 /**
344 * getFdImage
345 *
346 * This function is to get class member "fdImage"
347 *
348 * @return fdImage name of input FDI image file.
349 */
350 public String getFdImage() {
351 return fdImage;
352 }
353
354 /**
355 * setFdImage
356 *
357 * This function is to set class member "fdImage"
358 *
359 * @param fdImage
360 * name of input FDI image file.
361 */
362 public void setFdImage(String fdImage) {
363 this.fdImage = fdImage;
364 argList.add("-discover");
365 argList.add(this.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 flashDevice;
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 = flashDevice;
389 argList.add("-flashdevice");
390 argList.add(this.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 flashDeviceImage;
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 = flashDeviceImage;
414 argList.add("-flashdeviceimage");
415 argList.add(this.flashDeviceImage);
416
417 }
418
419 /**
420 * getHeaderFile
421 *
422 * This function is to get class member "headerFile"
423 *
424 * @return headerFile name of include file
425 */
426 public String getHeaderFile() {
427 return headerFile;
428 }
429
430 /**
431 * setHeaderFile
432 *
433 * This function is to set class member "headerFile"
434 *
435 * @param headerFile
436 * name of include file
437 */
438 public void setHeaderFile(String headerFile) {
439 this.headerFile = headerFile;
440 argList.add("-hfile");
441 argList.add(this.headerFile);
442 }
443
444 /**
445 * getImageOutFile
446 *
447 * This function is to get class member "imageOutFile"
448 *
449 * @return imageOutFile name of output image file
450 */
451 public String getImageOutFile() {
452 return imageOutFile;
453 }
454
455 /**
456 * setImageOutFile
457 *
458 * This function is to set class member "ImageOutFile"
459 *
460 * @param imageOutFile
461 * name of output image file
462 */
463 public void setImageOutFile(String imageOutFile) {
464 this.imageOutFile = imageOutFile;
465 argList.add("-imageout");
466 argList.add(this.imageOutFile);
467 }
468
469 /**
470 * getInStrFile
471 *
472 * This function is to get class member "inStrFile"
473 *
474 * @return inStrFile name of input file which used to replace symbol names.
475 */
476 public String getInStrFile() {
477 return inStrFile;
478 }
479
480 /**
481 * setInStrFile
482 *
483 * This function is to set class member "inStrFile"
484 *
485 * @param inStrFile
486 * name of input file which used to replace symbol names.
487 */
488 public void setInStrFile(String inStrFile) {
489 this.inStrFile = inStrFile;
490 }
491
492 /**
493 * getMciFile
494 *
495 * This function is to get class member "mciFile"
496 *
497 * @return mciFile name of input microcode file
498 */
499 public String getMciFile() {
500 return mciFile;
501 }
502
503 /**
504 * setMciFile
505 *
506 * This function is to set class member "mciFile"
507 *
508 * @param mciFile
509 * name of input microcode file
510 */
511 public void setMciFile(String mciFile) {
512 this.mciFile = mciFile;
513 argList.add("-mci");
514 argList.add(this.mciFile);
515 }
516
517 /**
518 * getMcoFile
519 *
520 * This function is to get class member "mcoFile"
521 *
522 * @return mcoFile name of output binary microcode image
523 */
524 public String getMcoFile() {
525 return mcoFile;
526 }
527
528 /**
529 * setMcoFile
530 *
531 * This function is to set class member "mcoFile"
532 *
533 * @param mcoFile
534 * name of output binary microcode image
535 */
536 public void setMcoFile(String mcoFile) {
537 this.mcoFile = mcoFile;
538 argList.add("-mco");
539 argList.add(this.mcoFile);
540 }
541
542 /**
543 * getOutStrFile
544 *
545 * This function is to get class member "outStrFile"
546 *
547 * @return outStrFile name of output string substitution file
548 */
549 public String getOutStrFile() {
550 return outStrFile;
551 }
552
553 /**
554 * setOutStrFile
555 *
556 * This function is to set class member "outStrFile"
557 *
558 * @param outStrFile
559 * name of output string substitution file
560 */
561 public void setOutStrFile(String outStrFile) {
562 this.outStrFile = outStrFile;
563 }
564
565 /**
566 * getPadValue
567 *
568 * This function is to get class member "padValue"
569 *
570 * @return padValue string of byte value to use as padding
571 */
572 public String getPadValue() {
573 return padValue;
574 }
575
576 /**
577 * setPadValue
578 *
579 * This function is to set class member "padValue"
580 *
581 * @param padValue
582 * string of byte value to use as padding
583 */
584 public void setPadValue(String padValue) {
585 this.padValue = padValue;
586 argList.add("-padvalue");
587 argList.add(this.padValue);
588 }
589
590 /**
591 * addMciFile
592 *
593 * This function is to add Microcode binary file
594 *
595 * @param mciFile
596 * instance of input class
597 */
598 public void addMciFile(Input mciFile) {
599 this.mciFileArray.add(mciFile);
600 }
601
602 /**
603 * getOutputDir
604 *
605 * This function is to get class member "outputDir"
606 *
607 * @return outputDir string of output directory
608 */
609 public String getOutputDir() {
610 return outputDir;
611 }
612
613 /**
614 * setOutputDir
615 *
616 * This function is to set class member "outputDir"
617 *
618 * @param outputDir
619 * string of output directory
620 */
621 public void setOutputDir(String outputDir) {
622 this.outputDir = outputDir;
623 }
624 }