]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Support calling customized compression tool in FrameworkTask.
authorqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 10 Sep 2006 12:51:19 +0000 (12:51 +0000)
committerqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 10 Sep 2006 12:51:19 +0000 (12:51 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1506 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/GenSectionTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java
Tools/Source/GenBuild/org/tianocore/build/FfsProcess.java

index 46a0ec6677d686ba425b4d22e1274f831f4c6e93..d0cc2f50dd3221db6135d665a2bf280d100f499a 100644 (file)
@@ -36,14 +36,13 @@ public class CompressSection implements Section, FfsTypes{
     //\r
     // The attribute of compressName.\r
     //\r
-    String compressName = "";\r
+    private String compressName = "";\r
     //\r
     // The list contained the SectFile element.\r
     //\r
-    List<Object>   SectList     = new ArrayList<Object>();\r
+    private List<Section> sectList = new ArrayList<Section>();\r
 \r
     public static Object semaphore = new Object();\r
-    \r
     /**\r
       toBuffer\r
       \r
@@ -69,7 +68,7 @@ public class CompressSection implements Section, FfsTypes{
             //  Get each section which under the compress {};\r
             //  And add it is contains to File;\r
             //\r
-            Iterator SectionIter = SectList.iterator();\r
+            Iterator SectionIter = sectList.iterator();\r
             while (SectionIter.hasNext()){\r
                 sect = (Section)SectionIter.next();\r
                 \r
@@ -87,7 +86,6 @@ public class CompressSection implements Section, FfsTypes{
             }\r
             Do.close();    \r
             \r
-            \r
             synchronized (semaphore) {\r
             //\r
             //  Call compress\r
@@ -186,7 +184,7 @@ public class CompressSection implements Section, FfsTypes{
       @param sectFile    SectFile element which succeed from section class.\r
     **/\r
     public void addSectFile (SectFile sectFile) {\r
-        SectList.add(sectFile);\r
+        sectList.add(sectFile);\r
             \r
     }    \r
     \r
@@ -197,6 +195,6 @@ public class CompressSection implements Section, FfsTypes{
       @param tool        Tool element which succeed from section class.\r
     **/\r
     public void addTool (Tool tool) {\r
-        SectList.add(tool);\r
+        sectList.add(tool);\r
     }\r
 }
\ No newline at end of file
index b7c5b7f8a06a057952b5007d3e4bc3328c037855..cbe20f02960aa12b715422bc26ba9c33e0be7a04 100644 (file)
@@ -113,7 +113,12 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
     /// The path of Framewor_Tools_Paht.\r
     ///\r
     static String path = "";  \r
\r
+    \r
+    ///\r
+    /// Gensection\r
+    ///\r
+    List<GenSectionTask> genSectList = new ArrayList<GenSectionTask>();\r
+    \r
     /**\r
       execute\r
       \r
@@ -931,4 +936,15 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
         }\r
 \r
     }\r
+    \r
+    /**\r
+      addGenSection\r
+      \r
+      This function is to add gensection instance to list\r
+      \r
+      @param task    Instance of GenSectionTask\r
+    **/\r
+    public void addGenSection (GenSectionTask task){\r
+        this.sectionList.add(task);\r
+    }\r
 }\r
index a631d93de506bda10c736768620f947306314dbd..bb477f031e2f518302b2578e764becc015f08a5c 100644 (file)
 \r
 package org.tianocore.framework.tasks;\r
 \r
+import java.io.ByteArrayOutputStream;\r
+import java.io.DataOutputStream;\r
 import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
@@ -24,8 +29,9 @@ import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.Execute;\r
 import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
 import org.apache.tools.ant.types.Commandline;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
-public class GenSectionTask extends Task implements EfiDefine {\r
+public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes {\r
     ///\r
     /// inputfile name\r
     ///\r
@@ -50,7 +56,11 @@ public class GenSectionTask extends Task implements EfiDefine {
     /// interface string\r
     ///\r
     private String interfaceString = "";\r
-\r
+    ///\r
+    /// Section file list\r
+    ///\r
+    private List<Section> sectFileList = new ArrayList<Section>();\r
+   \r
     /**\r
       execute\r
       \r
@@ -74,7 +84,7 @@ public class GenSectionTask extends Task implements EfiDefine {
         //\r
         // argument of tools\r
         //\r
-        String argument = inputFile + outputFile + sectionType + versionNum\r
+        String argument = inputFile + outputFile + " -s "+ sectionType + versionNum\r
                 + interfaceString;\r
         //\r
         // return value of gensection execution\r
@@ -93,8 +103,8 @@ public class GenSectionTask extends Task implements EfiDefine {
             runner.setAntRun(project);\r
             runner.setCommandline(cmdline.getCommandline());\r
 \r
-            log(inputFileName);\r
-            log(Commandline.toString(cmdline.getCommandline()), Project.MSG_VERBOSE);\r
+            EdkLog.log(this, EdkLog.EDK_INFO, inputFileName);\r
+            EdkLog.log(this, EdkLog.EDK_DEBUG, Commandline.toString(cmdline.getCommandline()));\r
             revl = runner.execute();\r
             if (EFI_SUCCESS == revl) {\r
                 log("GenSection succeeded!", Project.MSG_VERBOSE);\r
@@ -173,7 +183,7 @@ public class GenSectionTask extends Task implements EfiDefine {
       @param sectionType              section type\r
     **/\r
     public void setSectionType(String sectionType) {\r
-        this.sectionType = " -s " + sectionType;\r
+        this.sectionType = sectionType;\r
     }\r
 \r
     /**\r
@@ -215,4 +225,148 @@ public class GenSectionTask extends Task implements EfiDefine {
     public void setInterfaceString(String interfaceString) {\r
         this.interfaceString = " -a " + "\"" + interfaceString + "\"";\r
     }\r
+    \r
+    /**\r
+      addSectFile\r
+      \r
+      This function is to add sectFile to list.\r
+      \r
+      @param sectFile     instance of sectFile.\r
+    **/\r
+    public void addSectFile(SectFile sectFile){\r
+        this.sectFileList.add(sectFile);\r
+    }\r
+\r
+    /**\r
+      setTool\r
+      \r
+      This function is to set the class member "Tool";\r
+      \r
+      @param tool \r
+    **/\r
+    public void addTool(Tool tool) {\r
+        this.sectFileList.add(tool);\r
+    }\r
+    \r
+    /**\r
+      addGenSection\r
+      \r
+      This function is to add GenSectin element to list\r
+      @param task         Instance of genSection\r
+    **/\r
+    public void addGenSection(GenSectionTask task){\r
+        this.sectFileList.add(task);\r
+    }\r
+    \r
+    public void toBuffer(DataOutputStream buffer){\r
+        //\r
+        //  Search SectionList find earch section and call it's \r
+        //  ToBuffer function.\r
+        //\r
+        if (this.sectionType.equalsIgnoreCase("EFI_SECTION_COMPRESSION")){\r
+            Section    sect;\r
+            \r
+            //\r
+            //  Get section file in compress node.\r
+            //\r
+            try{\r
+                ByteArrayOutputStream bo = new ByteArrayOutputStream ();\r
+                DataOutputStream Do = new DataOutputStream (bo);\r
+                \r
+                //\r
+                //  Get each section which under the compress {};\r
+                //  And add it is contains to File;\r
+                //\r
+                Iterator SectionIter = this.sectFileList.iterator();\r
+                while (SectionIter.hasNext()){\r
+                    sect = (Section)SectionIter.next();\r
+                    \r
+                    //\r
+                    //  Call each section class's toBuffer function.\r
+                    //\r
+                    try {\r
+                        sect.toBuffer(Do);\r
+                    }\r
+                    catch (BuildException e) {\r
+                        System.out.print(e.getMessage());\r
+                        throw new BuildException ("Compress.toBuffer failed at section");\r
+                    }    \r
+                                \r
+                }\r
+                Do.close();    \r
+                \r
+                //\r
+                //  Call compress\r
+                //\r
+                byte[] fileBuffer = bo.toByteArray();\r
+                Compress myCompress = new Compress(fileBuffer, fileBuffer.length);            \r
+                \r
+                //\r
+                //  Add Compress header\r
+                //\r
+                CompressHeader Ch        = new CompressHeader();\r
+                Ch.SectionHeader.Size[0] = (byte)((myCompress.outputBuffer.length +\r
+                                                   Ch.GetSize()) &\r
+                                                   0xff\r
+                                                  );\r
+                Ch.SectionHeader.Size[1] = (byte)(((myCompress.outputBuffer.length + \r
+                                                    Ch.GetSize())&\r
+                                                   0xff00) >> 8\r
+                                                  );\r
+                Ch.SectionHeader.Size[2] = (byte)(((myCompress.outputBuffer.length + \r
+                                                    Ch.GetSize()) & \r
+                                                   0xff0000) >> 16\r
+                                                 );\r
+                Ch.SectionHeader.type    = (byte) EFI_SECTION_COMPRESSION;\r
+                \r
+                //\r
+                //  Note: The compressName was not efsfective now. Using the\r
+                //  EFI_STANDARD_COMPRSSION for compressType .\r
+                //  That is follow old Genffsfile tools. Some code will be added for \r
+                //  the different compressName;\r
+                //\r
+                Ch.UncompressLen         = fileBuffer.length;\r
+                Ch.CompressType          = EFI_STANDARD_COMPRESSION; \r
+                \r
+                //\r
+                //  Change header struct to byte buffer\r
+                //\r
+                byte [] headerBuffer = new byte[Ch.GetSize()];\r
+                Ch.StructToBuffer(headerBuffer);\r
+                \r
+                //\r
+                //  First add CompressHeader to Buffer, then add Compress data.\r
+                //\r
+                buffer.write (headerBuffer);\r
+                buffer.write(myCompress.outputBuffer);            \r
+                    \r
+                //\r
+                //  Buffer 4 Byte aligment \r
+                //\r
+                int size = Ch.GetSize() + myCompress.outputBuffer.length;\r
+                \r
+                while ((size & 0x03) != 0){\r
+                    size ++;\r
+                    buffer.writeByte(0);\r
+                }\r
+            }\r
+            catch (Exception e){\r
+                throw new BuildException("compress.toBuffer failed!\n");\r
+            }    \r
+        } else {\r
+            Section sect;\r
+            Iterator sectionIter = this.sectFileList.iterator();\r
+            while (sectionIter.hasNext()) {\r
+                sect = (Section)sectionIter.next(); \r
+                try {\r
+                    //\r
+                    //  The last section don't need 4 byte ffsAligment.\r
+                    //\r
+                    sect.toBuffer(buffer);\r
+                } catch (Exception e) {\r
+                    throw new BuildException (e.getMessage());\r
+                }\r
+            }\r
+        }\r
+    }\r
 }\r
index 7f04bf231b59f4845337c63563775c31e08b505a..ea9546487a54d0fa73338f26b82deba695ea2ec3 100644 (file)
@@ -13,15 +13,19 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.framework.tasks;\r
 \r
+import java.io.ByteArrayOutputStream;\r
 import java.io.DataInputStream;\r
 import java.io.DataOutputStream;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.List;\r
 \r
 import org.apache.tools.ant.BuildException;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
  Class Tool is to define an external tool to be used for genffsfile\r
@@ -33,7 +37,8 @@ public class Tool implements EfiDefine, Section {
     String outputPath;\r
     File outputFile ;\r
     List<Input>    inputFiles = new ArrayList<Input>();\r
-\r
+    List<Section>  gensectList = new ArrayList<Section>();\r
+    String inputArg = "-i ";\r
     /**\r
      Call extern tool\r
 \r
@@ -107,7 +112,41 @@ public class Tool implements EfiDefine, Section {
         Iterator inputIter = inputFiles.iterator();\r
         ToolArg toolArg;\r
         Input file = null;\r
+              \r
+        \r
+        //\r
+        //  Get each section which under the compress {};\r
+        //  And add it is contains to File;\r
+        //\r
+        Section sect;\r
+        try{\r
+            Iterator SectionIter = this.gensectList.iterator();\r
+            while (SectionIter.hasNext()){\r
+                sect = (Section)SectionIter.next();\r
+                //\r
+                // Parse <genSection> element\r
+                //\r
+                File outputFile = File.createTempFile("temp", "sec1",new File(outputPath));\r
+                FileOutputStream bo = new FileOutputStream(outputFile);\r
+                DataOutputStream Do = new DataOutputStream (bo);\r
+                //\r
+                //  Call each section class's toBuffer function.\r
+                //\r
+                try {\r
+                    sect.toBuffer(Do);\r
+                }\r
+                catch (BuildException e) {\r
+                    System.out.print(e.getMessage());\r
+                    throw new BuildException ("GenSection failed at Tool!");\r
+                }  \r
+                Do.close();\r
+                this.inputArg += outputFile.getPath() + " ";                        \r
+            }        \r
+        } catch (IOException e){\r
+            throw new BuildException ("Gensection failed at tool!");\r
+        }\r
 \r
+        \r
         ///\r
         /// argument of tools\r
         ///\r
@@ -120,21 +159,19 @@ public class Tool implements EfiDefine, Section {
         ///\r
         /// input files for tools\r
         ///\r
-        argument += " -i ";\r
         while (inputIter.hasNext()) {\r
             file = (Input)inputIter.next();\r
-            argument += file.toString(" ");\r
+            inputArg += file.toString(" ");\r
         }\r
-\r
         try {\r
-            outputFile = File.createTempFile("temp", ".crc", new File(outputPath));\r
-            argument   = argument + " -o " + outputFile.getPath();\r
-\r
+            outputFile = File.createTempFile("temp", null, new File(outputPath));\r
+            argument   = argument + inputArg + " -o " + outputFile.getPath();\r
+            EdkLog.log(EdkLog.EDK_INFO, argument);\r
             ///\r
             /// execute command line\r
             ///\r
-            Process crcProcess = Runtime.getRuntime().exec(command + " " + argument);\r
-            crcProcess.waitFor();\r
+            Process process = Runtime.getRuntime().exec(command + " " + argument);\r
+            process.waitFor();\r
         } catch (Exception e) {\r
             System.out.print (e.getMessage());\r
             throw new BuildException("Execution of externalTool task failed!\n");\r
@@ -194,6 +231,22 @@ public class Tool implements EfiDefine, Section {
     public void addInput(Input file) {\r
         inputFiles.add(file);\r
     }\r
+    \r
+//    /**\r
+//      addTool\r
+//      \r
+//      This function is to add instance of Tool to list.\r
+//      \r
+//      @param tool             instance of Tool.\r
+//    **/\r
+//    public void addTool(Tool tool){\r
+//        this.toolList.add(tool);\r
+//    }\r
+    \r
+    public void addGenSection(GenSectionTask genSect){\r
+        this.gensectList.add(genSect);\r
+    }\r
+    \r
 }\r
 \r
 \r
index a09871907356a3099e178eb8927eee7c8cc7e42f..3a67e6eb3467ae1ae13b6f017d0ffb212c4db27b 100644 (file)
@@ -238,7 +238,9 @@ public class FfsProcess {
     **/\r
     private void dealSections(int mode, Document doc, Element root, XmlCursor cursor, Vector<String> list) {\r
         String type = cursor.getAttributeText(new QName("EncapsulationType"));\r
-        if (type == null) {\r
+        String toolName = cursor.getAttributeText(new QName("ToolName"));\r
+        String sectType = cursor.getAttributeText(new QName("SectionType"));\r
+        if (type == null && sectType == null) {\r
             if (cursor.toFirstChild()) {\r
                 do {\r
                     if (cursor.getName().getLocalPart().equalsIgnoreCase("Section")) {\r
@@ -255,33 +257,69 @@ public class FfsProcess {
             return;\r
         }\r
         Element ele;\r
-        if (type.equalsIgnoreCase("COMPRESS")) {\r
+        Element toolEle = null;\r
+        if (type.equalsIgnoreCase("COMPRESS") && (toolName == null || toolName.equalsIgnoreCase(""))) {\r
             mode = MODE_COMPRESS;\r
             //\r
-            // <compress compressName = "dummy">\r
-            //\r
-            ele = doc.createElement("compress");\r
-            ele.setAttribute("compressName", "dummy");\r
+            // <gensection sectiontype="EFI_SECTION_COMPRESSION">   \r
+            // \r
+            ele = doc.createElement("gensection");\r
+            ele.setAttribute("sectionType", "EFI_SECTION_COMPRESSION");\r
+            \r
         } else {\r
             mode = MODE_GUID_DEFINED;\r
             //\r
+            // <gensection sectiontype="EFI_SECTION_GUID_DEFINED">\r
+            // \r
+            ele = doc.createElement("gensection");\r
+            if (type != null) {\r
+                ele.setAttribute("sectiontype", "EFI_SECTION_GUID_DEFINED");\r
+            } else {\r
+                ele.setAttribute("sectiontype", sectType);\r
+            }\r
+            //\r
             // <tool toolName="${OEMTOOLPATH}\toolname"\r
             // outputPath = "${DEST_DIR_OUTPUT}">\r
             //\r
-            ele = doc.createElement("tool");\r
-            ele.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "bin"\r
+            toolEle = doc.createElement("tool");\r
+            if (toolName == null || toolName.equalsIgnoreCase("")) {\r
+                toolEle.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "bin"\r
                                          + File.separatorChar + "GenCRC32Section");\r
-            ele.setAttribute("outputPath", "${DEST_DIR_OUTPUT}");\r
+            }else{\r
+                File toolExe = new File(toolName);\r
+                //\r
+                //  If <Tool> element exist, add sub element under <tool> . \r
+                // \r
+                if (toolExe.isAbsolute()) {\r
+                    toolEle.setAttribute("toolName", toolName);\r
+                } else {\r
+                    toolEle.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "bin"\r
+                                         + File.separatorChar + toolName);\r
+                }\r
+            }\r
+            \r
+            toolEle.setAttribute("outputPath", "${DEST_DIR_OUTPUT}");\r
+            ele.appendChild(toolEle);\r
         }\r
         if (cursor.toFirstChild()) {\r
             do {\r
                 if (cursor.getName().getLocalPart().equalsIgnoreCase("Section")) {\r
                     cursor.push();\r
-                    dealSection(mode, doc, ele, cursor, list);\r
+                    if (toolEle == null) {\r
+                        dealSection(mode, doc, ele, cursor, list);\r
+                    } else {\r
+                        dealSection(mode, doc, toolEle, cursor, list);\r
+                    }\r
+                    \r
                     cursor.pop();\r
                 } else if (cursor.getName().getLocalPart().equalsIgnoreCase("Sections")) {\r
                     cursor.push();\r
-                    dealSections(mode, doc, ele, cursor, list);\r
+                    if (toolEle == null) {\r
+                        dealSections(mode, doc, ele, cursor, list);\r
+                    } else {\r
+                        dealSections(mode, doc, toolEle, cursor, list);\r
+                    }\r
+                    \r
                     cursor.pop();\r
                 }\r
             } while (cursor.toNextSibling());\r