]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FfsHeader.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / FfsHeader.java
1 /** @file
2 FfsHeader
3
4 FfsHeader class describe the struct of Ffs file header.
5
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
11
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.
14
15 **/
16 package org.tianocore.framework.tasks;
17
18 import org.apache.tools.ant.BuildException;
19
20 /**
21 FfsHeader
22
23 FfsHeader class describe the struct of Ffs file header.
24 **/
25 public class FfsHeader {
26
27 /**
28 FfsGuid
29
30 FfsGuid is interal class of FfsHeader, it describe the struct of Guid.
31 **/
32 public class FfsGuid {
33
34 int data1 = 0;
35 short data2 = 0;
36 short data3 = 0;
37 byte[] data4 = new byte[8];
38 byte[] dataBuffer = new byte[16];
39
40 /**
41 bufferToStruct
42
43 This function is to convert GUID to ffsGuid class member.
44
45 @param dataBuffer Buffer contained the GUID value in byte.
46 For example: if the input string as : "A6F691AC
47 31C8 4444 854C E2C1A6950F92"
48 Then Data1: AC91F6A6
49 Data2: C831
50 Data3: 4444
51 Data4: 4C85E2C1A6950F92
52 **/
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!");
56 }
57
58 data1 = (int)(dataBuffer[3]& 0xff);
59 data1 = data1 << 8;
60 data1 = (int)data1 | (dataBuffer[2]& 0xff);
61 data1 = ((data1 << 8) & 0xffff00) | (dataBuffer[1]& 0xff);
62 data1 = ((data1 << 8) & 0xffffff00) | (dataBuffer[0]& 0xff);
63
64
65 data2 = (short) (dataBuffer[5] & 0xff);
66 data2 = (short)((data2 << 8) | (dataBuffer[4]& 0xff));
67
68 data3 = (short)(dataBuffer[7] & 0xff);
69 data3 = (short)((data3 << 8) | (dataBuffer[6] & 0xff));
70
71 for (int i = 0; i < 8; i++) {
72 data4[i] = dataBuffer[i+8];
73 }
74
75 }
76
77 /**
78 structToBuffer
79
80 This function is to store ffsHeader class member to buffer.
81
82 @return Byte buffer which contained the ffsHeader class member
83 **/
84 public byte[] structToBuffer (){
85
86 byte[] buffer = new byte [16];
87
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);
92
93 buffer[5] = (byte)(data2 & 0x00ff);
94 buffer[4] = (byte)((data2 & 0xff00)>> 8);
95
96 buffer[7] = (byte)(data3 & 0x00ff);
97 buffer[6] = (byte)((data3 & 0xff00)>> 8);
98
99 for (int i = 8; i < 16; i++) {
100 buffer[i] = data4[i-8];
101 }
102 return buffer;
103 }
104
105
106 }
107
108 /**
109 integrityCheckSum
110
111 This class is used to record the struct of checksum.
112 **/
113 public class IntegrityCheckSum {
114 byte header;
115 byte file;
116 }
117
118 ///
119 /// Guid
120 ///
121 FfsGuid name = new FfsGuid();
122
123 ///
124 /// CheckSum
125 ///
126 IntegrityCheckSum integrityCheck = new IntegrityCheckSum();
127
128 ///
129 /// File type
130 ///
131 byte fileType;
132 ///
133 /// Ffs attributes.
134 ///
135 byte ffsAttributes;
136 ///
137 /// Ffs file size
138 ///
139 byte[] ffsFileSize = new byte[3];
140 ///
141 /// Ffs state.
142 ///
143 byte ffsState;
144
145 /**
146 structToBuffer
147
148 This function is to store FfsHeader class member to buffer.
149
150 @return Byte buffer which contained the FfsHeader class member.
151 **/
152 public byte[] structToBuffer () {
153 int i;
154 byte[] buffer1;
155 byte[] buffer = new byte[24];
156 buffer1 = name.structToBuffer();
157
158 for (i = 0; i < 16; i++) {
159 buffer[i] = buffer1[i];
160 }
161
162 buffer[16] = integrityCheck.header;
163 buffer[17] = integrityCheck.file;
164 buffer[18] = fileType;
165 buffer[19] = ffsAttributes;
166
167 for (i=20; i < 23; i++) {
168 buffer[i] = ffsFileSize[i-20];
169 }
170
171 buffer[23] = ffsState;
172 return buffer;
173 }
174
175 /**
176 getSize
177
178 This function is to get the size of FfsHeader in byte.
179
180 @return The size of FfsHeader.
181 **/
182 public int getSize(){
183 return 24;
184 }
185 }