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 String inputFile
= "";
42 private String inputFileName
= "";
46 private String outputFile
= "";
50 private String sectionType
= "";
54 private String versionNum
= "";
58 private String interfaceString
= "";
62 private List
<Section
> sectFileList
= new ArrayList
<Section
>();
67 GenSectionTaks execute is to assemble tool command line & execute tool
70 @throws BuildException
72 public void execute() throws BuildException
{
74 Project project
= this.getOwningTarget().getProject();
76 // absolute path of efi tools
78 String path
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
80 command
= "GenSection";
82 command
= path
+ "/" + "GenSection";
87 String argument
= inputFile
+ outputFile
+ " -s "+ sectionType
+ versionNum
90 // return value of gensection execution
95 Commandline cmdline
= new Commandline();
96 cmdline
.setExecutable(command
);
97 cmdline
.createArgument().setLine(argument
);
99 LogStreamHandler streamHandler
= new LogStreamHandler(this,
100 Project
.MSG_INFO
, Project
.MSG_WARN
);
101 Execute runner
= new Execute(streamHandler
, null);
103 runner
.setAntRun(project
);
104 runner
.setCommandline(cmdline
.getCommandline());
106 EdkLog
.log(this, EdkLog
.EDK_INFO
, inputFileName
);
107 EdkLog
.log(this, EdkLog
.EDK_DEBUG
, Commandline
.toString(cmdline
.getCommandline()));
108 revl
= runner
.execute();
109 if (EFI_SUCCESS
== revl
) {
110 log("GenSection succeeded!", Project
.MSG_VERBOSE
);
113 // command execution fail
115 log("ERROR = " + Integer
.toHexString(revl
));
116 throw new BuildException("GenSection failed!");
118 } catch (Exception e
) {
119 throw new BuildException(e
.getMessage());
126 This function is to get class member "inputFile".
128 @return name of input file
130 public String
getInputFile() {
131 return this.inputFile
;
137 This function is to set class member "inputFile".
139 @param inputFile name of input file
141 public void setInputFile(String inputFile
) {
142 this.inputFileName
= (new File(inputFile
)).getName();
143 this.inputFile
= " -i " + inputFile
;
149 This function is to get class member "outputFile".
151 @return name of output file
153 public String
getOutputFile() {
154 return this.outputFile
;
160 This function is to set class member "outputFile".
161 @param outputFile name of output file
163 public void setOutputfile(String outputFile
) {
164 this.outputFile
= " -o " + outputFile
;
170 This function is to get class member "sectionType".
174 public String
getSectionType() {
175 return this.sectionType
;
181 This function is to set class member "sectionType".
183 @param sectionType section type
185 public void setSectionType(String sectionType
) {
186 this.sectionType
= sectionType
;
192 This function is to get class member "versionNum".
193 @return version number
195 public String
getVersionNum() {
196 return this.versionNum
;
202 This function is to set class member "versionNum".
203 @param versionNum version number
205 public void setVersionNum(String versionNum
) {
206 this.versionNum
= " -v " + versionNum
;
212 This function is to get class member "interfaceString".
213 @return interface string
215 public String
getInterfaceString() {
216 return this.interfaceString
;
222 This funcion is to set class member "interfaceString".
223 @param interfaceString interface string
225 public void setInterfaceString(String interfaceString
) {
226 this.interfaceString
= " -a " + "\"" + interfaceString
+ "\"";
232 This function is to add sectFile to list.
234 @param sectFile instance of sectFile.
236 public void addSectFile(SectFile sectFile
){
237 this.sectFileList
.add(sectFile
);
243 This function is to set the class member "Tool";
247 public void addTool(Tool tool
) {
248 this.sectFileList
.add(tool
);
254 This function is to add GenSectin element to list
255 @param task Instance of genSection
257 public void addGenSection(GenSectionTask task
){
258 this.sectFileList
.add(task
);
261 public void toBuffer(DataOutputStream buffer
){
263 // Search SectionList find earch section and call it's
264 // ToBuffer function.
266 if (this.sectionType
.equalsIgnoreCase("EFI_SECTION_COMPRESSION")){
270 // Get section file in compress node.
273 ByteArrayOutputStream bo
= new ByteArrayOutputStream ();
274 DataOutputStream Do
= new DataOutputStream (bo
);
277 // Get each section which under the compress {};
278 // And add it is contains to File;
280 Iterator SectionIter
= this.sectFileList
.iterator();
281 while (SectionIter
.hasNext()){
282 sect
= (Section
)SectionIter
.next();
285 // Call each section class's toBuffer function.
290 catch (BuildException e
) {
291 System
.out
.print(e
.getMessage());
292 throw new BuildException ("Compress.toBuffer failed at section");
301 byte[] fileBuffer
= bo
.toByteArray();
302 Compress myCompress
= new Compress(fileBuffer
, fileBuffer
.length
);
305 // Add Compress header
307 CompressHeader Ch
= new CompressHeader();
308 Ch
.SectionHeader
.Size
[0] = (byte)((myCompress
.outputBuffer
.length
+
312 Ch
.SectionHeader
.Size
[1] = (byte)(((myCompress
.outputBuffer
.length
+
316 Ch
.SectionHeader
.Size
[2] = (byte)(((myCompress
.outputBuffer
.length
+
320 Ch
.SectionHeader
.type
= (byte) EFI_SECTION_COMPRESSION
;
323 // Note: The compressName was not efsfective now. Using the
324 // EFI_STANDARD_COMPRSSION for compressType .
325 // That is follow old Genffsfile tools. Some code will be added for
326 // the different compressName;
328 Ch
.UncompressLen
= fileBuffer
.length
;
329 Ch
.CompressType
= EFI_STANDARD_COMPRESSION
;
332 // Change header struct to byte buffer
334 byte [] headerBuffer
= new byte[Ch
.GetSize()];
335 Ch
.StructToBuffer(headerBuffer
);
338 // First add CompressHeader to Buffer, then add Compress data.
340 buffer
.write (headerBuffer
);
341 buffer
.write(myCompress
.outputBuffer
);
344 // Buffer 4 Byte aligment
346 int size
= Ch
.GetSize() + myCompress
.outputBuffer
.length
;
348 while ((size
& 0x03) != 0){
354 throw new BuildException("compress.toBuffer failed!\n");
358 Iterator sectionIter
= this.sectFileList
.iterator();
359 while (sectionIter
.hasNext()) {
360 sect
= (Section
)sectionIter
.next();
363 // The last section don't need 4 byte ffsAligment.
365 sect
.toBuffer(buffer
);
366 } catch (Exception e
) {
367 throw new BuildException (e
.getMessage());