Modify GenFfsTask to make it don't create ORG file.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1271 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qouyang 2006-08-15 08:05:34 +00:00
parent 9c7790d2cb
commit 87379bbecf
6 changed files with 274 additions and 361 deletions

View File

@ -17,11 +17,8 @@
package org.tianocore.framework.tasks;
import java.io.DataInputStream;
import java.io.ByteArrayOutputStream;
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;
@ -54,18 +51,17 @@ public class CompressSection implements Section, FfsTypes{
@param Buffer The point of output buffer
**/
public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){
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);
ByteArrayOutputStream bo = new ByteArrayOutputStream ();
DataOutputStream Do = new DataOutputStream (bo);
//
// Get each section which under the compress {};
@ -79,7 +75,7 @@ public class CompressSection implements Section, FfsTypes{
// Call each section class's toBuffer function.
//
try {
sect.toBuffer(Do, orgBuffer);
sect.toBuffer(Do);
}
catch (BuildException e) {
System.out.print(e.getMessage());
@ -89,17 +85,10 @@ public class CompressSection implements Section, FfsTypes{
}
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
//
byte[] fileBuffer = bo.toByteArray();
Compress myCompress = new Compress(fileBuffer, fileBuffer.length);
//
@ -151,18 +140,10 @@ public class CompressSection implements Section, FfsTypes{
buffer.writeByte(0);
}
//
// orgBuffer 4 Byte aligment
//
size = (int)compressOut.length();
while ((size & 0x03) != 0){
size ++;
orgBuffer.writeByte(0);
}
//
// Delete temp file
//
di.close();
compressOut.delete();
//di.close();
//compressOut.delete();
}
catch (Exception e){

View File

@ -27,6 +27,7 @@ import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.tianocore.common.logger.EdkLog;
/**
GenFfsFileTask
@ -112,7 +113,7 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
/// The path of Framewor_Tools_Paht.
///
static String path = "";
/**
execute
@ -120,18 +121,17 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
dscriptive information.
**/
public void execute() throws BuildException {
Section sect;
int fileSize;
int orgFileSize;
int fileDataSize;
int orgFileDataSize;
File ffsFile;
File ffsOrgFile;
FfsHeader ffsHeader = new FfsHeader();
FfsHeader orgFfsHeader = new FfsHeader();
String ffsSuffix = "";
String outputPath = "";
Project project = this.getOwningTarget().getProject();
//
// set Logger
//
FrameworkLogger logger = new FrameworkLogger(project, "genFfs");
EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
EdkLog.setLogger(logger);
//
// Get Fraemwork_Tools_Path
//
@ -170,267 +170,8 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
}
String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix;
ffsFile = new File (ffsFilePath);
//
// Create ffs ORG file. fileName = FfsFileGuid + BaseName + ffsSuffix +
// ".org".
//
ffsOrgFile = new File(ffsFilePath + ".org");
log(ffsFile.getName());
log(ffsOrgFile.getName());
try {
//
// Create file output stream -- dataBuffer.
//
FileOutputStream dataFs = new FileOutputStream (ffsFile.getAbsolutePath());
DataOutputStream dataBuffer = new DataOutputStream (dataFs);
//
// Create org file output stream -- orgDataBuffer
//
FileOutputStream orgDataFs = new FileOutputStream (ffsOrgFile.getAbsolutePath());
DataOutputStream orgDataBuffer = new DataOutputStream (orgDataFs);
//
// 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, (DataOutputStream) orgDataBuffer);
} catch (Exception e) {
throw new BuildException (e.getMessage());
}
}
dataBuffer.close();
orgDataBuffer.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();
//
// create input org stream to read file data
//
byte[] orgFileBuffer = new byte[(int)ffsOrgFile.length()];
FileInputStream ofi = new FileInputStream (ffsOrgFile.getAbsolutePath());
DataInputStream odi = new DataInputStream (ofi);
odi.read(orgFileBuffer);
odi.close();
//
// Add GUID to header struct
//
if (this.ffsFileGuid != null) {
stringToGuid (this.ffsFileGuid, ffsHeader.name);
//
// Add Guid to org header struct
//
stringToGuid (this.ffsFileGuid, orgFfsHeader.name);
}
ffsHeader.ffsAttributes = this.attributes;
if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) {
throw new BuildException ("FFS_FILE_TYPE unknow!\n");
}
//
// Copy ffsHeader.ffsAttribute and fileType to orgFfsHeader.ffsAttribute
// and fileType
//
orgFfsHeader.ffsAttributes = ffsHeader.ffsAttributes;
orgFfsHeader.fileType = ffsHeader.fileType;
//
// 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);
orgFileDataSize = adjustFileSize (orgFileBuffer);
} else {
fileDataSize = fileBuffer.length;
orgFileDataSize = orgFileBuffer.length;
}
//
// 1. add header size to file size
//
fileSize = fileDataSize + ffsHeader.getSize();
//
// add header size to org file size
//
orgFileSize = orgFileDataSize + 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 zero length files"
);
}
fileSize = fileSize + 2;
orgFileSize = orgFileSize + 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);
//
// set file size to org header struct
//
orgFfsHeader.ffsFileSize[0] = (byte)(orgFileSize & 0x00FF);
orgFfsHeader.ffsFileSize[1] = (byte)((orgFileSize & 0x00FF00)>>8);
orgFfsHeader.ffsFileSize[2] = (byte)(((int)orgFileSize & 0xFF0000)>>16);
//
// Fill in checksums and state, these must be zero for checksumming
//
ffsHeader.integrityCheck.header = calculateChecksum8 (
ffsHeader.structToBuffer(),
ffsHeader.getSize()
);
//
// Fill in org file's header check sum and state
//
orgFfsHeader.integrityCheck.header = calculateChecksum8 (
orgFfsHeader.structToBuffer(),
orgFfsHeader.getSize()
);
if ((this.attributes & FFS_ATTRIB_CHECKSUM) != 0) {
if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
ffsHeader.integrityCheck.file = calculateChecksum8 (
fileBuffer,
fileDataSize
);
//
// Add org file header
//
orgFfsHeader.integrityCheck.file = calculateChecksum8 (
orgFileBuffer,
orgFileDataSize
);
} else {
ffsHeader.integrityCheck.file = calculateChecksum8 (
fileBuffer,
fileDataSize
);
//
// Add org file header
//
orgFfsHeader.integrityCheck.file = calculateChecksum8 (
orgFileBuffer,
orgFileDataSize
);
}
} else {
ffsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;
orgFfsHeader.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;
orgFfsHeader.ffsState = ffsHeader.ffsState;
//
// 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);
FileOutputStream orgHeaderFfs = new FileOutputStream (ffsOrgFile.getAbsolutePath());
DataOutputStream orgFfsBuffer = new DataOutputStream (orgHeaderFfs);
//
// Add header struct and file data to FFS file
//
ffsBuffer.write(ffsHeader.structToBuffer());
orgFfsBuffer.write(orgFfsHeader.structToBuffer());
for (int i = 0; i< fileDataSize; i++) {
ffsBuffer.write(fileBuffer[i]);
}
for (int i = 0; i < orgFileDataSize; i++){
orgFfsBuffer.write(orgFileBuffer[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]);
orgFfsBuffer.write(tailByte[0]);
orgFfsBuffer.write(tailByte[1]);
}
//
// close output stream. Note if don't close output stream
// the buffer can't be rewritten to file.
//
ffsBuffer.close();
orgFfsBuffer.close();
} catch (Exception e) {
log("genffsfile failed!");
throw new BuildException (e.getMessage());
}
File ffsFile = new File (ffsFilePath);
genFfs(ffsFile);
}
/**
@ -941,43 +682,260 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
this.outputDir = outputDir;
}
/**
getModuleTyp
This function is to get string of module type.
@return moduleType The string of module type.
**/
public String getModuleType() {
return this.moduleType;
}
/**
setModuleType
This function is to set moduleType.
@param moduleType The string of module type.
**/
public void setModuleType(String moduleType) {
this.moduleType = moduleType;
}
/**
Convert a string to a integer.
@param intString The string representing a integer
@retval int The value of integer represented by the
given string; -1 is returned if the format
of the string is wrong.
**/
private int stringToInt(String intString) {
int value;
int hexPrefixPos = intString.indexOf("0x");
int radix = 10;
String intStringNoPrefix;
Convert a string to a integer.
@param intString The string representing a integer
@retval int The value of integer represented by the
given string; -1 is returned if the format
of the string is wrong.
**/
private int stringToInt(String intString) {
int value;
int hexPrefixPos = intString.indexOf("0x");
int radix = 10;
String intStringNoPrefix;
if (hexPrefixPos >= 0) {
radix = 16;
intStringNoPrefix = intString.substring(hexPrefixPos + 2, intString.length());
} else {
intStringNoPrefix = intString;
}
if (hexPrefixPos >= 0) {
radix = 16;
intStringNoPrefix = intString.substring(hexPrefixPos + 2, intString.length());
} else {
intStringNoPrefix = intString;
}
try {
value = Integer.parseInt(intStringNoPrefix, radix);
} catch (NumberFormatException e) {
log("Incorrect format of int [" + intString + "]. -1 is assumed");
return -1;
}
return value;
}
/**
genFfs
This function is to generate FFS file.
@param ffsFile Name of FFS file.
@param isOrg Flag to indicate generate ORG ffs file or not.
**/
private void genFfs(File ffsFile) {
Section sect;
int fileSize;
int fileDataSize;
FfsHeader ffsHeader = new FfsHeader();
FfsHeader orgFfsHeader = new FfsHeader();
EdkLog.log(EdkLog.EDK_INFO, ffsFile.getName());
try {
value = Integer.parseInt(intStringNoPrefix, radix);
} catch (NumberFormatException e) {
log("Incorrect format of int [" + intString + "]. -1 is assumed");
return -1;
//
// Create file output stream -- dataBuffer.
//
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");
}
//
// Copy ffsHeader.ffsAttribute and fileType to orgFfsHeader.ffsAttribute
// and fileType
//
orgFfsHeader.ffsAttributes = ffsHeader.ffsAttributes;
orgFfsHeader.fileType = ffsHeader.fileType;
//
// 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;
orgFfsHeader.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());
ffsBuffer.write(fileBuffer, 0, fileDataSize);
//
// 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();
} catch (Exception e) {
log("genffsfile failed!");
throw new BuildException (e.getMessage());
}
return value;
}
}

