]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java
This file is never used any more. Enhance Cpptasks.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFfsFileTask.java
... / ...
CommitLineData
1/** @file\r
2 GenFfsFileTask class.\r
3\r
4 GenFfsFileTaks is to generate ffs file.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16package org.tianocore.framework.tasks;\r
17\r
18import java.io.DataInputStream;\r
19import java.io.DataOutputStream;\r
20import java.io.File;\r
21import java.io.FileInputStream;\r
22import java.io.FileOutputStream;\r
23import java.util.ArrayList;\r
24import java.util.Iterator;\r
25import java.util.List;\r
26\r
27import org.apache.tools.ant.BuildException;\r
28import org.apache.tools.ant.Project;\r
29import org.apache.tools.ant.Task;\r
30\r
31/**\r
32 GenFfsFileTask\r
33 \r
34 GenFfsFileTaks is to generate ffs file.\r
35\r
36**/\r
37public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {\r
38 /**\r
39 * GenFfsFile Task Class\r
40 * class member \r
41 * -baseName : module baseName\r
42 * -ffsFileGuid : module Guid.\r
43 * -ffsFileType : Ffs file type. \r
44 * -ffsAttributeRecovery : The file is required for recovery.\r
45 * -ffsAligment : The file data alignment (0 if none required). See FFS \r
46 * specification for supported alignments (0-7 are only possible \r
47 * values). *\r
48 * -ffsAttributeCheckSum : The file data is checksummed. If this is FALSE a \r
49 * value of 0x5A will be inserted in the file \r
50 * checksum field of the file header. *\r
51 * -sectFileDir : specifies the full path to the component build directory.\r
52 * Required.\r
53 * -ffsAttrib : Data recorde attribute added result.\r
54 * -sectionList : List recorded all section elemet in task.\r
55 */\r
56 ///\r
57 /// module baseName\r
58 ///\r
59 String baseName = "";\r
60 ///\r
61 /// module Guid\r
62 ///\r
63 String ffsFileGuid = "";\r
64 ///\r
65 /// Ffs file type\r
66 ///\r
67 String ffsFileType = "";\r
68 ///\r
69 /// ffsAttribHeaderExtension value is used to set the corresponding bit in \r
70 /// the output FFS file header \r
71 ///\r
72 boolean ffsAttribHeaderExtension = false;\r
73 ///\r
74 /// ffsAttribTailPresent value is used to set the corresponding bit in the \r
75 /// output FFS file header\r
76 ///\r
77 boolean ffsAttribTailPresent = false;\r
78 ///\r
79 /// ffsAttribRecovery value is used to set the corresponding bit in the \r
80 /// output FFS file header\r
81 ///\r
82 boolean ffsAttribRecovery = false;\r
83 ///\r
84 /// ffsAligenment value is used to set the corresponding bit in the output \r
85 /// FFS file header.The specified FFS alignment must be a value between 0 \r
86 /// and 7 inclusive\r
87 ///\r
88 int ffsAlignment = 0;\r
89 ///\r
90 /// ffsAttribChecksum value is used to set the corresponding bit in the \r
91 /// output FFS file header\r
92 ///\r
93 boolean FfsAttribChecksum = false;\r
94 ///\r
95 /// Attribute is used to record the sum of all bit in the output FFS file.\r
96 ///\r
97 byte attributes = 0;\r
98 ///\r
99 /// The output directory of ffs file.\r
100 ///\r
101 String outputDir = "";\r
102 ///\r
103 /// List of section.\r
104 ///\r
105 List<Object> sectionList = new ArrayList<Object>();\r
106\r
107 ///\r
108 /// The path of Framewor_Tools_Paht.\r
109 ///\r
110 static String path = ""; \r
111\r
112 /**\r
113 execute\r
114 \r
115 GenFfsFileTask execute is to generate ffs file according to input section \r
116 dscriptive information.\r
117 **/\r
118 public void execute() throws BuildException {\r
119 Section sect;\r
120 int fileSize;\r
121 int orgFileSize;\r
122 int fileDataSize;\r
123 int orgFileDataSize;\r
124 File ffsFile;\r
125 File ffsOrgFile;\r
126 FfsHeader ffsHeader = new FfsHeader(); \r
127 FfsHeader orgFfsHeader = new FfsHeader();\r
128 String ffsSuffix = "";\r
129 String outputPath = "";\r
130\r
131 //\r
132 // Get Fraemwork_Tools_Path\r
133 //\r
134 Project pj = this.getOwningTarget().getProject();\r
135 path = pj.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
136\r
137 //\r
138 // Check does the BaseName, Guid, FileType set value.\r
139 //\r
140 if (this.baseName.equals("")) {\r
141 throw new BuildException ("Must set BaseName!\n");\r
142 }\r
143\r
144 if (this.ffsFileGuid.equals("")) {\r
145 throw new BuildException ("Must set ffsFileGuid!\n");\r
146 }\r
147\r
148 if (this.ffsFileType.equals("")) {\r
149 throw new BuildException ("Must set ffsFileType!\n");\r
150 }\r
151\r
152 //\r
153 // Create ffs file. File name = FfsFileGuid + BaseName + ffsSuffix.\r
154 // If outputDir's value was set, file will output to the outputDir.\r
155 //\r
156 ffsSuffix = TypeToSuffix (this.ffsFileType);\r
157 if (!this.outputDir.equals("")) {\r
158 String temp;\r
159 outputPath = this.outputDir;\r
160 temp = outputPath.replace('\\', File.separatorChar);\r
161 outputPath = temp.replace('/', File.separatorChar);\r
162 if (outputPath.charAt(outputPath.length()-1) != File.separatorChar) {\r
163 outputPath = outputPath + File.separator;\r
164 }\r
165\r
166 }\r
167\r
168 ffsFile = new File (outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix); \r
169 System.out.print("General Ffs file: file name is:\n");\r
170 System.out.print(outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix);\r
171 System.out.print("\n");\r
172 \r
173 //\r
174 // Create ffs ORG file. fileName = FfsFileGuid + BaseName + ffsSuffix +\r
175 // ".org".\r
176 //\r
177 ffsOrgFile = new File(outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix + ".org");\r
178 \r
179 try {\r
180 //\r
181 // Create file output stream -- dataBuffer.\r
182 //\r
183 FileOutputStream dataFs = new FileOutputStream (ffsFile.getAbsolutePath());\r
184 DataOutputStream dataBuffer = new DataOutputStream (dataFs);\r
185 \r
186 //\r
187 // Create org file output stream -- orgDataBuffer\r
188 //\r
189 FileOutputStream orgDataFs = new FileOutputStream (ffsOrgFile.getAbsolutePath());\r
190 DataOutputStream orgDataBuffer = new DataOutputStream (orgDataFs);\r
191 \r
192 //\r
193 // Search SectionList find earch section and call it's \r
194 // ToBuffer function.\r
195 //\r
196 Iterator sectionIter = this.sectionList.iterator();\r
197 while (sectionIter.hasNext()) {\r
198 sect = (Section)sectionIter.next(); \r
199\r
200 try {\r
201 //\r
202 // The last section don't need 4 byte ffsAligment.\r
203 //\r
204 sect.toBuffer((DataOutputStream)dataBuffer, (DataOutputStream) orgDataBuffer);\r
205 } catch (Exception e) {\r
206 throw new BuildException (e.getMessage());\r
207 }\r
208 }\r
209 dataBuffer.close();\r
210 orgDataBuffer.close();\r
211 } catch (Exception e) {\r
212 throw new BuildException (e.getMessage());\r
213 }\r
214\r
215 //\r
216 // Creat Ffs file header\r
217 //\r
218 try {\r
219\r
220 //\r
221 // create input stream to read file data\r
222 //\r
223 byte[] fileBuffer = new byte[(int)ffsFile.length()];\r
224 FileInputStream fi = new FileInputStream (ffsFile.getAbsolutePath());\r
225 DataInputStream di = new DataInputStream (fi);\r
226 di.read(fileBuffer);\r
227 di.close();\r
228 \r
229 //\r
230 // create input org stream to read file data\r
231 //\r
232 byte[] orgFileBuffer = new byte[(int)ffsOrgFile.length()];\r
233 FileInputStream ofi = new FileInputStream (ffsOrgFile.getAbsolutePath());\r
234 DataInputStream odi = new DataInputStream (ofi);\r
235 odi.read(orgFileBuffer);\r
236 odi.close();\r
237\r
238 //\r
239 // Add GUID to header struct\r
240 //\r
241 if (this.ffsFileGuid != null) {\r
242 stringToGuid (this.ffsFileGuid, ffsHeader.name);\r
243 //\r
244 // Add Guid to org header struct\r
245 //\r
246 stringToGuid (this.ffsFileGuid, orgFfsHeader.name);\r
247 }\r
248\r
249 ffsHeader.ffsAttributes = this.attributes;\r
250 if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) {\r
251 throw new BuildException ("FFS_FILE_TYPE unknow!\n");\r
252 }\r
253 \r
254 //\r
255 // Copy ffsHeader.ffsAttribute and fileType to orgFfsHeader.ffsAttribute\r
256 // and fileType\r
257 // \r
258 orgFfsHeader.ffsAttributes = ffsHeader.ffsAttributes;\r
259 orgFfsHeader.fileType = ffsHeader.fileType;\r
260 \r
261 //\r
262 // Adjust file size. The function is used to tripe the last \r
263 // section padding of 4 binary boundary. \r
264 // \r
265 //\r
266 if (ffsHeader.fileType != EFI_FV_FILETYPE_RAW) {\r
267\r
268 fileDataSize = adjustFileSize (fileBuffer);\r
269 orgFileDataSize = adjustFileSize (orgFileBuffer);\r
270\r
271 } else {\r
272 fileDataSize = fileBuffer.length;\r
273 orgFileDataSize = orgFileBuffer.length;\r
274 }\r
275\r
276 //\r
277 // 1. add header size to file size\r
278 //\r
279 fileSize = fileDataSize + ffsHeader.getSize();\r
280 //\r
281 // add header size to org file size\r
282 //\r
283 orgFileSize = orgFileDataSize + ffsHeader.getSize();\r
284\r
285 if ((ffsHeader.ffsAttributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
286 if (ffsHeader.fileType == EFI_FV_FILETYPE_FFS_PAD) {\r
287\r
288 throw new BuildException (\r
289 "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +\r
290 "invalid for PAD files"\r
291 );\r
292 }\r
293 if (fileSize == ffsHeader.getSize()) {\r
294 throw new BuildException (\r
295 "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +\r
296 "invalid for 0-length files"\r
297 ); \r
298 }\r
299 fileSize = fileSize + 2;\r
300 orgFileSize = orgFileSize + 2;\r
301 }\r
302\r
303 //\r
304 // 2. set file size to header struct\r
305 //\r
306 ffsHeader.ffsFileSize[0] = (byte)(fileSize & 0x00FF);\r
307 ffsHeader.ffsFileSize[1] = (byte)((fileSize & 0x00FF00)>>8);\r
308 ffsHeader.ffsFileSize[2] = (byte)(((int)fileSize & 0xFF0000)>>16);\r
309 \r
310 //\r
311 // set file size to org header struct\r
312 //\r
313 orgFfsHeader.ffsFileSize[0] = (byte)(orgFileSize & 0x00FF);\r
314 orgFfsHeader.ffsFileSize[1] = (byte)((orgFileSize & 0x00FF00)>>8);\r
315 orgFfsHeader.ffsFileSize[2] = (byte)(((int)orgFileSize & 0xFF0000)>>16);\r
316 \r
317 //\r
318 // Fill in checksums and state, these must be zero for checksumming\r
319 //\r
320 ffsHeader.integrityCheck.header = calculateChecksum8 (\r
321 ffsHeader.structToBuffer(),\r
322 ffsHeader.getSize()\r
323 );\r
324 //\r
325 // Fill in org file's header check sum and state\r
326 //\r
327 orgFfsHeader.integrityCheck.header = calculateChecksum8 (\r
328 orgFfsHeader.structToBuffer(),\r
329 orgFfsHeader.getSize()\r
330 );\r
331 \r
332 if ((this.attributes & FFS_ATTRIB_CHECKSUM) != 0) {\r
333 if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
334 ffsHeader.integrityCheck.file = calculateChecksum8 (\r
335 fileBuffer, \r
336 fileDataSize\r
337 );\r
338 //\r
339 // Add org file header\r
340 //\r
341 orgFfsHeader.integrityCheck.file = calculateChecksum8 (\r
342 orgFileBuffer,\r
343 orgFileDataSize\r
344 );\r
345 } else {\r
346 ffsHeader.integrityCheck.file = calculateChecksum8 (\r
347 fileBuffer,\r
348 fileDataSize\r
349 );\r
350 //\r
351 // Add org file header\r
352 //\r
353 orgFfsHeader.integrityCheck.file = calculateChecksum8 (\r
354 orgFileBuffer,\r
355 orgFileDataSize\r
356 );\r
357 }\r
358 } else {\r
359 ffsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;\r
360 orgFfsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;\r
361 }\r
362\r
363 //\r
364 // Set the state now. Spec says the checksum assumes the state is 0.\r
365 //\r
366 ffsHeader.ffsState = EFI_FILE_HEADER_CONSTRUCTION | \r
367 EFI_FILE_HEADER_VALID | \r
368 EFI_FILE_DATA_VALID;\r
369 orgFfsHeader.ffsState = ffsHeader.ffsState;\r
370 \r
371 //\r
372 // create output stream to first write header data in file, then write sect data in file.\r
373 //\r
374 FileOutputStream headerFfs = new FileOutputStream (ffsFile.getAbsolutePath());\r
375 DataOutputStream ffsBuffer = new DataOutputStream (headerFfs);\r
376 \r
377 FileOutputStream orgHeaderFfs = new FileOutputStream (ffsOrgFile.getAbsolutePath());\r
378 DataOutputStream orgFfsBuffer = new DataOutputStream (orgHeaderFfs);\r
379 \r
380 //\r
381 // Add header struct and file data to FFS file\r
382 //\r
383 ffsBuffer.write(ffsHeader.structToBuffer());\r
384 orgFfsBuffer.write(orgFfsHeader.structToBuffer());\r
385 \r
386 for (int i = 0; i< fileDataSize; i++) {\r
387 ffsBuffer.write(fileBuffer[i]);\r
388 }\r
389 \r
390 for (int i = 0; i < orgFileDataSize; i++){\r
391 orgFfsBuffer.write(orgFileBuffer[i]);\r
392 }\r
393\r
394 //\r
395 // If there is a tail, then set it\r
396 //\r
397 if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
398 short tailValue ;\r
399 byte [] tailByte = new byte[2];\r
400\r
401 //\r
402 // reverse tailvalue , integritycheck.file as hight byte, and \r
403 // integritycheck.header as low byte.\r
404 //\r
405 tailValue = (short)(ffsHeader.integrityCheck.header & 0xff);\r
406 tailValue = (short)((tailValue) | ((ffsHeader.integrityCheck.file << 8) & 0xff00)); \r
407 tailValue = (short)~tailValue;\r
408\r
409 //\r
410 // Change short to byte[2]\r
411 //\r
412 tailByte[0] = (byte)(tailValue & 0xff);\r
413 tailByte[1] = (byte)((tailValue & 0xff00)>>8); \r
414 ffsBuffer.write(tailByte[0]);\r
415 ffsBuffer.write(tailByte[1]);\r
416 \r
417 orgFfsBuffer.write(tailByte[0]);\r
418 orgFfsBuffer.write(tailByte[1]);\r
419 }\r
420\r
421 //\r
422 // close output stream. Note if don't close output stream \r
423 // the buffer can't be rewritten to file. \r
424 //\r
425 ffsBuffer.close();\r
426 orgFfsBuffer.close();\r
427 System.out.print ("Successful create ffs file!\n");\r
428 } catch (Exception e) {\r
429 throw new BuildException (e.getMessage());\r
430 }\r
431 } \r
432\r
433 /**\r
434 addCompress\r
435 \r
436 This function is to add compress section to section list.\r
437 @param compress Section of compress \r
438 **/\r
439 public void addCompress(CompressSection compress) {\r
440 this.sectionList.add(compress);\r
441 }\r
442\r
443 /**\r
444 addTool\r
445 \r
446 This function is to add tool section to section list.\r
447 @param tool Section of tool\r
448 **/\r
449 public void addTool(Tool tool) {\r
450 this.sectionList.add(tool);\r
451 }\r
452\r
453 /**\r
454 addSectionFile\r
455 \r
456 This function is to add sectFile section to section list.\r
457 @param sectFile Section of sectFile.\r
458 **/\r
459 public void addSectFile (SectFile sectFile) {\r
460 this.sectionList.add(sectFile); \r
461 }\r
462\r
463 /**\r
464 getBaseName\r
465 \r
466 This function is to get basename\r
467 \r
468 @return String of base name\r
469 **/\r
470 public String getBaseName() {\r
471 return this.baseName;\r
472 }\r
473\r
474 /**\r
475 setBaseName\r
476 \r
477 This function is to set base name.\r
478 @param baseName\r
479 **/\r
480 public void setBaseName(String baseName) {\r
481 this.baseName = baseName.trim();\r
482 }\r
483\r
484 /**\r
485 getFfsAligment\r
486 \r
487 This function is to get the ffsAligment\r
488 @return The value of ffsAligment.\r
489 **/\r
490 public int getFfsAligment() {\r
491 return this.ffsAlignment;\r
492 }\r
493\r
494 /**\r
495 setFfsAligment\r
496 \r
497 This function is to set ffsAligment \r
498 @param ffsAligment The value of ffsAligment.\r
499 **/\r
500 public void setFfsAligment(int ffsAligment) {\r
501 this.ffsAlignment = ffsAligment;\r
502 if (this.ffsAlignment > 7) {\r
503 throw new BuildException ("FFS_ALIGMENT Scope is 0-7");\r
504 } else {\r
505 attributes |= (((byte)this.ffsAlignment) << 3);\r
506 }\r
507 }\r
508\r
509 /**\r
510 getFfsAttribCheckSum\r
511 \r
512 This function is to get ffsAttribCheckSum\r
513 \r
514 @return Value of ffsAttribChecksum \r
515 **/\r
516 public boolean getFfsAttribChecksum() {\r
517 return this.FfsAttribChecksum;\r
518 }\r
519\r
520 /**\r
521 setFfsAttribChecksum\r
522 \r
523 This function is to set ffsAttribChecksum\r
524 @param ffsAttributeCheckSum Value of ffsAttribCheckSum\r
525 **/\r
526 public void setFfsAttribChecksum(boolean ffsAttributeCheckSum) {\r
527 this.FfsAttribChecksum = ffsAttributeCheckSum;\r
528 if (ffsAttributeCheckSum) {\r
529 attributes |= FFS_ATTRIB_CHECKSUM;\r
530 }\r
531 }\r
532\r
533 /**\r
534 getFfsAttribRecovery\r
535 \r
536 This function is to get ffsAttribRecovery\r
537 @return Value of ffsAttribRecovery\r
538 **/\r
539 public boolean getFfsAttribRecovery() {\r
540 return this.ffsAttribRecovery;\r
541 }\r
542\r
543 /**\r
544 setRecovery\r
545 \r
546 This function is to set ffsAttributeRecovery\r
547 \r
548 @param ffsAttributeRecovery Value of ffsAttributeRecovery\r
549 **/\r
550 public void setRecovery(boolean ffsAttributeRecovery) {\r
551 this.ffsAttribRecovery = ffsAttributeRecovery;\r
552 if (ffsAttributeRecovery) {\r
553 attributes |= FFS_ATTRIB_RECOVERY;\r
554 }\r
555 }\r
556\r
557 /**\r
558 getFileGuid\r
559 \r
560 This function is to get fileGuid\r
561 @return Guid\r
562 **/\r
563 public String getFileGuid() {\r
564 return this.ffsFileGuid;\r
565 }\r
566\r
567 /**\r
568 setFileGuid\r
569 \r
570 This function is to set fileGuid\r
571 @param ffsFileGuid String of GUID\r
572 **/\r
573 public void setFileGuid(String ffsFileGuid) {\r
574 this.ffsFileGuid = ffsFileGuid.trim();\r
575 }\r
576\r
577 /**\r
578 getFfsFileType\r
579 \r
580 This function is to get ffsFileType.\r
581 \r
582 @return value of ffsFileType\r
583 **/\r
584 public String getFfsFileType() {\r
585 return this.ffsFileType;\r
586 }\r
587\r
588 /**\r
589 setFfsFileType\r
590 \r
591 This function is to set ffsFileType.\r
592 \r
593 @param ffsFileType \r
594 **/\r
595 public void setFfsFileType(String ffsFileType) {\r
596 this.ffsFileType = ffsFileType.trim();\r
597 }\r
598\r
599 /**\r
600 ffsAttribHeaderExtension\r
601 \r
602 This function is to get ffsAttribHeaderExtension\r
603 \r
604 @return Value of ffsAttribHeaderExtension\r
605 **/\r
606 public boolean isFfsAttribHeaderExtension() {\r
607 return this.ffsAttribHeaderExtension;\r
608 }\r
609\r
610 /**\r
611 setHeaderExension\r
612 \r
613 This function is to set headerExtension\r
614 @param headerExtension Value of headerExension\r
615 **/\r
616 public void setHeaderExtension(boolean headerExtension) {\r
617 this.ffsAttribHeaderExtension = headerExtension;\r
618 if (headerExtension) {\r
619 attributes |= FFS_ATTRIB_HEADER_EXTENSION;\r
620 }\r
621 }\r
622\r
623 /**\r
624 isFfsAttribTailPresent\r
625 \r
626 This function is to get ffsAttribTailPresent value.\r
627 @return Value of ffsAttribTailPresent.\r
628 **/\r
629 public boolean isFfsAttribTailPresent() {\r
630 return this.ffsAttribTailPresent;\r
631 }\r
632\r
633 /**\r
634 setFfsAttribTailPresent\r
635 \r
636 This function is to set ffsAttribTailPresent.\r
637 @param tailPresent Value of ffsAttribTailPresent.\r
638 **/\r
639 public void setFfsAttribTailPresent(boolean tailPresent) {\r
640 this.ffsAttribTailPresent = tailPresent;\r
641 if (tailPresent) {\r
642 attributes |= FFS_ATTRIB_TAIL_PRESENT;\r
643 }\r
644 } \r
645\r
646\r
647 /**\r
648 stringToGuid\r
649 \r
650 This function is to convert string to GUID.\r
651 * @param GuidStr String of GUID.\r
652 * @param Guid GUID form.\r
653 */\r
654 private void stringToGuid (String GuidStr, FfsHeader.FfsGuid Guid){ \r
655\r
656 int i = 0;\r
657 int j = 0;\r
658 int k = 0;\r
659 char [] charArry;\r
660 String [] SplitStr;\r
661\r
662 byte[] buffer = new byte[16];\r
663 if (GuidStr.length()!=36) {\r
664 throw new BuildException ("Guid length is not correct!");\r
665 }\r
666\r
667\r
668 SplitStr = GuidStr.split("-");\r
669 if (SplitStr.length != 5) {\r
670 throw new BuildException ("Guid type is not correct!");\r
671 }\r
672\r
673\r
674\r
675 for (i= 0; i < SplitStr.length; i++) {\r
676 String str = SplitStr[i]; \r
677 charArry = str.toCharArray();\r
678\r
679 for (j =0; j < (str.toCharArray().length)/2; j++) {\r
680\r
681 buffer[k] = hexCharToByte (charArry[j*2]); \r
682 buffer[k] = (byte)( buffer[k]& 0x0f); \r
683 buffer[k] = (byte)((buffer[k]<< 4));\r
684 buffer[k] = (byte)( buffer[k]& 0xf0); \r
685 buffer[k] = (byte)( buffer[k]|hexCharToByte(charArry[j*2+1]));\r
686 k++; \r
687 }\r
688 }\r
689 Guid.bufferToStruct(buffer);\r
690 }\r
691\r
692 /**\r
693 typeToSuffix\r
694 \r
695 This function is to get suffix of ffs file according to ffsFileType.\r
696 \r
697 @param ffsFileType ffsFileType\r
698 @return The suffix of ffs file\r
699 **/\r
700 private String TypeToSuffix (String ffsFileType){\r
701 if (ffsFileType.equals("EFI_FV_FILETYPE_ALL")) {\r
702 return "";\r
703 }\r
704 if (ffsFileType.equals("EFI_FV_FILETYPE_RAW")) {\r
705 return EFI_FV_FFS_FILETYPE_STR;\r
706 }\r
707 if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {\r
708 return EFI_FV_FFS_FILETYPE_STR;\r
709 }\r
710 if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {\r
711 return EFI_FV_SEC_FILETYPE_STR;\r
712 }\r
713 if (ffsFileType.equals("EFI_FV_FILETYPE_PEI_CORE")) {\r
714 return EFI_FV_PEI_FILETYPE_STR;\r
715 }\r
716 if (ffsFileType.equals("EFI_FV_FILETYPE_DXE_CORE")) {\r
717 return EFI_FV_DXE_FILETYPE_STR;\r
718 }\r
719 if (ffsFileType.equals("EFI_FV_FILETYPE_PEIM")) {\r
720 return EFI_FV_PEI_FILETYPE_STR;\r
721 }\r
722 if (ffsFileType.equals("EFI_FV_FILETYPE_DRIVER")) {\r
723 return EFI_FV_DXE_FILETYPE_STR;\r
724 }\r
725 if (ffsFileType.equals("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER")) {\r
726 return EFI_FV_PEI_FILETYPE_STR;\r
727 }\r
728 if (ffsFileType.equals("EFI_FV_FILETYPE_APPLICATION")) {\r
729 return EFI_FV_APP_FILETYPE_STR;\r
730 }\r
731 if (ffsFileType.equals("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE")) {\r
732 return EFI_FV_FVI_FILETYPE_STR;\r
733 }\r
734 if (ffsFileType.equals("EFI_FV_FILETYPE_FFS_PAD")) {\r
735 return EFI_FV_FFS_FILETYPE_STR;\r
736 }\r
737 return "";\r
738 }\r
739\r
740\r
741 /**\r
742 stringToType\r
743 \r
744 This function is to get ffsFileType integer value according to ffsFileType.\r
745 @param ffsFileType String value of ffsFileType\r
746 @return Integer value of ffsFileType.\r
747 **/\r
748 private byte stringToType (String ffsFileType){\r
749\r
750 if (ffsFileType.equals("EFI_FV_FILETYPE_ALL")) {\r
751 return(byte)EFI_FV_FILETYPE_ALL;\r
752 }\r
753\r
754 if (ffsFileType.equals("EFI_FV_FILETYPE_RAW")) {\r
755 return(byte)EFI_FV_FILETYPE_RAW;\r
756 }\r
757\r
758 if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {\r
759 return(byte)EFI_FV_FILETYPE_FREEFORM;\r
760 }\r
761\r
762 if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {\r
763 return(byte)EFI_FV_FILETYPE_SECURITY_CORE;\r
764 }\r
765\r
766 if (ffsFileType.equals("EFI_FV_FILETYPE_PEI_CORE")) {\r
767 return(byte) EFI_FV_FILETYPE_PEI_CORE;\r
768 }\r
769\r
770 if (ffsFileType.equals("EFI_FV_FILETYPE_DXE_CORE")) {\r
771 return(byte)EFI_FV_FILETYPE_DXE_CORE;\r
772 }\r
773\r
774 if (ffsFileType.equals("EFI_FV_FILETYPE_PEIM")) {\r
775 return(byte)EFI_FV_FILETYPE_PEIM;\r
776 }\r
777\r
778 if (ffsFileType.equals("EFI_FV_FILETYPE_DRIVER")) {\r
779 return(byte) EFI_FV_FILETYPE_DRIVER;\r
780 }\r
781\r
782 if (ffsFileType.equals("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER")) {\r
783 return(byte)EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER;\r
784 }\r
785\r
786 if (ffsFileType.equals("EFI_FV_FILETYPE_APPLICATION")) {\r
787 return(byte)EFI_FV_FILETYPE_APPLICATION;\r
788 }\r
789\r
790 if (ffsFileType.equals("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE")) {\r
791 return(byte)EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE;\r
792 }\r
793 if (ffsFileType.equals("EFI_FV_FILETYPE_FFS_PAD")) {\r
794 return(byte) EFI_FV_FILETYPE_FFS_PAD;\r
795 }\r
796\r
797 return -1;\r
798 }\r
799\r
800\r
801\r
802 /**\r
803 calculateCheckSum8\r
804 \r
805 This function is to calculate the value needed for a valid UINT8 checksum\r
806 @param buffer Byte buffer containing byte data of component.\r
807 @param size Size of the buffer.\r
808 @return The 8 bit checksum value needed.\r
809 **/\r
810 private byte calculateChecksum8 (byte[] buffer, int size){\r
811 return(byte) (0x100 - calculateSum8 (buffer, size));\r
812 }\r
813\r
814\r
815 /**\r
816 calculateSum8\r
817 \r
818 This function is to calculate the UINT8 sum for the requested region.\r
819 @param buffer Byte buffer containing byte data of component\r
820 @param size Size of the buffer.\r
821 @return The 8 bit checksum value needed.\r
822 **/ \r
823 private short calculateSum8 (byte[] buffer, int size){\r
824 int Index;\r
825 byte Sum;\r
826 Sum = 0;\r
827\r
828 //\r
829 // Perform the word sum for buffer\r
830 //\r
831 for (Index = 0; Index < size; Index++) {\r
832 Sum = (byte) (Sum + buffer[Index]); \r
833 }\r
834\r
835 return(byte) Sum; \r
836 }\r
837\r
838 /**\r
839 hexCharToByte\r
840 \r
841 This function is to convert hex character to byte\r
842 \r
843 @param hexChar hex character\r
844 @return Byte which corresponding to the character.\r
845 **/\r
846 private byte hexCharToByte (char hexChar){\r
847 switch (hexChar) {\r
848 case '0':\r
849 return(byte)0x00;\r
850 case '1':\r
851 return(byte)0x01;\r
852 case '2':\r
853 return(byte)0x02;\r
854 case '3':\r
855 return(byte)0x03;\r
856 case '4':\r
857 return(byte)0x04;\r
858 case '5':\r
859 return(byte)0x05;\r
860 case '6':\r
861 return(byte)0x06;\r
862 case '7':\r
863 return(byte)0x07;\r
864 case '8':\r
865 return(byte)0x08;\r
866 case '9':\r
867 return(byte)0x09;\r
868 case 'a':\r
869 case 'A':\r
870 return(byte)0x0a;\r
871 case 'b':\r
872 case 'B':\r
873 return(byte)0x0b;\r
874 case 'c':\r
875 case 'C':\r
876 return(byte)0x0c;\r
877\r
878 case 'd':\r
879 case 'D': \r
880 return(byte)0x0d;\r
881\r
882 case 'e':\r
883 case 'E':\r
884 return(byte)0x0e;\r
885 case 'f':\r
886 case 'F':\r
887 return(byte)0x0f;\r
888\r
889 default:\r
890 return(byte)0xff; \r
891 }\r
892 }\r
893\r
894 /**\r
895 adjustFileSize\r
896 \r
897 This function is used to adjusts file size to insure sectioned file is exactly the right length such\r
898 that it ends on exactly the last byte of the last section. ProcessScript()\r
899 may have padded beyond the end of the last section out to a 4 byte boundary.\r
900 This padding is stripped. \r
901 \r
902 @param buffer Byte buffer contains a section stream\r
903 @return Corrected size of file.\r
904 **/\r
905 private int adjustFileSize (byte[] buffer){ \r
906\r
907 int orignalLen = buffer.length;\r
908 int adjustLen = 0;\r
909 int sectionPoint = 0;\r
910 int nextSectionPoint = 0;\r
911 int sectionLen = 0;\r
912 int totalLen = 0;\r
913 int firstSectionHeader = 0;\r
914\r
915\r
916 firstSectionHeader = buffer[0]& 0xff;\r
917 firstSectionHeader = ((buffer[1]&0xff)<<8) | firstSectionHeader;\r
918 firstSectionHeader = ((buffer[2]&0xff)<<16)| firstSectionHeader;\r
919\r
920\r
921 while (sectionPoint < buffer.length) {\r
922 sectionLen = buffer[0 + sectionPoint]& 0xff;\r
923 sectionLen = ((buffer[1 + sectionPoint]&0xff)<<8)| sectionLen;\r
924 sectionLen = ((buffer[2 + sectionPoint]&0xff)<<16)| sectionLen; \r
925 totalLen = totalLen + sectionLen;\r
926\r
927 if (totalLen == orignalLen) {\r
928 return totalLen;\r
929 }\r
930\r
931 sectionPoint = sectionPoint + sectionLen;\r
932 adjustLen = sectionPoint;\r
933\r
934 nextSectionPoint = (sectionPoint + 0x03) & (~0x03);\r
935 totalLen = totalLen + nextSectionPoint - sectionLen;\r
936 sectionPoint = nextSectionPoint;\r
937 }\r
938 return adjustLen;\r
939 }\r
940\r
941 /**\r
942 getOutputDir\r
943 \r
944 This function is to get output directory.\r
945 \r
946 @return Path of output directory.\r
947 **/\r
948 public String getOutputDir() {\r
949 return outputDir;\r
950 }\r
951\r
952 /**\r
953 setOutputDir\r
954 \r
955 This function is to set output directory.\r
956 \r
957 @param outputDir The output direcotry.\r
958 **/\r
959 public void setOutputDir(String outputDir) {\r
960 this.outputDir = outputDir;\r
961 }\r
962}\r