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