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:
@@ -17,11 +17,8 @@
|
|||||||
|
|
||||||
package org.tianocore.framework.tasks;
|
package org.tianocore.framework.tasks;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,18 +51,17 @@ public class CompressSection implements Section, FfsTypes{
|
|||||||
@param Buffer The point of output buffer
|
@param Buffer The point of output buffer
|
||||||
|
|
||||||
**/
|
**/
|
||||||
public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){
|
public void toBuffer (DataOutputStream buffer){
|
||||||
|
|
||||||
Section sect;
|
Section sect;
|
||||||
File compressOut;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get section file in compress node.
|
// Get section file in compress node.
|
||||||
//
|
//
|
||||||
try{
|
try{
|
||||||
compressOut = new File ("Compress.temp");
|
|
||||||
FileOutputStream fo = new FileOutputStream (compressOut.getName());
|
ByteArrayOutputStream bo = new ByteArrayOutputStream ();
|
||||||
DataOutputStream Do = new DataOutputStream (fo);
|
DataOutputStream Do = new DataOutputStream (bo);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get each section which under the compress {};
|
// Get each section which under the compress {};
|
||||||
@@ -79,7 +75,7 @@ public class CompressSection implements Section, FfsTypes{
|
|||||||
// Call each section class's toBuffer function.
|
// Call each section class's toBuffer function.
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
sect.toBuffer(Do, orgBuffer);
|
sect.toBuffer(Do);
|
||||||
}
|
}
|
||||||
catch (BuildException e) {
|
catch (BuildException e) {
|
||||||
System.out.print(e.getMessage());
|
System.out.print(e.getMessage());
|
||||||
@@ -89,17 +85,10 @@ public class CompressSection implements Section, FfsTypes{
|
|||||||
}
|
}
|
||||||
Do.close();
|
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
|
// Call compress
|
||||||
//
|
//
|
||||||
|
byte[] fileBuffer = bo.toByteArray();
|
||||||
Compress myCompress = new Compress(fileBuffer, fileBuffer.length);
|
Compress myCompress = new Compress(fileBuffer, fileBuffer.length);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -151,18 +140,10 @@ public class CompressSection implements Section, FfsTypes{
|
|||||||
buffer.writeByte(0);
|
buffer.writeByte(0);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// orgBuffer 4 Byte aligment
|
|
||||||
//
|
|
||||||
size = (int)compressOut.length();
|
|
||||||
while ((size & 0x03) != 0){
|
|
||||||
size ++;
|
|
||||||
orgBuffer.writeByte(0);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Delete temp file
|
// Delete temp file
|
||||||
//
|
//
|
||||||
di.close();
|
//di.close();
|
||||||
compressOut.delete();
|
//compressOut.delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
|
@@ -27,6 +27,7 @@ import java.util.List;
|
|||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
import org.apache.tools.ant.Project;
|
import org.apache.tools.ant.Project;
|
||||||
import org.apache.tools.ant.Task;
|
import org.apache.tools.ant.Task;
|
||||||
|
import org.tianocore.common.logger.EdkLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
GenFfsFileTask
|
GenFfsFileTask
|
||||||
@@ -120,17 +121,16 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
|
|||||||
dscriptive information.
|
dscriptive information.
|
||||||
**/
|
**/
|
||||||
public void execute() throws BuildException {
|
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 ffsSuffix = "";
|
||||||
String outputPath = "";
|
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
|
// Get Fraemwork_Tools_Path
|
||||||
@@ -170,267 +170,8 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix;
|
String ffsFilePath = outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix;
|
||||||
ffsFile = new File (ffsFilePath);
|
File ffsFile = new File (ffsFilePath);
|
||||||
//
|
genFfs(ffsFile);
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -941,10 +682,24 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
|
|||||||
this.outputDir = outputDir;
|
this.outputDir = outputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
getModuleTyp
|
||||||
|
|
||||||
|
This function is to get string of module type.
|
||||||
|
|
||||||
|
@return moduleType The string of module type.
|
||||||
|
**/
|
||||||
public String getModuleType() {
|
public String getModuleType() {
|
||||||
return this.moduleType;
|
return this.moduleType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
setModuleType
|
||||||
|
|
||||||
|
This function is to set moduleType.
|
||||||
|
|
||||||
|
@param moduleType The string of module type.
|
||||||
|
**/
|
||||||
public void setModuleType(String moduleType) {
|
public void setModuleType(String moduleType) {
|
||||||
this.moduleType = moduleType;
|
this.moduleType = moduleType;
|
||||||
}
|
}
|
||||||
@@ -980,4 +735,207 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
|
|||||||
|
|
||||||
return value;
|
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 {
|
||||||
|
//
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,19 +18,11 @@ package org.tianocore.framework.tasks;
|
|||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
import org.apache.tools.ant.Project;
|
import org.apache.tools.ant.Project;
|
||||||
import org.apache.tools.ant.Task;
|
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.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.ProcessBuilder;
|
import java.lang.ProcessBuilder;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
GenFvImageTask
|
GenFvImageTask
|
||||||
|
@@ -53,10 +53,9 @@ public class SectFile implements Section {
|
|||||||
|
|
||||||
@param Buffer buffer to contain the section file content with alignment
|
@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;
|
File sectFile;
|
||||||
byte data;
|
int fileLen;
|
||||||
long fileLen;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// open file
|
/// open file
|
||||||
@@ -67,7 +66,7 @@ public class SectFile implements Section {
|
|||||||
/// check if file exist.
|
/// check if file exist.
|
||||||
///
|
///
|
||||||
if (! sectFile.exists()) {
|
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());
|
FileInputStream fs = new FileInputStream (sectFile.getAbsoluteFile());
|
||||||
DataInputStream In = new DataInputStream (fs);
|
DataInputStream In = new DataInputStream (fs);
|
||||||
fileLen = sectFile.length();
|
fileLen = (int)sectFile.length();
|
||||||
|
byte[] sectBuffer = new byte[fileLen];
|
||||||
int i = 0;
|
In.read(sectBuffer);
|
||||||
while (i < fileLen) {
|
buffer.write(sectBuffer);
|
||||||
data = In.readByte();
|
|
||||||
buffer.writeByte(data);
|
|
||||||
//
|
|
||||||
// Add data to org file
|
|
||||||
//
|
|
||||||
orgBuffer.writeByte(data);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// 4 byte alignment
|
/// 4 byte alignment
|
||||||
@@ -97,10 +88,6 @@ public class SectFile implements Section {
|
|||||||
while ((fileLen & 0x03)!= 0) {
|
while ((fileLen & 0x03)!= 0) {
|
||||||
fileLen ++;
|
fileLen ++;
|
||||||
buffer.writeByte(0);
|
buffer.writeByte(0);
|
||||||
//
|
|
||||||
// Add data to org file
|
|
||||||
//
|
|
||||||
orgBuffer.writeByte(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@@ -19,5 +19,5 @@ import java.io.DataOutputStream;
|
|||||||
Section interface is for geting the contain buffer form compress, tool, and sectFile
|
Section interface is for geting the contain buffer form compress, tool, and sectFile
|
||||||
**/
|
**/
|
||||||
public interface Section {
|
public interface Section {
|
||||||
public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer);
|
public void toBuffer (DataOutputStream buffer);
|
||||||
}
|
}
|
@@ -39,7 +39,7 @@ public class Tool implements EfiDefine, Section {
|
|||||||
|
|
||||||
@param buffer The buffer to put the result with alignment
|
@param buffer The buffer to put the result with alignment
|
||||||
**/
|
**/
|
||||||
public void toBuffer (DataOutputStream buffer, DataOutputStream orgBuffer){
|
public void toBuffer (DataOutputStream buffer){
|
||||||
File OutputFile;
|
File OutputFile;
|
||||||
byte data;
|
byte data;
|
||||||
|
|
||||||
@@ -72,10 +72,6 @@ public class Tool implements EfiDefine, Section {
|
|||||||
while (i < fileLen) {
|
while (i < fileLen) {
|
||||||
data = In.readByte();
|
data = In.readByte();
|
||||||
buffer.writeByte(data);
|
buffer.writeByte(data);
|
||||||
//
|
|
||||||
// Add data to org file
|
|
||||||
//
|
|
||||||
orgBuffer.writeByte(data);
|
|
||||||
i ++;
|
i ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +81,6 @@ public class Tool implements EfiDefine, Section {
|
|||||||
while ((fileLen & 0x03) != 0) {
|
while ((fileLen & 0x03) != 0) {
|
||||||
fileLen++;
|
fileLen++;
|
||||||
buffer.writeByte(0);
|
buffer.writeByte(0);
|
||||||
orgBuffer.writeByte(0);
|
|
||||||
}
|
}
|
||||||
In.close();
|
In.close();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user