]>
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.FileReader;\r | |
21 | import java.io.BufferedReader;\r | |
22 | \r | |
23 | import java.util.List;\r | |
24 | import java.util.ArrayList;\r | |
25 | import java.util.regex.Pattern;\r | |
26 | import java.util.regex.Matcher;\r | |
27 | \r | |
28 | import org.apache.tools.ant.Task;\r | |
29 | import org.apache.tools.ant.Project;\r | |
30 | import org.apache.tools.ant.BuildException;\r | |
31 | import org.apache.tools.ant.taskdefs.Execute;\r | |
32 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
33 | import org.apache.tools.ant.types.Commandline;\r | |
34 | \r | |
35 | import org.tianocore.common.logger.EdkLog;\r | |
36 | \r | |
37 | /**\r | |
38 | * FlashMapTask class.\r | |
39 | *\r | |
40 | * FlashMapTask is used to call FlashMap.exe to generate flash map defition files and fd files.\r | |
41 | */\r | |
42 | public class FlashMapTask extends Task implements EfiDefine {\r | |
43 | //\r | |
44 | // tool name\r | |
45 | //\r | |
46 | private static final String toolName = "FlashMap";\r | |
47 | \r | |
48 | //\r | |
49 | // \r | |
50 | // \r | |
51 | private static Pattern fileBlock = Pattern.compile("\\s*File\\s*\\{([^\\{\\}]+)\\}");\r | |
52 | private static Pattern fileNameDef = Pattern.compile("\\bName\\s*=\\s*\"([^\"]+)\"");\r | |
53 | \r | |
54 | //\r | |
55 | // Flash definition file\r | |
56 | //\r | |
57 | private FileArg flashDefFile = new FileArg();\r | |
58 | \r | |
59 | //\r | |
60 | // Flash device\r | |
61 | //\r | |
62 | private ToolArg flashDevice = new ToolArg();\r | |
63 | \r | |
64 | //\r | |
65 | // Flash device Image\r | |
66 | //\r | |
67 | private ToolArg flashDeviceImage = new ToolArg();\r | |
68 | \r | |
69 | //\r | |
70 | // MCI file\r | |
71 | //\r | |
72 | private FileArg mciFile = new FileArg();\r | |
73 | \r | |
74 | //\r | |
75 | // MCO file\r | |
76 | //\r | |
77 | private FileArg mcoFile = new FileArg();\r | |
78 | \r | |
79 | //\r | |
80 | // Discover FD image\r | |
81 | //\r | |
82 | private ToolArg fdImage = new ToolArg();\r | |
83 | \r | |
84 | //\r | |
85 | // Dsc file\r | |
86 | //\r | |
87 | private FileArg dscFile = new FileArg();\r | |
88 | \r | |
89 | //\r | |
90 | // Asm INC file\r | |
91 | //\r | |
92 | private FileArg asmIncFile = new FileArg();\r | |
93 | \r | |
94 | //\r | |
95 | // Image out file\r | |
96 | //\r | |
97 | private FileArg imageOutFile = new FileArg();\r | |
98 | \r | |
99 | //\r | |
100 | // Header file\r | |
101 | //\r | |
102 | private FileArg headerFile = new FileArg();\r | |
103 | \r | |
104 | //\r | |
105 | // Input string file\r | |
106 | //\r | |
107 | private String inStrFile = "";\r | |
108 | \r | |
109 | //\r | |
110 | // Output string file\r | |
111 | //\r | |
112 | private String outStrFile = "";\r | |
113 | \r | |
114 | //\r | |
115 | //\r | |
116 | //\r | |
117 | private FileArg strFile = new FileArg();\r | |
118 | //\r | |
119 | // Base address\r | |
120 | //\r | |
121 | private ToolArg baseAddr = new ToolArg();\r | |
122 | \r | |
123 | //\r | |
124 | // Aligment\r | |
125 | //\r | |
126 | private ToolArg aligment = new ToolArg();\r | |
127 | \r | |
128 | //\r | |
129 | // Padding value\r | |
130 | //\r | |
131 | private ToolArg padValue = new ToolArg();\r | |
132 | \r | |
133 | //\r | |
134 | // output directory\r | |
135 | //\r | |
136 | private String outputDir = ".";\r | |
137 | \r | |
138 | //\r | |
139 | // MCI file array\r | |
140 | //\r | |
141 | FileArg mciFileArray = new FileArg();\r | |
142 | \r | |
143 | /**\r | |
144 | execute\r | |
145 | \r | |
146 | FlashMapTask execute function is to assemble tool command line & execute\r | |
147 | tool command line\r | |
148 | \r | |
149 | @throws BuidException\r | |
150 | **/\r | |
151 | public void execute() throws BuildException {\r | |
152 | if (isUptodate()) {\r | |
153 | EdkLog.log(this, EdkLog.EDK_VERBOSE, headerFile.toFileList()\r | |
154 | + imageOutFile.toFileList()\r | |
155 | + mcoFile.toFileList()\r | |
156 | + dscFile.toFileList()\r | |
157 | + asmIncFile.toFileList()\r | |
158 | + outStrFile\r | |
159 | + " is up-to-date!");\r | |
160 | return;\r | |
161 | }\r | |
162 | \r | |
163 | Project project = this.getOwningTarget().getProject();\r | |
164 | //\r | |
165 | // absolute path of efi tools\r | |
166 | //\r | |
167 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
168 | String command;\r | |
169 | if (path == null) {\r | |
170 | command = toolName;\r | |
171 | } else {\r | |
172 | command = path + File.separator + toolName;\r | |
173 | }\r | |
174 | \r | |
175 | //\r | |
176 | // add substituted input file and output file\r | |
177 | //\r | |
178 | if (this.inStrFile != null && this.outStrFile != null\r | |
179 | && this.inStrFile.length() > 0 && this.outStrFile.length() > 0) {\r | |
180 | strFile.setPrefix(" -strsub ");\r | |
181 | strFile.insValue(this.inStrFile);\r | |
182 | strFile.insValue(this.outStrFile);\r | |
183 | }\r | |
184 | \r | |
185 | String argument = "" + flashDefFile + flashDevice + flashDeviceImage\r | |
186 | + mciFile + mcoFile + fdImage + dscFile + asmIncFile\r | |
187 | + imageOutFile + headerFile + strFile + baseAddr\r | |
188 | + aligment + padValue + mciFileArray;\r | |
189 | \r | |
190 | \r | |
191 | //\r | |
192 | // lauch the program\r | |
193 | //\r | |
194 | // ProcessBuilder pb = new ProcessBuilder(argList);\r | |
195 | // pb.directory(new File(outputDir));\r | |
196 | int exitCode = 0;\r | |
197 | try {\r | |
198 | Commandline cmdline = new Commandline();\r | |
199 | cmdline.setExecutable(command);\r | |
200 | cmdline.createArgument().setLine(argument);\r | |
201 | \r | |
202 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
203 | Project.MSG_INFO, Project.MSG_WARN);\r | |
204 | Execute runner = new Execute(streamHandler, null);\r | |
205 | \r | |
206 | runner.setAntRun(project);\r | |
207 | runner.setCommandline(cmdline.getCommandline());\r | |
208 | \r | |
209 | if (outputDir != null) {\r | |
210 | runner.setWorkingDirectory(new File(outputDir));\r | |
211 | }\r | |
212 | //\r | |
213 | // log command line string.\r | |
214 | //\r | |
215 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r | |
216 | EdkLog.log(this, flashDefFile.toFileList()\r | |
217 | + mciFile.toFileList()\r | |
218 | + mciFileArray.toFileList()\r | |
219 | + fdImage.toFileList()\r | |
220 | + inStrFile\r | |
221 | + " => "\r | |
222 | + headerFile.toFileList()\r | |
223 | + imageOutFile.toFileList()\r | |
224 | + mcoFile.toFileList()\r | |
225 | + dscFile.toFileList()\r | |
226 | + asmIncFile.toFileList()\r | |
227 | + outStrFile);\r | |
228 | \r | |
229 | exitCode = runner.execute();\r | |
230 | if (exitCode != 0) {\r | |
231 | EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));\r | |
232 | } else {\r | |
233 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "FlashMap succeeded!");\r | |
234 | }\r | |
235 | } catch (Exception e) {\r | |
236 | throw new BuildException(e.getMessage());\r | |
237 | } finally {\r | |
238 | if (exitCode != 0) {\r | |
239 | throw new BuildException("FlashMap failed!");\r | |
240 | }\r | |
241 | }\r | |
242 | }\r | |
243 | \r | |
244 | /**\r | |
245 | getFlashDefFile\r | |
246 | \r | |
247 | This function is to get class member "flashDefFile"\r | |
248 | \r | |
249 | @return flashDeFile Name of flash definition file.\r | |
250 | **/\r | |
251 | public String getFlashDefFile() {\r | |
252 | return this.flashDefFile.getValue();\r | |
253 | }\r | |
254 | \r | |
255 | /**\r | |
256 | setFlashDefFile\r | |
257 | \r | |
258 | This function is to set class member "flashDefFile"\r | |
259 | \r | |
260 | @param flashDefFile\r | |
261 | Name of flash definition file.\r | |
262 | **/\r | |
263 | public void setFlashDefFile(String flashDefFile) {\r | |
264 | this.flashDefFile.setArg(" -fdf ", flashDefFile);\r | |
265 | }\r | |
266 | \r | |
267 | /**\r | |
268 | getAligment\r | |
269 | \r | |
270 | This function is to get class member "aligment"\r | |
271 | \r | |
272 | @return aligment String of aligment value.\r | |
273 | **/\r | |
274 | public String getAligment() {\r | |
275 | return this.aligment.getValue();\r | |
276 | }\r | |
277 | \r | |
278 | /**\r | |
279 | setAligment\r | |
280 | \r | |
281 | This function is to set class member "aligment"\r | |
282 | \r | |
283 | @param aligment\r | |
284 | String of aligment value.\r | |
285 | **/\r | |
286 | public void setAligment(String aligment) {\r | |
287 | this.aligment.setArg(" -align ", aligment);\r | |
288 | }\r | |
289 | \r | |
290 | /**\r | |
291 | getAsmIncFile\r | |
292 | \r | |
293 | This function is to get class member "asmIncFile"\r | |
294 | \r | |
295 | @return asmIncFile String of ASM include file.\r | |
296 | **/\r | |
297 | public String getAsmIncFile() {\r | |
298 | return this.asmIncFile.getValue();\r | |
299 | }\r | |
300 | \r | |
301 | /**\r | |
302 | setAsmIncFile\r | |
303 | \r | |
304 | This function is to set class member "asmIncFile"\r | |
305 | \r | |
306 | @param asmIncFile\r | |
307 | String of ASM include file.\r | |
308 | **/\r | |
309 | public void setAsmIncFile(String asmIncFile) {\r | |
310 | this.asmIncFile.setArg(" -asmincfile ", asmIncFile);\r | |
311 | }\r | |
312 | \r | |
313 | /**\r | |
314 | getBaseAddr\r | |
315 | \r | |
316 | This function is to get class member "baseAddr"\r | |
317 | \r | |
318 | @return baseAddr String of base address value.\r | |
319 | **/\r | |
320 | public String getBaseAddr() {\r | |
321 | return this.baseAddr.getValue();\r | |
322 | }\r | |
323 | \r | |
324 | /**\r | |
325 | setBaseAddr\r | |
326 | \r | |
327 | This function is to set class member "baseAddr"\r | |
328 | \r | |
329 | @param baseAddr\r | |
330 | String of base address value.\r | |
331 | **/\r | |
332 | public void setBaseAddr(String baseAddr) {\r | |
333 | this.baseAddr.setArg(" -baseaddr ", baseAddr);\r | |
334 | }\r | |
335 | \r | |
336 | /**\r | |
337 | getDscFile\r | |
338 | \r | |
339 | This function is to get class member "dscFile"\r | |
340 | \r | |
341 | @return dscFile name of DSC file\r | |
342 | **/\r | |
343 | public String getDscFile() {\r | |
344 | return this.dscFile.getValue();\r | |
345 | }\r | |
346 | \r | |
347 | /**\r | |
348 | setDscFile\r | |
349 | \r | |
350 | This function is to set class member "dscFile"\r | |
351 | \r | |
352 | @param dscFile\r | |
353 | name of DSC file\r | |
354 | **/\r | |
355 | public void setDscFile(String dscFile) {\r | |
356 | this.dscFile.setArg(" -dsc ", dscFile);\r | |
357 | }\r | |
358 | \r | |
359 | /**\r | |
360 | getFdImage\r | |
361 | \r | |
362 | This function is to get class member "fdImage"\r | |
363 | \r | |
364 | @return fdImage name of input FDI image file.\r | |
365 | **/\r | |
366 | public String getFdImage() {\r | |
367 | return this.fdImage.getValue();\r | |
368 | }\r | |
369 | \r | |
370 | /**\r | |
371 | setFdImage\r | |
372 | \r | |
373 | This function is to set class member "fdImage"\r | |
374 | \r | |
375 | @param fdImage\r | |
376 | name of input FDI image file.\r | |
377 | **/\r | |
378 | public void setFdImage(String fdImage) {\r | |
379 | this.fdImage.setArg(" -discover ", fdImage);\r | |
380 | }\r | |
381 | \r | |
382 | /**\r | |
383 | getFlashDevice\r | |
384 | \r | |
385 | This function is to get class member "flashDevice".\r | |
386 | \r | |
387 | @return flashDevice name of flash device.\r | |
388 | **/\r | |
389 | public String getFlashDevice() {\r | |
390 | return this.flashDevice.getValue();\r | |
391 | }\r | |
392 | \r | |
393 | /**\r | |
394 | setFlashDevice\r | |
395 | \r | |
396 | This function is to set class member "flashDevice"\r | |
397 | \r | |
398 | @param flashDevice\r | |
399 | name of flash device.\r | |
400 | **/\r | |
401 | public void setFlashDevice(String flashDevice) {\r | |
402 | this.flashDevice.setArg(" -flashdevice ", flashDevice);\r | |
403 | }\r | |
404 | \r | |
405 | /**\r | |
406 | getFlashDeviceImage\r | |
407 | \r | |
408 | This function is to get class member "flashDeviceImage"\r | |
409 | \r | |
410 | @return flashDeviceImage name of flash device image\r | |
411 | **/\r | |
412 | public String getFlashDeviceImage() {\r | |
413 | return this.flashDeviceImage.getValue();\r | |
414 | }\r | |
415 | \r | |
416 | /**\r | |
417 | setFlashDeviceImage\r | |
418 | \r | |
419 | This function is to set class member "flashDeviceImage"\r | |
420 | \r | |
421 | @param flashDeviceImage\r | |
422 | name of flash device image\r | |
423 | **/\r | |
424 | public void setFlashDeviceImage(String flashDeviceImage) {\r | |
425 | this.flashDeviceImage.setArg(" -flashdeviceimage ", flashDeviceImage);\r | |
426 | \r | |
427 | }\r | |
428 | \r | |
429 | /**\r | |
430 | getHeaderFile\r | |
431 | \r | |
432 | This function is to get class member "headerFile"\r | |
433 | \r | |
434 | @return headerFile name of include file\r | |
435 | **/\r | |
436 | public String getHeaderFile() {\r | |
437 | return this.headerFile.getValue();\r | |
438 | }\r | |
439 | \r | |
440 | /**\r | |
441 | setHeaderFile\r | |
442 | \r | |
443 | This function is to set class member "headerFile"\r | |
444 | \r | |
445 | @param headerFile\r | |
446 | name of include file\r | |
447 | **/\r | |
448 | public void setHeaderFile(String headerFile) {\r | |
449 | this.headerFile.setArg(" -hfile ", headerFile);\r | |
450 | }\r | |
451 | \r | |
452 | /**\r | |
453 | getImageOutFile\r | |
454 | \r | |
455 | This function is to get class member "imageOutFile"\r | |
456 | \r | |
457 | @return imageOutFile name of output image file\r | |
458 | **/\r | |
459 | public String getImageOutFile() {\r | |
460 | return this.imageOutFile.getValue();\r | |
461 | }\r | |
462 | \r | |
463 | /**\r | |
464 | setImageOutFile\r | |
465 | \r | |
466 | This function is to set class member "ImageOutFile"\r | |
467 | \r | |
468 | @param imageOutFile\r | |
469 | name of output image file\r | |
470 | **/\r | |
471 | public void setImageOutFile(String imageOutFile) {\r | |
472 | this.imageOutFile.setArg(" -imageout ", imageOutFile);\r | |
473 | }\r | |
474 | \r | |
475 | /**\r | |
476 | getInStrFile\r | |
477 | \r | |
478 | This function is to get class member "inStrFile"\r | |
479 | \r | |
480 | @return inStrFile name of input file which used to replace symbol names.\r | |
481 | **/\r | |
482 | public String getInStrFile() {\r | |
483 | return this.inStrFile;\r | |
484 | }\r | |
485 | \r | |
486 | /**\r | |
487 | setInStrFile\r | |
488 | \r | |
489 | This function is to set class member "inStrFile"\r | |
490 | \r | |
491 | @param inStrFile\r | |
492 | name of input file which used to replace symbol names.\r | |
493 | **/\r | |
494 | public void setInStrFile(String inStrFile) {\r | |
495 | this.inStrFile = inStrFile;\r | |
496 | }\r | |
497 | \r | |
498 | /**\r | |
499 | getMciFile\r | |
500 | \r | |
501 | This function is to get class member "mciFile"\r | |
502 | \r | |
503 | @return mciFile name of input microcode file\r | |
504 | **/\r | |
505 | public String getMciFile() {\r | |
506 | return this.mciFile.getValue();\r | |
507 | }\r | |
508 | \r | |
509 | /**\r | |
510 | setMciFile\r | |
511 | \r | |
512 | This function is to set class member "mciFile"\r | |
513 | \r | |
514 | @param mciFile\r | |
515 | name of input microcode file\r | |
516 | **/\r | |
517 | public void setMciFile(String mciFile) {\r | |
518 | this.mciFile.setArg(" -mci ", mciFile);\r | |
519 | }\r | |
520 | \r | |
521 | /**\r | |
522 | getMcoFile\r | |
523 | \r | |
524 | This function is to get class member "mcoFile"\r | |
525 | \r | |
526 | @return mcoFile name of output binary microcode image\r | |
527 | **/\r | |
528 | public String getMcoFile() {\r | |
529 | return this.mcoFile.getValue();\r | |
530 | }\r | |
531 | \r | |
532 | /**\r | |
533 | setMcoFile\r | |
534 | \r | |
535 | This function is to set class member "mcoFile"\r | |
536 | \r | |
537 | @param mcoFile\r | |
538 | name of output binary microcode image\r | |
539 | **/\r | |
540 | public void setMcoFile(String mcoFile) {\r | |
541 | this.mcoFile.setArg(" -mco ", mcoFile);\r | |
542 | }\r | |
543 | \r | |
544 | /**\r | |
545 | getOutStrFile\r | |
546 | \r | |
547 | This function is to get class member "outStrFile"\r | |
548 | \r | |
549 | @return outStrFile name of output string substitution file\r | |
550 | **/\r | |
551 | public String getOutStrFile() {\r | |
552 | return this.outStrFile;\r | |
553 | }\r | |
554 | \r | |
555 | /**\r | |
556 | setOutStrFile\r | |
557 | \r | |
558 | This function is to set class member "outStrFile"\r | |
559 | \r | |
560 | @param outStrFile\r | |
561 | name of output string substitution file\r | |
562 | **/\r | |
563 | public void setOutStrFile(String outStrFile) {\r | |
564 | this.outStrFile = outStrFile;\r | |
565 | }\r | |
566 | \r | |
567 | /**\r | |
568 | getPadValue\r | |
569 | \r | |
570 | This function is to get class member "padValue"\r | |
571 | \r | |
572 | @return padValue string of byte value to use as padding\r | |
573 | **/\r | |
574 | public String getPadValue() {\r | |
575 | return this.padValue.getValue();\r | |
576 | }\r | |
577 | \r | |
578 | /**\r | |
579 | setPadValue\r | |
580 | \r | |
581 | This function is to set class member "padValue"\r | |
582 | \r | |
583 | @param padValue\r | |
584 | string of byte value to use as padding\r | |
585 | **/\r | |
586 | public void setPadValue(String padValue) {\r | |
587 | this.padValue.setArg(" -padvalue ", 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 addConfiguredMciFile(FileArg mciFile) {\r | |
599 | this.mciFileArray.setPrefix(" -mcmerge ");\r | |
600 | this.mciFileArray.insert(mciFile);\r | |
601 | }\r | |
602 | \r | |
603 | /**\r | |
604 | getOutputDir\r | |
605 | \r | |
606 | This function is to get class member "outputDir"\r | |
607 | \r | |
608 | @return outputDir string of output directory\r | |
609 | **/\r | |
610 | public String getOutputDir() {\r | |
611 | return outputDir;\r | |
612 | }\r | |
613 | \r | |
614 | /**\r | |
615 | setOutputDir\r | |
616 | \r | |
617 | This function is to set class member "outputDir"\r | |
618 | \r | |
619 | @param outputDir\r | |
620 | string of output directory\r | |
621 | **/\r | |
622 | public void setOutputDir(String outputDir) {\r | |
623 | this.outputDir = outputDir;\r | |
624 | }\r | |
625 | \r | |
626 | //\r | |
627 | // Dependency check\r | |
628 | //\r | |
629 | private boolean isUptodate() {\r | |
630 | long srcTimeStamp = 0;\r | |
631 | String srcName = "";\r | |
632 | String dstName = "";\r | |
633 | long timeStamp = 0;\r | |
634 | \r | |
635 | if (!flashDefFile.isEmpty()) {\r | |
636 | srcName = flashDefFile.getValue();\r | |
637 | timeStamp = new File(srcName).lastModified();\r | |
638 | if (timeStamp > srcTimeStamp) {\r | |
639 | srcTimeStamp = timeStamp;\r | |
640 | }\r | |
641 | }\r | |
642 | \r | |
643 | if (!mciFile.isEmpty()) {\r | |
644 | srcName = mciFile.getValue();\r | |
645 | timeStamp = new File(srcName).lastModified();\r | |
646 | if (timeStamp > srcTimeStamp) {\r | |
647 | srcTimeStamp = timeStamp;\r | |
648 | }\r | |
649 | }\r | |
650 | \r | |
651 | if (!fdImage.isEmpty()) {\r | |
652 | srcName = fdImage.getValue();\r | |
653 | timeStamp = new File(srcName).lastModified();\r | |
654 | if (timeStamp > srcTimeStamp) {\r | |
655 | srcTimeStamp = timeStamp;\r | |
656 | }\r | |
657 | }\r | |
658 | \r | |
659 | if (inStrFile.length() != 0) {\r | |
660 | srcName = inStrFile;\r | |
661 | timeStamp = new File(srcName).lastModified();\r | |
662 | if (timeStamp > srcTimeStamp) {\r | |
663 | srcTimeStamp = timeStamp;\r | |
664 | }\r | |
665 | }\r | |
666 | \r | |
667 | if (!mciFileArray.isEmpty()) {\r | |
668 | for (int i = 0; i < mciFileArray.nameList.size(); ++i) {\r | |
669 | srcName += mciFileArray.nameList.get(i) + " ";\r | |
670 | timeStamp = new File(mciFileArray.nameList.get(i)).lastModified();\r | |
671 | if (timeStamp > srcTimeStamp) {\r | |
672 | srcTimeStamp = timeStamp;\r | |
673 | }\r | |
674 | }\r | |
675 | }\r | |
676 | \r | |
677 | if (!headerFile.isEmpty()) {\r | |
678 | dstName = headerFile.getValue();\r | |
679 | File dstFile = new File(dstName);\r | |
680 | if (!dstFile.isAbsolute()) {\r | |
681 | dstName = outputDir + File.separator + dstName;\r | |
682 | dstFile = new File(dstName);\r | |
683 | }\r | |
684 | \r | |
685 | if (srcTimeStamp > dstFile.lastModified()) {\r | |
686 | EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r | |
687 | return false;\r | |
688 | }\r | |
689 | }\r | |
690 | \r | |
691 | if (!imageOutFile.isEmpty()) {\r | |
692 | dstName = imageOutFile.getValue();\r | |
693 | File dstFile = new File(dstName);\r | |
694 | if (!dstFile.isAbsolute()) {\r | |
695 | dstName = outputDir + File.separator + dstName;\r | |
696 | dstFile = new File(dstName);\r | |
697 | }\r | |
698 | \r | |
699 | if (srcTimeStamp > dstFile.lastModified()) {\r | |
700 | EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r | |
701 | return false;\r | |
702 | }\r | |
703 | \r | |
704 | //\r | |
705 | // we need to check the time stamp of each FV file specified in fdf file\r | |
706 | // \r | |
707 | if (!isFdUptodate(dstName, getFvFiles(flashDefFile.getValue()))) {\r | |
708 | return false;\r | |
709 | }\r | |
710 | }\r | |
711 | \r | |
712 | if (!mcoFile.isEmpty()) {\r | |
713 | dstName = mcoFile.getValue();\r | |
714 | File dstFile = new File(dstName);\r | |
715 | if (!dstFile.isAbsolute()) {\r | |
716 | dstName = outputDir + File.separator + dstName;\r | |
717 | dstFile = new File(dstName);\r | |
718 | }\r | |
719 | \r | |
720 | if (srcTimeStamp > dstFile.lastModified()) {\r | |
721 | EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r | |
722 | return false;\r | |
723 | }\r | |
724 | }\r | |
725 | \r | |
726 | if (!dscFile.isEmpty()) {\r | |
727 | dstName = dscFile.getValue();\r | |
728 | File dstFile = new File(dstName);\r | |
729 | if (!dstFile.isAbsolute()) {\r | |
730 | dstName = outputDir + File.separator + dstName;\r | |
731 | dstFile = new File(dstName);\r | |
732 | }\r | |
733 | \r | |
734 | if (srcTimeStamp > dstFile.lastModified()) {\r | |
735 | EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r | |
736 | return false;\r | |
737 | }\r | |
738 | }\r | |
739 | \r | |
740 | if (!asmIncFile.isEmpty()) {\r | |
741 | dstName = asmIncFile.getValue();\r | |
742 | File dstFile = new File(dstName);\r | |
743 | if (!dstFile.isAbsolute()) {\r | |
744 | dstName = outputDir + File.separator + dstName;\r | |
745 | dstFile = new File(dstName);\r | |
746 | }\r | |
747 | \r | |
748 | if (srcTimeStamp > dstFile.lastModified()) {\r | |
749 | EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r | |
750 | return false;\r | |
751 | }\r | |
752 | }\r | |
753 | \r | |
754 | if (outStrFile.length() != 0) {\r | |
755 | dstName = outStrFile;\r | |
756 | File dstFile = new File(dstName);\r | |
757 | if (!dstFile.isAbsolute()) {\r | |
758 | dstName = outputDir + File.separator + dstName;\r | |
759 | dstFile = new File(dstName);\r | |
760 | }\r | |
761 | \r | |
762 | if (srcTimeStamp > dstFile.lastModified()) {\r | |
763 | EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r | |
764 | return false;\r | |
765 | }\r | |
766 | }\r | |
767 | \r | |
768 | return true;\r | |
769 | }\r | |
770 | \r | |
771 | //\r | |
772 | // Parse the flash definition file and find out the FV file names\r | |
773 | // \r | |
774 | private List<String> getFvFiles(String fdfFileName) {\r | |
775 | File fdfFile = new File(fdfFileName);\r | |
776 | int fileLength = (int)fdfFile.length();\r | |
777 | char[] fdfContent = new char[fileLength];\r | |
778 | List<String> fileList = new ArrayList<String>();\r | |
779 | \r | |
780 | try {\r | |
781 | FileReader reader = new FileReader(fdfFile);\r | |
782 | BufferedReader in = new BufferedReader(reader);\r | |
783 | \r | |
784 | in.read(fdfContent, 0, fileLength);\r | |
785 | String str = new String(fdfContent);\r | |
786 | \r | |
787 | //\r | |
788 | // match the \r | |
789 | // File {\r | |
790 | // ...\r | |
791 | // }\r | |
792 | // block\r | |
793 | // \r | |
794 | Matcher matcher = fileBlock.matcher(str);\r | |
795 | while (matcher.find()) {\r | |
796 | String fileBlockContent = str.substring(matcher.start(1), matcher.end(1));\r | |
797 | //\r | |
798 | // match the definition like\r | |
799 | // Name = "..."\r | |
800 | // \r | |
801 | Matcher nameMatcher = fileNameDef.matcher(fileBlockContent);\r | |
802 | if (nameMatcher.find()) {\r | |
803 | fileList.add(fileBlockContent.substring(nameMatcher.start(1), nameMatcher.end(1)));\r | |
804 | }\r | |
805 | }\r | |
806 | \r | |
807 | in.close();\r | |
808 | reader.close();\r | |
809 | } catch (Exception ex) {\r | |
810 | throw new BuildException(ex.getMessage());\r | |
811 | }\r | |
812 | \r | |
813 | return fileList;\r | |
814 | }\r | |
815 | \r | |
816 | private boolean isFdUptodate(String fdFile, List<String> fvFileList) {\r | |
817 | String fvDir = ".";\r | |
818 | File fd = new File(fdFile);\r | |
819 | \r | |
820 | if (outputDir.equals(".")) {\r | |
821 | if (!fd.isAbsolute()) {\r | |
822 | //\r | |
823 | // If we cannot get the absolute path of fd file, we caanot\r | |
824 | // get its time stamp. Re-generate it always in such situation.\r | |
825 | // \r | |
826 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "Cannot retrieve the time stamp of " + fdFile);\r | |
827 | return false;\r | |
828 | }\r | |
829 | fvDir = fd.getParent();\r | |
830 | } else {\r | |
831 | fvDir = outputDir;\r | |
832 | if (!fd.isAbsolute()) {\r | |
833 | fd = new File(fvDir + File.separator + fdFile);\r | |
834 | }\r | |
835 | }\r | |
836 | \r | |
837 | long fdTimeStamp = fd.lastModified();\r | |
838 | for (int i = 0; i < fvFileList.size(); ++i) {\r | |
839 | File fv = new File(fvDir + File.separator + fvFileList.get(i));\r | |
840 | if (fv.lastModified() > fdTimeStamp) {\r | |
841 | EdkLog.log(this, EdkLog.EDK_VERBOSE, fv.getPath() + " has been changed since last build!");\r | |
842 | return false;\r | |
843 | }\r | |
844 | }\r | |
845 | \r | |
846 | return true;\r | |
847 | }\r | |
848 | }\r |