import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / masp / asf / core / sec_hdr.c
1 #include "sec_hdr.h"
2
3 /**************************************************************************
4 * INTERNAL VARIABLES
5 **************************************************************************/
6 static SEC_IMG_HEADER_VER sec_ver = UNSET;
7
8 /**************************************************************************
9 * GET VALUE
10 **************************************************************************/
11 uint32 shdr_magic (SEC_IMG_HEADER_U* sec_hdr)
12 {
13 switch(sec_ver)
14 {
15 case SEC_HDR_V1:
16 return sec_hdr->v1.magic_number;
17 case SEC_HDR_V2:
18 return sec_hdr->v2.magic_number;
19 case SEC_HDR_V3:
20 return sec_hdr->v3.magic_number;
21 default:
22 SEC_ASSERT(0);
23 return 0;
24 }
25 }
26
27 uchar* shdr_cust_name (SEC_IMG_HEADER_U* sec_hdr)
28 {
29 switch(sec_ver)
30 {
31 case SEC_HDR_V1:
32 return sec_hdr->v1.cust_name;
33 case SEC_HDR_V2:
34 return sec_hdr->v2.cust_name;
35 case SEC_HDR_V3:
36 return sec_hdr->v3.cust_name;
37 default:
38 SEC_ASSERT(0);
39 return 0;
40 }
41 }
42
43 uint32 shdr_cust_name_len (SEC_IMG_HEADER_U* sec_hdr)
44 {
45 switch(sec_ver)
46 {
47 case SEC_HDR_V1:
48 return sizeof(sec_hdr->v1.cust_name);
49 case SEC_HDR_V2:
50 return sizeof(sec_hdr->v2.cust_name);
51 case SEC_HDR_V3:
52 return sizeof(sec_hdr->v3.cust_name);
53 default:
54 SEC_ASSERT(0);
55 return 0;
56 }
57 }
58
59 uint32 shdr_img_ver (SEC_IMG_HEADER_U* sec_hdr)
60 {
61 switch(sec_ver)
62 {
63 case SEC_HDR_V1:
64 return sec_hdr->v1.image_version;
65 case SEC_HDR_V2:
66 return sec_hdr->v2.image_version;
67 case SEC_HDR_V3:
68 return sec_hdr->v3.image_version;
69 default:
70 SEC_ASSERT(0);
71 return 0;
72 }
73 }
74
75 uint32 shdr_img_len (SEC_IMG_HEADER_U* sec_hdr)
76 {
77 switch(sec_ver)
78 {
79 case SEC_HDR_V1:
80 return sec_hdr->v1.image_length;
81 case SEC_HDR_V2:
82 return sec_hdr->v2.image_length;
83 case SEC_HDR_V3:
84 return sec_hdr->v3.image_length;
85 default:
86 SEC_ASSERT(0);
87 return 0;
88 }
89 }
90
91 uint32 shdr_img_offset (SEC_IMG_HEADER_U* sec_hdr)
92 {
93 switch(sec_ver)
94 {
95 case SEC_HDR_V1:
96 return sec_hdr->v1.image_offset;
97 case SEC_HDR_V2:
98 return sec_hdr->v2.image_offset;
99 case SEC_HDR_V3:
100 return sec_hdr->v3.image_offset;
101 default:
102 SEC_ASSERT(0);
103 return 0;
104 }
105 }
106
107 uint32 shdr_sign_len (SEC_IMG_HEADER_U* sec_hdr)
108 {
109 switch(sec_ver)
110 {
111 case SEC_HDR_V1:
112 return sec_hdr->v1.sign_length;
113 case SEC_HDR_V2:
114 return sec_hdr->v2.sign_length;
115 case SEC_HDR_V3:
116 return sec_hdr->v3.sign_length;
117 default:
118 SEC_ASSERT(0);
119 return 0;
120 }
121 }
122
123 uint32 shdr_sign_offset (SEC_IMG_HEADER_U* sec_hdr)
124 {
125 switch(sec_ver)
126 {
127 case SEC_HDR_V1:
128 return sec_hdr->v1.sign_offset;
129 case SEC_HDR_V2:
130 return sec_hdr->v2.sign_offset;
131 case SEC_HDR_V3:
132 return sec_hdr->v3.sign_offset;
133 default:
134 SEC_ASSERT(0);
135 return 0;
136 }
137 }
138
139 uint32 shdr_sig_len (SEC_IMG_HEADER_U* sec_hdr)
140 {
141 switch(sec_ver)
142 {
143 case SEC_HDR_V1:
144 return sec_hdr->v1.signature_length;
145 case SEC_HDR_V2:
146 return sec_hdr->v2.signature_length;
147 case SEC_HDR_V3:
148 return sec_hdr->v3.signature_length;
149 default:
150 SEC_ASSERT(0);
151 return 0;
152 }
153 }
154
155 uint32 shdr_sig_offset (SEC_IMG_HEADER_U* sec_hdr)
156 {
157 switch(sec_ver)
158 {
159 case SEC_HDR_V1:
160 return sec_hdr->v1.signature_offset;
161 case SEC_HDR_V2:
162 return sec_hdr->v2.signature_offset;
163 case SEC_HDR_V3:
164 return sec_hdr->v3.signature_offset;
165 default:
166 SEC_ASSERT(0);
167 return 0;
168 }
169 }
170
171 /**************************************************************************
172 * SET VALUE
173 **************************************************************************/
174 void set_shdr_magic (SEC_IMG_HEADER_U* sec_hdr, uint32 val)
175 {
176 switch(sec_ver)
177 {
178 case SEC_HDR_V1:
179 sec_hdr->v1.magic_number= val;
180 break;
181 case SEC_HDR_V2:
182 sec_hdr->v2.magic_number = val;
183 break;
184 case SEC_HDR_V3:
185 sec_hdr->v3.magic_number = val;
186 default:
187 SEC_ASSERT(0);
188 }
189 }
190
191 void set_shdr_img_ver (SEC_IMG_HEADER_U* sec_hdr, uint32 ver)
192 {
193 switch(sec_ver)
194 {
195 case SEC_HDR_V1:
196 sec_hdr->v1.image_version = ver;
197 break;
198 case SEC_HDR_V2:
199 sec_hdr->v2.image_version = ver;
200 break;
201 case SEC_HDR_V3:
202 sec_hdr->v3.image_version = ver;
203 default:
204 SEC_ASSERT(0);
205 }
206 }
207
208 void set_shdr_cust_name (SEC_IMG_HEADER_U* sec_hdr, uchar* name, uint32 len)
209 {
210 switch(sec_ver)
211 {
212 case SEC_HDR_V1:
213 memset(sec_hdr->v1.cust_name,0,sizeof(sec_hdr->v1.cust_name));
214 mcpy(sec_hdr->v1.cust_name,name,len);
215 break;
216 case SEC_HDR_V2:
217 memset(sec_hdr->v2.cust_name,0,sizeof(sec_hdr->v2.cust_name));
218 mcpy(sec_hdr->v2.cust_name,name,len);
219 break;
220 case SEC_HDR_V3:
221 memset(sec_hdr->v3.cust_name,0,sizeof(sec_hdr->v3.cust_name));
222 mcpy(sec_hdr->v3.cust_name,name,len);
223 break;
224 default:
225 SEC_ASSERT(0);
226 }
227 }
228
229 void set_shdr_sign_len (SEC_IMG_HEADER_U* sec_hdr, uint32 val)
230 {
231 switch(sec_ver)
232 {
233 case SEC_HDR_V1:
234 sec_hdr->v1.sign_length = val;
235 break;
236 case SEC_HDR_V2:
237 sec_hdr->v2.sign_length = val;
238 break;
239 case SEC_HDR_V3:
240 sec_hdr->v3.sign_length = val;
241 break;
242 default:
243 SEC_ASSERT(0);
244 }
245 }
246
247 void set_shdr_sign_offset (SEC_IMG_HEADER_U* sec_hdr, uint32 val)
248 {
249 switch(sec_ver)
250 {
251 case SEC_HDR_V1:
252 sec_hdr->v1.sign_offset = val;
253 break;
254 case SEC_HDR_V2:
255 sec_hdr->v2.sign_offset = val;
256 break;
257 case SEC_HDR_V3:
258 sec_hdr->v3.sign_offset = val;
259 break;
260 default:
261 SEC_ASSERT(0);
262 }
263 }
264
265 /**************************************************************************
266 * VERSION
267 **************************************************************************/
268
269 SEC_IMG_HEADER_VER get_shdr_ver (void)
270 {
271 switch(sec_ver)
272 {
273 case SEC_HDR_V1:
274 case SEC_HDR_V2:
275 case SEC_HDR_V3:
276 return sec_ver;
277 default:
278 SEC_ASSERT(0);
279 return 0;
280 }
281 }
282
283 void set_shdr_ver (SEC_IMG_HEADER_VER ver)
284 {
285 switch(ver)
286 {
287 case SEC_HDR_V1:
288 case SEC_HDR_V2:
289 case SEC_HDR_V3:
290 sec_ver = ver;
291 break;
292 default:
293 SEC_ASSERT(0);
294 }
295 }