4 FfsHeader class describe the struct of Ffs file header.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.framework
.tasks
;
18 import org
.apache
.tools
.ant
.BuildException
;
23 FfsHeader class describe the struct of Ffs file header.
25 public class FfsHeader
{
30 FfsGuid is interal class of FfsHeader, it describe the struct of Guid.
32 public class FfsGuid
{
37 byte[] data4
= new byte[8];
38 byte[] dataBuffer
= new byte[16];
43 This function is to convert GUID to ffsGuid class member.
45 @param dataBuffer Buffer contained the GUID value in byte.
46 For example: if the input string as : "A6F691AC
47 31C8 4444 854C E2C1A6950F92"
51 Data4: 4C85E2C1A6950F92
53 public void bufferToStruct (byte[] dataBuffer
){
54 if (dataBuffer
.length
!= 16) {
55 throw new BuildException ("Buffer is not sized [" + dataBuffer
.length
+ "] for data type, GUID!");
58 data1
= (int)(dataBuffer
[3]& 0xff);
60 data1
= (int)data1
| (dataBuffer
[2]& 0xff);
61 data1
= ((data1
<< 8) & 0xffff00) | (dataBuffer
[1]& 0xff);
62 data1
= ((data1
<< 8) & 0xffffff00) | (dataBuffer
[0]& 0xff);
65 data2
= (short) (dataBuffer
[5] & 0xff);
66 data2
= (short)((data2
<< 8) | (dataBuffer
[4]& 0xff));
68 data3
= (short)(dataBuffer
[7] & 0xff);
69 data3
= (short)((data3
<< 8) | (dataBuffer
[6] & 0xff));
71 for (int i
= 0; i
< 8; i
++) {
72 data4
[i
] = dataBuffer
[i
+8];
80 This function is to store ffsHeader class member to buffer.
82 @return Byte buffer which contained the ffsHeader class member
84 public byte[] structToBuffer (){
86 byte[] buffer
= new byte [16];
88 buffer
[3] = (byte)(data1
& 0x000000ff);
89 buffer
[2] = (byte)((data1
& 0x0000ff00)>> 8);
90 buffer
[1] = (byte)((data1
& 0x00ff0000)>> 16);
91 buffer
[0] = (byte)((data1
& 0xff000000)>> 24);
93 buffer
[5] = (byte)(data2
& 0x00ff);
94 buffer
[4] = (byte)((data2
& 0xff00)>> 8);
96 buffer
[7] = (byte)(data3
& 0x00ff);
97 buffer
[6] = (byte)((data3
& 0xff00)>> 8);
99 for (int i
= 8; i
< 16; i
++) {
100 buffer
[i
] = data4
[i
-8];
111 This class is used to record the struct of checksum.
113 public class IntegrityCheckSum
{
121 FfsGuid name
= new FfsGuid();
126 IntegrityCheckSum integrityCheck
= new IntegrityCheckSum();
139 byte[] ffsFileSize
= new byte[3];
148 This function is to store FfsHeader class member to buffer.
150 @return Byte buffer which contained the FfsHeader class member.
152 public byte[] structToBuffer () {
155 byte[] buffer
= new byte[24];
156 buffer1
= name
.structToBuffer();
158 for (i
= 0; i
< 16; i
++) {
159 buffer
[i
] = buffer1
[i
];
162 buffer
[16] = integrityCheck
.header
;
163 buffer
[17] = integrityCheck
.file
;
164 buffer
[18] = fileType
;
165 buffer
[19] = ffsAttributes
;
167 for (i
=20; i
< 23; i
++) {
168 buffer
[i
] = ffsFileSize
[i
-20];
171 buffer
[23] = ffsState
;
178 This function is to get the size of FfsHeader in byte.
180 @return The size of FfsHeader.
182 public int getSize(){