]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | FfsHeader \r | |
3 | \r | |
4 | FfsHeader class describe the struct of Ffs file header.\r | |
5 | \r | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | package org.tianocore.framework.tasks;\r | |
17 | \r | |
18 | import org.apache.tools.ant.BuildException;\r | |
19 | \r | |
20 | /**\r | |
21 | FfsHeader\r | |
22 | \r | |
23 | FfsHeader class describe the struct of Ffs file header.\r | |
24 | **/\r | |
25 | public class FfsHeader {\r | |
26 | \r | |
27 | /**\r | |
28 | FfsGuid\r | |
29 | \r | |
30 | FfsGuid is interal class of FfsHeader, it describe the struct of Guid.\r | |
31 | **/\r | |
32 | public class FfsGuid {\r | |
33 | \r | |
34 | int data1 = 0;\r | |
35 | short data2 = 0;\r | |
36 | short data3 = 0;\r | |
37 | byte[] data4 = new byte[8]; \r | |
38 | byte[] dataBuffer = new byte[16];\r | |
39 | \r | |
40 | /**\r | |
41 | bufferToStruct \r | |
42 | \r | |
43 | This function is to convert GUID to ffsGuid class member.\r | |
44 | \r | |
45 | @param dataBuffer Buffer contained the GUID value in byte.\r | |
46 | For example: if the input string as : "A6F691AC\r | |
47 | 31C8 4444 854C E2C1A6950F92"\r | |
48 | Then Data1: AC91F6A6\r | |
49 | Data2: C831\r | |
50 | Data3: 4444\r | |
51 | Data4: 4C85E2C1A6950F92\r | |
52 | **/ \r | |
53 | public void bufferToStruct (byte[] dataBuffer){\r | |
54 | if (dataBuffer.length != 16) {\r | |
55 | throw new BuildException ("Buffer is not fitting GUID type!");\r | |
56 | }\r | |
57 | \r | |
58 | data1 = (int)(dataBuffer[3]& 0xff);\r | |
59 | data1 = data1 << 8; \r | |
60 | data1 = (int)data1 | (dataBuffer[2]& 0xff); \r | |
61 | data1 = ((data1 << 8) & 0xffff00) | (dataBuffer[1]& 0xff);\r | |
62 | data1 = ((data1 << 8) & 0xffffff00) | (dataBuffer[0]& 0xff);\r | |
63 | \r | |
64 | \r | |
65 | data2 = (short) (dataBuffer[5] & 0xff);\r | |
66 | data2 = (short)((data2 << 8) | (dataBuffer[4]& 0xff));\r | |
67 | \r | |
68 | data3 = (short)(dataBuffer[7] & 0xff);\r | |
69 | data3 = (short)((data3 << 8) | (dataBuffer[6] & 0xff));\r | |
70 | \r | |
71 | for (int i = 0; i < 8; i++) {\r | |
72 | data4[i] = dataBuffer[i+8];\r | |
73 | }\r | |
74 | \r | |
75 | }\r | |
76 | \r | |
77 | /**\r | |
78 | structToBuffer\r | |
79 | \r | |
80 | This function is to store ffsHeader class member to buffer.\r | |
81 | \r | |
82 | @return Byte buffer which contained the ffsHeader class member\r | |
83 | **/\r | |
84 | public byte[] structToBuffer (){\r | |
85 | \r | |
86 | byte[] buffer = new byte [16]; \r | |
87 | \r | |
88 | buffer[3] = (byte)(data1 & 0x000000ff);\r | |
89 | buffer[2] = (byte)((data1 & 0x0000ff00)>> 8);\r | |
90 | buffer[1] = (byte)((data1 & 0x00ff0000)>> 16); \r | |
91 | buffer[0] = (byte)((data1 & 0xff000000)>> 24);\r | |
92 | \r | |
93 | buffer[5] = (byte)(data2 & 0x00ff);\r | |
94 | buffer[4] = (byte)((data2 & 0xff00)>> 8);\r | |
95 | \r | |
96 | buffer[7] = (byte)(data3 & 0x00ff);\r | |
97 | buffer[6] = (byte)((data3 & 0xff00)>> 8);\r | |
98 | \r | |
99 | for (int i = 8; i < 16; i++) {\r | |
100 | buffer[i] = data4[i-8];\r | |
101 | } \r | |
102 | return buffer;\r | |
103 | }\r | |
104 | \r | |
105 | \r | |
106 | }\r | |
107 | \r | |
108 | /**\r | |
109 | integrityCheckSum\r | |
110 | \r | |
111 | This class is used to record the struct of checksum.\r | |
112 | **/\r | |
966ea827 | 113 | public class IntegrityCheckSum {\r |
878ddf1f | 114 | byte header;\r |
115 | byte file;\r | |
116 | }\r | |
117 | \r | |
118 | ///\r | |
119 | /// Guid\r | |
120 | ///\r | |
121 | FfsGuid name = new FfsGuid();\r | |
122 | \r | |
123 | ///\r | |
124 | /// CheckSum\r | |
125 | ///\r | |
966ea827 | 126 | IntegrityCheckSum integrityCheck = new IntegrityCheckSum();\r |
878ddf1f | 127 | \r |
128 | ///\r | |
129 | /// File type\r | |
130 | ///\r | |
131 | byte fileType;\r | |
132 | ///\r | |
133 | /// Ffs attributes.\r | |
134 | ///\r | |
135 | byte ffsAttributes;\r | |
136 | ///\r | |
137 | /// Ffs file size\r | |
138 | ///\r | |
139 | byte[] ffsFileSize = new byte[3];\r | |
140 | ///\r | |
141 | /// Ffs state.\r | |
142 | ///\r | |
143 | byte ffsState;\r | |
144 | \r | |
145 | /**\r | |
146 | structToBuffer\r | |
147 | \r | |
148 | This function is to store FfsHeader class member to buffer.\r | |
149 | \r | |
150 | @return Byte buffer which contained the FfsHeader class member.\r | |
151 | **/\r | |
152 | public byte[] structToBuffer () {\r | |
153 | int i;\r | |
154 | byte[] buffer1; \r | |
155 | byte[] buffer = new byte[24];\r | |
156 | buffer1 = name.structToBuffer();\r | |
157 | \r | |
158 | for (i = 0; i < 16; i++) {\r | |
159 | buffer[i] = buffer1[i];\r | |
160 | }\r | |
161 | \r | |
162 | buffer[16] = integrityCheck.header;\r | |
163 | buffer[17] = integrityCheck.file;\r | |
164 | buffer[18] = fileType;\r | |
165 | buffer[19] = ffsAttributes;\r | |
166 | \r | |
167 | for (i=20; i < 23; i++) {\r | |
168 | buffer[i] = ffsFileSize[i-20];\r | |
169 | }\r | |
170 | \r | |
171 | buffer[23] = ffsState;\r | |
172 | return buffer;\r | |
173 | }\r | |
174 | \r | |
175 | /**\r | |
176 | getSize\r | |
177 | \r | |
178 | This function is to get the size of FfsHeader in byte.\r | |
179 | \r | |
180 | @return The size of FfsHeader.\r | |
181 | **/\r | |
182 | public int getSize(){\r | |
183 | return 24;\r | |
184 | }\r | |
185 | }\r |