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