Initial import.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
bbahnsen
2006-04-21 22:54:32 +00:00
commit 878ddf1fc3
2651 changed files with 624620 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project name="FrameworkTasks" default="all">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="workspace" value="${env.WORKSPACE}"/>
<property name="buildDir" value="build"/>
<property name="installLocation" value="${workspace}/Tools/Jars"/>
<target name="all" depends="install"/>
<target name="source">
<mkdir dir="${buildDir}"/>
<javac srcdir="." destdir="${buildDir}">
<classpath>
<fileset dir="${workspace}/Tools/Jars">
<include name="*.jar"/>
</fileset>
</classpath>
<compilerarg value="-Xlint"/>
</javac>
</target>
<target name="clean">
<delete dir="${buildDir}"/>
</target>
<target name="cleanall">
<delete dir="${buildDir}"/>
<if>
<available file="${installLocation}/frameworktasks.jar"/>
<then>
<echo message="You must manually remove the file: ${installLocation}/frameworktasks.jar"/>
<echo message="Java has already loaded the file, and cannot remove it within ANT!"/>
</then>
</if>
</target>
<target name="install" depends="source">
<copy file="frameworktasks.tasks" toDir="${buildDir}"/>
<jar destfile="${installLocation}/frameworktasks.jar"
basedir="${buildDir}"
includes="**"
/>
</target>
</project>

View File

@@ -0,0 +1,11 @@
fwimage=org.tianocore.framework.tasks.FwImageTask
setstamp=org.tianocore.framework.tasks.SetStampTask
gendepex=org.tianocore.framework.tasks.GenDepexTask
gensection=org.tianocore.framework.tasks.GenSectionTask
genffsfile=org.tianocore.framework.tasks.GenFfsFileTask
vfrcompile=org.tianocore.framework.tasks.VfrCompilerTask
strgather=org.tianocore.framework.tasks.StrGatherTask
genfvimage=org.tianocore.framework.tasks.GenFvImageTask
guidchk= org.tianocore.framework.tasks.GuidChkTask
gencrc32section=org.tianocore.framework.tasks.GenCRC32SectionTask
makedeps=org.tianocore.framework.tasks.MakeDeps

View File

@@ -0,0 +1,78 @@
/** @file
Compress class.
This class is to call CompressDll.dll to compress section.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
/**
This class is to call CompressDll.dll to compress section.
**/
public class Compress {
byte[] inputBuffer;
byte[] outputBuffer;
int size;
static {
String dllPath;
dllPath = GenFfsFileTask.path;
dllPath = dllPath +
File.separator +
"CompressDll.dll";
System.load(dllPath);
}
/**
CallCompress
This function is to call the compressDll.dll to compress the contents in
buffer.
@param inputBuffer The input buffer.
@param size The size of buffer in byte.
@param dllPath The compressDll.dll path.
@return The buffer contained the comrpessed input.
**/
public native byte[] CallCompress (byte[] inputBuffer, int size, String dllPath);
/**
Construct function
This function is to initialize the class member and call the compress
function.
@param inBuffer The input buffer.
@param size The size of buffer in byte.
**/
public Compress (byte[] inBuffer, int size){
this.inputBuffer = inBuffer;
this.size = size;
String path = GenFfsFileTask.path;
//
// Call Compress function.
//
this.outputBuffer = CallCompress (
this.inputBuffer,
this.size,
path
);
}
}

View File

@@ -0,0 +1,78 @@
/** @file
CompressHeader class.
This class is to generate the compressed section header.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import org.apache.tools.ant.BuildException;
/**
Internal class: This class is to generate the compressed section header.
**/
public class CompressHeader {
/**
CommonSectionHeader
This class define the compressed header structor.
**/
public class CommonSectionHeader {
byte[] Size = new byte[3];
byte type;
}
///
/// Section header.
///
public CommonSectionHeader SectionHeader = new CommonSectionHeader();
///
/// Length of uncompress section in byte.
///
public int UncompressLen;
///
/// Compress type.
///
public byte CompressType;
///
/// The size of compress header in byte.
///
public int GetSize (){
return 9;
}
///
/// Write class member to buffer.
///
public void StructToBuffer (byte[] Buffer){
if (Buffer.length != GetSize()) {
throw new BuildException ("CompressHeader Buffer size is not correct!");
}
for (int i = 0; i < 3; i++){
Buffer[i] = SectionHeader.Size[i];
}
Buffer[3] = SectionHeader.type;
Buffer[4] = (byte)(UncompressLen & 0xff);
Buffer[5] = (byte)((UncompressLen & 0xff00)>>8);
Buffer[6] = (byte)((UncompressLen & 0xff0000)>>16);
Buffer[7] = (byte)((UncompressLen & 0xff000000)>>24);
Buffer[8] = CompressType;
}
}

View File

@@ -0,0 +1,209 @@
/** @file
CompressSection class.
CompressSection indicate that all section which in it should be compressed.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.BuildException;
/**
CompressSection
CompressSection indicate that all section which in it should be compressed.
**/
public class CompressSection implements Section, FfsTypes{
//
// The attribute of compressName.
//
String compressName = "";
//
// The list contained the SectFile element.
//
List<Object> SectList = new ArrayList<Object>();
/**
toBuffer
This function is to collect all sectFile and compress it , then output
the result to buffer.
@param Buffer The point of output buffer
**/
public void toBuffer (DataOutputStream Buffer){
Section sect;
File compressOut;
//
// Get section file in compress node.
//
try{
compressOut = new File ("Compress.temp");
FileOutputStream fo = new FileOutputStream (compressOut.getName());
DataOutputStream Do = new DataOutputStream (fo);
//
// Get each section which under the compress {};
// And add it is contains to File;
//
Iterator SectionIter = SectList.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();
//
// Get contain to Buffer
//
FileInputStream fi = new FileInputStream (compressOut.getName());
DataInputStream di = new DataInputStream (fi);
byte[] fileBuffer = new byte[(int)compressOut.length()];
di.read(fileBuffer);
//
// Call compress
//
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 effective 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);
//
// 4 Byte aligment
//
int size = Ch.GetSize() + myCompress.outputBuffer.length;
while ((size & 0x03) != 0){
size ++;
Buffer.writeByte(0);
}
//
// Delete temp file
//
di.close();
compressOut.delete();
}
catch (Exception e){
throw new BuildException("compress.toBuffer failed!\n");
}
}
/**
getCompressName
This function is to get compressName.
@return The compressName.
**/
public String getCompressName() {
return compressName;
}
/**
setCompressName
This function is to set compressName.
@param compressName The string of compressName
**/
public void setCompressName(String compressName) {
this.compressName = compressName;
}
/**
addSectFile
This function is to add sectFile element to SectList.
@param sectFile SectFile element which succeed from section class.
**/
public void addSectFile (SectFile sectFile) {
SectList.add(sectFile);
}
/**
addTool
This function is to add tool element to SectList.
@param tool Tool element which succeed from section class.
**/
public void addTool (Tool tool) {
SectList.add(tool);
}
}

View File

@@ -0,0 +1,112 @@
/** @file
Database class.
Database represents an exceplicity name list of database file.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
Database
Database represents an exceplicity name list of database file.
**/
public class Database implements NestElement{
///
/// name of database file
///
private String name = "";
///
/// name of file including database files
///
private File file;
///
/// the database file name list
///
private List<String> nameList = new ArrayList<String>();
/**
getName
This function is to get class member "name".
@return class member "name".
**/
public String getName() {
return this.name;
}
/**
setName
This function is to set class member "name".
@param name : name of database file.
**/
public void setName(String name) {
this.name = " -db " + name;
}
/**
toString
This function is to call getName() function.
@return class member "name".
**/
public String toString() {
return getName();
}
/**
getFile
This function is to get file which include the database file list.
@return class member "file"
**/
public File getFile() {
return this.file;
}
/**
setFile
This function is to set class member "file".
@param file The file which include the database file list.
**/
public void setFile(File file) {
this.file = file;
}
public void setList(String fileNameList) {
if (fileNameList != null && fileNameList.length() > 0) {
StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);
while (tokens.hasMoreTokens()) {
String fileName = tokens.nextToken().trim();
if (fileName.length() > 0) {
this.nameList.add(fileName);
}
}
}
}
public List<String> getList() {
return nameList;
}
}

View File

@@ -0,0 +1,56 @@
/** @file
EfiDefine class.
EfiDefine class records the UEFI return status value.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
/**
EfiDefine class.
EfiDefine class records the UEFI return status value.
**/
public interface EfiDefine {
//
// EFI define Interface for define constant related to UEFI.
//
static final int EFI_SUCCESS = 0;
static final int EFI_LOAD_ERROR = 0x80000001;
static final int EFI_INVALID_PARAMETER = 0x80000002;
static final int EFI_UNSUPPORTED = 0x80000003;
static final int EFI_BAD_BUFFER_SIZE = 0x80000004;
static final int EFI_BUFFER_TOO_SMALL = 0x80000005;
static final int EFI_NOT_READY = 0x80000006;
static final int EFI_DEVICE_ERROR = 0x80000007;
static final int EFI_WRITE_PROTECTED = 0x80000008;
static final int EFI_OUT_OF_RESOURCES = 0x80000009;
static final int EFI_VOLUME_CORRUPTED = 0x8000000a;
static final int EFI_VOLUME_FULL = 0x8000000b;
static final int EFI_NO_MEDIA = 0x8000000c;
static final int EFI_MEDIA_CHANGED = 0x8000000d;
static final int EFI_NOT_FOUND = 0x8000000e;
static final int EFI_ACCESS_DENIED = 0x8000000f;
static final int EFI_NO_RESPONSE = 0x80000010;
static final int EFI_NO_MAPPING = 0x80000011;
static final int EFI_TIMEOUT = 0x80000012;
static final int EFI_NOT_STARTED = 0x80000013;
static final int EFI_ALREADY_STARTED = 0x80000014;
static final int EFI_ABORTED = 0x80000015;
static final int EFI_ICMP_ERROR = 0x80000016;
static final int EFI_TFTP_ERROR = 0x80000017;
static final int EFI_PROTOCOL_ERROR = 0x80000018;
static final int EFI_INCOMPATIBLE_VERSION = 0x80000019;
static final int EFI_SECURITY_VIOLATION = 0x80000020;
static final int EFI_CRC_ERROR = 0x80000021;
}

View File

