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