X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkTasks%2Forg%2Ftianocore%2Fframework%2Ftasks%2FGenSectionTask.java;h=4cd7a96cdbd76fc71dd2e0ea72cf5e2dcebf8418;hp=1995d709dd351ca5a8646ed84a6ccc886effebda;hb=c493be6c9d2829c73e2e884846d098d955738f62;hpb=2da8968bb588b2bf72501a90597b8de464394024 diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java index 1995d709dd..4cd7a96cdb 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java @@ -16,34 +16,60 @@ 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; import org.apache.tools.ant.Task; -import org.apache.tools.ant.BuildException; 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, Section, FfsTypes { + // + // Tool name + // + private final static String toolName = "GenSection"; + // + // inputfile name + // + private FileArg inputFile = new FileArg(); + + // + // outputfile name + // + private FileArg outputFile = new FileArg(); + + // + // section type + // + private ToolArg sectionType = new ToolArg(); -public class GenSectionTask extends Task implements EfiDefine { - /// - /// inputfile name - /// - private String inputFile = ""; - /// - /// outputfile name - /// - private String outputFile = ""; - /// - /// section type - /// - private String sectionType = ""; - /// - /// version number - /// - private String versionNum = ""; - /// - /// interface string - /// - private String interfaceString = ""; + // + // version number + // + private ToolArg versionNum = new ToolArg(); + + // + // interface string + // + private ToolArg interfaceString = new ToolArg(); + + // + // Section file list + // + private List
sectFileList = new ArrayList
(); + + // + // flag indicated the element + // + private boolean haveTool = false; /** execute @@ -61,15 +87,14 @@ public class GenSectionTask extends Task implements EfiDefine { // String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); if (path == null) { - command = "gensection"; + command = toolName; } else { - command = path + "/" + "gensection"; + command = path + File.separator + toolName; } // // argument of tools // - String argument = inputFile + outputFile + sectionType + versionNum - + interfaceString; + String argument = "" + inputFile + outputFile + sectionType + versionNum + interfaceString; // // return value of gensection execution // @@ -86,22 +111,20 @@ public class GenSectionTask extends Task implements EfiDefine { runner.setAntRun(project); runner.setCommandline(cmdline.getCommandline()); - System.out.println(Commandline.toString(cmdline.getCommandline())); + + EdkLog.log(this, inputFile.toFileList() + versionNum.getValue() + + interfaceString.getValue() + " => " + outputFile.toFileList()); + EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline())); revl = runner.execute(); if (EFI_SUCCESS == revl) { - // - // command execution success - // - System.out.println("gensection successed!"); + EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!"); } else { // // command execution fail // - System.out.println("gensection failed. (error=" - + Integer.toHexString(revl) + ")"); - throw new BuildException("gensection failed. (error=" - + Integer.toHexString(revl) + ")"); + EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl)); + throw new BuildException(toolName + " failed!"); } } catch (Exception e) { throw new BuildException(e.getMessage()); @@ -116,7 +139,7 @@ public class GenSectionTask extends Task implements EfiDefine { @return name of input file **/ public String getInputFile() { - return this.inputFile; + return this.inputFile.getValue(); } /** @@ -127,7 +150,7 @@ public class GenSectionTask extends Task implements EfiDefine { @param inputFile name of input file **/ public void setInputFile(String inputFile) { - this.inputFile = " -i " + inputFile; + this.inputFile.setArg(" -i ", inputFile); } /** @@ -138,7 +161,7 @@ public class GenSectionTask extends Task implements EfiDefine { @return name of output file **/ public String getOutputFile() { - return this.outputFile; + return this.outputFile.getValue(); } /** @@ -148,7 +171,7 @@ public class GenSectionTask extends Task implements EfiDefine { @param outputFile name of output file **/ public void setOutputfile(String outputFile) { - this.outputFile = " -o " + outputFile; + this.outputFile.setArg(" -o ", outputFile); } /** @@ -159,7 +182,7 @@ public class GenSectionTask extends Task implements EfiDefine { @return sectoin type **/ public String getSectionType() { - return this.sectionType; + return this.sectionType.getValue(); } /** @@ -170,7 +193,7 @@ public class GenSectionTask extends Task implements EfiDefine { @param sectionType section type **/ public void setSectionType(String sectionType) { - this.sectionType = " -s " + sectionType; + this.sectionType.setArg(" -s ", sectionType); } /** @@ -180,7 +203,7 @@ public class GenSectionTask extends Task implements EfiDefine { @return version number **/ public String getVersionNum() { - return this.versionNum; + return this.versionNum.getValue(); } /** @@ -190,7 +213,7 @@ public class GenSectionTask extends Task implements EfiDefine { @param versionNum version number **/ public void setVersionNum(String versionNum) { - this.versionNum = " -v " + versionNum; + this.versionNum.setArg(" -v ", versionNum); } /** @@ -200,7 +223,7 @@ public class GenSectionTask extends Task implements EfiDefine { @return interface string **/ public String getInterfaceString() { - return this.interfaceString; + return this.interfaceString.getValue(); } /** @@ -210,6 +233,153 @@ public class GenSectionTask extends Task implements EfiDefine { @param interfaceString interface string **/ public void setInterfaceString(String interfaceString) { - this.interfaceString = " -a " + "\"" + interfaceString + "\""; + this.interfaceString.setArg(" -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); + this.haveTool = true; + } + + /** + 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.getValue().equalsIgnoreCase( + "EFI_SECTION_COMPRESSION") + && !this.haveTool) { + 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"); + } finally { + if (Do != null){ + Do.close(); + } + } + } + // + // Call compress + // + byte[] fileBuffer = bo.toByteArray(); + + synchronized (CompressSection.semaphore) { + 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()); + } + } + } } }