]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add genDigest() method to class FfsProcess to generate MD5 digest value for the FFS...
authorjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 5 Feb 2007 06:25:58 +0000 (06:25 +0000)
committerjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 5 Feb 2007 06:25:58 +0000 (06:25 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2353 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Java/Source/GenBuild/org/tianocore/build/FfsProcess.java

index dd86346b7f112d6c62747e2788fdfa998e51ad48..f63b7d95f0bdaba9af05666454dfa42175106ecc 100644 (file)
@@ -14,6 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 package org.tianocore.build;\r
 \r
 import java.io.File;\r
 package org.tianocore.build;\r
 \r
 import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.FileReader;\r
+import java.io.FileWriter;\r
+import java.security.MessageDigest;\r
 import java.util.Vector;\r
 \r
 import javax.xml.namespace.QName;\r
 import java.util.Vector;\r
 \r
 import javax.xml.namespace.QName;\r
@@ -55,6 +60,7 @@ public class FfsProcess {
 \r
     private BuildOptionsDocument.BuildOptions.Ffs ffsXmlObject;\r
 \r
 \r
     private BuildOptionsDocument.BuildOptions.Ffs ffsXmlObject;\r
 \r
+    private Project project = null;\r
     ///\r
     /// ANT script to call GenFfs\r
     ///\r
     ///\r
     /// ANT script to call GenFfs\r
     ///\r
@@ -113,6 +119,7 @@ public class FfsProcess {
               If can't find FFS Layout in FPD.\r
     **/\r
     public boolean initSections(String buildType, Project project, FpdModuleIdentification fpdModuleId) throws BuildException {\r
               If can't find FFS Layout in FPD.\r
     **/\r
     public boolean initSections(String buildType, Project project, FpdModuleIdentification fpdModuleId) throws BuildException {\r
+        this.project = project;\r
         //\r
         // Try to find Ffs layout from FPD file\r
         //\r
         //\r
         // Try to find Ffs layout from FPD file\r
         //\r
@@ -121,6 +128,7 @@ public class FfsProcess {
         for (int i = 0; i < ffsArray.length; i++) {\r
             if (isMatch(ffsArray[i].getFfsKey(), buildType)) {\r
                 ffsXmlObject = ffsArray[i];\r
         for (int i = 0; i < ffsArray.length; i++) {\r
             if (isMatch(ffsArray[i].getFfsKey(), buildType)) {\r
                 ffsXmlObject = ffsArray[i];\r
+                genDigest();\r
                 return true;\r
             }\r
         }\r
                 return true;\r
             }\r
         }\r
@@ -196,6 +204,13 @@ public class FfsProcess {
             pathEle.setAttribute("name", getSectionFile(basename, section));\r
             sourceEle.appendChild(pathEle);\r
         }\r
             pathEle.setAttribute("name", getSectionFile(basename, section));\r
             sourceEle.appendChild(pathEle);\r
         }\r
+        //\r
+        // add FFS layout digest into the source file list\r
+        // \r
+        Element pathEle = document.createElement("file");\r
+        pathEle.setAttribute("name", "${DEST_DIR_OUTPUT}" + File.separator + "ffs.md5");\r
+        sourceEle.appendChild(pathEle);\r
+\r
         String[] result = sections.toArray(new String[sections.size()]);\r
 \r
         outofdateEle.appendChild(sourceEle);\r
         String[] result = sections.toArray(new String[sections.size()]);\r
 \r
         outofdateEle.appendChild(sourceEle);\r
@@ -439,4 +454,73 @@ public class FfsProcess {
     public Element getFfsNode() {\r
         return ffsNode;\r
     }\r
     public Element getFfsNode() {\r
         return ffsNode;\r
     }\r
+\r
+    private void genDigest() {\r
+        String digestFilePath = project.getProperty("DEST_DIR_OUTPUT");\r
+        if (digestFilePath == null) {\r
+            EdkLog.log(EdkLog.EDK_WARNING, "Warning: cannot get DEST_DIR_OUTPUT!");\r
+            return;\r
+        }\r
+\r
+        //\r
+        // use MD5 algorithm\r
+        // \r
+        MessageDigest md5 = null;\r
+        try {\r
+            md5 = MessageDigest.getInstance("MD5");\r
+            //\r
+            // convert the FFS layout XML DOM tree into string and use it to\r
+            // calculate its MD5 digest value\r
+            // \r
+            md5.update(ffsXmlObject.xmlText().getBytes());\r
+        } catch (Exception e) {\r
+            EdkLog.log(EdkLog.EDK_WARNING, "Warning: " + e.getMessage());\r
+            return;\r
+        }\r
+\r
+        //\r
+        // get the MD5 digest value\r
+        // \r
+        byte[] digest = md5.digest();\r
+\r
+        //\r
+        // put the digest in a file named "ffs.md5" if it doesn't exist, otherwise\r
+        // we will compare the digest in the file with the one just calculated\r
+        // \r
+        digestFilePath += File.separator + "ffs.md5";\r
+        File digestFile = new File(digestFilePath);\r
+        if (digestFile.exists()) {\r
+            byte[] oldDigest = new byte[digest.length];\r
+            try {\r
+                FileInputStream fIn = new FileInputStream(digestFile);\r
+                fIn.read(oldDigest);\r
+                fIn.close();\r
+            } catch (Exception e) {\r
+                throw new BuildException(e.getMessage());\r
+            }\r
+\r
+            boolean noChange = true;\r
+            for (int i = 0; i < oldDigest.length; ++i) {\r
+                if (digest[i] != oldDigest[i]) {\r
+                    noChange = false;\r
+                    break;\r
+                }\r
+            }\r
+\r
+            if (noChange) {\r
+                return;\r
+            }\r
+        }\r
+\r
+        //\r
+        // update the "ffs.md5" file content with new digest value\r
+        // \r
+        try {\r
+            FileOutputStream fOut = new FileOutputStream(digestFile);\r
+            fOut.write(digest);\r
+            fOut.close();\r
+        } catch (Exception e) {\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+    }\r
 }\r
 }\r