]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
dc3463890e14bcd9149d1ce3b3431e92ce2bbb24
[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 import org.tianocore.logger.EdkLog;
30
31 /**
32 * SecFixupTask class.
33 *
34 * SecFixupTask is used to call SecFixup.exe to fix up sec image.
35 */
36 public class FlashMapTask extends Task implements EfiDefine {
37 // /
38 // / tool name
39 // /
40 private final String toolName = "FlashMap";
41
42 // /
43 // / Flash default file
44 // /
45 private String flashDefFile = "";
46
47 // /
48 // / Flash device
49 // /
50 private String flashDevice = "";
51
52 // /
53 // / Flash device Image
54 // /
55 private String flashDeviceImage = "";
56
57 // /
58 // / MCI file
59 // /
60 private String mciFile = "";
61
62 // /
63 // / MCO file
64 // /
65 private String mcoFile = "";
66
67 // /
68 // / Discover FD image
69 // /
70 private String fdImage = "";
71
72 // /
73 // / Dsc file
74 // /
75 private String dscFile = "";
76
77 // /
78 // / Asm INC file
79 // /
80 private String asmIncFile = "";
81
82 // /
83 // / Image out file
84 // /
85 private String imageOutFile = "";
86
87 // /
88 // / Header file
89 // /
90 private String headerFile = "";
91
92 // /
93 // / Input string file
94 // /
95 private String inStrFile = "";
96
97 // /
98 // / Output string file
99 // /
100 private String outStrFile = "";
101
102 // /
103 // / Base address
104 // /
105 private String baseAddr = "";
106
107 // /
108 // / Aligment
109 // /
110 private String aligment = "";
111
112 // /
113 // / Padding value
114 // /
115 private String padValue = "";
116
117 // /
118 // / output directory
119 // /
120 private String outputDir = "";
121
122 // /
123 // / MCI file array
124 // /
125 List<Input> mciFileArray = new ArrayList<Input>();
126
127 // /
128 // / command and argument list
129 // /
130 LinkedList<String> argList = new LinkedList<String>();
131
132 /**
133 * execute
134 *
135 * FlashMapTask execute function is to assemble tool command line & execute
136 * tool command line
137 *
138 * @throws BuidException
139 */
140 public void execute() throws BuildException {
141
142 Project project = this.getOwningTarget().getProject();
143 //
144 // set Logger
145 //
146 FrameworkLogger logger = new FrameworkLogger(project, "flashmap");
147 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
148 EdkLog.setLogger(logger);
149 //
150 // absolute path of efi tools
151 //
152 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
153 String command;
154 if (path == null) {
155 command = toolName;
156 } else {
157 command = path + File.separatorChar + toolName;
158 }
159 argList.addFirst(command);
160
161 //
162 // add substituted input file and output file
163 //
164 if (this.inStrFile != null && this.outStrFile != null
165 && !this.inStrFile.equalsIgnoreCase("")
166 && !this.inStrFile.equalsIgnoreCase("")) {
167 argList.add("-strsub");
168 argList.add(this.inStrFile);
169 argList.add(this.outStrFile);
170 }
171
172
173 //
174 // add microcode binary files
175 //
176 if (mciFileArray.size() > 0) {
177 argList.add("-mcmerge");
178 Iterator mciList = mciFileArray.iterator();
179 while (mciList.hasNext()) {
180 argList.add(((Input) mciList.next()).getFile());
181 }
182 }
183
184 EdkLog.log(EdkLog.EDK_INFO, argList.toString().replace(",",""));
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_INFO, cmdProc.getOutputStream().toString());
202 if (exitCode != 0) {
203 int len = cmdOut.read(buf, 0, 1024);
204 EdkLog.log(EdkLog.EDK_ERROR, new String(buf, 0, len));
205 } else {
206 EdkLog.log(EdkLog.EDK_INFO, "FlashMap succeed!");
207 }
208 } catch (Exception e) {
209 throw new BuildException(e.getMessage());
210 } finally {
211 if (exitCode != 0) {
212 // throw new BuildException("GenFvImage: failed to generate FV
213 // file!");
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 }