From e3cc406130b14c020c75e3a169f94ba001bf2128 Mon Sep 17 00:00:00 2001 From: jwang36 Date: Thu, 25 Jan 2007 01:25:02 +0000 Subject: - Fixed EDKT240. Now the Blank.pad file for alignment purpose will no longer be needed. - Fixed EDKT366. For NT32, using "build run" to launch the NT32 emulator. The run.cmd is still be generated in the ${TARGET_DIR} git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2305 6f19259b-4bc3-4df7-8a09-765794883524 --- .../tianocore/framework/tasks/CompressSection.java | 13 +++++ .../tianocore/framework/tasks/GenFfsFileTask.java | 67 +++++++++++++++++++--- .../tianocore/framework/tasks/GenSectionTask.java | 13 +++++ .../org/tianocore/framework/tasks/SectFile.java | 13 +++++ .../org/tianocore/framework/tasks/Section.java | 3 + .../org/tianocore/framework/tasks/Tool.java | 14 +++++ 6 files changed, 114 insertions(+), 9 deletions(-) (limited to 'Tools/Java/Source/FrameworkTasks') diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java index 5f35685fbe..3e2a98f695 100644 --- a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java +++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/CompressSection.java @@ -33,6 +33,7 @@ import org.apache.tools.ant.BuildException; **/ public class CompressSection implements Section, FfsTypes { + private int alignment = 0; // // The attribute of compressName. // @@ -197,4 +198,16 @@ public class CompressSection implements Section, FfsTypes { public void addTool (Tool tool) { sectList.add(tool); } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + if (alignment > 7) { + this.alignment = 7; + } else { + this.alignment = alignment; + } + } } \ No newline at end of file diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java index 3fdeb8d76a..ebc26b92a4 100644 --- a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java +++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java @@ -741,15 +741,53 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes { 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 alignSection(DataOutputStream dataBuffer, int dataSize, int alignment) throws BuildException { + if (alignment == 0) { + return; + } + dataSize += 4; // take the section header into account + int[] alignedBytes = {0, 16, 128, 512, 1024, 4096, 32768, 65536}; + int padSize = (alignedBytes[alignment] - dataSize) & (alignedBytes[alignment] - 1); + if (padSize == 0) { + // + // already aligned + // + return; + } + // + // if the pad size is not times of 4, there must be something wrong in previous sections + // + if (((4 - padSize) & (4 - 1)) != 0) { + EdkLog.log(this, EdkLog.EDK_ERROR, "PAD section size must be 4-byte aligned (" + padSize + ")!"); + throw new BuildException ("Alignment can't be satisfied!"); + } + byte[] pad = new byte[padSize]; + // + // first three byte stores the section size + // + pad[0] = (byte)(padSize & 0xff); + pad[1] = (byte)((padSize >> 8) & 0xff); + pad[2] = (byte)((padSize >> 16) & 0xff); + // + // the fourth byte are section type. use raw type (0x19) + // + pad[3] = 0x19; + try { + dataBuffer.write(pad); + } catch (Exception e) { + throw new BuildException(e.getMessage()); + } + } + + /** + 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) throws BuildException { Section sect; int fileSize; @@ -775,6 +813,11 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes { sect = (Section)sectionIter.next(); try { + int alignment = sect.getAlignment(); + if (this.ffsAttribDataAlignment < alignment) { + this.ffsAttribDataAlignment = alignment; + } + alignSection(dataBuffer, dataBuffer.size(), alignment); // // The last section don't need 4 byte ffsAligment. // @@ -812,6 +855,12 @@ public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes { stringToGuid (this.ffsFileGuid, ffsHeader.name); } + // + // because we may have changed the ffsAttribDataAlignment, we need to refresh attributes + // + this.attributes &= ~(((byte)7) << 3); + this.attributes |= (((byte)this.ffsAttribDataAlignment) << 3); + ffsHeader.ffsAttributes = this.attributes; if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) { throw new BuildException ("FFS_FILE_TYPE unknow!\n"); diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java index e329c0e3eb..82844f080f 100644 --- a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java +++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java @@ -32,6 +32,7 @@ import org.apache.tools.ant.types.Commandline; import org.tianocore.common.logger.EdkLog; public class GenSectionTask extends Task implements EfiDefine, Section, FfsTypes { + private int alignment = 0; // // Tool name // @@ -269,6 +270,18 @@ public class GenSectionTask extends Task implements EfiDefine, Section, FfsTypes this.sectFileList.add(task); } + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + if (alignment > 7) { + this.alignment = 7; + } else { + this.alignment = alignment; + } + } + public void toBuffer(DataOutputStream buffer){ // // Search SectionList find earch section and call it's diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java index c110f3bc50..9d53a21999 100644 --- a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java +++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SectFile.java @@ -25,6 +25,7 @@ import org.apache.tools.ant.BuildException; **/ public class SectFile implements Section { private String fileName = ""; /// section file name + private int alignment = 0; /** Get method of ANT task/datatype for "FileName" attribute @@ -44,6 +45,18 @@ public class SectFile implements Section { this.fileName = fileName; } + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + if (alignment > 7) { + this.alignment = 7; + } else { + this.alignment = alignment; + } + } + public SectFile (){ } diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Section.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Section.java index 5fa8d7b1ee..ff4c6d6d11 100644 --- a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Section.java +++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Section.java @@ -19,5 +19,8 @@ import java.io.DataOutputStream; Section interface is for geting the contain buffer form compress, tool, and sectFile **/ public interface Section { + int alignment = 0; public void toBuffer (DataOutputStream buffer); + public void setAlignment(int alignment); + public int getAlignment(); } \ No newline at end of file diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java index 761a0efab0..ea320366b1 100644 --- a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java +++ b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/Tool.java @@ -32,6 +32,7 @@ import org.tianocore.common.logger.EdkLog; **/ public class Tool implements EfiDefine, Section { + private int alignment = 0; private String toolName = ""; private ToolArg toolArgList = new ToolArg(); private Input inputFiles = new Input(); @@ -247,6 +248,19 @@ public class Tool implements EfiDefine, Section { public synchronized int getRand() { return ran.nextInt(); } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + if (alignment > 7) { + this.alignment = 7; + } else { + this.alignment = alignment; + } + } + } -- cgit v1.2.3