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