]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java
1.Change environment variable from "Framework_Tools_Path" to "FRAMEWORK_TOOLS_PATH".
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFfsFileTask.java
index 00712d8bb6875459c9a079a6cebb0cae0a4c861c..4d4c99625bda39e7aa0ddddef384c63670177824 100644 (file)
@@ -114,13 +114,17 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
       \r
       GenFfsFileTask execute is to generate ffs file according to input section \r
       dscriptive information.\r
-     */\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
         String            ffsSuffix = "";\r
         String            outputPath = "";\r
 \r
@@ -128,7 +132,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         //  Get Fraemwork_Tools_Path\r
         //\r
         Project pj = this.getOwningTarget().getProject();\r
-        path       = pj.getProperty("env.Framework_Tools_Path");\r
+        path       = pj.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
 \r
         //\r
         //  Check does the BaseName, Guid, FileType set value.\r
@@ -165,14 +169,26 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         System.out.print("General Ffs file: file name is:\n");\r
         System.out.print(outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix);\r
         System.out.print("\n");\r
-\r
+        \r
         //\r
-        //  Create file output stream -- dataBuffer.\r
-        //   \r
+        // Create ffs ORG file. fileName = FfsFileGuid + BaseName + ffsSuffix +\r
+        // ".org".\r
+        //\r
+        ffsOrgFile = new File(outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix + ".org");\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
+            //\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
@@ -185,7 +201,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
                     //\r
                     //  The last section don't need 4 byte ffsAligment.\r
                     //\r
-                    sect.toBuffer((DataOutputStream)dataBuffer);\r
+                    sect.toBuffer((DataOutputStream)dataBuffer, (DataOutputStream) orgDataBuffer);\r
                 } catch (Exception e) {\r
                     throw new BuildException (e.getMessage());\r
                 }\r
@@ -207,22 +223,40 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
             FileInputStream fi = new FileInputStream (ffsFile.getAbsolutePath());\r
             DataInputStream di = new DataInputStream (fi);\r
             di.read(fileBuffer);\r
-            di.close(); \r
-\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
+            \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
@@ -231,15 +265,21 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
             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
@@ -256,6 +296,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
                                              );            \r
                 }\r
                 fileSize = fileSize + 2;\r
+                orgFileSize = orgFileSize + 2;\r
             }\r
 \r
             //\r
@@ -264,7 +305,14 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
             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
+            //\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
@@ -272,21 +320,43 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
                                                                  ffsHeader.structToBuffer(),\r
                                                                  ffsHeader.getSize()\r
                                                                  );\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
@@ -295,21 +365,30 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
             ffsHeader.ffsState = EFI_FILE_HEADER_CONSTRUCTION | \r
                                  EFI_FILE_HEADER_VALID | \r
                                  EFI_FILE_DATA_VALID;\r
-\r
-\r
+            orgFfsHeader.integrityCheck.file = 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
+            \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
@@ -333,6 +412,9 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
                 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
@@ -340,6 +422,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
             //  the buffer can't be rewritten to file. \r
             //\r
             ffsBuffer.close();\r
+            orgFfsBuffer.close();\r
             System.out.print ("Successful create ffs file!\n");\r
         } catch (Exception e) {\r
             throw new BuildException (e.getMessage());\r
@@ -672,7 +755,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         }\r
 \r
         if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {\r
-            return(byte)EFI_FV_FILETYPE_SECURITY_CORE;\r
+            return(byte)EFI_FV_FILETYPE_FREEFORM;\r
         }\r
 \r
         if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {\r