]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
e494e564c835f94094a8e58948cf629dd241c48f
[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 * FlashMapTask class.
33 *
34 * FlashMapTask is used to call FlashMap.exe to generate flash map defition files and fd files.
35 */
36 public class FlashMapTask extends Task implements EfiDefine {
37 // /
38 // / tool name
39 // /
40 private final String toolName = "FlashMap";
41
42 // /
43 // / Flash definition 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 //
185 // lauch the program
186 //
187 ProcessBuilder pb = new ProcessBuilder(argList);
188 pb.directory(new File(outputDir));
189 int exitCode = 0;
190 try {
191 Process cmdProc = pb.start();
192 InputStreamReader cmdOut = new InputStreamReader(cmdProc
193 .getInputStream());
194 char[] buf = new char[1024];
195
196 exitCode = cmdProc.waitFor();
197 //
198 // log command line string.
199 //
200 EdkLog.log(EdkLog.EDK_VERBOSE, cmdProc.getOutputStream().toString());
201 EdkLog.log(EdkLog.EDK_INFO, (new File(this.flashDefFile)).getName());
202 if (exitCode != 0) {
203 int len = cmdOut.read(buf, 0, 1024);
204 EdkLog.log(EdkLog.EDK_INFO, new String(buf, 0, len));
205 } else {
206 EdkLog.log(EdkLog.EDK_VERBOSE, "FlashMap succeeded!");
207 }
208 } catch (Exception e) {
209 throw new BuildException(e.getMessage());
210 } finally {
211 if (exitCode != 0) {
212 throw new BuildException("FlashMap failed!");
213 }
214 }
215 }
216
217 /**
218 * getFlashDefFile
219 *
220 * This function is to get class member "flashDefFile"
221 *
222 * @return flashDeFile Name of flash definition file.
223 */
224 public String getFlashDefFile() {
225 return flashDefFile;
226 }
227
228 /**
229 * setFlashDefFile
230 *
231 * This function is to set class member "flashDefFile"
232 *
233 * @param flashDefFile
234 * Name of flash definition file.
235 */
236 public void setFlashDefFile(String flashDefFile) {
237 this.flashDefFile = flashDefFile;
238 argList.add("-fdf");
239 argList.add(this.flashDefFile);
240 }
241
242 /**
243 * getAligment
244 *
245 * This function is to get class member "aligment"
246 *
247 * @return aligment String of aligment value.
248 */
249 public String getAligment() {
250 return aligment;
251 }
252
253 /**
254 * setAligment
255 *
256 * This function is to set class member "aligment"
257 *
258 * @param aligment
259 * String of aligment value.
260 */
261 public void setAligment(String aligment) {
262 this.aligment = aligment;
263 argList.add("-align");
264 argList.add(this.aligment);
265 }
266
267 /**
268 * getAsmIncFile
269 *
270 * This function is to get class member "asmIncFile"
271 *
272 * @return asmIncFile String of ASM include file.
273 */
274 public String getAsmIncFile() {
275 return asmIncFile;
276 }
277
278 /**
279 * setAsmIncFile
280 *
281 * This function is to set class member "asmIncFile"
282 *
283 * @param asmIncFile
284 * String of ASM include file.
285 */
286 public void setAsmIncFile(String asmIncFile) {
287 this.asmIncFile = asmIncFile;
288 argList.add("-asmincfile");
289 argList.add(this.asmIncFile);
290 }
291
292 /**
293 * getBaseAddr
294 *
295 * This function is to get class member "baseAddr"
296 *
297 * @return baseAddr String of base address value.
298 */
299 public String getBaseAddr() {
300 return baseAddr;
301 }
302
303 /**
304 * setBaseAddr
305 *
306 * This function is to set class member "baseAddr"
307 *
308 * @param baseAddr
309 * String of base address value.
310 */
311 public void setBaseAddr(String baseAddr) {
312 this.baseAddr = baseAddr;
313 argList.add("-baseaddr");
314 argList.add(this.baseAddr);
315 }
316
317 /**
318 * getDscFile
319 *
320 * This function is to get class member "dscFile"
321 *
322 * @return dscFile name of DSC file
323 */
324 public String getDscFile() {
325 return dscFile;
326 }
327
328 /**
329 * setDscFile
330 *
331 * This function is to set class member "dscFile"
332 *
333 * @param dscFile
334 * name of DSC file
335 */
336 public void setDscFile(String dscFile) {
337 this.dscFile = dscFile;
338 argList.add("-dsc");
339 argList.add(this.dscFile);
340 }
341
342 /**
343 * getFdImage
344 *
345 * This function is to get class member "fdImage"
346 *
347 * @return fdImage name of input FDI image file.
348 */
349 public String getFdImage() {
350 return fdImage;
351 }
352
353 /**
354 * setFdImage
355 *
356 * This function is to set class member "fdImage"
357 *
358 * @param fdImage
359 * name of input FDI image file.
360 */
361 public void setFdImage(String fdImage) {
362 this.fdImage = fdImage;
363 argList.add("-discover");
364 argList.add(this.fdImage);
365 }
366
367 /**
368 * getFlashDevice
369 *
370 * This function is to get class member "flashDevice".
371 *
372 * @return flashDevice name of flash device.
373 */
374 public String getFlashDevice() {
375 return flashDevice;
376 }
377
378 /**
379 * setFlashDevice
380 *
381 * This function is to set class member "flashDevice"
382 *
383 * @param flashDevice
384 * name of flash device.
385 */
386 public void setFlashDevice(String flashDevice) {
387 this.flashDevice = flashDevice;
388 argList.add("-flashdevice");
389 argList.add(this.flashDevice);
390 }
391
392 /**
393 * getFlashDeviceImage
394 *
395 * This function is to get class member "flashDeviceImage"
396 *
397 * @return flashDeviceImage name of flash device image
398 */
399 public String getFlashDeviceImage() {
400 return flashDeviceImage;
401 }
402
403 /**
404 * setFlashDeviceImage
405 *
406 * This function is to set class member "flashDeviceImage"
407 *
408 * @param flashDeviceImage
409 * name of flash device image
410 */
411 public void setFlashDeviceImage(String flashDeviceImage) {
412 this.flashDeviceImage = flashDeviceImage;
413 argList.add("-flashdeviceimage");
414 argList.add(this.flashDeviceImage);
415
416 }
417
418 /**
419 * getHeaderFile
420 *
421 * This function is to get class member "headerFile"
422 *
423 * @return headerFile name of include file
424 */
425 public String getHeaderFile() {
426 return headerFile;
427 }
428
429 /**
430 * setHeaderFile
431 *
432 * This function is to set class member "headerFile"
433 *
434 * @param headerFile
435 * name of include file
436 */
437 public void setHeaderFile(String headerFile) {
438 this.headerFile = headerFile;
439 argList.add("-hfile");
440 argList.add(this.headerFile);
441 }
442
443 /**
444 * getImageOutFile
445 *
446 * This function is to get class member "imageOutFile"
447 *
448 * @return imageOutFile name of output image file
449 */
450 public String getImageOutFile() {
451 return imageOutFile;
452 }
453
454 /**
455 * setImageOutFile
456 *
457 * This function is to set class member "ImageOutFile"
458 *
459 * @param imageOutFile
460 * name of output image file
461 */
462 public void setImageOutFile(String imageOutFile) {
463 this.imageOutFile = imageOutFile;
464 argList.add("-imageout");
465 argList.add(this.imageOutFile);
466 }
467
468 /**
469 * getInStrFile
470 *
471 * This function is to get class member "inStrFile"
472 *
473 * @return inStrFile name of input file which used to replace symbol names.
474 */
475 public String getInStrFile() {
476 return inStrFile;
477 }
478
479 /**
480 * setInStrFile
481 *
482 * This function is to set class member "inStrFile"
483 *
484 * @param inStrFile
485 * name of input file which used to replace symbol names.
486 */
487 public void setInStrFile(String inStrFile) {
488 this.inStrFile = inStrFile;
489 }
490
491 /**
492 * getMciFile
493 *
494 * This function is to get class member "mciFile"
495 *
496 * @return mciFile name of input microcode file
497 */
498 public String getMciFile() {
499 return mciFile;
500 }
501
502 /**
503 * setMciFile
504 *
505 * This function is to set class member "mciFile"
506 *
507 * @param mciFile
508 * name of input microcode file
509 */
510 public void setMciFile(String mciFile) {
511 this.mciFile = mciFile;
512 argList.add("-mci");
513 argList.add(this.mciFile);
514 }
515
516 /**
517 * getMcoFile
518 *
519 * This function is to get class member "mcoFile"
520 *
521 * @return mcoFile name of output binary microcode image
522 */
523 public String getMcoFile() {
524 return mcoFile;
525 }
526
527 /**
528 * setMcoFile
529 *
530 * This function is to set class member "mcoFile"
531 *
532 * @param mcoFile
533 * name of output binary microcode image
534 */
535 public void setMcoFile(String mcoFile) {
536 this.mcoFile = mcoFile;
537 argList.add("-mco");
538 argList.add(this.mcoFile);
539 }
540
541 /**
542 * getOutStrFile
543 *
544 * This function is to get class member "outStrFile"
545 *
546 * @return outStrFile name of output string substitution file
547 */
548 public String getOutStrFile() {
549 return outStrFile;
550 }
551
552 /**
553 * setOutStrFile
554 *
555 * This function is to set class member "outStrFile"
556 *
557 * @param outStrFile
558 * name of output string substitution file
559 */
560 public void setOutStrFile(String outStrFile) {
561 this.outStrFile = outStrFile;
562 }
563
564 /**
565 * getPadValue
566 *
567 * This function is to get class member "padValue"
568 *
569 * @return padValue string of byte value to use as padding
570 */
571 public String getPadValue() {
572 return padValue;
573 }
574
575 /**
576 * setPadValue
577 *
578 * This function is to set class member "padValue"
579 *
580 * @param padValue
581 * string of byte value to use as padding
582 */
583 public void setPadValue(String padValue) {
584 this.padValue = padValue;
585 argList.add("-padvalue");
586 argList.add(this.padValue);
587 }
588
589 /**
590 * addMciFile
591 *
592 * This function is to add Microcode binary file
593 *
594 * @param mciFile
595 * instance of input class
596 */
597 public void addMciFile(Input mciFile) {
598 this.mciFileArray.add(mciFile);
599 }
600
601 /**
602 * getOutputDir
603 *
604 * This function is to get class member "outputDir"
605 *
606 * @return outputDir string of output directory
607 */
608 public String getOutputDir() {
609 return outputDir;
610 }
611
612 /**
613 * setOutputDir
614 *
615 * This function is to set class member "outputDir"
616 *
617 * @param outputDir
618 * string of output directory
619 */
620 public void setOutputDir(String outputDir) {
621 this.outputDir = outputDir;
622 }
623 }