@@ -0,0 +1,185 @@
/** @file
FfsHeader
FfsHeader class describe the struct of Ffs file header.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import org.apache.tools.ant.BuildException;
/**
FfsHeader
FfsHeader class describe the struct of Ffs file header.
**/
public class FfsHeader {
/**
FfsGuid
FfsGuid is interal class of FfsHeader, it describe the struct of Guid.
**/
public class FfsGuid {
int data1 = 0;
short data2 = 0;
short data3 = 0;
byte[] data4 = new byte[8];
byte[] dataBuffer = new byte[16];
/**
bufferToStruct
This function is to convert GUID to ffsGuid class member.
@param dataBuffer Buffer contained the GUID value in byte.
For example: if the input string as : "A6F691AC
31C8 4444 854C E2C1A6950F92"
Then Data1: AC91F6A6
Data2: C831
Data3: 4444
Data4: 4C85E2C1A6950F92
**/
public void bufferToStruct (byte[] dataBuffer){
if (dataBuffer.length != 16) {
throw new BuildException ("Buffer is not fitting GUID type!");
}
data1 = (int)(dataBuffer[3]& 0xff);
data1 = data1 << 8;
data1 = (int)data1 | (dataBuffer[2]& 0xff);
data1 = ((data1 << 8) & 0xffff00) | (dataBuffer[1]& 0xff);
data1 = ((data1 << 8) & 0xffffff00) | (dataBuffer[0]& 0xff);
data2 = (short) (dataBuffer[5] & 0xff);
data2 = (short)((data2 << 8) | (dataBuffer[4]& 0xff));
data3 = (short)(dataBuffer[7] & 0xff);
data3 = (short)((data3 << 8) | (dataBuffer[6] & 0xff));
for (int i = 0; i < 8; i++) {
data4[i] = dataBuffer[i+8];
}
}
/**
structToBuffer
This function is to store ffsHeader class member to buffer.
@return Byte buffer which contained the ffsHeader class member
**/
public byte[] structToBuffer (){
byte[] buffer = new byte [16];
buffer[3] = (byte)(data1 & 0x000000ff);
buffer[2] = (byte)((data1 & 0x0000ff00)>> 8);
buffer[1] = (byte)((data1 & 0x00ff0000)>> 16);
buffer[0] = (byte)((data1 & 0xff000000)>> 24);
buffer[5] = (byte)(data2 & 0x00ff);
buffer[4] = (byte)((data2 & 0xff00)>> 8);
buffer[7] = (byte)(data3 & 0x00ff);
buffer[6] = (byte)((data3 & 0xff00)>> 8);
for (int i = 8; i < 16; i++) {
buffer[i] = data4[i-8];
}
return buffer;
}
}
/**
integrityCheckSum
This class is used to record the struct of checksum.
**/
public class integrityCheckSum {
byte header;
byte file;
}
///
/// Guid
///
FfsGuid name = new FfsGuid();
///
/// CheckSum
///
integrityCheckSum integrityCheck = new integrityCheckSum();
///
/// File type
///
byte fileType;
///
/// Ffs attributes.
///
byte ffsAttributes;
///
/// Ffs file size
///
byte[] ffsFileSize = new byte[3];
///
/// Ffs state.
///
byte ffsState;
/**
structToBuffer
This function is to store FfsHeader class member to buffer.
@return Byte buffer which contained the FfsHeader class member.
**/
public byte[] structToBuffer () {
int i;
byte[] buffer1;
byte[] buffer = new byte[24];
buffer1 = name.structToBuffer();
for (i = 0; i < 16; i++) {
buffer[i] = buffer1[i];
}
buffer[16] = integrityCheck.header;
buffer[17] = integrityCheck.file;
buffer[18] = fileType;
buffer[19] = ffsAttributes;
for (i=20; i < 23; i++) {
buffer[i] = ffsFileSize[i-20];
}
buffer[23] = ffsState;
return buffer;
}
/**
getSize
This function is to get the size of FfsHeader in byte.
@return The size of FfsHeader.
**/
public int getSize(){
return 24;
}
}

View File

@@ -0,0 +1,115 @@
/** @file
FfsTypes class.
FfsType class record the costant value of Ffs File attribute, type, and
architecture.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
/**
FfsType
FfsType class record the costant value of Ffs File attribute, type, and
architecture.
**/
public interface FfsTypes {
//
// Ffs file attributes
//
static final int FFS_ATTRIB_TAIL_PRESENT = 0x01;
static final int FFS_ATTRIB_RECOVERY = 0x02;
static final int FFS_ATTRIB_HEADER_EXTENSION = 0x04;
static final int FFS_ATTRIB_DATA_ALIGNMENT = 0x38;
static final int FFS_ATTRIB_CHECKSUM = 0x40;
//
// Ffs states difinitions
//
static final int EFI_FILE_HEADER_CONSTRUCTION = 0x01;
static final int EFI_FILE_HEADER_VALID = 0x02;
static final int EFI_FILE_DATA_VALID = 0x04;
static final int EFI_FILE_MARKED_FOR_UPDATE = 0x08;
static final int EFI_FILE_DELETED = 0x10;
static final int EFI_FILE_HEADER_INVALID = 0x20;
//
// FFS_FIXED_CHECKSUM is the default checksum value used when the
// FFS_ATTRIB_CHECKSUM attribute bit is clear note this is NOT an
// architecturally defined value, but is in this file for implementation
// convenience
//
static final int FFS_FIXED_CHECKSUM = 0x5a;
//
// Architectural file types
//
static final int EFI_FV_FILETYPE_ALL = 0x00;
static final int EFI_FV_FILETYPE_RAW = 0x01;
static final int EFI_FV_FILETYPE_FREEFORM = 0x02;
static final int EFI_FV_FILETYPE_SECURITY_CORE = 0x03;
static final int EFI_FV_FILETYPE_PEI_CORE = 0x04;
static final int EFI_FV_FILETYPE_DXE_CORE = 0x05;
static final int EFI_FV_FILETYPE_PEIM = 0x06;
static final int EFI_FV_FILETYPE_DRIVER = 0x07;
static final int EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER = 0x08;
static final int EFI_FV_FILETYPE_APPLICATION = 0x09;
static final int EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE = 0x0B;
static final int EFI_FV_FILETYPE_FFS_PAD = 0xF0;
//
// Ffs file type
//
static final String EFI_FV_FFS_FILETYPE_STR = ".FFS";
static final String EFI_FV_DXE_FILETYPE_STR = ".DXE";
static final String EFI_FV_PEI_FILETYPE_STR = ".PEI";
static final String EFI_FV_APP_FILETYPE_STR = ".APP";
static final String EFI_FV_FVI_FILETYPE_STR = ".FVI";
static final String EFI_FV_SEC_FILETYPE_STR = ".SEC";
//
// Section Type copy from EfiImageFormat.h
//
static final int EFI_SECTION_COMPRESSION = 0x01;
static final int EFI_SECTION_GUID_DEFINED = 0x02;
//
// CompressionType values, we currently don't support
// "EFI_CUSTOMIZED_COMPRESSION".
//
static final int EFI_NOT_COMPRESSED = 0x00;
static final int EFI_STANDARD_COMPRESSION = 0x01;
static final int EFI_CUSTOMIZED_COMPRESSION = 0x02;
}

View File

@@ -0,0 +1,72 @@
/** @file
FileParser class.
FileParser class is to parse file which contains the list of file name and
add those files to list.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.*;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
/**
FileParser class.
FileParser class is to parse file which contains the list of file name and
add those files to list.
**/
public class FileParser {
/**
loadFile
This function is to add files to array from input file which contains the
files list.
@param project The current project.
@param list File array.
@param file File which contains the file list.
@param tag Target of architecture.
@throws BuildException
**/
public static synchronized void loadFile(Project project, List<Object> list, File file, String tag) throws BuildException{
FileReader fileReader;
BufferedReader in;
String str;
if (!file.exists()) {
throw new BuildException("The file" + file + "is not exist");
}
try {
fileReader = new FileReader(file);
in = new BufferedReader(fileReader);
while((str=in.readLine())!= null){
if (str.trim()==""){
continue;
}
str = project.replaceProperties(str);
if (str.trim().substring(0,2).equalsIgnoreCase(tag)) {
list.add(str.trim());
} else {
list.add(tag + " " + str.trim());
}
}
} catch (Exception e){
System.out.println(e.getMessage());
}
}
}

View File

