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