4 GenSectionTask is to call GenSection.exe to generate Section.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 package org
.tianocore
.framework
.tasks
;
19 import java
.io
.ByteArrayOutputStream
;
20 import java
.io
.DataOutputStream
;
22 import java
.util
.ArrayList
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
26 import org
.apache
.tools
.ant
.BuildException
;
27 import org
.apache
.tools
.ant
.Project
;
28 import org
.apache
.tools
.ant
.Task
;
29 import org
.apache
.tools
.ant
.taskdefs
.Execute
;
30 import org
.apache
.tools
.ant
.taskdefs
.LogStreamHandler
;
31 import org
.apache
.tools
.ant
.types
.Commandline
;
32 import org
.tianocore
.common
.logger
.EdkLog
;
34 public class GenSectionTask
extends Task
implements EfiDefine
, Section
, FfsTypes
{
38 private FileArg inputFile
= new FileArg();
42 private FileArg outputFile
= new FileArg();
46 private ToolArg sectionType
= new ToolArg();
50 private ToolArg versionNum
= new ToolArg();
54 private ToolArg interfaceString
= new ToolArg();
58 private List
<Section
> sectFileList
= new ArrayList
<Section
>();
63 GenSectionTaks execute is to assemble tool command line & execute tool
66 @throws BuildException
68 public void execute() throws BuildException
{
70 Project project
= this.getOwningTarget().getProject();
72 // absolute path of efi tools
74 String path
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
76 command
= "GenSection";
78 command
= path
+ "/" + "GenSection";
83 String argument
= "" + inputFile
+ outputFile
+ sectionType
+ versionNum
+ interfaceString
;
85 // return value of gensection execution
90 Commandline cmdline
= new Commandline();
91 cmdline
.setExecutable(command
);
92 cmdline
.createArgument().setLine(argument
);
94 LogStreamHandler streamHandler
= new LogStreamHandler(this,
95 Project
.MSG_INFO
, Project
.MSG_WARN
);
96 Execute runner
= new Execute(streamHandler
, null);
98 runner
.setAntRun(project
);
99 runner
.setCommandline(cmdline
.getCommandline());
101 EdkLog
.log(this, inputFile
.toFileList() + " => " + outputFile
.toFileList());
102 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, Commandline
.toString(cmdline
.getCommandline()));
104 revl
= runner
.execute();
105 if (EFI_SUCCESS
== revl
) {
106 EdkLog
.log(this, EdkLog
.EDK_VERBOSE
, "GenSection succeeded!");
109 // command execution fail
111 EdkLog
.log(this, EdkLog
.EDK_INFO
, "ERROR = " + Integer
.toHexString(revl
));
112 throw new BuildException("GenSection failed!");
114 } catch (Exception e
) {
115 throw new BuildException(e
.getMessage());
122 This function is to get class member "inputFile".
124 @return name of input file
126 public String
getInputFile() {
127 return this.inputFile
.getValue();
133 This function is to set class member "inputFile".
135 @param inputFile name of input file
137 public void setInputFile(String inputFile
) {
138 this.inputFile
.setArg(" -i ", inputFile
);
144 This function is to get class member "outputFile".
146 @return name of output file
148 public String
getOutputFile() {
149 return this.outputFile
.getValue();
155 This function is to set class member "outputFile".
156 @param outputFile name of output file
158 public void setOutputfile(String outputFile
) {
159 this.outputFile
.setArg(" -o ", outputFile
);
165 This function is to get class member "sectionType".
169 public String
getSectionType() {
170 return this.sectionType
.getValue();
176 This function is to set class member "sectionType".
178 @param sectionType section type
180 public void setSectionType(String sectionType
) {
181 this.sectionType
.setArg(" -s ", sectionType
);
187 This function is to get class member "versionNum".
188 @return version number
190 public String
getVersionNum() {
191 return this.versionNum
.getValue();
197 This function is to set class member "versionNum".
198 @param versionNum version number
200 public void setVersionNum(String versionNum
) {
201 this.versionNum
.setArg(" -v ", versionNum
);
207 This function is to get class member "interfaceString".
208 @return interface string
210 public String
getInterfaceString() {
211 return this.interfaceString
.getValue();
217 This funcion is to set class member "interfaceString".
218 @param interfaceString interface string
220 public void setInterfaceString(String interfaceString
) {
221 this.interfaceString
.setArg(" -a ", "\"" + interfaceString
+ "\"");
227 This function is to add sectFile to list.
229 @param sectFile instance of sectFile.
231 public void addSectFile(SectFile sectFile
){
232 this.sectFileList
.add(sectFile
);
238 This function is to set the class member "Tool";
242 public void addTool(Tool tool
) {
243 this.sectFileList
.add(tool
);
249 This function is to add GenSectin element to list
250 @param task Instance of genSection
252 public void addGenSection(GenSectionTask task
){
253 this.sectFileList
.add(task
);
256 public void toBuffer(DataOutputStream buffer
){
258 // Search SectionList find earch section and call it's
259 // ToBuffer function.
261 if (this.sectionType
.getValue().equalsIgnoreCase("EFI_SECTION_COMPRESSION")){
265 // Get section file in compress node.
268 ByteArrayOutputStream bo
= new ByteArrayOutputStream ();
269 DataOutputStream Do
= new DataOutputStream (bo
);
272 // Get each section which under the compress {};
273 // And add it is contains to File;
275 Iterator SectionIter
= this.sectFileList
.iterator();
276 while (SectionIter
.hasNext()){
277 sect
= (Section
)SectionIter
.next();
280 // Call each section class's toBuffer function.
285 catch (BuildException e
) {
286 System
.out
.print(e
.getMessage());
287 throw new BuildException ("Compress.toBuffer failed at section");
296 byte[] fileBuffer
= bo
.toByteArray();
298 synchronized (CompressSection
.semaphore
) {
299 Compress myCompress
= new Compress(fileBuffer
, fileBuffer
.length
);
302 // Add Compress header
304 CompressHeader Ch
= new CompressHeader();
305 Ch
.SectionHeader
.Size
[0] = (byte)((myCompress
.outputBuffer
.length
+
309 Ch
.SectionHeader
.Size
[1] = (byte)(((myCompress
.outputBuffer
.length
+
313 Ch
.SectionHeader
.Size
[2] = (byte)(((myCompress
.outputBuffer
.length
+
317 Ch
.SectionHeader
.type
= (byte) EFI_SECTION_COMPRESSION
;
320 // Note: The compressName was not efsfective now. Using the
321 // EFI_STANDARD_COMPRSSION for compressType .
322 // That is follow old Genffsfile tools. Some code will be added for
323 // the different compressName;
325 Ch
.UncompressLen
= fileBuffer
.length
;
326 Ch
.CompressType
= EFI_STANDARD_COMPRESSION
;
329 // Change header struct to byte buffer
331 byte [] headerBuffer
= new byte[Ch
.GetSize()];
332 Ch
.StructToBuffer(headerBuffer
);
335 // First add CompressHeader to Buffer, then add Compress data.
337 buffer
.write (headerBuffer
);
338 buffer
.write(myCompress
.outputBuffer
);
341 // Buffer 4 Byte aligment
343 int size
= Ch
.GetSize() + myCompress
.outputBuffer
.length
;
345 while ((size
& 0x03) != 0){
352 throw new BuildException("compress.toBuffer failed!\n");
356 Iterator sectionIter
= this.sectFileList
.iterator();
357 while (sectionIter
.hasNext()) {
358 sect
= (Section
)sectionIter
.next();
361 // The last section don't need 4 byte ffsAligment.
363 sect
.toBuffer(buffer
);
364 } catch (Exception e
) {
365 throw new BuildException (e
.getMessage());