//\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
// 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
}\r
Do.close(); \r
\r
- \r
synchronized (semaphore) {\r
//\r
// Call compress\r
@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
@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
/// 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
}\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
\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
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
/// 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
//\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
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
@param sectionType section type\r
**/\r
public void setSectionType(String sectionType) {\r
- this.sectionType = " -s " + sectionType;\r
+ this.sectionType = sectionType;\r
}\r
\r
/**\r
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
**/\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
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
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
///\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
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
**/\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
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