@@ -0,0 +1,199 @@
/** @file
FwImageTask class.
FwImageTask is used to call FwImage.ext to generate the FwImage.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
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;
/**
FwImageTask class.
FwImageTask is used to call FwImage.ext to generate the FwImage.
**/
public class FwImageTask extends Task implements EfiDefine{
///
/// time&data
///
private String time = "";
///
/// input PE image
///
private String peImage = "";
///
/// output EFI image
///
private String outImage = "";
///
/// component type
///
private String componentType = "";
/**
* assemble tool command line & execute tool command line
*
* @throws BuildException
*/
/**
execute
FwimageTask execute function is to assemble tool command line & execute
tool command line
@throws BuidException
**/
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
//
// absolute path of efi tools
//
String path = project.getProperty("env.Framework_Tools_Path");
String command;
if (path == null) {
command = "fwimage";
} else {
command = path + "/" + "fwimage";
}
//
// argument of tools
//
String argument = time + componentType + peImage + outImage;
//
// return value of fwimage execution
//
int revl = -1;
try {
Commandline cmdline = new Commandline();
cmdline.setExecutable(command);
cmdline.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(cmdline.getCommandline());
System.out.println(Commandline.toString(cmdline.getCommandline()));
revl = runner.execute();
if (EFI_SUCCESS == revl) {
//
// command execution success
//
System.out.println("fwimage successed!");
} else {
//
// command execution fail
//
System.out.println("fwimage failed. (error="
+ Integer.toHexString(revl) + ")");
throw new BuildException("fwimage failed. (error="
+ Integer.toHexString(revl) + ")");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
setTime
This function is to set operation of class member "time".
@param time string of time
**/
public void setTime(String time) {
this.time = " -t " + time;
}
/**
getTime
This function is to get class member "time"
@return time string of time
**/
public String getTime() {
return this.time;
}
/**
getPeImage
This function is to get class member "peImage".
@return name of PE image
**/
public String getPeImage() {
return this.peImage;
}
/**
setPeImage
This function is to set class member "peImage"
@param peImage name of PE image
**/
public void setPeImage(String peImage) {
this.peImage = " " + peImage;
}
/**
getOutImage
This function is to get class member "outImage".
@return name of output EFI image
**/
public String getOutImage() {
return this.outImage;
}
/**
setOutImage
This function is to set class member "outImage".
@param outImage name of output EFI image
**/
public void setOutImage(String outImage) {
this.outImage = " " + outImage;
}
/**
getComponentType
This function is to get class member "componentType".
@return string of componentType
**/
public String getComponentType() {
return this.componentType;
}
/**
setComponentType
This function is to set class member "componentType".
@param componentType string of component type
**/
public void setComponentType(String componentType) {
this.componentType = " " + componentType;
}
}

View File

@@ -0,0 +1,183 @@
/** @file
GenCRC32SectionTask class.
GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.util.*;
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;
/**
GenCRC32SectionTask
GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section.
**/
public class GenCRC32SectionTask extends Task implements EfiDefine{
///
/// output file
///
private String outputFile;
///
/// inputFile list
///
private List<Object> inputFileList = new ArrayList<Object>();
///
/// Project
///
static private Project project;
/**
execute
GenCRC32SectionTask execute is to assemble tool command line & execute
tool command line
@throws BuildException
**/
public void execute() throws BuildException {
project = this.getOwningTarget().getProject();
///
/// absolute path of efi tools
///
String path = project.getProperty("env.Framework_Tools_Path");
String command;
if (path == null) {
command = "gencrc32section";
} else {
command = path + "/" + "gencrc32section" ;
}
//
// string line of input files
//
String inputFiles = list2Str(inputFileList, "");
//
// assemble argument
//
String argument = inputFiles + outputFile;
//
// return value of fwimage execution
//
int revl = -1;
try {
Commandline cmdline = new Commandline();
cmdline.setExecutable(command);
cmdline.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(cmdline.getCommandline());
System.out.println(Commandline.toString(cmdline.getCommandline()));
revl = runner.execute();
if (EFI_SUCCESS == revl){
//
// command execution success
//
System.out.println("gencrc32section succeeded!");
}
else
{
//
// command execution fail
//
System.out.println("gencrc32section failed. (error=" +
Integer.toHexString(revl) +
")"
);
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
addInputFile
This function is to add a inputFile element into list
@param inputFile : inputFile element
**/
public void addInputfile(InputFile inputFile) {
inputFileList.add(inputFile);
}
/**
get class member "outputFile"
* @return name of output file
*/
public String getOutputFile() {
return this.outputFile;
}
/**
* set class member "outputFile"
* @param outputFile : outputFile parameter
*/
public void setOutputFile(String outputFile) {
this.outputFile = " -o " + outputFile;
};
/**
* transfer List to String
* @param list : nested element list
* @param tag : interval tag of parameter
* @return string line of parameters
*/
private String list2Str(List list, String tag) {
/*
* string line for return
*/
String paraStr = " -i";
/*
* nested element in list
*/
NestElement element;
/*
* iterator of nested element list
*/
Iterator elementIter = list.iterator();
/*
* string parameter list
*/
List<Object> strList = new ArrayList<Object>();
while (elementIter.hasNext()) {
element = (NestElement) elementIter.next();
if (null != element.getFile()) {
FileParser.loadFile(project, strList, element.getFile(), tag);
} else {
paraStr = paraStr + element.getName();
}
}
/*
* iterator of string parameter list
*/
Iterator strIter = strList.iterator();
while (strIter.hasNext()) {
paraStr = paraStr + " " + strIter.next();
}
return paraStr;
}
}

View File

@@ -0,0 +1,166 @@
/** @file
GenDepexTask class.
GenDepexTask is to call GenDepex.exe to generate depex section.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
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;
/**
GenDepexTask
GenDepexTask is to call GenDepex.exe to generate depex section.
**/
public class GenDepexTask extends Task implements EfiDefine {
///
/// output binary dependency files name
///
private String outputFile = "";
///
/// input pre-processed dependency text files name
///
private String inputFile = "";
///
/// padding integer value
///
private String padding = "";
/**
execute
GenDepexTask execute is to assemble tool command line & execute tool
command line.
*/
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
//
// absolute path of edk tools
//
String path = project.getProperty("env.Framework_Tools_Path");
String command;
if (path == null) {
command = "gendepex";
} else {
command = path + "/" + "gendepex";
}
//
// argument of GenDepex tool
//
String argument = inputFile + outputFile + padding;
//
// reture value of GenDepex execution
//
int returnVal = -1;
try {
Commandline commandLine = new Commandline();
commandLine.setExecutable(command);
commandLine.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(commandLine.getCommandline());
System.out.println(Commandline.toString(commandLine
.getCommandline()));
returnVal = runner.execute();
if (EFI_SUCCESS == returnVal) {
//
// command execution success
//
System.out.println("GenDepex execute successed!");
} else {
//
// command execution fail
//
System.out.println("GenDepex failed. (error="
+ Integer.toHexString(returnVal) + ")");
throw new BuildException("GenDepex failed. (error="
+ Integer.toHexString(returnVal) + ")");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
setOutputFile
This function is to set class member "outputFile"
@param outputFileName name of output file
**/
public void setOutputFile(String outputFileName) {
this.outputFile = " -O " + outputFileName;
}
/**
getOutputFile
This function is to get class member "outputFile".
@return name of ouput file
**/
public String getOutputFile() {
return this.outputFile;
}
/**
setInputFile
This function is to set class member "inputFile".
@param inputFileName name of inputFile
**/
public void setInputFile(String inputFileName) {
this.inputFile = " -I " + inputFileName;
}
/**
getInputFile
This function is to get class member "inputFile"
@return name of input file
**/
public String getInputFile() {
return this.inputFile;
}
/**
setPadding
This function is to set class member "padding"
@param paddingNum padding value
**/
public void setPadding(String paddingNum) {
this.padding = " -P " + paddingNum;
}
/**
getPadding
This function is to get class member "padding"
@return value of padding
**/
public String getPadding() {
return this.padding;
}
}

View File

@@ -0,0 +1,878 @@
/** @file
GenFfsFileTask class.
GenFfsFileTaks is to generate ffs file.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
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;
/**
GenFfsFileTask
GenFfsFileTaks is to generate ffs file.
**/
public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
/**
* GenFfsFile Task Class
* class member
* -baseName : module baseName
* -ffsFileGuid : module Guid.
* -ffsFileType : Ffs file type.
* -ffsAttributeRecovery : The file is required for recovery.
* -ffsAligment : The file data alignment (0 if none required). See FFS
* specification for supported alignments (0-7 are only possible
* values). *
* -ffsAttributeCheckSum : The file data is checksummed. If this is FALSE a
* value of 0x5A will be inserted in the file
* checksum field of the file header. *
* -sectFileDir : specifies the full path to the component build directory.
* Required.
* -ffsAttrib : Data recorde attribute added result.
* -sectionList : List recorded all section elemet in task.
*/
///
/// module baseName
///
String baseName = "";
///
/// module Guid
///
String ffsFileGuid = "";
///
/// Ffs file type
///
String ffsFileType = "";
///
/// ffsAttribHeaderExtension value is used to set the corresponding bit in
/// the output FFS file header
///
boolean ffsAttribHeaderExtension = false;
///
/// ffsAttribTailPresent value is used to set the corresponding bit in the
/// output FFS file header
///
boolean ffsAttribTailPresent = false;
///
/// ffsAttribRecovery value is used to set the corresponding bit in the
/// output FFS file header
///
boolean ffsAttribRecovery = false;
///
/// ffsAligenment value is used to set the corresponding bit in the output
/// FFS file header.The specified FFS alignment must be a value between 0
/// and 7 inclusive
///
int ffsAlignment = 0;
///
/// ffsAttribChecksum value is used to set the corresponding bit in the
/// output FFS file header
///
boolean FfsAttribChecksum = false;
///
/// Attribute is used to record the sum of all bit in the output FFS file.
///
byte attributes = 0;
///
/// The output directory of ffs file.
///
String outputDir = "";
///
/// List of section.
///
List<Object> sectionList = new ArrayList<Object>();
///
/// The path of Framewor_Tools_Paht.
///
static String path = "";
/**
execute
GenFfsFileTask execute is to generate ffs file according to input section
dscriptive information.
*/
public void execute() throws BuildException {
Section sect;
int fileSize;
int fileDataSize;
File ffsFile;
FfsHeader ffsHeader = new FfsHeader();
String ffsSuffix = "";
String outputPath = "";
//
// Get Fraemwork_Tools_Path
//
Project pj = this.getOwningTarget().getProject();
path = pj.getProperty("env.Framework_Tools_Path");
//
// Check does the BaseName, Guid, FileType set value.
//
if (this.baseName.equals("")) {
throw new BuildException ("Must set BaseName!\n");
}
if (this.ffsFileGuid.equals("")) {
throw new BuildException ("Must set ffsFileGuid!\n");
}
if (this.ffsFileType.equals("")) {
throw new BuildException ("Must set ffsFileType!\n");
}
//
// Create ffs file. File name = FfsFileGuid + BaseName + ffsSuffix.
// If outputDir's value was set, file will output to the outputDir.
//
ffsSuffix = TypeToSuffix (this.ffsFileType);
if (!this.outputDir.equals("")) {
String temp;
outputPath = this.outputDir;
temp = outputPath.replace('\\', File.separatorChar);
outputPath = temp.replace('/', File.separatorChar);
if (outputPath.charAt(outputPath.length()-1) != File.separatorChar) {
outputPath = outputPath + File.separator;
}
}
ffsFile = new File (outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix);
System.out.print("General Ffs file: file name is:\n");
System.out.print(outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix);
System.out.print("\n");
//
// Create file output stream -- dataBuffer.
//
try {
FileOutputStream dataFs = new FileOutputStream (ffsFile.getAbsolutePath());
DataOutputStream dataBuffer = new DataOutputStream (dataFs);
//
// Search SectionList find earch section and call it's
// ToBuffer function.
//
Iterator sectionIter = this.sectionList.iterator();
while (sectionIter.hasNext()) {
sect = (Section)sectionIter.next();
try {
//
// The last section don't need 4 byte ffsAligment.
//
sect.toBuffer((DataOutputStream)dataBuffer);
} catch (Exception e) {
throw new BuildException (e.getMessage());
}
}
dataBuffer.close();
} catch (Exception e) {
throw new BuildException (e.getMessage());
}
//
// Creat Ffs file header
//
try {
//
// create input stream to read file data
//
byte[] fileBuffer = new byte[(int)ffsFile.length()];
FileInputStream fi = new FileInputStream (ffsFile.getAbsolutePath());
DataInputStream di = new DataInputStream (fi);
di.read(fileBuffer);
di.close();
//
// Add GUID to header struct
//
if (this.ffsFileGuid != null) {
stringToGuid (this.ffsFileGuid, ffsHeader.name);
}
ffsHeader.ffsAttributes = this.attributes;
if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) {
throw new BuildException ("FFS_FILE_TYPE unknow!\n");
}
//
// Adjust file size. The function is used to tripe the last
// section padding of 4 binary boundary.
//
//
if (ffsHeader.fileType != EFI_FV_FILETYPE_RAW) {
fileDataSize = adjustFileSize (fileBuffer);
} else {
fileDataSize = fileBuffer.length;
}
//
// 1. add header size to file size
//
fileSize = fileDataSize + ffsHeader.getSize();
if ((ffsHeader.ffsAttributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
if (ffsHeader.fileType == EFI_FV_FILETYPE_FFS_PAD) {
throw new BuildException (
"FFS_ATTRIB_TAIL_PRESENT=TRUE is " +
"invalid for PAD files"
);
}
if (fileSize == ffsHeader.getSize()) {
throw new BuildException (
"FFS_ATTRIB_TAIL_PRESENT=TRUE is " +
"invalid for 0-length files"
);
}
fileSize = fileSize + 2;
}
//
// 2. set file size to header struct
//
ffsHeader.ffsFileSize[0] = (byte)(fileSize & 0x00FF);
ffsHeader.ffsFileSize[1] = (byte)((fileSize & 0x00FF00)>>8);
ffsHeader.ffsFileSize[2] = (byte)(((int)fileSize & 0xFF0000)>>16);
//
// Fill in checksums and state, these must be zero for checksumming
//
ffsHeader.integrityCheck.header = calculateChecksum8 (
ffsHeader.structToBuffer(),
ffsHeader.getSize()
);
if ((this.attributes & FFS_ATTRIB_CHECKSUM) != 0) {
if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
ffsHeader.integrityCheck.file = calculateChecksum8 (
fileBuffer,
fileDataSize
);
} else {
ffsHeader.integrityCheck.file = calculateChecksum8 (
fileBuffer,
fileDataSize
);
}
} else {
ffsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;
}
//
// Set the state now. Spec says the checksum assumes the state is 0.
//
ffsHeader.ffsState = EFI_FILE_HEADER_CONSTRUCTION |
EFI_FILE_HEADER_VALID |
EFI_FILE_DATA_VALID;
//
// create output stream to first write header data in file, then write sect data in file.
//
FileOutputStream headerFfs = new FileOutputStream (ffsFile.getAbsolutePath());
DataOutputStream ffsBuffer = new DataOutputStream (headerFfs);
//
// Add header struct and file data to FFS file
//
ffsBuffer.write(ffsHeader.structToBuffer());
for (int i = 0; i< fileDataSize; i++) {
ffsBuffer.write(fileBuffer[i]);
}
//
// If there is a tail, then set it
//
if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
short tailValue ;
byte [] tailByte = new byte[2];
//
// reverse tailvalue , integritycheck.file as hight byte, and
// integritycheck.header as low byte.
//
tailValue = (short)(ffsHeader.integrityCheck.header & 0xff);
tailValue = (short)((tailValue) | ((ffsHeader.integrityCheck.file << 8) & 0xff00));
tailValue = (short)~tailValue;
//
// Change short to byte[2]
//
tailByte[0] = (byte)(tailValue & 0xff);
tailByte[1] = (byte)((tailValue & 0xff00)>>8);
ffsBuffer.write(tailByte[0]);
ffsBuffer.write(tailByte[1]);
}
//
// close output stream. Note if don't close output stream
// the buffer can't be rewritten to file.
//
ffsBuffer.close();
System.out.print ("Successful create ffs file!\n");
} catch (Exception e) {
throw new BuildException (e.getMessage());
}
}
/**
addCompress
This function is to add compress section to section list.
@param compress Section of compress
**/
public void addCompress(CompressSection compress) {
this.sectionList.add(compress);
}
/**
addTool
This function is to add tool section to section list.
@param tool Section of tool
**/
public void addTool(Tool tool) {
this.sectionList.add(tool);
}
/**
addSectionFile
This function is to add sectFile section to section list.
@param sectFile Section of sectFile.
**/
public void addSectFile (SectFile sectFile) {
this.sectionList.add(sectFile);
}
/**
getBaseName
This function is to get basename
@return String of base name
**/
public String getBaseName() {
return this.baseName;
}
/**
setBaseName
This function is to set base name.
@param baseName
**/
public void setBaseName(String baseName) {
this.baseName = baseName.trim();
}
/**
getFfsAligment
This function is to get the ffsAligment
@return The value of ffsAligment.
**/
public int getFfsAligment() {
return this.ffsAlignment;
}
/**
setFfsAligment
This function is to set ffsAligment
@param ffsAligment The value of ffsAligment.
**/
public void setFfsAligment(int ffsAligment) {
this.ffsAlignment = ffsAligment;
if (this.ffsAlignment > 7) {
throw new BuildException ("FFS_ALIGMENT Scope is 0-7");
} else {
attributes |= (((byte)this.ffsAlignment) << 3);
}
}
/**
getFfsAttribCheckSum
This function is to get ffsAttribCheckSum
@return Value of ffsAttribChecksum
**/
public boolean getFfsAttribChecksum() {
return this.FfsAttribChecksum;
}
/**
setFfsAttribChecksum
This function is to set ffsAttribChecksum
@param ffsAttributeCheckSum Value of ffsAttribCheckSum
**/
public void setFfsAttribChecksum(boolean ffsAttributeCheckSum) {
this.FfsAttribChecksum = ffsAttributeCheckSum;
if (ffsAttributeCheckSum) {
attributes |= FFS_ATTRIB_CHECKSUM;
}
}
/**
getFfsAttribRecovery
This function is to get ffsAttribRecovery
@return Value of ffsAttribRecovery
**/
public boolean getFfsAttribRecovery() {
return this.ffsAttribRecovery;
}
/**
setRecovery
This function is to set ffsAttributeRecovery
@param ffsAttributeRecovery Value of ffsAttributeRecovery
**/
public void setRecovery(boolean ffsAttributeRecovery) {
this.ffsAttribRecovery = ffsAttributeRecovery;
if (ffsAttributeRecovery) {
attributes |= FFS_ATTRIB_RECOVERY;
}
}
/**
getFileGuid
This function is to get fileGuid
@return Guid
**/
public String getFileGuid() {
return this.ffsFileGuid;
}
/**
setFileGuid
This function is to set fileGuid
@param ffsFileGuid String of GUID
**/
public void setFileGuid(String ffsFileGuid) {
this.ffsFileGuid = ffsFileGuid.trim();
}
/**
getFfsFileType
This function is to get ffsFileType.
@return value of ffsFileType
**/
public String getFfsFileType() {
return this.ffsFileType;
}
/**
setFfsFileType
This function is to set ffsFileType.
@param ffsFileType
**/
public void setFfsFileType(String ffsFileType) {
this.ffsFileType = ffsFileType.trim();
}
/**
ffsAttribHeaderExtension
This function is to get ffsAttribHeaderExtension
@return Value of ffsAttribHeaderExtension
**/
public boolean isFfsAttribHeaderExtension() {
return this.ffsAttribHeaderExtension;
}
/**
setHeaderExension
This function is to set headerExtension
@param headerExtension Value of headerExension
**/
public void setHeaderExtension(boolean headerExtension) {
this.ffsAttribHeaderExtension = headerExtension;
if (headerExtension) {
attributes |= FFS_ATTRIB_HEADER_EXTENSION;
}
}
/**
isFfsAttribTailPresent
This function is to get ffsAttribTailPresent value.
@return Value of ffsAttribTailPresent.
**/
public boolean isFfsAttribTailPresent() {
return this.ffsAttribTailPresent;
}
/**
setFfsAttribTailPresent
This function is to set ffsAttribTailPresent.
@param tailPresent Value of ffsAttribTailPresent.
**/
public void setFfsAttribTailPresent(boolean tailPresent) {
this.ffsAttribTailPresent = tailPresent;
if (tailPresent) {
attributes |= FFS_ATTRIB_TAIL_PRESENT;
}
}
/**
stringToGuid
This function is to convert string to GUID.
* @param GuidStr String of GUID.
* @param Guid GUID form.
*/
private void stringToGuid (String GuidStr, FfsHeader.FfsGuid Guid){
int i = 0;
int j = 0;
int k = 0;
char [] charArry;
String [] SplitStr;
byte[] buffer = new byte[16];
if (GuidStr.length()!=36) {
throw new BuildException ("Guid length is not correct!");
}
SplitStr = GuidStr.split("-");
if (SplitStr.length != 5) {
throw new BuildException ("Guid type is not correct!");
}
for (i= 0; i < SplitStr.length; i++) {
String str = SplitStr[i];
charArry = str.toCharArray();
for (j =0; j < (str.toCharArray().length)/2; j++) {
buffer[k] = hexCharToByte (charArry[j*2]);
buffer[k] = (byte)( buffer[k]& 0x0f);
buffer[k] = (byte)((buffer[k]<< 4));
buffer[k] = (byte)( buffer[k]& 0xf0);
buffer[k] = (byte)( buffer[k]|hexCharToByte(charArry[j*2+1]));
k++;
}
}
Guid.bufferToStruct(buffer);
}
/**
typeToSuffix
This function is to get suffix of ffs file according to ffsFileType.
@param ffsFileType ffsFileType
@return The suffix of ffs file
**/
private String TypeToSuffix (String ffsFileType){
if (ffsFileType.equals("EFI_FV_FILETYPE_ALL")) {
return "";
}
if (ffsFileType.equals("EFI_FV_FILETYPE_RAW")) {
return EFI_FV_FFS_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {
return EFI_FV_FFS_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {
return EFI_FV_SEC_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_PEI_CORE")) {
return EFI_FV_PEI_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_DXE_CORE")) {
return EFI_FV_DXE_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_PEIM")) {
return EFI_FV_PEI_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_DRIVER")) {
return EFI_FV_DXE_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER")) {
return EFI_FV_PEI_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_APPLICATION")) {
return EFI_FV_APP_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE")) {
return EFI_FV_FVI_FILETYPE_STR;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_FFS_PAD")) {
return EFI_FV_FFS_FILETYPE_STR;
}
return "";
}
/**
stringToType
This function is to get ffsFileType integer value according to ffsFileType.
@param ffsFileType String value of ffsFileType
@return Integer value of ffsFileType.
**/
private byte stringToType (String ffsFileType){
if (ffsFileType.equals("EFI_FV_FILETYPE_ALL")) {
return(byte)EFI_FV_FILETYPE_ALL;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_RAW")) {
return(byte)EFI_FV_FILETYPE_RAW;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {
return(byte)EFI_FV_FILETYPE_SECURITY_CORE;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {
return(byte)EFI_FV_FILETYPE_SECURITY_CORE;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_PEI_CORE")) {
return(byte) EFI_FV_FILETYPE_PEI_CORE;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_DXE_CORE")) {
return(byte)EFI_FV_FILETYPE_DXE_CORE;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_PEIM")) {
return(byte)EFI_FV_FILETYPE_PEIM;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_DRIVER")) {
return(byte) EFI_FV_FILETYPE_DRIVER;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER")) {
return(byte)EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_APPLICATION")) {
return(byte)EFI_FV_FILETYPE_APPLICATION;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE")) {
return(byte)EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE;
}
if (ffsFileType.equals("EFI_FV_FILETYPE_FFS_PAD")) {
return(byte) EFI_FV_FILETYPE_FFS_PAD;
}
return -1;
}
/**
calculateCheckSum8
This function is to calculate the value needed for a valid UINT8 checksum
@param buffer Byte buffer containing byte data of component.
@param size Size of the buffer.
@return The 8 bit checksum value needed.
**/
private byte calculateChecksum8 (byte[] buffer, int size){
return(byte) (0x100 - calculateSum8 (buffer, size));
}
/**
calculateSum8
This function is to calculate the UINT8 sum for the requested region.
@param buffer Byte buffer containing byte data of component
@param size Size of the buffer.
@return The 8 bit checksum value needed.
**/
private short calculateSum8 (byte[] buffer, int size){
int Index;
byte Sum;
Sum = 0;
//
// Perform the word sum for buffer
//
for (Index = 0; Index < size; Index++) {
Sum = (byte) (Sum + buffer[Index]);
}
return(byte) Sum;
}
/**
hexCharToByte
This function is to convert hex character to byte
@param hexChar hex character
@return Byte which corresponding to the character.
**/
private byte hexCharToByte (char hexChar){
switch (hexChar) {
case '0':
return(byte)0x00;
case '1':
return(byte)0x01;
case '2':
return(byte)0x02;
case '3':
return(byte)0x03;
case '4':
return(byte)0x04;
case '5':
return(byte)0x05;
case '6':
return(byte)0x06;
case '7':
return(byte)0x07;
case '8':
return(byte)0x08;
case '9':
return(byte)0x09;
case 'a':
case 'A':
return(byte)0x0a;
case 'b':
case 'B':
return(byte)0x0b;
case 'c':
case 'C':
return(byte)0x0c;
case 'd':
case 'D':
return(byte)0x0d;
case 'e':
case 'E':
return(byte)0x0e;
case 'f':
case 'F':
return(byte)0x0f;
default:
return(byte)0xff;
}
}
/**
adjustFileSize
This function is used to adjusts file size to insure sectioned file is exactly the right length such
that it ends on exactly the last byte of the last section. ProcessScript()
may have padded beyond the end of the last section out to a 4 byte boundary.
This padding is stripped.
@param buffer Byte buffer contains a section stream
@return Corrected size of file.
**/
private int adjustFileSize (byte[] buffer){
int orignalLen = buffer.length;
int adjustLen = 0;
int sectionPoint = 0;
int nextSectionPoint = 0;
int sectionLen = 0;
int totalLen = 0;
int firstSectionHeader = 0;
firstSectionHeader = buffer[0]& 0xff;
firstSectionHeader = ((buffer[1]&0xff)<<8) | firstSectionHeader;
firstSectionHeader = ((buffer[2]&0xff)<<16)| firstSectionHeader;
while (sectionPoint < buffer.length) {
sectionLen = buffer[0 + sectionPoint]& 0xff;
sectionLen = ((buffer[1 + sectionPoint]&0xff)<<8)| sectionLen;
sectionLen = ((buffer[2 + sectionPoint]&0xff)<<16)| sectionLen;
totalLen = totalLen + sectionLen;
if (totalLen == orignalLen) {
return totalLen;
}
sectionPoint = sectionPoint + sectionLen;
adjustLen = sectionPoint;
nextSectionPoint = (sectionPoint + 0x03) & (~0x03);
totalLen = totalLen + nextSectionPoint - sectionLen;
sectionPoint = nextSectionPoint;
}
return adjustLen;
}
/**
getOutputDir
This function is to get output directory.
@return Path of output directory.
**/
public String getOutputDir() {
return outputDir;
}
/**
setOutputDir
This function is to set output directory.
@param outputDir The output direcotry.
**/
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
}

View File

@@ -0,0 +1,154 @@
/** @file
GenFvImageTask class.
GenFvImageTask is to call GenFvImage.exe to generate FvImage.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
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;
/**
GenFvImageTask
GenFvImageTask is to call GenFvImage.exe to generate the FvImage.
**/
public class GenFvImageTask extends Task implements EfiDefine{
///
/// The name of input inf file
///
private String infFile="";
///
/// The target architecture.
///
private String arch="";
/**
execute
GenFvImageTask execute is to assemble tool command line & execute tool
command line.
**/
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
String path = project.getProperty("env.Framework_Tools_Path");
String command = "";
if (path == null){
path = "";
}else {
path = path + File.separatorChar;
}
if (arch.equalsIgnoreCase("")){
command = path + "GenFvImage";
}
if (arch.equalsIgnoreCase("ia32")){
command = path + "GenFvImage_IA32";
}
if (arch.equalsIgnoreCase("x64")){
command = path + "GenFvImage_X64";
}
if (arch.equalsIgnoreCase("ipf")){
command = path + "GenFvImage_IPF";
}
String argument = infFile;
try {
Commandline commandLine = new Commandline();
commandLine.setExecutable(command);
commandLine.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO,
Project.MSG_WARN);
//
// create a execute object and set it's commandline
//
Execute runner = new Execute(streamHandler,null);
runner.setAntRun(project);
runner.setCommandline(commandLine.getCommandline());
System.out.println(Commandline.toString(commandLine.getCommandline()));
int revl = -1;
//
// user execute class call external programs - GenFvImage
//
revl = runner.execute();
//
// execute command line success!
//
if (EFI_SUCCESS == revl){
System.out.println("GenFvImage succeeded!");
} else {
//
// execute command line failed!
//
throw new BuildException("GenFvImage failed !(error =" +
Integer.toHexString(revl) + ")");
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
/**
getInfFile
This function is to get class member of infFile
@return String name of infFile
**/
public String getInfFile() {
return infFile;
}
/**
setInfFile
This function is to set class member of infFile.
@param infFile name of infFile
**/
public void setInfFile(String infFile) {
this.infFile = "-I " + infFile;
}
/**
getArch
This function is to get class member of arch.
@return The target architecture.
**/
public String getArch() {
return arch;
}
/**
setArch
This function is to set class member of arch.
@param arch The target architecture.
**/
public void setArch(String arch) {
this.arch = arch;
}
}

View File

@@ -0,0 +1,215 @@
/** @file
GenSectionTask class.
GenSectionTask is to call GenSection.exe to generate Section.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
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;
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 = "";
/**
execute
GenSectionTaks execute is to assemble tool command line & execute tool
command line.
@throws BuildException
**/
public void execute() throws BuildException {
String command;
Project project = this.getOwningTarget().getProject();
//
// absolute path of efi tools
//
String path = project.getProperty("env.Framework_Tools_Path");
if (path == null) {
command = "gensection";
} else {
command = path + "/" + "gensection";
}
//
// argument of tools
//
String argument = inputFile + outputFile + sectionType + versionNum
+ interfaceString;
//
// return value of gensection execution
//
int revl = -1;
try {
Commandline cmdline = new Commandline();
cmdline.setExecutable(command);
cmdline.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(cmdline.getCommandline());
System.out.println(Commandline.toString(cmdline.getCommandline()));
revl = runner.execute();
if (EFI_SUCCESS == revl) {
//
// command execution success
//
System.out.println("gensection successed!");
} else {
//
// command execution fail
//
System.out.println("gensection failed. (error="
+ Integer.toHexString(revl) + ")");
throw new BuildException("gensection failed. (error="
+ Integer.toHexString(revl) + ")");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
getInputFile
This function is to get class member "inputFile".
@return name of input file
**/
public String getInputFile() {
return this.inputFile;
}
/**
setInputFile
This function is to set class member "inputFile".
@param inputFile name of input file
**/
public void setInputFile(String inputFile) {
this.inputFile = " -i " + inputFile;
}
/**
getOutputFile
This function is to get class member "outputFile".
@return name of output file
**/
public String getOutputFile() {
return this.outputFile;
}
/**
setOutputfile
This function is to set class member "outputFile".
@param outputFile name of output file
**/
public void setOutputfile(String outputFile) {
this.outputFile = " -o " + outputFile;
}
/**
getSectionType
This function is to get class member "sectionType".
@return sectoin type
**/
public String getSectionType() {
return this.sectionType;
}
/**
setSectionType
This function is to set class member "sectionType".
@param sectionType section type
**/
public void setSectionType(String sectionType) {
this.sectionType = " -s " + sectionType;
}
/**
getVersionNum
This function is to get class member "versionNum".
@return version number
**/
public String getVersionNum() {
return this.versionNum;
}
/**
setVersionNume
This function is to set class member "versionNum".
@param versionNum version number
**/
public void setVersionNum(String versionNum) {
this.versionNum = " -v " + versionNum;
}
/**
getInterfaceString
This function is to get class member "interfaceString".
@return interface string
**/
public String getInterfaceString() {
return this.interfaceString;
}
/**
setInterfaceString
This funcion is to set class member "interfaceString".
@param interfaceString interface string
**/
public void setInterfaceString(String interfaceString) {
this.interfaceString = " -a " + "\"" + interfaceString + "\"";
}
}

View File

@@ -0,0 +1,367 @@
/** @file
GuidChkTask class.
GuidChkTask is to call GuidChk.exe to generate Section.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
/**
GuidChkTask
GuidChkTask is to call GuidChk.exe to generate Section.
**/
public class GuidChkTask extends Task implements EfiDefine{
/**
* GuidChk task class
* class member
* -exDir : directory name of exclusion searching
* -exFile : file name of exclusion searching
* -exExt : extension name of exclusion searching
* -exSubDir: extesnion name of sub dir which excluded searching
* -outFile : out put file wrote internal GUID+basename list
* -chkGui : check for duplicate guids
* -chkSign : check for duplicate signatures
* -printGuiDef : if set will print guid+defined symbol name
* -printAllGuid: if set will print all GUIDS found
* -outPut : redirection file name
* -fos : out put redirect to this file
*
*/
///
/// Directory name of exclusion searching
///
private String exDir = "";
///
/// File name of exclusion searching.
///
private String exFile = "";
///
/// Extension name of exclusion searching.
///
private String exExt = "";
///
/// Extesnion name of sub dir which excluded searching.
///
private String exSubDir = "";
///
/// Out put file wrote internal GUID+basename list
///
private String outFile = "";
///
/// Check for duplicate guids.
///
private String chkGui = "";
///
/// Check for duplicate signatures
///
private String chkSign = "";
///
/// If set will print guid+defined symbol name
///
private String printGuiDef = "";
///
/// If set will print all GUIDS found
///
private String printAllGuid = "";
///
/// redirection file name.
///
private String outPut = "";
///
/// out put redirect to this file.
///
protected PrintWriter fos = null;
//
// overload class execute method
//
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
String path = project.getProperty("env.Framework_Tools_Path");
String command;
if (path == null) {
command = "GuidChk";
} else {
command = path + File.separatorChar + "GuidChk";
}
String argument = exDir +
exFile +
exExt +
exSubDir +
outFile +
chkGui +
chkSign +
printGuiDef +
printAllGuid;
try {
System.out.println(command + " " + argument);
//
// execute command line
//
Process proc = Runtime.getRuntime().exec(command + "" + argument);
//
// if set output, redirect out put to output file, else print output to screen
//
if ( !this.outPut.equals("")) {
fos = new PrintWriter(this.outPut);
BufferedReader bin = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = bin.readLine();
while (line != null ){
fos.println(line);
line = bin.readLine();
}
fos.close();
}
else {
BufferedReader bin = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = bin.readLine();
System.out.println(line);
while (line != null ){
System.out.print(line);
line = bin.readLine();
}
}
System.out.println("GuidChkTask Success!");
} catch (Exception e) {
System.out.println("GuidChkTask failed!");
System.out.println(e.getMessage());
}
}
/**
getChkGui
This function is to get the string of flag of ChkGui
@return string of flag of ChkGui
**/
public String getChkGui() {
return chkGui;
}
/**
setChkGui
This function is to set chkGui
@param chkGui set class member of chkGui
**/
public void setChkGui(String chkGui) {
if (chkGui.equals("on")||(chkGui.equals("ON"))){
this.chkGui = " -g ";
}
}
/**
getChkSign
This function is to get chkSign
@return chkSign
**/
public String getChkSign() {
return chkSign;
}
/**
setChkSign
This function is to set class member of chkSign
* @param chkSign
*/
public void setChkSign(String chkSign) {
if (chkSign.equals("on")|| chkSign.equals("ON")){
this.chkSign = " -s ";
}
}
/**
getExDir
This function is to get class member of exDir
@return exDir
**/
public String getExDir() {
return exDir;
}
/**
setExDir
This function is to set class member of exDir
@param exDir
**/
public void setExDir(String exDir) {
this.exDir = " -d " + exDir;
}
/**
getExExt
This function is to get class member of exExt
@return exExt
**/
public String getExExt() {
return exExt;
}
/**
setExExt
This function is to set class member of exExt
@param exExt
**/
public void setExExt(String exExt) {
this.exExt = " -e " + exExt;
}
/**
getExFile
This function is to get class member of exFile
@return exFile
**/
public String getExFile() {
return exFile;
}
/**
setExFile
This function is to set class member of exFile.
@param exFile
**/
public void setExFile(String exFile) {
this.exFile = " -f " + exFile;
}
/**
getExSubDir
This function is to get class member of exSubDir
@return exSubDir
**/
public String getExSubDir() {
return exSubDir;
}
/**
setExSubDir
This function is to set class member of exSubDir.
@param exSubDir
**/
public void setExSubDir(String exSubDir) {
this.exSubDir = " -u " + exSubDir;
}
/**
getOutFile
This function is to get outFile
@return outFile
**/
public String getOutFile() {
return outFile;
}
/**
* set class member of outFile
* @param outFile
*/
public void setOutFile(String outFile) {
this.outFile = " -b " + outFile;
}
/**
getPrintGuidDef
This function is to get printGuidDef
@return flage of printing (guid+defined symbol name)
**/
public String getPrintGuiDef() {
return printGuiDef;
}
/**
setPrintGuidDef
This function is to set class member of printGuiDef.
@param printGuiDef
**/
public void setPrintGuiDef(String printGuiDef) {
if (printGuiDef.equals("on")|| printGuiDef.equals("ON")){
this.printGuiDef = " -x ";
}
}
/**
getOutput
This function is to get output
@return name of outPut file
**/
public String getOutPut() {
return outPut;
}
/**
setOutPut
This function is to set class member of outPut.
@param outPut
**/
public void setOutPut(String outPut) {
this.outPut = outPut;
}
/**
getPrintAllGuid
This function is to get printAllGuid
@return printAllGuid
**/
public String getPrintAllGuid() {
return printAllGuid;
}
/**
setPrintAllGuid
This function is to set class member of printAllGuid.
@param printAllGuid
**/
public void setPrintAllGuid(String printAllGuid) {
if (printAllGuid.equals("on")||printAllGuid.equals("ON")) {
this.printAllGuid = " -p ";
}
}
}

View File

@@ -0,0 +1,123 @@
/** @file
This file is used to nest elements which is meant for include path name
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class IncludePath implements NestElement {
/**
IncludePath nested element Class
class member
-name : name of include path
-file : name of file including include path
**/
private String path = "";
private File file;
private List<String> nameList = new ArrayList<String>();
/**
get class member "file"
@returns The File object
**/
public File getFile() {
return this.file;
}
/**
set class member "file"
@param file The name of include path
**/
public void setFile(File file) {
this.file = file;
}
/**
get class member "file"
@returns The name of include path
**/
public String getPath() {
return this.path;
}
/**
get class member "name"
@returns The name of include path
**/
public String getName() {
return this.path;
}
/**
set class member "name"
@param name The name of include path
**/
public void setName(String name){
this.path = "-I " + name;
}
/**
set class member "path"
@param name name of file including include paths
**/
public void setPath(String name) {
this.path = " -I " + name;
}
/**
override Object.toString()
@returns name of file including include paths
**/
public String toString() {
return getPath();
}
/**
set class member "list"
@param fileNameList name list of include paths, sperated by space, tab,
comma or semi-comma
**/
public void setList(String fileNameList) {
if (fileNameList != null && fileNameList.length() > 0) {
StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);
while (tokens.hasMoreTokens()) {
String fileName = tokens.nextToken().trim();
if (fileName.length() > 0) {
this.nameList.add(fileName);
}
}
}
}
/**
get class member "list"
@returns The include paths list.
**/
public List<String> getList() {
return nameList;
}
}

View File

@@ -0,0 +1,44 @@
/** @file
This file is used to nest elements which is meant for file path
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
/**
Input class is defined to be as nested elements of other elements, to specify
the path of file(s)
**/
public class Input {
private String filePath;
public Input() {
}
/**
Standard set method of ANT task, for "file" attribute
@param path The path of a file
**/
public void setFile(String path) {
filePath = path;
}
/**
Standard get method of ANT task, for "file" attribute
@returns The path of current specified file.
**/
public String getFile() {
return filePath;
}
}

View File

@@ -0,0 +1,95 @@
/** @file
This file is used to nest elements which is meant for specifying files
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class InputFile implements NestElement {
/**
InputFile nested element Class
class member
-name : name of input file
-file : name of file including input files
**/
private String name = "";
private File file;
private List<String> nameList = new ArrayList<String>();
/**
get class member "name"
@returns name parameter
**/
public String getName() {
return this.name;
}
/**
set class member "name"
@param name name of input file
**/
public void setName(String name) {
this.name = " " + name;
}
public String toString() {
return getName();
}
/**
get class member "file"
@returns file parameter
**/
public File getFile() {
return this.file;
}
/**
set class member "file"
@param ext name of file including input files
**/
public void setFile(File file) {
this.file = file;
}
/**
set class member "list"
@param fileNameList name list of include paths, sperated by space, tab,
comma or semi-comma
**/
public void setList(String fileNameList) {
if (fileNameList != null && fileNameList.length() > 0) {
StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);
while (tokens.hasMoreTokens()) {
String fileName = tokens.nextToken().trim();
if (fileName.length() > 0) {
this.nameList.add(fileName);
}
}
}
}
/**
get class member "list"
@returns The include paths list.
**/
public List<String> getList() {
return nameList;
}
}

View File

@@ -0,0 +1,443 @@
/** @file
This file is to wrap MakeDeps.exe tool as ANT task, which is used to generate
dependency files for source code.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
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.apache.tools.ant.types.Path;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
Class MakeDeps is used to wrap MakeDeps.exe as an ANT task.
**/
public class MakeDeps extends Task {
//
// private members, use set/get to access them
//
private static final String cmdName = "MakeDeps";
private static final String target = "dummy";
private String includePath = null;
private String depsFile = null;
private String subDir = null;
private boolean quietMode = true;
private boolean ignoreError = true;
private String extraDeps = "";
private List<IncludePath> includePathList = new ArrayList<IncludePath>();
private List<Input> inputFileList = new ArrayList<Input>();
public MakeDeps() {
}
/**
The Standard execute method for ANT task. It will check if it's necessary
to generate the dependency list file. If no file is found or the dependency
is changed, it will compose the command line and call MakeDeps.exe to
generate the dependency list file.
@throws BuildException
**/
public void execute() throws BuildException {
///
/// check if the dependency list file is uptodate or not
///
if (isUptodate()) {
return;
}
Project prj = this.getOwningTarget().getProject();
String toolPath = prj.getProperty("env.Framework_Tools_Path");
///
/// compose full tool path
///
if (toolPath == null || toolPath.length() == 0) {
toolPath = "./" + cmdName;
} else {
if (toolPath.endsWith("/") || toolPath.endsWith("\\")) {
toolPath = toolPath + cmdName;
} else {
toolPath = toolPath + "/" + cmdName;
}
}
///
/// compose tool arguments
///
StringBuffer args = new StringBuffer(4096);
if (ignoreError) {
args.append(" -ignorenotfound");
}
if (quietMode) {
args.append(" -q");
}
if (subDir != null && subDir.length() > 0) {
args.append(" -s ");
args.append(subDir);
}
///
/// if there's no source files, we can do nothing about dependency
///
if (inputFileList.size() == 0) {
throw new BuildException("No source files specified to scan");
}
///
/// compose source file arguments
///
Iterator iterator = inputFileList.iterator();
while (iterator.hasNext()) {
Input inputFile = (Input)iterator.next();
args.append(" -f ");
args.append(cleanupPathName(inputFile.getFile()));
}
///
/// compose search pathes argument
///
StringBuffer includePathArg = new StringBuffer(4096);
if (includePath != null && includePath.length() > 0) {
StringTokenizer pathTokens = new StringTokenizer(includePath, ";");
while (pathTokens.hasMoreTokens()) {
String tmpPath = pathTokens.nextToken().trim();
if (tmpPath.length() == 0) {
continue;
}
includePathArg.append(" -i ");
includePathArg.append(cleanupPathName(tmpPath));
}
}
iterator = includePathList.iterator();
while (iterator.hasNext()) {
IncludePath path = (IncludePath)iterator.next();
includePathArg.append(cleanupPathName(path.getPath()));
}
args.append(includePathArg);
///
/// We don't need a real target. So just a "dummy" is given
///
args.append(" -target dummy");
args.append(" -o ");
args.append(cleanupPathName(depsFile));
///
/// prepare to execute the tool
///
Commandline cmd = new Commandline();
cmd.setExecutable(toolPath);
cmd.createArgument().setLine(args.toString());
LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(prj);
runner.setCommandline(cmd.getCommandline());
int result = 0;
try {
result = runner.execute();
} catch (IOException e) {
throw new BuildException(e.getMessage());
}
if (result != 0) {
log ("MakeDeps failed");
return;
}
// change the old DEP file format (makefile compatible) to just file list
if (!cleanup()) {
throw new BuildException(depsFile + " was not generated");
}
}
///
/// Remove any duplicated path separator or inconsistent path separator
///
private String cleanupPathName(String path) {
String separator = "\\" + File.separator;
String duplicateSeparator = separator + "{2}";
path = Path.translateFile(path);
path = path.replaceAll(duplicateSeparator, separator);
return path;
}
/**
Set method for "DepsFile" attribute
@param name The name of dependency list file
**/
public void setDepsFile(String name) {
depsFile = cleanupPathName(name);
}
/**
Get method for "DepsFile" attribute
@returns The name of dependency list file
**/
public String getDepsFile() {
return depsFile;
}
/**
Set method for "IgnoreError" attribute
@param ignore flag to control error handling (true/false)
**/
public void setIgnoreError(boolean ignore) {
ignoreError = ignore;
}
/**
Get method for "IgnoreError" attribute
@returns The value of current IgnoreError flag
**/
public boolean getIgnoreError() {
return ignoreError;
}
/**
Set method for "QuietMode" attribute
@param quiet flag to control the output information (true/false)
**/
public void setQuietMode(boolean quiet) {
quietMode = quiet;
}
/**
Get method for "QuietMode" attribute
@returns value of current QuietMode flag
**/
public boolean getQuietMode() {
return quietMode;
}
/**
Set method for "SubDir" attribute
@param dir The name of sub-directory in which source files will be scanned
**/
public void setSubDir(String dir) {
subDir = dir;
}
/**
Get method for "SubDir" attribute
@returns The name of sub-directory
**/
public String getSubDir() {
return subDir;
}
/**
Set method for "IncludePath" attribute
@param path The name of include path
**/
public void setIncludePath(String path) {
includePath = cleanupPathName(path);
}
/**
Get method for "IncludePath" attribute
@returns The name of include path
**/
public String getIncludePath() {
return includePath;
}
/**
Set method for "ExtraDeps" attribute
@param deps The name of dependency file specified separately
**/
public void setExtraDeps(String deps) {
extraDeps = deps;
}
/**
Get method for "ExtraDeps" attribute
@returns The name of dependency file specified separately
**/
public String getExtraDeps () {
return extraDeps;
}
/**
Add method for "IncludePath" nested element
@param path The IncludePath object from nested IncludePath type of element
**/
public void addIncludepath(IncludePath path) {
includePathList.add(path);
}
/**
Add method for "Input" nested element
@param input The Input object from nested Input type of element
**/
public void addInput(Input inputFile) {
inputFileList.add(inputFile);
}
/**
The original file generated by MakeDeps.exe is for makefile uses. The target
part (before :) is not useful for ANT. This method will do the removal.
@returns true if cleaned files is saved successfully
@returns false if error occurs in file I/O system
**/
private boolean cleanup() {
File df = new File(depsFile);
if (!df.exists()) {
return false;
}
LineNumberReader lineReader = null;
FileReader fileReader = null;
try {
fileReader = new FileReader(df);
lineReader = new LineNumberReader(fileReader);
///
/// clean-up each line in deps file
//
String line = null;
StringBuffer cleanedLines = new StringBuffer(4096);
while ((line = lineReader.readLine()) != null) {
Pattern pattern = Pattern.compile(target + "[ ]*:[ ]*(.+)");
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
///
/// keep the file name after ":"
///
String filePath = line.substring(matcher.start(1), matcher.end(1));
filePath = cleanupPathName(filePath);
cleanedLines.append(filePath);
cleanedLines.append("\n");
}
}
lineReader.close();
fileReader.close();
///
/// we may have explicitly specified dependency files
///
StringTokenizer fileTokens = new StringTokenizer(extraDeps, ";");
while (fileTokens.hasMoreTokens()) {
cleanedLines.append(cleanupPathName(fileTokens.nextToken()));
cleanedLines.append("\n");
}
///
/// overwrite old dep file with new content
///
FileWriter fileWriter = null;
fileWriter = new FileWriter(df);
fileWriter.write(cleanedLines.toString());
fileWriter.close();
} catch (IOException e) {
log (e.getMessage());
}
return true;
}
/**
Check if the dependency list file should be (re-)generated or not.
@returns true The dependency list file is uptodate. No re-generation is needed.
@returns false The dependency list file is outofdate. Re-generation is needed.
**/
private boolean isUptodate() {
File df = new File(depsFile);
if (!df.exists()) {
return false;
}
///
/// If the source file(s) is newer than dependency list file, we need to
/// re-generate the dependency list file
///
long depsFileTimeStamp = df.lastModified();
Iterator iterator = inputFileList.iterator();
while (iterator.hasNext()) {
Input inputFile = (Input)iterator.next();
File sf = new File(inputFile.getFile());
if (sf.lastModified() > depsFileTimeStamp) {
return false;
}
}
///
/// If the source files haven't been changed since last time the dependency
/// list file was generated, we need to check each file in the file list to
/// see if any of them is changed or not. If anyone of them is newer than
/// the dependency list file, MakeDeps.exe is needed to run again.
///
LineNumberReader lineReader = null;
FileReader fileReader = null;
boolean ret = true;
try {
fileReader = new FileReader(df);
lineReader = new LineNumberReader(fileReader);
String line = null;
while ((line = lineReader.readLine()) != null) {
File sourceFile = new File(line);
if (sourceFile.lastModified() > depsFileTimeStamp) {
ret = false;
break;
}
}
lineReader.close();
fileReader.close();
} catch (IOException e) {
log (e.getMessage());
}
return ret;
}
}

View File

@@ -0,0 +1,40 @@
/** @file
This file is to define common interfaces for nested element of frameworktasks
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
import java.util.List;
/**
Interface NestElement is just to define common interfaces for nested element
**/
public interface NestElement {
/**
nested element Interface for up-casting
**/
public String getName();
public void setName(String name);
public String toString();
public File getFile();
public void setFile(File file);
public void setList(String fileNameList);
public List<String> getList();
}

View File

@@ -0,0 +1,108 @@
/** @file
This file is to define nested element which is meant for specifying section file
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import org.apache.tools.ant.BuildException;
/**
Class SectFile is to define a class corresponding to ANT nested element. It's
used to specify section file(s) when used with GenFfsFile task
**/
public class SectFile implements Section {
private String fileName = ""; /// section file name
/**
Get method of ANT task/datatype for "FileName" attribute
@returns The name of section file
**/
public String getFileName() {
return fileName;
}
/**
Set method of ANT task/datatype for "FileName" attribute
@param fileName The name of section file
**/
public void setFileName(String fileName) {
this.fileName = fileName;
}
public SectFile (){
}
/**
Put the content of section file into specified buffer with extra bytes for
alignment requirement.
@param Buffer buffer to contain the section file content with alignment
**/
public void toBuffer (DataOutputStream Buffer){
File sectFile;
byte data;
long fileLen;
///
/// open file
///
sectFile = new File (this.fileName);
///
/// check if file exist.
///
if (! sectFile.exists()) {
throw new BuildException("The file " + this.fileName + " is not exist!\n");
}
///
/// Read section file and add it's contains to buffer.
///
try {
FileInputStream fs = new FileInputStream (sectFile.getAbsoluteFile());
DataInputStream In = new DataInputStream (fs);
fileLen = sectFile.length();
int i = 0;
while (i < fileLen) {
data = In.readByte();
Buffer.writeByte(data);
i++;
}
///
/// 4 byte alignment
///
while ((fileLen & 0x03)!= 0) {
fileLen ++;
Buffer.writeByte(0);
}
///
/// close inputStream
///
In.close();
} catch (Exception e) {
System.out.print(e.getMessage());
throw new BuildException("section file2Buffer failed!\n");
}
}
}

View File

@@ -0,0 +1,23 @@
/** @file
This file is to define interface for manipulating section file
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.DataOutputStream;
/**
Section interface is for geting the contain buffer form compress, tool, and sectFile
**/
public interface Section {
public void toBuffer (DataOutputStream Buffer);
}

View File

@@ -0,0 +1,136 @@
/** @file
This file is to define an ANT task to wrap setstamp.exe tool
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
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;
/**
Class SetStampTask is a wrap class for setstamp.exe.
**/
public class SetStampTask extends Task implements EfiDefine {
/**
SetStamp Task Class
class member
-peFile : file of PE
-timeFile: Txt file of time
**/
private String peFile = "";
private String timeFile = "";
/**
assemble tool command line & execute tool command line
@throws BuildException
**/
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
///
/// absolute path of edk tools
///
String path = project.getProperty("env.Framework_Tools_Path");
String command;
if (path == null) {
command = "setstamp";
} else {
command = path + "/" + "setstamp";
}
///
/// argument of SetStamp tool
///
String argument = peFile + timeFile;
///
/// reture value of SetStamp execution
///
int returnVal = -1;
try {
Commandline commandLine = new Commandline();
commandLine.setExecutable(command);
commandLine.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(commandLine.getCommandline());
System.out.println(Commandline.toString(commandLine
.getCommandline()));
returnVal = runner.execute();
if (EFI_SUCCESS == returnVal) {
///
/// command execution success
///
System.out.println("SetStamp execute successed!");
} else {
///
/// command execution fail
///
System.out.println("SetStamp failed. (error="
+ Integer.toHexString(returnVal) + ")");
throw new BuildException("SetStamp failed. (error="
+ Integer.toHexString(returnVal) + ")");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
set operation of class member "peFile"
@param peFile name of PE File
**/
public void setPeFile(String peFile) {
this.peFile = " " + peFile;
}
/**
get operation of class member "peFile"
@return peFile name of PE file
**/
public String getPeFile() {
return this.peFile;
}
/**
set operation of class member "timeFile"
@param timeFile name of time file
**/
public void setTimeFile(String timeFile) {
this.timeFile = " " + timeFile;
}
/**
get class member "timeFile"
@returns name of time file
**/
public String getTimeFile() {
return this.timeFile;
}
}

View File

@@ -0,0 +1,83 @@
/** @file
This file is to define nested element which is meant for specifying skipped file list
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
SkipExt nested element Class
class member
-name : extension name of skiped file
-file : name of file including ext
**/
public class SkipExt implements NestElement {
private String name = "";
private File file;
private List<String> nameList = new ArrayList<String>();
/**
get class member "name"
@returns name parameter
**/
public String getName() {
return this.name;
}
/**
set class member "name"
@param name extension name of skiped file
**/
public void setName(String name) {
this.name = " -skipext " + name;
}
public String toString() {
return getName();
}
/**
get class member "file"
@returns file parameter
**/
public File getFile() {
return this.file;
}
/**
set class member "file"
@param name of file including ext
**/
public void setFile(File file) {
this.file = file;
}
public void setList(String fileNameList) {
if (fileNameList != null && fileNameList.length() > 0) {
StringTokenizer tokens = new StringTokenizer(fileNameList, " \t,;", false);
while (tokens.hasMoreTokens()) {
String fileName = tokens.nextToken().trim();
if (fileName.length() > 0) {
this.nameList.add(fileName);
}
}
}
}
public List<String> getList() {
return nameList;
}
}

View File

@@ -0,0 +1,527 @@
/** @file
This file is to define an ANT task which wraps StrGather.exe tool.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.util.*;
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;
/**
StrGather Task Class
class memberg
-commandType : command type [parse/scan/dump]
-baseName : base name of component
-verbose : level of verbose [all/read/write]
-outputDatabase : file name of output database file
-databaseList : file name list of database files
-inputFileList : file name list of input files
-newDatabase : whether to need new database [ture/false]
-unquotedString : whether to unquoted strings are used [ture/false]
-includePathList: path list of include paths
-ignoreNotFound : whether to ignore a given STRING_TOKEN(STR) is not found in database [ture/false]
-skipExtList : skip scan of files with extension name
-outputString : write string data to filename
-outputDefines : write string defines to filename
-outputUnicode : dump database to unicode file filename
-lang : only dump for the language
-indirectionFile: specify an indirection file
-outputHpk : create an HII export pack of the strings
**/
public class StrGatherTask extends Task implements EfiDefine {
///
/// common options
///
private String commandType = "";
private String baseName = "";
///
/// "all/read/write"
///
private String verbose = "";
private String outputDatabase = "";
private List<Object> databaseList = new ArrayList<Object>();
private List<Object> inputFileList = new ArrayList<Object>();
///
/// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"
///
private String newDatabase = "";
private String unquotedString = "";
private List<Object> includePathList = new ArrayList<Object>();
///
/// scan options ignoreNotFound -- "ture/false"
///
private String ignoreNotFound = "";
private List<Object> skipExtList = new ArrayList<Object>();
///
/// dump options
///
private String outputString = "";
private String outputDefines = "";
private String outputUnicode = "";
private String lang = "";
private String indirectionFile = "";
private String outputHpk = "";
///
/// global variable
///
static private Project project;
/**
assemble tool command line & execute tool command line
@throws BuildException
**/
public void execute() throws BuildException {
project = this.getOwningTarget().getProject();
///
/// absolute path of efi tools
///
String path = project.getProperty("env.Framework_Tools_Path");
String command;
if (path == null) {
command = "strgather";
} else {
command = path + "/" + "strgather";
}
///
/// transfer nested elements into string
///
String databases = list2Str(databaseList, "-db");
String skipExts = list2Str(skipExtList, "-skipext");
String includePaths = list2Str(includePathList, "-I");
String inputFiles = list2Str(inputFileList, "");
///
/// assemble argument
///
String argument = commandType + verbose + databases + baseName
+ outputDatabase + includePaths + newDatabase + unquotedString
+ skipExts + ignoreNotFound + outputString + outputDefines
+ outputUnicode + lang + indirectionFile + outputHpk
+ inputFiles;
///
/// return value of fwimage execution
///
int revl = -1;
try {
Commandline cmdline = new Commandline();
cmdline.setExecutable(command);
cmdline.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(cmdline.getCommandline());
System.out.println(Commandline.toString(cmdline.getCommandline()));
revl = runner.execute();
if (EFI_SUCCESS == revl) {
///
/// command execution success
///
System.out.println("strgather succeeded!");
} else {
///
/// command execution fail
///
System.out.println("strgather failed. (error="
+ Integer.toHexString(revl) + ")");
throw new BuildException("strgather failed. (error="
+ Integer.toHexString(revl) + ")");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
get class member "commandType"
@returns commandType parameter
**/
public String getCommandType() {
return this.commandType;
}
/**
set class member ""
@param commandType type of strgather command [parse/scan/dump]
**/
public void setCommandType(String commandType) {
this.commandType = " -" + commandType;
}
/**
get class member "verbose"
@returns verbose parameter
**/
public String getVerbose() {
return this.verbose;
}
/**
set class member "verbose"
@param verbose verbose level [all/read/write]
**/
public void setVerbose(String verbose) {
if (verbose.equals("all")) {
///
/// for verbose output
///
this.verbose = " -v ";
} else if (verbose.equals("read")) {
///
/// for verbose output when reading database
///
this.verbose = " -vdbr ";
} else if (verbose.equals("write")) {
///
/// for verbose output when writing database
///
this.verbose = " -vdbw ";
}
}
/**
get class member baseName
@returns baseName parameter
**/
public String getBaseName() {
return this.baseName;
}
/**
set class member baseName
@param baseName name of the output files of .c and .h
**/
public void setBaseName(String baseName) {
this.baseName = " -bn " + baseName;
}
/**
get class member "outputDatabase"
@returns outputDatabase parameter
**/
public String getOutputDatabase() {
return this.outputDatabase;
}
/**
set class member "outputDatabase"
@param outputDatabase filename of output database file
**/
public void setOutputDatabase(String outputDatabase) {
this.outputDatabase = " -od " + outputDatabase;
}
/**
get class member "newDatabase"
@returns newDatabase parameter
**/
public String getNewDatabse() {
return this.newDatabase;
}
/**
set class member "newDatabase"
@param newDatabase whether to not read in existing database file
**/
public void setNewDatabase(String newDatabase) {
if (newDatabase.equals("true")) {
this.newDatabase = " -newdb ";
}
}
/**
get class member "unquotedString"
@returns unquotedString parameter
**/
public String getUnquotedString() {
return this.unquotedString;
}
/**
set class member "unquotedString"
@param unquotedString :
whether to indicate that unquoted strings are used
**/
public void setUnquotedString(String unquotedString) {
if (unquotedString.equals("true")) {
this.unquotedString = " -uqs ";
}
}
/**
get class member "ignoreNotFound"
@returns ignoreNotFound parameter
**/
public String getIgnoreNotFound() {
return this.ignoreNotFound;
}
/**
set class member "ignoreNotFound"
@param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR)
is not found in the database
**/
public void setIgnoreNotFound(String ignoreNotFound) {
if (ignoreNotFound.equals("true")) {
this.ignoreNotFound = " -ignorenotfound ";
}
}
/**
get class member "outputString"
@returns outputString parameter
**/
public String getOutputString() {
return this.outputString;
}
/**
set class member "outputString"
@param outputString filename of string data file
**/
public void setOutputString(String outputString) {
this.outputString = " -oc " + outputString;
}
/**
get class member "outputDefines"
@returns outputDefines parameter
**/
public String getOutputDefines() {
return this.outputDefines;
}
/**
set class member "outputDefines"
@param outputDefines filename of string defines file
**/
public void setOutputDefines(String outputDefines) {
this.outputDefines = " -oh " + outputDefines;
}
/**
get class member "outputUnicode"
@returns outputUnicode parameter
**/
public String getOutputUnicode() {
return this.outputUnicode;
}
/**
set class member "outputUnicode"
@param outputUnicode filename of unicode file to be dumped database
**/
public void setOutputUnicode(String outputUnicode) {
this.outputUnicode = " -ou " + outputUnicode;
}
/**
get class member "lang"
@returns lang parameter
**/
public String getLang() {
return this.lang;
}
/**
set class member "lang"
@param lang language of dump
**/
public void setLang(String lang) {
this.lang = " -lang " + lang;
}
/**
get class member "indirectionFile"
@returns indirectionFile parameter
**/
public String getIndirectionFile() {
return this.indirectionFile;
}
/**
set class member "indirectionFile"
@param indirectionFile filename of indirection file
**/
public void setIndirectionFile(String indirectionFile) {
this.indirectionFile = " -if " + indirectionFile;
}
/**
get class member "outputHpk"
@returns outputHpk parameter
**/
public String getOutputHpk() {
return this.outputHpk;
}
/**
set class member "outputHpk"
@param outputHpk filename of output HII export pack of the strings
**/
public void setOutputHpk(String outputHpk) {
this.outputHpk = " -hpk " + outputHpk;
}
/**
add a skipExt element into list
@param skipExt skipExt element
**/
public void addSkipext(SkipExt skipExt) {
skipExtList.add(skipExt);
};
/**
add a includePath element into list
@param includePath includePath element
**/
public void addIncludepath(IncludePath includePath) {
includePathList.add(includePath);
};
/**
add a inputFile element into list
@param inputFile inputFile element
**/
public void addInputfile(InputFile inputFile) {
inputFileList.add(inputFile);
};
/**
add a database element into list
@param database :
database element
**/
public void addDatabase(Database database) {
databaseList.add(database);
}
/**
transfer List to String
@param list nested element list
@param tag interval tag of parameter
@returns string line of parameters
**/
private String list2Str(List list, String tag) {
///
/// string line for return
///
String paraStr = "";
///
/// nested element in list
///
NestElement element;
///
/// iterator of nested element list
///
Iterator elementIter = list.iterator();
///
/// string parameter list
///
List<Object> strList = new ArrayList<Object>();
while (elementIter.hasNext()) {
element = (NestElement) elementIter.next();
if (null != element.getFile()) {
///
/// nested element include file
///
FileParser.loadFile(project, strList, element.getFile(), tag);
}
if (element.getName().length() > 0) {
///
/// nested element include name
///
paraStr = paraStr + " " + element.getName();
}
List<String> nameList = element.getList();
if (nameList.size() > 0) {
Iterator nameIter = nameList.iterator();
while (nameIter.hasNext()) {
paraStr = paraStr + " " + tag + " " + (String)nameIter.next();
}
}
}
///
/// iterator of string parameter list
///
Iterator strIter = strList.iterator();
while (strIter.hasNext()) {
paraStr = paraStr + " " + strIter.next();
}
return paraStr;
}
}

View File

@@ -0,0 +1,194 @@
/** @file
This file is to define nested element which is meant for specifying a tool
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.BuildException;
/**
Class Tool is to define an external tool to be used for genffsfile
**/
public class Tool implements EfiDefine, Section {
String toolName = "";
List<Object> toolArgList = new ArrayList<Object>();
String outputPath;
String outPutFileName ;
List<Input> inputFiles = new ArrayList<Input>();
/**
Call extern tool
@param buffer The buffer to put the result with alignment
**/
public void toBuffer (DataOutputStream buffer){
File OutputFile;
byte data;
///
/// call extern tool
///
try {
executeTool ();
} catch (Exception e) {
throw new BuildException("Call tools failed!\n");
}
///
/// check if file exist
///
OutputFile = new File (this.outPutFileName);
long fileLen = OutputFile.length();
if (!OutputFile.exists()) {
throw new BuildException("The file " + outPutFileName + " is not exist!\n");
}
///
/// Read output file and write it's cotains to buffer
///
try {
FileInputStream fs = new FileInputStream (this.outPutFileName);
DataInputStream In = new DataInputStream (fs);
int i = 0;
while (i < fileLen) {
data = In.readByte();
buffer.writeByte(data);
i ++;
}
///
/// 4 byte alignment
///
while ((fileLen & 0x03) != 0) {
fileLen++;
buffer.writeByte(0);
}
In.close();
} catch (Exception e) {
System.out.print(e.getMessage());
throw new BuildException("Call tool2buffer failed!\n");
}
}
///
/// execute external tool for genffsfile
///
private void executeTool () {
String command = "";
String argument = "";
command = toolName;
Iterator argIter = toolArgList.iterator();
Iterator inputIter = inputFiles.iterator();
ToolArg toolArg;
Input file = null;
///
/// argument of tools
///
while (argIter.hasNext()) {
toolArg = (ToolArg)argIter.next();
argument = argument + toolArg.getLine() + " ";
}
///
/// input files for tools
///
argument = argument + "-i ";
while (inputIter.hasNext()) {
file = (Input)inputIter.next();
argument = argument + file.getFile() + " ";
}
outPutFileName = outputPath + File.separatorChar + (new File(file.getFile())).getName() + ".crc";
argument = argument + " -o " + outPutFileName;
try {
///
/// execute command line
///
Process crcProcess = Runtime.getRuntime().exec(command + " " + argument);
crcProcess.waitFor();
} catch (Exception e) {
System.out.print (e.getMessage());
throw new BuildException("Execute tools fails!\n");
}
}
/**
Add method of ANT task/datatype for nested ToolArg type of element
@param toolArg The ToolArg object containing arguments for the tool
**/
public void addToolArg (ToolArg toolArg) {
toolArgList.add (toolArg);
}
/**
Get method of ANT task/datatype for attribute "OutputPath"
@returns The name of output path
**/
public String getOutputPath() {
return outputPath;
}
/**
Set method of ANT task/datatype for attribute "OutputPath"
@param outputPath The name of output path
**/
public void setOutputPath(String outPutPath) {
this.outputPath = outPutPath;
}
/**
Get method of ANT task/datatype for attribute "ToolName"
@returns The name of the tool.
**/
public String getToolName() {
return toolName;
}
/**
Set method of ANT task/datatype for attribute "ToolName"
@param toolName The name of the tool
**/
public void setToolName(String toolName) {
this.toolName = toolName;
}
/**
Add method of ANT task/datatype for nested Input type of element
@param file The Input objec which represents a file
**/
public void addInput(Input file) {
inputFiles.add(file);
}
}

View File

@@ -0,0 +1,42 @@
/** @file
This file is to define nested element which is meant for specifying tool arguments
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
/**
Class ToolArg is just used to specify arguments for genffsfile tool
**/
public class ToolArg {
///
/// keep the argument string
///
private String line = "";
/**
Get method of ANT task/datatype for attribute "line"
@returns The argument string
**/
public String getLine() {
return line;
}
/**
Set method of ANT task/datatype for attribute "line"
@param line The argument string
**/
public void setLine(String line) {
this.line = line;
}
}

View File

@@ -0,0 +1,221 @@
/** @file
This file is to define an ANT task which wraps VfrCompile.exe tool
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.io.IOException;
import java.util.ArrayList;
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.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.types.Commandline;
/**
VfrcompilerTask Task Class
class member
-createListFile : create an output IFR listing file.
-outPutDir : deposit all output files to directory OutputDir (default=cwd)
-createIfrBinFile: create an IFR HII pack file
-vfrFile : name of the input VFR script file
-processArg : c processer argument
-includepathList : add IncPath to the search path for VFR included files
**/
public class VfrCompilerTask extends Task implements EfiDefine {
private String createListFile = "";
private String outPutDir = "";
private String createIfrBinFile = "";
private String processerArg ="";
private String vfrFile;
private List<Object> includepathList = new ArrayList<Object>();
/**
get class member of createList file
@returns file name of createList
**/
public String getCreateListFile() {
return createListFile;
}
/**
set class member of createList file
@param createListFile if createList string equal "on" set '-l' flag
**/
public void setCreateListFile(String createListFile) {
if (createListFile.equals("ON")||createListFile.equals("on"))
this.createListFile = " -l";
}
/**
get output dir
@returns name of output dir
**/
public String getOutPutDir() {
return outPutDir;
}
/**
set class member of outPutDir
@param outPutDir The directory name for ouput file
**/
public void setOutPutDir(String outPutDir) {
this.outPutDir = " -od " + outPutDir;
}
/**
get class member of ifrBinFile
@return file name of ifrBinFile
**/
public String getCreateIfrBinFile() {
return createIfrBinFile;
}
/**
set class member of ifrBinFile
@param createIfrBinFile The flag to specify if the IFR binary file should
be generated or not
*/
public void setCreateIfrBinFile(String createIfrBinFile) {
if (createIfrBinFile.equals("ON") || createIfrBinFile.equals("on"));
this.createIfrBinFile = " -ibin";
}
/**
get class member of vfrFile
@returns name of vfrFile
**/
public String getVfrFile() {
return vfrFile;
}
/**
set class member of vfrFile
@param vfrFile The name of VFR file
**/
public void setVfrFile(String vfrFile) {
this.vfrFile = " " + vfrFile;
}
/**
add includePath in includepath List
@param includepath The IncludePath object which represents include path
**/
public void addIncludepath(IncludePath includepath){
includepathList.add(includepath);
}
/**
get class member of processerArg
@returns processer argument
**/
public String getProcesserArg() {
return processerArg;
}
/**
set class member of processerArg
@param processerArg The processor argument
*/
public void setProcesserArg(String processerArg) {
this.processerArg = " -ppflag " + processerArg;
}
/**
The standard execute method of ANT task.
**/
public void execute() throws BuildException {
Project project = this.getProject();
String toolPath= project.getProperty("env.Framework_Tools_Path");
String command;
if (toolPath == null) {
command = "VfrCompile";
} else {
command = toolPath + "/" + "VfrCompile";
}
List<Object> includePath = new ArrayList<Object>();
String incPath = "";
int count = includepathList.size();
IncludePath path;
for (int i = 0; i < count; i++) {
path = (IncludePath) includepathList.get(i);
if (path.getFile() != null) {
FileParser.loadFile( project,includePath,path.getFile(), "-I");
}
}
for (int i = 0; i < count; i++) {
incPath = incPath + " " + includepathList.get(i);
}
count = includePath.size();
for (int i = 0; i < count; i++) {
incPath = incPath + " " + includePath.get(i);
}
String argument = this.createIfrBinFile +
this.processerArg +
incPath +
this.outPutDir +
this.createListFile +
this.vfrFile ;
try {
///
/// constructs the command-line
///
Commandline commandLine = new Commandline();
commandLine.setExecutable(command);
commandLine.createArgument().setLine(argument);
///
/// configures the Execute object
///
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO,
Project.MSG_WARN);
Execute runner = new Execute(streamHandler,null);
runner.setAntRun(project);
runner.setCommandline(commandLine.getCommandline());
System.out.println(Commandline.toString(commandLine.getCommandline()));
int returnVal = runner.execute();
if (EFI_SUCCESS == returnVal) {
System.out.println("VfrCompiler execution succeeded!");
} else {
System.out.println("VfrCompiler failed. (error=" +
Integer.toHexString(returnVal) + ")");
throw new BuildException("VfrCompiler failed. (error=" +
Integer.toHexString(returnVal) + ")");
}
} catch (IOException e) {
throw new BuildException(e.getMessage());
}
}
}