blob: cbac1dfd5571778c25e8bc2553d64d1f02f8fc4f [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * nvram_internal.h
40 *
41 * Project:
42 * --------
43 * MT6208
44 *
45 * Description:
46 * ------------
47 * This file is intends for NVRAM.
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 *==============================================================================
54 * HISTORY
55 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56 *------------------------------------------------------------------------------
57 * removed!
58 *
59 * removed!
60 * removed!
61 * removed!
62 * removed!
63 *
64 * removed!
65 * removed!
66 * removed!
67 * removed!
68 * removed!
69 * removed!
70 *
71 * removed!
72 * removed!
73 * removed!
74 * removed!
75 * removed!
76 * removed!
77 * removed!
78 * removed!
79 *
80 * removed!
81 * removed!
82 * removed!
83 *
84 * removed!
85 * removed!
86 * removed!
87 *
88 * removed!
89 * removed!
90 * removed!
91 *
92 * removed!
93 * removed!
94 *
95 * removed!
96 * removed!
97 *
98 * removed!
99 * removed!
100 * removed!
101 *
102 * removed!
103 * removed!
104 * removed!
105 *
106 * removed!
107 * removed!
108 * removed!
109 *
110 * removed!
111 * removed!
112 * removed!
113 *
114 * removed!
115 * removed!
116 * removed!
117 *
118 * removed!
119 * removed!
120 * removed!
121 *
122 * removed!
123 * removed!
124 * removed!
125 *
126 * removed!
127 * removed!
128 * removed!
129 *
130 * removed!
131 * removed!
132 * removed!
133 *
134 * removed!
135 * removed!
136 * removed!
137 *
138 * removed!
139 * removed!
140 * removed!
141 *
142 * removed!
143 * removed!
144 * removed!
145 *
146 *------------------------------------------------------------------------------
147 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
148 *==============================================================================
149 *******************************************************************************/
150
151#ifndef NVRAM_INTERNAL_H
152#define NVRAM_INTERNAL_H
153
154#include "nvram_config.h"
155#include "nvram_enums.h"
156
157/********************************************************************************
158* *
159* NVRAM internal LID *
160* *
161********************************************************************************/
162/*
163NVRAM_EF_SYS_SIZE Equal NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_SIZE,
164if modify the NVRAM_EF_SYS_SIZE,must modify NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_SIZE
165*/
166
167#define NVRAM_EF_SYS_SIZE 34
168#define NVRAM_EF_SYS_TOTAL 4
169
170#define NVRAM_EF_BRANCH_VERNO_SIZE NVRAM_EF_SYS_SIZE
171#define NVRAM_EF_BRANCH_VERNO_TOTAL NVRAM_EF_SYS_TOTAL
172
173#define NVRAM_EF_FLAVOR_VERNO_SIZE NVRAM_EF_SYS_SIZE
174#define NVRAM_EF_FLAVOR_VERNO_TOTAL NVRAM_EF_SYS_TOTAL
175
176#define NVRAM_EF_BUILD_TIME_SIZE NVRAM_EF_SYS_SIZE
177#define NVRAM_EF_BUILD_TIME_TOTAL NVRAM_EF_SYS_TOTAL
178
179#define NVRAM_EF_CUSTPACK_VERNO_SIZE NVRAM_EF_SYS_SIZE
180#define NVRAM_EF_CUSTPACK_VERNO_TOTAL NVRAM_EF_SYS_TOTAL
181
182#define NVRAM_EF_SECUPACK_VERNO_SIZE sizeof(kal_uint16)
183#define NVRAM_EF_SECUPACK_VERNO_TOTAL NVRAM_EF_SYS_TOTAL
184
185//#define NVRAM_EF_NVRAM_LOCK_SIZE 16
186//#define NVRAM_EF_NVRAM_LOCK_TOTAL 1
187
188#define NVRAM_EF_READ_RESERVED_TOTAL 1
189#define NVRAM_EF_READ_RESERVED_SIZE 1
190
191/********************************************************************************
192* *
193* NVRAM state *
194* *
195********************************************************************************/
196/* State definitions */
197typedef enum
198{
199 NVRAM_STATE_NULL,
200 NVRAM_STATE_NOT_READY,
201 NVRAM_STATE_READY
202} nvram_state_enum;
203
204
205/********************************************************************************
206* *
207* NVRAM Boot-up type *
208* *
209********************************************************************************/
210typedef enum
211{
212 NVRAM_FIRST_BOOTUP,
213 NVRAM_NORMAL_BOOTUP,
214 NVRAM_NORMAL_SUCCESS_BOOTUP
215}nvram_bootup_enum;
216/********************************************************************************
217* *
218* NVRAM SW status *
219* *
220********************************************************************************/
221#define NVRAM_SW_VERSION_CHANGE 0x0001
222#define NVRAM_SW_BRANCH_CHANGE 0x0002
223#define NVRAM_SW_CUSTPACK_CHANGE 0x0004
224#define NVRAM_SW_EMPTY_FAT 0x0008
225#define NVRAM_SW_SOME_CORRUPT 0x0010
226#define NVRAM_SW_PACKAGE_CHANGE 0x0020
227#define NVRAM_SW_SECUPACK_CHANGE 0x0100
228#define NVRAM_SW_EMPTY_SDS 0x0200
229
230/********************************************************************************
231* *
232* NVRAM storage type *
233* *
234********************************************************************************/
235#define NVRAM_STORAGE_TYPE_FAT 0
236#define NVRAM_STORAGE_TYPE_OTP 1
237#define NVRAM_STORAGE_TYPE_SECRO 2
238
239
240/********************************************************************************
241* *
242* Attribute *
243* *
244********************************************************************************/
245
246#define NVRAM_IS_ATTR_MULTI_DEFAULT(x) ((x) & NVRAM_ATTR_MULTI_DEFAULT)
247#define NVRAM_IS_ATTR_AVERAGE(x) ((x) & NVRAM_ATTR_AVERAGE)
248#define NVRAM_IS_ATTR_WRITEPROTECT(x) ((x) & NVRAM_ATTR_WRITEPROTECT)
249#define NVRAM_IS_ATTR_MULTIPLE(x) ((x) & NVRAM_ATTR_MULTIPLE)
250#define NVRAM_IS_ATTR_CONFIDENTIAL(x) ((x) & NVRAM_ATTR_CONFIDENTIAL)
251#define NVRAM_IS_ATTR_RAW_DATA(x) ((x) & NVRAM_ATTR_RAW_DATA)
252#define NVRAM_IS_ATTR_RESERVE_BACKWARD(x)((x) & NVRAM_ATTR_RESERVE_BACKWARD)
253#define NVRAM_IS_ATTR_FAULT_ASSERT(x) ((x) & NVRAM_ATTR_FAULT_ASSERT)
254#define NVRAM_IS_ATTR_OTA_RESET(x) ((x) & NVRAM_ATTR_OTA_RESET)
255#define NVRAM_IS_ATTR_GEN_DEFAULT(x) ((x) & NVRAM_ATTR_GEN_DEFAULT)
256#define NVRAM_TURNOFF_ATTR_MULTIPLE(x) ((x) &= ~(NVRAM_ATTR_MULTIPLE))
257#define NVRAM_TURNOFF_ATTR_AUTORECOVER(x) ((x) &= ~(NVRAM_ATTR_AUTO_RECOVER))
258#define NVRAM_IS_ATTR_MSP(x) ((x) & NVRAM_ATTR_MSP)
259#define NVRAM_IS_ATTR_RING(x) ((x) & NVRAM_ATTR_RING)
260#ifdef __NV_CHKSUM_ENHANCE__
261#define NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(x) ((x) & NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM)
262#endif
263
264#ifdef __NVRAM_PSEUDO_MERGE__
265#define NVRAM_IS_ATTR_PACKAGE(x) ((x) & NVRAM_ATTR_PACKAGE)
266#else
267#define NVRAM_IS_ATTR_PACKAGE(x) (0)
268#endif
269
270#ifdef __NVRAM_BACKUP_DISK_FAT__
271#define NVRAM_IS_ATTR_BACKUP_FAT(x) ((x) & NVRAM_ATTR_BACKUP_FAT)
272#else
273#define NVRAM_IS_ATTR_BACKUP_FAT(x) (0)
274#endif
275
276#ifdef __NVRAM_BACKUP_DISK_RAW__
277#define NVRAM_IS_ATTR_BACKUP_RAW(x) ((x) & NVRAM_ATTR_BACKUP_RAW)
278#else
279#define NVRAM_IS_ATTR_BACKUP_RAW(x) (0)
280#endif
281
282#ifdef __NVRAM_COMPRESS_SUPPORT__
283#define NVRAM_IS_ATTR_ZIP_DEFAULT(x) ((x) & NVRAM_ATTR_ZIP_DEFAULT)
284#define NVRAM_IS_ATTR_NOT_ZIP_DEFAULT(x) ((x) & NVRAM_ATTR_NOT_ZIP_DEFAULT)
285#else
286#define NVRAM_IS_ATTR_ZIP_DEFAULT(x) (0)
287#define NVRAM_IS_ATTR_NOT_ZIP_DEFAULT(x) (1)
288#endif
289
290/********************************************************************************
291* *
292* Category *
293* *
294********************************************************************************/
295
296#define NVRAM_IS_CATEGORY_INTERNAL(x) ((x) & NVRAM_CATEGORY_INTERNAL)
297#define NVRAM_IS_CATEGORY_CALIBRAT(x) ((x) & NVRAM_CATEGORY_CALIBRAT)
298#define NVRAM_IS_CATEGORY_IMPORTANT(x) ((x) & NVRAM_CATEGORY_IMPORTANT)
299#define NVRAM_IS_CATEGORY_SECUPACK(x) ((x) & NVRAM_CATEGORY_SECUPACK)
300#define NVRAM_IS_CATEGORY_RESERVED(x) ((x) & NVRAM_CATEGORY_RESERVED) /* for __NVRAM_READ_RESERVED_FILE__ feature */
301
302#define NVRAM_IS_CATEGORY_CUSTPACK(x) ((x) & NVRAM_CATEGORY_CUSTPACK)
303#define NVRAM_IS_CATEGORY_SECUPACK(x) ((x) & NVRAM_CATEGORY_SECUPACK)
304#define NVRAM_IS_CATEGORY_FUNC_DEFAULT(x) ((x) & NVRAM_CATEGORY_FUNC_DEFAULT)
305
306#ifdef __NVRAM_OTP__
307#define NVRAM_IS_CATEGORY_OTP(x) ((x) & NVRAM_CATEGORY_OTP)
308#else
309#define NVRAM_IS_CATEGORY_OTP(x) (0)
310#endif
311
312#if defined(__CCCIFS_SUPPORT__)
313#define NVRAM_IS_CATEGORY_IMPORTANT_L4(x) ((x) & NVRAM_CATEGORY_IMPORTANT_L4)
314#define NVRAM_IS_CATEGORY_IMPORTANT_L1(x) ((x) & NVRAM_CATEGORY_IMPORTANT_L1)
315#else
316#define NVRAM_IS_CATEGORY_IMPORTANT_L4(x) (0)
317#define NVRAM_IS_CATEGORY_IMPORTANT_L1(x) (0)
318#endif
319
320#ifdef __NVRAM_CUSTOM_DISK__
321#define NVRAM_IS_CATEGORY_CUSTOM_DISK(x) (x & NVRAM_CATEGORY_CUSTOM_DISK)
322#else
323#define NVRAM_IS_CATEGORY_CUSTOM_DISK(x) (0)
324#endif
325
326#ifdef __NVRAM_CUSTOM_SENSITIVE__
327#define NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(x) (x & NVRAM_CATEGORY_CUSTOM_SENSITIVE)
328#else
329#define NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(x) (0)
330#endif
331
332#ifdef __NVRAM_SECURE_DATA_STORAGE__
333#define NVRAM_IS_CATEGORY_BACKUP_SDS(x) ((x) & NVRAM_CATEGORY_BACKUP_SDS)
334#else
335#define NVRAM_IS_CATEGORY_BACKUP_SDS(x) (0)
336#endif
337
338#define NVRAM_IS_CATEGORY_FACTORY_RESET(x) (!((x) & (NVRAM_CATEGORY_IMPORTANT_L4 | NVRAM_CATEGORY_IMPORTANT_L1)))
339#define NVRAM_IS_CATEGORY_IN_BIN_REGION(x) (x & (NVRAM_CATEGORY_CALIBRAT | NVRAM_CATEGORY_IMPORTANT))
340
341/********************************************************************************
342* *
343* NVRAM folder enums *
344* *
345********************************************************************************/
346typedef enum
347{
348 NVRAM_FOLDER_BEGIN,
349 NVRAM_NVD_DATA = NVRAM_FOLDER_BEGIN,
350#ifdef __NVRAM_MULTI_FOLDERS__
351 NVRAM_NVD_CORE,
352 NVRAM_NVD_CALI,
353 NVRAM_NVD_IMPT,
354 #if defined(__CCCIFS_SUPPORT__)
355 NVRAM_NVD_IMPNT,
356 #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
357 NVRAM_NVD_IMPNT2,
358 #endif
359 #endif
360 NVRAM_NVD_BACKUP,
361 #ifdef __NVRAM_CUSTOM_SENSITIVE__
362 NVRAM_NVD_CUST,
363 #endif
364#endif
365 NVRAM_FOLDER_TOTAL
366}nvram_folder_enum;
367
368#ifdef __SYSDRV_BACKUP_DISK_FAT__
369#define NVRAM_NVD_BAK (NVRAM_FOLDER_TOTAL + 1)
370#endif
371
372/********************************************************************************
373* *
374* NVRAM OTA feature *
375* *
376********************************************************************************/
377#define NVRAM_OTA_RESERVE_CNT 5
378
379/********************************************************************************
380* *
381* Misc *
382* *
383********************************************************************************/
384#ifdef __NVRAM_READ_RESERVED_FILE__
385typedef kal_char NVRAM_FILE_NAME[NVRAM_FILE_LEN + 1 + FILE_RESERVED_LEN];
386#else
387typedef kal_char NVRAM_FILE_NAME[NVRAM_FILE_LEN + 1];
388#endif
389typedef kal_wchar NVRAM_FULL_PATH[NVRAM_MAX_PATH_LEN];
390typedef struct {
391 kal_wchar fileprefix[FILE_PREFIX_LEN];
392 kal_wchar multiple[1];
393 kal_wchar fileverno[FILE_VERNO_LEN];
394 kal_wchar separator[1];
395 kal_wchar record[4];
396 kal_wchar size[4];
397} NVRAM_OTA_FILE_NAME;
398
399#if defined(__NVRAM_DEFVAL_CHANGE_RESET__) || defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
400/* (NVRAM_IS_ATTR_GEN_DEFAULT(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_GEN_DEFAULT(ldi->attr)) */
401#define NVRAM_IS_ATTRIBUTE_CHANGE(nv_header, ldi) \
402 ((NVRAM_IS_ATTR_MULTI_DEFAULT(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_MULTI_DEFAULT(ldi->attr)) || \
403 (NVRAM_IS_ATTR_CONFIDENTIAL(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_CONFIDENTIAL(ldi->attr)) || \
404 (NVRAM_IS_ATTR_MULTIPLE(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_MULTIPLE(ldi->attr)) || \
405 (NVRAM_IS_ATTR_MSP(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_MSP(ldi->attr)) || \
406 (NVRAM_IS_ATTR_RING(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_RING(ldi->attr)) || \
407 (NVRAM_IS_ATTR_RAW_DATA(nv_header.nv_ota_header.ldi_attr) != NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) || \
408 (NVRAM_IS_CATEGORY_FUNC_DEFAULT(nv_header.nv_ota_header.ldi_category) != NVRAM_IS_CATEGORY_FUNC_DEFAULT(ldi->category)))
409#endif
410
411#if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
412#define NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi) \
413 ( (ldi->LID != NVRAM_EF_SYS_LID) && \
414 (ldi->LID != NVRAM_EF_NVRAM_LOCK_LID) && \
415 (ldi->LID != NVRAM_EF_READ_RESERVED_LID) && \
416 !(NVRAM_IS_ATTR_OTA_RESET(ldi->attr)) && \
417 !(NVRAM_IS_CATEGORY_INTERNAL(ldi->category)) && \
418 !(NVRAM_IS_CATEGORY_CALIBRAT(ldi->category)) && \
419 !(NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)) && \
420 !(NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) && \
421 !(NVRAM_IS_CATEGORY_FUNC_DEFAULT(ldi->category)) )
422#endif
423
424#if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
425#define NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi) \
426 ( (ldi->LID != NVRAM_EF_SYS_LID) && \
427 (ldi->LID != NVRAM_EF_NVRAM_LOCK_LID) && \
428 (ldi->LID != NVRAM_EF_READ_RESERVED_LID) && \
429 !(NVRAM_IS_ATTR_OTA_RESET(ldi->attr)) && \
430 !(NVRAM_IS_CATEGORY_INTERNAL(ldi->category)) && \
431 !(NVRAM_IS_CATEGORY_CALIBRAT(ldi->category)) && \
432 !(NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)) && \
433 !(NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) )
434#endif
435
436
437/* AES 16 byte alignment, must be power of 2*/
438#if 0
439/* under construction !*/
440/* under construction !*/
441/* under construction !*/
442/* under construction !*/
443/* under construction !*/
444/* under construction !*/
445/* under construction !*/
446#endif
447
448#endif /* NVRAM_INTERNAL_H */