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