Modify GenFfsTask to make it don't create ORG file.
authorqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 08:05:34 +0000 (08:05 +0000)
committerqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 08:05:34 +0000 (08:05 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1271 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Section.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java

index 674c6c86676ce13eeaee4a5d72260c423e3802fb..84f9176e786f7a120b9eae62eff8bb45a3fbe044 100644 (file)
 \r
 package org.tianocore.framework.tasks;\r
 \r
-import java.io.DataInputStream;\r
+import java.io.ByteArrayOutputStream;\r
 import java.io.DataOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.List;\r
@@ -54,18 +51,17 @@ public class CompressSection implements Section, FfsTypes{
       @param Buffer     The point of output buffer\r
       \r
     **/\r
-    public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){\r
+    public void toBuffer (DataOutputStream buffer){\r
         \r
         Section    sect;\r
-        File       compressOut;\r
     \r
         //\r
         //  Get section file in compress node.\r
         //\r
         try{\r
-            compressOut = new File ("Compress.temp");\r
-            FileOutputStream fo = new FileOutputStream (compressOut.getName());\r
-            DataOutputStream Do = new DataOutputStream (fo);\r
+            \r
+            ByteArrayOutputStream bo = new ByteArrayOutputStream ();\r
+            DataOutputStream Do = new DataOutputStream (bo);\r
             \r
             //\r
             //  Get each section which under the compress {};\r
@@ -79,7 +75,7 @@ public class CompressSection implements Section, FfsTypes{
                 //  Call each section class's toBuffer function.\r
                 //\r
                 try {\r
-                    sect.toBuffer(Do, orgBuffer);\r
+                    sect.toBuffer(Do);\r
                 }\r
                 catch (BuildException e) {\r
                     System.out.print(e.getMessage());\r
@@ -89,17 +85,10 @@ public class CompressSection implements Section, FfsTypes{
             }\r
             Do.close();    \r
             \r
-            //\r
-            //  Get contain to Buffer\r
-            //\r
-            FileInputStream fi = new FileInputStream (compressOut.getName());\r
-            DataInputStream di = new DataInputStream (fi);\r
-            byte[] fileBuffer  = new byte[(int)compressOut.length()];\r
-            di.read(fileBuffer);\r
-            \r
             //\r
             //  Call compress\r
             //\r
+            byte[] fileBuffer = bo.toByteArray();\r
             Compress myCompress = new Compress(fileBuffer, fileBuffer.length);            \r
             \r
             //\r
@@ -151,18 +140,10 @@ public class CompressSection implements Section, FfsTypes{
                 buffer.writeByte(0);\r
             }\r
             //\r
-            // orgBuffer 4 Byte aligment\r
-            //\r
-            size = (int)compressOut.length();\r
-            while ((size & 0x03) != 0){\r
-                size ++;\r
-                orgBuffer.writeByte(0);\r
-            }\r
-            //\r
             //  Delete temp file\r
             //\r
-            di.close();\r
-            compressOut.delete();\r
+            //di.close();\r
+            //compressOut.delete();\r
                 \r
         }\r
         catch (Exception e){\r
index 117ef393f5309b0daa96cde838c23cdcbc163c1c..b41e7f8a0a9b11193c80c932ae0f806425a7c773 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
 import org.apache.tools.ant.Task;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
   GenFfsFileTask\r
@@ -112,7 +113,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
     /// The path of Framewor_Tools_Paht.\r
     ///\r
     static String path = "";  \r
-\r
\r
     /**\r
       execute\r
       \r
@@ -120,18 +121,17 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
       dscriptive information.\r
     **/\r
     public void execute() throws BuildException {\r
-        Section           sect;\r
-        int               fileSize;\r
-        int               orgFileSize;\r
-        int               fileDataSize;\r
-        int               orgFileDataSize;\r
-        File              ffsFile;\r
-        File              ffsOrgFile;\r
-        FfsHeader         ffsHeader = new FfsHeader();  \r
-        FfsHeader         orgFfsHeader = new FfsHeader();\r
+\r
         String            ffsSuffix = "";\r
         String            outputPath = "";\r
-\r
+        Project project = this.getOwningTarget().getProject();\r
+        //\r
+        // set Logger\r
+        //\r
+        FrameworkLogger logger = new FrameworkLogger(project, "genFfs");\r
+        EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r
+        EdkLog.setLogger(logger);\r
+        \r
         //\r
         //  Get Fraemwork_Tools_Path\r
         //\r
@@ -170,267 +170,8 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         }\r
 \r
         String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix;\r
-        ffsFile = new File (ffsFilePath);  \r
-        //\r
-        // Create ffs ORG file. fileName = FfsFileGuid + BaseName + ffsSuffix +\r
-        // ".org".\r
-        //\r
-        ffsOrgFile = new File(ffsFilePath + ".org");\r
-           \r
-        log(ffsFile.getName());\r
-        log(ffsOrgFile.getName());\r
-        try {\r
-            //\r
-            //  Create file output stream -- dataBuffer.\r
-            //\r
-            FileOutputStream dataFs     = new FileOutputStream (ffsFile.getAbsolutePath());\r
-            DataOutputStream dataBuffer = new DataOutputStream (dataFs);\r
-            \r
-            //\r
-            // Create org file output stream -- orgDataBuffer\r
-            //\r
-            FileOutputStream orgDataFs     = new FileOutputStream (ffsOrgFile.getAbsolutePath());\r
-            DataOutputStream orgDataBuffer = new DataOutputStream (orgDataFs);\r
-            \r
-            //\r
-            //  Search SectionList find earch section and call it's \r
-            //  ToBuffer function.\r
-            //\r
-            Iterator sectionIter = this.sectionList.iterator();\r
-            while (sectionIter.hasNext()) {\r
-                sect = (Section)sectionIter.next(); \r
-\r
-                try {\r
-                    //\r
-                    //  The last section don't need 4 byte ffsAligment.\r
-                    //\r
-                    sect.toBuffer((DataOutputStream)dataBuffer, (DataOutputStream) orgDataBuffer);\r
-                } catch (Exception e) {\r
-                    throw new BuildException (e.getMessage());\r
-                }\r
-            }\r
-            dataBuffer.close();\r
-            orgDataBuffer.close();\r
-        } catch (Exception e) {\r
-            throw new BuildException (e.getMessage());\r
-        }\r
-\r
-        //\r
-        //  Creat Ffs file header\r
-        //\r
-        try {\r
-\r
-            //\r
-            //  create input stream to read file data\r
-            //\r
-            byte[] fileBuffer  = new byte[(int)ffsFile.length()];\r
-            FileInputStream fi = new FileInputStream (ffsFile.getAbsolutePath());\r
-            DataInputStream di = new DataInputStream (fi);\r
-            di.read(fileBuffer);\r
-            di.close();\r
-            \r
-            //\r
-            // create input org stream to read file data\r
-            //\r
-            byte[] orgFileBuffer = new byte[(int)ffsOrgFile.length()];\r
-            FileInputStream ofi  = new FileInputStream (ffsOrgFile.getAbsolutePath());\r
-            DataInputStream odi  = new DataInputStream (ofi);\r
-            odi.read(orgFileBuffer);\r
-            odi.close();\r
-\r
-            //\r
-            //  Add GUID to header struct\r
-            //\r
-            if (this.ffsFileGuid != null) {\r
-                stringToGuid (this.ffsFileGuid, ffsHeader.name);\r
-                //\r
-                // Add Guid to org header struct\r
-                //\r
-                stringToGuid (this.ffsFileGuid, orgFfsHeader.name);\r
-            }\r
-\r
-            ffsHeader.ffsAttributes = this.attributes;\r
-            if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) {\r
-                throw new BuildException ("FFS_FILE_TYPE unknow!\n");\r
-            }\r
-            \r
-            //\r
-            // Copy ffsHeader.ffsAttribute and fileType to orgFfsHeader.ffsAttribute\r
-            // and fileType\r
-            //            \r
-            orgFfsHeader.ffsAttributes = ffsHeader.ffsAttributes;\r
-            orgFfsHeader.fileType      = ffsHeader.fileType;\r
-            \r
-            //\r
-            //  Adjust file size. The function is used to tripe the last \r
-            //  section padding of 4 binary boundary. \r
-            //  \r
-            //\r
-            if (ffsHeader.fileType != EFI_FV_FILETYPE_RAW) {\r
-\r
-                fileDataSize = adjustFileSize (fileBuffer);\r
-                orgFileDataSize = adjustFileSize (orgFileBuffer);\r
-\r
-            } else {\r
-                fileDataSize = fileBuffer.length;\r
-                orgFileDataSize = orgFileBuffer.length;\r
-            }\r
-\r
-            //\r
-            //  1. add header size to file size\r
-            //\r
-            fileSize = fileDataSize + ffsHeader.getSize();\r
-            //\r
-            //     add header size to org file size\r
-            //\r
-            orgFileSize = orgFileDataSize + ffsHeader.getSize();\r
-\r
-            if ((ffsHeader.ffsAttributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
-                if (ffsHeader.fileType == EFI_FV_FILETYPE_FFS_PAD) {\r
-\r
-                    throw new BuildException (\r
-                                             "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +\r
-                                             "invalid for PAD files"\r
-                                             );\r
-                }\r
-                if (fileSize == ffsHeader.getSize()) {\r
-                    throw new BuildException (\r
-                                             "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +\r
-                                             "invalid for zero length files"\r
-                                             );            \r
-                }\r
-                fileSize = fileSize + 2;\r
-                orgFileSize = orgFileSize + 2;\r
-            }\r
-\r
-            //\r
-            //  2. set file size to header struct\r
-            //\r
-            ffsHeader.ffsFileSize[0] = (byte)(fileSize & 0x00FF);\r
-            ffsHeader.ffsFileSize[1] = (byte)((fileSize & 0x00FF00)>>8);\r
-            ffsHeader.ffsFileSize[2] = (byte)(((int)fileSize & 0xFF0000)>>16);\r
-            \r
-            //\r
-            //     set file size to org header struct\r
-            //\r
-            orgFfsHeader.ffsFileSize[0] = (byte)(orgFileSize & 0x00FF);\r
-            orgFfsHeader.ffsFileSize[1] = (byte)((orgFileSize & 0x00FF00)>>8);\r
-            orgFfsHeader.ffsFileSize[2] = (byte)(((int)orgFileSize & 0xFF0000)>>16);\r
-            \r
-            //\r
-            //  Fill in checksums and state, these must be zero for checksumming\r
-            //\r
-            ffsHeader.integrityCheck.header = calculateChecksum8 (\r
-                                                                 ffsHeader.structToBuffer(),\r
-                                                                 ffsHeader.getSize()\r
-                                                                 );\r
-            //\r
-            // Fill in org file's header check sum and state\r
-            //\r
-            orgFfsHeader.integrityCheck.header = calculateChecksum8 (\r
-                                                                    orgFfsHeader.structToBuffer(),\r
-                                                                    orgFfsHeader.getSize()\r
-                                                                    );\r
-            \r
-            if ((this.attributes & FFS_ATTRIB_CHECKSUM) != 0) {\r
-                if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
-                    ffsHeader.integrityCheck.file = calculateChecksum8 (\r
-                                                                       fileBuffer, \r
-                                                                       fileDataSize\r
-                                                                       );\r
-                    //\r
-                    // Add org file header\r
-                    //\r
-                    orgFfsHeader.integrityCheck.file = calculateChecksum8 (\r
-                                                                           orgFileBuffer,\r
-                                                                           orgFileDataSize\r
-                                                                           );\r
-                } else {\r
-                    ffsHeader.integrityCheck.file = calculateChecksum8 (\r
-                                                                       fileBuffer,\r
-                                                                       fileDataSize\r
-                                                                       );\r
-                    //\r
-                    // Add org file header\r
-                    //\r
-                    orgFfsHeader.integrityCheck.file = calculateChecksum8 (\r
-                                                                          orgFileBuffer,\r
-                                                                          orgFileDataSize\r
-                                                                          );\r
-                }\r
-            } else {\r
-                ffsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;\r
-                orgFfsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;\r
-            }\r
-\r
-            //\r
-            //   Set the state now. Spec says the checksum assumes the state is 0.\r
-            //\r
-            ffsHeader.ffsState = EFI_FILE_HEADER_CONSTRUCTION | \r
-                                 EFI_FILE_HEADER_VALID | \r
-                                 EFI_FILE_DATA_VALID;\r
-            orgFfsHeader.ffsState = ffsHeader.ffsState;\r
-            \r
-            //\r
-            // create output stream to first write header data in file, then write sect data in file.\r
-            //\r
-            FileOutputStream headerFfs = new FileOutputStream (ffsFile.getAbsolutePath());\r
-            DataOutputStream ffsBuffer = new DataOutputStream (headerFfs);\r
-            \r
-            FileOutputStream orgHeaderFfs = new FileOutputStream (ffsOrgFile.getAbsolutePath());\r
-            DataOutputStream orgFfsBuffer = new DataOutputStream (orgHeaderFfs);\r
-            \r
-            //\r
-            //  Add header struct and file data to FFS file\r
-            //\r
-            ffsBuffer.write(ffsHeader.structToBuffer());\r
-            orgFfsBuffer.write(orgFfsHeader.structToBuffer());\r
-            \r
-            for (int i = 0; i< fileDataSize; i++) {\r
-                ffsBuffer.write(fileBuffer[i]);\r
-            }\r
-            \r
-            for (int i = 0; i < orgFileDataSize; i++){\r
-                orgFfsBuffer.write(orgFileBuffer[i]);\r
-            }\r
-\r
-            //\r
-            //  If there is a tail, then set it\r
-            //\r
-            if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
-                short tailValue ;\r
-                byte [] tailByte = new byte[2];\r
-\r
-                //\r
-                //  reverse tailvalue , integritycheck.file as hight byte, and \r
-                //  integritycheck.header as low byte.\r
-                //\r
-                tailValue = (short)(ffsHeader.integrityCheck.header & 0xff);\r
-                tailValue = (short)((tailValue) | ((ffsHeader.integrityCheck.file << 8) & 0xff00)); \r
-                tailValue = (short)~tailValue;\r
-\r
-                //\r
-                //  Change short to byte[2]\r
-                //\r
-                tailByte[0] = (byte)(tailValue & 0xff);\r
-                tailByte[1] = (byte)((tailValue & 0xff00)>>8);  \r
-                ffsBuffer.write(tailByte[0]);\r
-                ffsBuffer.write(tailByte[1]);\r
-                \r
-                orgFfsBuffer.write(tailByte[0]);\r
-                orgFfsBuffer.write(tailByte[1]);\r
-            }\r
-\r
-            //\r
-            //  close output stream. Note if don't close output stream \r
-            //  the buffer can't be rewritten to file. \r
-            //\r
-            ffsBuffer.close();\r
-            orgFfsBuffer.close();\r
-        } catch (Exception e) {\r
-            log("genffsfile failed!");\r
-            throw new BuildException (e.getMessage());\r
-        }\r
+        File ffsFile = new File (ffsFilePath);\r
+        genFfs(ffsFile);\r
     }   \r
 \r
     /**\r
@@ -941,43 +682,260 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         this.outputDir = outputDir;\r
     }\r
 \r
+    /**\r
+      getModuleTyp\r
+      \r
+      This function is to get string of module type.\r
+     \r
+      @return moduleType      The string of module type.\r
+    **/\r
     public String getModuleType() {\r
         return this.moduleType;\r
     }\r
 \r
+    /**\r
+      setModuleType\r
+      \r
+      This function is to set moduleType.\r
+      \r
+      @param moduleType       The string of module type.\r
+    **/\r
     public void setModuleType(String moduleType) {\r
         this.moduleType = moduleType;\r
     }\r
-\r
+    \r
     /**\r
-     Convert a string to a integer.\r
-     \r
-     @param     intString   The string representing a integer\r
-     \r
-     @retval    int     The value of integer represented by the\r
-                        given string; -1 is returned if the format\r
-                        of the string is wrong.\r
-     **/\r
-    private int stringToInt(String intString) {\r
-        int value;\r
-        int hexPrefixPos = intString.indexOf("0x");\r
-        int radix = 10;\r
-        String intStringNoPrefix;\r
-\r
-        if (hexPrefixPos >= 0) {\r
-            radix = 16;\r
-            intStringNoPrefix = intString.substring(hexPrefixPos + 2, intString.length());\r
-        } else {\r
-            intStringNoPrefix = intString;\r
+    Convert a string to a integer.\r
+    \r
+    @param     intString   The string representing a integer\r
+    \r
+    @retval    int     The value of integer represented by the\r
+                       given string; -1 is returned if the format\r
+                       of the string is wrong.\r
+    **/\r
+   private int stringToInt(String intString) {\r
+       int value;\r
+       int hexPrefixPos = intString.indexOf("0x");\r
+       int radix = 10;\r
+       String intStringNoPrefix;\r
+\r
+       if (hexPrefixPos >= 0) {\r
+           radix = 16;\r
+           intStringNoPrefix = intString.substring(hexPrefixPos + 2, intString.length());\r
+       } else {\r
+           intStringNoPrefix = intString;\r
+       }\r
+\r
+       try {\r
+           value = Integer.parseInt(intStringNoPrefix, radix);\r
+       } catch (NumberFormatException e) {\r
+           log("Incorrect format of int [" + intString + "]. -1 is assumed");\r
+           return -1;\r
+       }\r
+\r
+       return value;\r
+   }\r
+    \r
+    /**\r
+      genFfs\r
+      \r
+      This function is to generate FFS file.\r
+      \r
+       @param ffsFile          Name of FFS file.\r
+       @param isOrg            Flag to indicate generate ORG ffs file or not.\r
+    **/\r
+    private void genFfs(File ffsFile) {\r
+        Section           sect;\r
+        int               fileSize;\r
+        int               fileDataSize;\r
+        FfsHeader         ffsHeader = new FfsHeader();  \r
+        FfsHeader         orgFfsHeader = new FfsHeader();\r
+           \r
+        EdkLog.log(EdkLog.EDK_INFO, ffsFile.getName());\r
+      \r
+        try {\r
+            //\r
+            //  Create file output stream -- dataBuffer.\r
+            //\r
+            FileOutputStream dataFs     = new FileOutputStream (ffsFile.getAbsolutePath());\r
+            DataOutputStream dataBuffer = new DataOutputStream (dataFs);\r
+            \r
+            //\r
+            //  Search SectionList find earch section and call it's \r
+            //  ToBuffer function.\r
+            //\r
+            Iterator sectionIter = this.sectionList.iterator();\r
+            while (sectionIter.hasNext()) {\r
+                sect = (Section)sectionIter.next(); \r
+\r
+                try {\r
+                    //\r
+                    //  The last section don't need 4 byte ffsAligment.\r
+                    //\r
+                    sect.toBuffer((DataOutputStream)dataBuffer);\r
+                } catch (Exception e) {\r
+                    throw new BuildException (e.getMessage());\r
+                }\r
+            }\r
+            dataBuffer.close();\r
+        } catch (Exception e) {\r
+            throw new BuildException (e.getMessage());\r
         }\r
 \r
+        //\r
+        //  Creat Ffs file header\r
+        //\r
         try {\r
-            value = Integer.parseInt(intStringNoPrefix, radix);\r
-        } catch (NumberFormatException e) {\r
-            log("Incorrect format of int [" + intString + "]. -1 is assumed");\r
-            return -1;\r
+\r
+            //\r
+            //  create input stream to read file data\r
+            //\r
+            byte[] fileBuffer  = new byte[(int)ffsFile.length()];\r
+            FileInputStream fi = new FileInputStream (ffsFile.getAbsolutePath());\r
+            DataInputStream di = new DataInputStream (fi);\r
+            di.read(fileBuffer);\r
+            di.close();\r
+            \r
+            //\r
+            //  Add GUID to header struct\r
+            //\r
+            if (this.ffsFileGuid != null) {\r
+                stringToGuid (this.ffsFileGuid, ffsHeader.name);\r
+            }\r
+\r
+            ffsHeader.ffsAttributes = this.attributes;\r
+            if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) {\r
+                throw new BuildException ("FFS_FILE_TYPE unknow!\n");\r
+            }\r
+            \r
+            //\r
+            // Copy ffsHeader.ffsAttribute and fileType to orgFfsHeader.ffsAttribute\r
+            // and fileType\r
+            //            \r
+            orgFfsHeader.ffsAttributes = ffsHeader.ffsAttributes;\r
+            orgFfsHeader.fileType      = ffsHeader.fileType;\r
+            \r
+            //\r
+            //  Adjust file size. The function is used to tripe the last \r
+            //  section padding of 4 binary boundary. \r
+            //  \r
+            //\r
+            if (ffsHeader.fileType != EFI_FV_FILETYPE_RAW) {\r
+\r
+                fileDataSize = adjustFileSize (fileBuffer);\r
+            } else {\r
+                fileDataSize = fileBuffer.length;\r
+            }\r
+\r
+            //\r
+            //  1. add header size to file size\r
+            //\r
+            fileSize = fileDataSize + ffsHeader.getSize();\r
+\r
+            if ((ffsHeader.ffsAttributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
+                if (ffsHeader.fileType == EFI_FV_FILETYPE_FFS_PAD) {\r
+\r
+                    throw new BuildException (\r
+                                             "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +\r
+                                             "invalid for PAD files"\r
+                                             );\r
+                }\r
+                if (fileSize == ffsHeader.getSize()) {\r
+                    throw new BuildException (\r
+                                             "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +\r
+                                             "invalid for 0-length files"\r
+                                             );            \r
+                }\r
+                fileSize = fileSize + 2;\r
+            }\r
+\r
+            //\r
+            //  2. set file size to header struct\r
+            //\r
+            ffsHeader.ffsFileSize[0] = (byte)(fileSize & 0x00FF);\r
+            ffsHeader.ffsFileSize[1] = (byte)((fileSize & 0x00FF00)>>8);\r
+            ffsHeader.ffsFileSize[2] = (byte)(((int)fileSize & 0xFF0000)>>16);\r
+            \r
+            //\r
+            //  Fill in checksums and state, these must be zero for checksumming\r
+            //\r
+            ffsHeader.integrityCheck.header = calculateChecksum8 (\r
+                                                                 ffsHeader.structToBuffer(),\r
+                                                                 ffsHeader.getSize()\r
+                                                                 );\r
+            \r
+            if ((this.attributes & FFS_ATTRIB_CHECKSUM) != 0) {\r
+                if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
+                    ffsHeader.integrityCheck.file = calculateChecksum8 (\r
+                                                                       fileBuffer, \r
+                                                                       fileDataSize\r
+                                                                       );\r
+                } else {\r
+                    ffsHeader.integrityCheck.file = calculateChecksum8 (\r
+                                                                       fileBuffer,\r
+                                                                       fileDataSize\r
+                                                                       );\r
+                }\r
+            } else {\r
+                ffsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;\r
+                orgFfsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;\r
+            }\r
+\r
+            //\r
+            //   Set the state now. Spec says the checksum assumes the state is 0.\r
+            //\r
+            ffsHeader.ffsState = EFI_FILE_HEADER_CONSTRUCTION | \r
+                                 EFI_FILE_HEADER_VALID | \r
+                                 EFI_FILE_DATA_VALID;\r
+            \r
+            //\r
+            // create output stream to first write header data in file, then write sect data in file.\r
+            //\r
+            FileOutputStream headerFfs = new FileOutputStream (ffsFile.getAbsolutePath());\r
+            DataOutputStream ffsBuffer = new DataOutputStream (headerFfs);\r
+            \r
+            //\r
+            //  Add header struct and file data to FFS file\r
+            //\r
+            ffsBuffer.write(ffsHeader.structToBuffer());\r
+            ffsBuffer.write(fileBuffer, 0, fileDataSize);\r
+            \r
+\r
+\r
+            //\r
+            //  If there is a tail, then set it\r
+            //\r
+            if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {\r
+                short tailValue ;\r
+                byte [] tailByte = new byte[2];\r
+\r
+                //\r
+                //  reverse tailvalue , integritycheck.file as hight byte, and \r
+                //  integritycheck.header as low byte.\r
+                //\r
+                tailValue = (short)(ffsHeader.integrityCheck.header & 0xff);\r
+                tailValue = (short)((tailValue) | ((ffsHeader.integrityCheck.file << 8) & 0xff00)); \r
+                tailValue = (short)~tailValue;\r
+\r
+                //\r
+                //  Change short to byte[2]\r
+                //\r
+                tailByte[0] = (byte)(tailValue & 0xff);\r
+                tailByte[1] = (byte)((tailValue & 0xff00)>>8);  \r
+                ffsBuffer.write(tailByte[0]);\r
+                ffsBuffer.write(tailByte[1]);\r
+\r
+            }\r
+\r
+            //\r
+            //  close output stream. Note if don't close output stream \r
+            //  the buffer can't be rewritten to file. \r
+            //\r
+            ffsBuffer.close();\r
+        } catch (Exception e) {\r
+            log("genffsfile failed!");\r
+            throw new BuildException (e.getMessage());\r
         }\r
 \r
-        return value;\r
     }\r
 }\r
index 90a613f3aa6923e0e284ab0860302eb87aa391c5..78eabf9f8d032eecc2b29a8b1bfd5cb1b600915e 100644 (file)
@@ -18,19 +18,11 @@ package org.tianocore.framework.tasks;
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
 import org.apache.tools.ant.Task;\r
-import org.apache.tools.ant.taskdefs.Execute;\r
-import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
-import org.apache.tools.ant.types.Commandline;\r
 \r
 import java.io.File;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
 import java.io.InputStreamReader;\r
 import java.lang.ProcessBuilder;\r
-import java.util.ArrayList;\r
 import java.util.LinkedList;\r
-import java.util.List;\r
-import java.util.Map;\r
 \r
 /**\r
   GenFvImageTask\r
index b603a3eb80a92b84af3af0e0475796d4d78f395d..c110f3bc50b27f8e6cfd34bca66a7ee654daf8ab 100644 (file)
@@ -53,10 +53,9 @@ public class SectFile implements Section {
   \r
      @param   Buffer  buffer to contain the section file content with alignment\r
      **/\r
-    public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){\r
+    public void toBuffer (DataOutputStream buffer){\r
         File   sectFile;\r
-        byte   data;\r
-        long   fileLen;\r
+        int    fileLen;\r
 \r
         ///\r
         /// open file\r
@@ -67,7 +66,7 @@ public class SectFile implements Section {
         /// check if file exist.\r
         ///     \r
         if (! sectFile.exists()) {\r
-            throw new BuildException("The file  " + this.fileName + "  does not exist!\n");     \r
+            throw new BuildException("The file  " + this.fileName + "  is not exist!\n");     \r
         }\r
 \r
 \r
@@ -78,18 +77,10 @@ public class SectFile implements Section {
 \r
             FileInputStream fs = new FileInputStream (sectFile.getAbsoluteFile());\r
             DataInputStream In = new DataInputStream (fs);\r
-            fileLen            = sectFile.length();\r
-\r
-            int i = 0;\r
-            while (i < fileLen) {\r
-                data = In.readByte();\r
-                buffer.writeByte(data);\r
-                //\r
-                // Add data to org file \r
-                //\r
-                orgBuffer.writeByte(data);\r
-                i++;\r
-            }\r
+            fileLen            = (int)sectFile.length();\r
+            byte[] sectBuffer  = new byte[fileLen];\r
+            In.read(sectBuffer);\r
+            buffer.write(sectBuffer);\r
 \r
             ///\r
             /// 4 byte alignment\r
@@ -97,10 +88,6 @@ public class SectFile implements Section {
             while ((fileLen & 0x03)!= 0) {\r
                 fileLen ++;\r
                 buffer.writeByte(0);\r
-                //\r
-                // Add data to org file \r
-                //\r
-                orgBuffer.writeByte(0);\r
             } \r
 \r
             ///\r
@@ -113,4 +100,4 @@ public class SectFile implements Section {
             throw new BuildException("SectFile, toBuffer failed!\n");            \r
         }\r
     }\r
-}\r
+}
\ No newline at end of file
index 6abee52da3e0e28149b7cdb7b3eae8deaa630e94..5fa8d7b1ee35968f1bf228e12d1286cf131007a6 100644 (file)
@@ -19,5 +19,5 @@ import java.io.DataOutputStream;
  Section interface is for geting the contain buffer form compress, tool, and sectFile  \r
  **/\r
 public interface Section {\r
-    public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer);\r
+    public void toBuffer (DataOutputStream buffer);\r
 }
\ No newline at end of file
index 67e0a865a675abaebd1c8c751e52594124ee61c3..4cc4d374c43136b7a3a6eaaf0de712d62fd57c1e 100644 (file)
@@ -39,7 +39,7 @@ public class Tool implements EfiDefine, Section {
 \r
      @param     buffer  The buffer to put the result with alignment\r
      **/\r
-    public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){\r
+    public void toBuffer (DataOutputStream buffer){\r
         File           OutputFile;\r
         byte           data;\r
 \r
@@ -72,10 +72,6 @@ public class Tool implements EfiDefine, Section {
             while (i < fileLen) {\r
                 data = In.readByte();\r
                 buffer.writeByte(data);\r
-                //\r
-                // Add data to org file\r
-                //\r
-                orgBuffer.writeByte(data);\r
                 i ++;\r
             }\r
 \r
@@ -85,7 +81,6 @@ public class Tool implements EfiDefine, Section {
             while ((fileLen & 0x03) != 0) {\r
                 fileLen++;\r
                 buffer.writeByte(0);\r
-                orgBuffer.writeByte(0);\r
             }\r
             In.close();\r
 \r