]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
Remove FrameworkLogger in FrameworkTasks and EdkException in GenBuild. Update EdkLog...
[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 // absolute path of efi tools
146 //
147 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
148 String command;
149 if (path == null) {
150 command = toolName;
151 } else {
152 command = path + File.separatorChar + toolName;
153 }
154 argList.addFirst(command);
155
156 //
157 // add substituted input file and output file
158 //
159 if (this.inStrFile != null && this.outStrFile != null
160 && !this.inStrFile.equalsIgnoreCase("")
161 && !this.inStrFile.equalsIgnoreCase("")) {
162 argList.add("-strsub");
163 argList.add(this.inStrFile);
164 argList.add(this.outStrFile);
165 }
166
167
168 //
169 // add microcode binary files
170 //
171 if (mciFileArray.size() > 0) {
172 argList.add("-mcmerge");
173 Iterator mciList = mciFileArray.iterator();
174 while (mciList.hasNext()) {
175 argList.addAll(((Input) mciList.next()).getNameList());
176 }
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 Process cmdProc = pb.start();
187 InputStreamReader cmdOut = new InputStreamReader(cmdProc
188 .getInputStream());
189 char[] buf = new char[1024];
190
191 exitCode = cmdProc.waitFor();
192 //
193 // log command line string.
194 //
195 EdkLog.log(this, EdkLog.EDK_VERBOSE, cmdProc.getOutputStream().toString());
196 EdkLog.log(this, EdkLog.EDK_INFO, (new File(this.flashDefFile)).getName());
197 if (exitCode != 0) {
198 int len = cmdOut.read(buf, 0, 1024);
199 EdkLog.log(this, EdkLog.EDK_INFO, new String(buf, 0, len));
200 } else {
201 EdkLog.log(this, EdkLog.EDK_VERBOSE, "FlashMap succeeded!");
202 }
203 } catch (Exception e) {
204 throw new BuildException(e.getMessage());
205 } finally {
206 if (exitCode != 0) {
207 throw new BuildException("FlashMap failed!");
208 }
209 }
210 }
211
212 /**
213 * getFlashDefFile
214 *
215 * This function is to get class member "flashDefFile"
216 *
217 * @return flashDeFile Name of flash definition file.
218 */
219 public String getFlashDefFile() {
220 return flashDefFile;
221 }
222
223 /**
224 * setFlashDefFile
225 *
226 * This function is to set class member "flashDefFile"
227 *
228 * @param flashDefFile
229 * Name of flash definition file.
230 */
231 public void setFlashDefFile(String flashDefFile) {
232 this.flashDefFile = flashDefFile;
233 argList.add("-fdf");
234 argList.add(this.flashDefFile);
235 }
236
237 /**
238 * getAligment
239 *
240 * This function is to get class member "aligment"
241 *
242 * @return aligment String of aligment value.
243 */
244 public String getAligment() {
245 return aligment;
246 }
247
248 /**
249 * setAligment
250 *
251 * This function is to set class member "aligment"
252 *
253 * @param aligment
254 * String of aligment value.
255 */
256 public void setAligment(String aligment) {
257 this.aligment = aligment;
258 argList.add("-align");
259 argList.add(this.aligment);
260 }
261
262 /**
263 * getAsmIncFile
264 *
265 * This function is to get class member "asmIncFile"
266 *
267 * @return asmIncFile String of ASM include file.
268 */
269 public String getAsmIncFile() {
270 return asmIncFile;
271 }
272
273 /**
274 * setAsmIncFile
275 *
276 * This function is to set class member "asmIncFile"
277 *
278 * @param asmIncFile
279 * String of ASM include file.
280 */
281 public void setAsmIncFile(String asmIncFile) {
282 this.asmIncFile = asmIncFile;
283 argList.add("-asmincfile");
284 argList.add(this.asmIncFile);
285 }
286
287 /**
288 * getBaseAddr
289 *
290 * This function is to get class member "baseAddr"
291 *
292 * @return baseAddr String of base address value.
293 */
294 public String getBaseAddr() {
295 return baseAddr;
296 }
297
298 /**
299 * setBaseAddr
300 *
301 * This function is to set class member "baseAddr"
302 *
303 * @param baseAddr
304 * String of base address value.
305 */
306 public void setBaseAddr(String baseAddr) {
307 this.baseAddr = baseAddr;
308 argList.add("-baseaddr");
309 argList.add(this.baseAddr);
310 }
311
312 /**
313 * getDscFile
314 *
315 * This function is to get class member "dscFile"
316 *
317 * @return dscFile name of DSC file
318 */
319 public String getDscFile() {
320 return dscFile;
321 }
322
323 /**
324 * setDscFile
325 *
326 * This function is to set class member "dscFile"
327 *
328 * @param dscFile
329 * name of DSC file
330 */
331 public void setDscFile(String dscFile) {
332 this.dscFile = dscFile;
333 argList.add("-dsc");
334 argList.add(this.dscFile);
335 }
336
337 /**
338 * getFdImage
339 *
340 * This function is to get class member "fdImage"
341 *
342 * @return fdImage name of input FDI image file.
343 */
344 public String getFdImage() {
345 return fdImage;
346 }
347
348 /**
349 * setFdImage
350 *
351 * This function is to set class member "fdImage"
352 *
353 * @param fdImage
354 * name of input FDI image file.
355 */
356 public void setFdImage(String fdImage) {
357 this.fdImage = fdImage;
358 argList.add("-discover");
359 argList.add(this.fdImage);
360 }
361
362 /**
363 * getFlashDevice
364 *
365 * This function is to get class member "flashDevice".
366 *
367 * @return flashDevice name of flash device.
368 */
369 public String getFlashDevice() {
370 return flashDevice;
371 }
372
373 /**
374 * setFlashDevice
375 *
376 * This function is to set class member "flashDevice"
377 *
378 * @param flashDevice
379 * name of flash device.
380 */
381 public void setFlashDevice(String flashDevice) {
382 this.flashDevice = flashDevice;
383 argList.add("-flashdevice");
384 argList.add(this.flashDevice);
385 }
386
387 /**
388 * getFlashDeviceImage
389 *
390 * This function is to get class member "flashDeviceImage"
391 *
392 * @return flashDeviceImage name of flash device image
393 */
394 public String getFlashDeviceImage() {
395 return flashDeviceImage;
396 }
397
398 /**
399 * setFlashDeviceImage
400 *
401 * This function is to set class member "flashDeviceImage"
402 *
403 * @param flashDeviceImage
404 * name of flash device image
405 */
406 public void setFlashDeviceImage(String flashDeviceImage) {
407 this.flashDeviceImage = flashDeviceImage;
408 argList.add("-flashdeviceimage");
409 argList.add(this.flashDeviceImage);
410
411 }
412
413 /**
414 * getHeaderFile
415 *
416 * This function is to get class member "headerFile"
417 *
418 * @return headerFile name of include file
419 */
420 public String getHeaderFile() {
421 return headerFile;
422 }
423
424 /**
425 * setHeaderFile
426 *
427 * This function is to set class member "headerFile"
428 *
429 * @param headerFile
430 * name of include file
431 */
432 public void setHeaderFile(String headerFile) {
433 this.headerFile = headerFile;
434 argList.add("-hfile");
435 argList.add(this.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 imageOutFile;
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 = imageOutFile;
459 argList.add("-imageout");
460 argList.add(this.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 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 mciFile;
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 = mciFile;
507 argList.add("-mci");
508 argList.add(this.mciFile);
509 }
510
511 /**
512 * getMcoFile
513 *
514 * This function is to get class member "mcoFile"
515 *
516 * @return mcoFile name of output binary microcode image
517 */
518 public String getMcoFile() {
519 return mcoFile;
520 }
521
522 /**
523 * setMcoFile
524 *
525 * This function is to set class member "mcoFile"
526 *
527 * @param mcoFile
528 * name of output binary microcode image
529 */
530 public void setMcoFile(String mcoFile) {
531 this.mcoFile = mcoFile;
532 argList.add("-mco");
533 argList.add(this.mcoFile);
534 }
535
536 /**
537 * getOutStrFile
538 *
539 * This function is to get class member "outStrFile"
540 *
541 * @return outStrFile name of output string substitution file
542 */
543 public String getOutStrFile() {
544 return outStrFile;
545 }
546
547 /**
548 * setOutStrFile
549 *
550 * This function is to set class member "outStrFile"
551 *
552 * @param outStrFile
553 * name of output string substitution file
554 */
555 public void setOutStrFile(String outStrFile) {
556 this.outStrFile = outStrFile;
557 }
558
559 /**
560 * getPadValue
561 *
562 * This function is to get class member "padValue"
563 *
564 * @return padValue string of byte value to use as padding
565 */
566 public String getPadValue() {
567 return padValue;
568 }
569
570 /**
571 * setPadValue
572 *
573 * This function is to set class member "padValue"
574 *
575 * @param padValue
576 * string of byte value to use as padding
577 */
578 public void setPadValue(String padValue) {
579 this.padValue = padValue;
580 argList.add("-padvalue");
581 argList.add(this.padValue);
582 }
583
584 /**
585 * addMciFile
586 *
587 * This function is to add Microcode binary file
588 *
589 * @param mciFile
590 * instance of input class
591 */
592 public void addMciFile(Input mciFile) {
593 this.mciFileArray.add(mciFile);
594 }
595
596 /**
597 * getOutputDir
598 *
599 * This function is to get class member "outputDir"
600 *
601 * @return outputDir string of output directory
602 */
603 public String getOutputDir() {
604 return outputDir;
605 }
606
607 /**
608 * setOutputDir
609 *
610 * This function is to set class member "outputDir"
611 *
612 * @param outputDir
613 * string of output directory
614 */
615 public void setOutputDir(String outputDir) {
616 this.outputDir = outputDir;
617 }
618 }