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