View File

@ -18,19 +18,11 @@ 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 java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ProcessBuilder;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
GenFvImageTask

View File

@ -53,10 +53,9 @@ public class SectFile implements Section {
@param Buffer buffer to contain the section file content with alignment
**/
public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){
public void toBuffer (DataOutputStream buffer){
File sectFile;
byte data;
long fileLen;
int fileLen;
///
/// open file
@ -67,7 +66,7 @@ public class SectFile implements Section {
/// check if file exist.
///
if (! sectFile.exists()) {
throw new BuildException("The file " + this.fileName + " does not exist!\n");
throw new BuildException("The file " + this.fileName + " is not exist!\n");
}
@ -78,18 +77,10 @@ public class SectFile implements Section {
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);
//
// Add data to org file
//
orgBuffer.writeByte(data);
i++;
}
fileLen = (int)sectFile.length();
byte[] sectBuffer = new byte[fileLen];
In.read(sectBuffer);
buffer.write(sectBuffer);
///
/// 4 byte alignment
@ -97,10 +88,6 @@ public class SectFile implements Section {
while ((fileLen & 0x03)!= 0) {
fileLen ++;
buffer.writeByte(0);
//
// Add data to org file
//
orgBuffer.writeByte(0);
}
///
@ -113,4 +100,4 @@ public class SectFile implements Section {
throw new BuildException("SectFile, toBuffer failed!\n");
}
}
}
}

View File

@ -19,5 +19,5 @@ 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, DataOutputStream orgBuffer);
public void toBuffer (DataOutputStream buffer);
}

View File

@ -39,7 +39,7 @@ public class Tool implements EfiDefine, Section {
@param buffer The buffer to put the result with alignment
**/
public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){
public void toBuffer (DataOutputStream buffer){
File OutputFile;
byte data;
@ -72,10 +72,6 @@ public class Tool implements EfiDefine, Section {
while (i < fileLen) {
data = In.readByte();
buffer.writeByte(data);
//
// Add data to org file
//
orgBuffer.writeByte(data);
i ++;
}
@ -85,7 +81,6 @@ public class Tool implements EfiDefine, Section {
while ((fileLen & 0x03) != 0) {
fileLen++;
buffer.writeByte(0);
orgBuffer.writeByte(0);
}
In.close();