]>
Commit | Line | Data |
---|---|---|
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 | |
17 | package org.tianocore.framework.tasks;\r | |
18 | \r | |
19 | import java.io.File;\r | |
20 | import java.io.InputStreamReader;\r | |
21 | import java.util.ArrayList;\r | |
22 | import java.util.Iterator;\r | |
23 | import java.util.LinkedList;\r | |
24 | import java.util.List;\r | |
25 | \r | |
26 | import org.apache.tools.ant.Task;\r | |
27 | import org.apache.tools.ant.Project;\r | |
28 | import org.apache.tools.ant.BuildException;\r | |
29 | \r | |
30 | import org.tianocore.common.logger.EdkLog;\r | |
31 | \r | |
32 | /**\r | |
33 | * FlashMapTask class.\r | |
34 | *\r | |
35 | * FlashMapTask is used to call FlashMap.exe to generate flash map defition files and fd files.\r | |
36 | */\r | |
37 | public 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 | |
44 | // / Flash definition file\r | |
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 | |
121 | private String outputDir = ".";\r | |
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 | |
135 | *\r | |
136 | * FlashMapTask execute function is to assemble tool command line & execute\r | |
137 | * tool command line\r | |
138 | *\r | |
139 | * @throws BuidException\r | |
140 | */\r | |
141 | public void execute() throws BuildException {\r | |
142 | \r | |
143 | Project project = this.getOwningTarget().getProject();\r | |
144 | //\r | |
145 | // set Logger\r | |
146 | //\r | |
147 | FrameworkLogger logger = new FrameworkLogger(project, "flashmap");\r | |
148 | EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r | |
149 | EdkLog.setLogger(logger);\r | |
150 | //\r | |
151 | // absolute path of efi tools\r | |
152 | //\r | |
153 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
154 | String command;\r | |
155 | if (path == null) {\r | |
156 | command = toolName;\r | |
157 | } else {\r | |
158 | command = path + File.separatorChar + toolName;\r | |
159 | }\r | |
160 | argList.addFirst(command);\r | |
161 | \r | |
162 | //\r | |
163 | // add substituted input file and output file\r | |
164 | //\r | |
165 | if (this.inStrFile != null && this.outStrFile != null\r | |
166 | && !this.inStrFile.equalsIgnoreCase("")\r | |
167 | && !this.inStrFile.equalsIgnoreCase("")) {\r | |
168 | argList.add("-strsub");\r | |
169 | argList.add(this.inStrFile);\r | |
170 | argList.add(this.outStrFile);\r | |
171 | }\r | |
172 | \r | |
173 | \r | |
174 | //\r | |
175 | // add microcode binary files\r | |
176 | //\r | |
177 | if (mciFileArray.size() > 0) {\r | |
178 | argList.add("-mcmerge");\r | |
179 | Iterator mciList = mciFileArray.iterator();\r | |
180 | while (mciList.hasNext()) {\r | |
181 | argList.add(((Input) mciList.next()).getFile());\r | |
182 | }\r | |
183 | }\r | |
184 | \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_VERBOSE, cmdProc.getOutputStream().toString());\r | |
202 | EdkLog.log(EdkLog.EDK_INFO, (new File(this.flashDefFile)).getName());\r | |
203 | if (exitCode != 0) {\r | |
204 | int len = cmdOut.read(buf, 0, 1024);\r | |
205 | EdkLog.log(EdkLog.EDK_INFO, new String(buf, 0, len));\r | |
206 | } else {\r | |
207 | EdkLog.log(EdkLog.EDK_VERBOSE, "FlashMap succeeded!");\r | |
208 | }\r | |
209 | } catch (Exception e) {\r | |
210 | throw new BuildException(e.getMessage());\r | |
211 | } finally {\r | |
212 | if (exitCode != 0) {\r | |
213 | throw new BuildException("FlashMap failed!");\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 |