[Feature][Modem]Update MTK MODEM V1.6 baseline version: MOLY.NR15.R3.MD700.IVT.MP1MR3.MP.V1.6

MTK modem version: MT2735_IVT_MOLY.NR15.R3.MD700.IVT.MP1MR3.MP.V1.6.tar.gz
RF  modem version: NA

Change-Id: I45a4c2752fa9d1a618beacd5d40737fb39ab64fb
diff --git a/mcu/service/nvram/src/nvram_cache.c b/mcu/service/nvram/src/nvram_cache.c
new file mode 100644
index 0000000..f733260
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_cache.c
@@ -0,0 +1,3307 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+#include <string.h>
+    
+#include "kal_general_types.h"
+#include "kal_internal_api.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+    
+#include "syscomp_config.h"
+#include "task_config.h"
+#include "sysconf_statistics.h"     /* stack_statistics_struct */
+#include "custom_em.h"
+    /* Factory mode, should not send ADC calibration data to BMT  */
+#ifdef __MULTI_BOOT__
+#include "multiboot_config.h"
+#include "intrCtrl.h"               /* INT_BootMode */
+#endif /* __MULTI_BOOT__ */
+    
+#ifdef __CCCIFS_SUPPORT__
+#include "ccci.h"
+#endif
+    
+#if defined(__MTK_TARGET__)
+#include "SST_secure.h"
+#endif
+    
+#include "fs_type.h"                /* FS_HANDLE */
+#include "fs_func.h"                /* FS_Delete */
+#include "fs_errcode.h"             /* FS_NO_ERROR */
+#include "ex_item.h"                /* EX_LOG_T */
+
+#include "tst_msgid.h"
+#include "sbp_public_utility.h"
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+
+#include "nvram_cache_interface.h"
+#ifdef __NV_CHKSUM_ENHANCE__
+#include "nvram_chksum_algorithm.h"
+#endif
+
+
+#if defined(__HIF_CCCI_SUPPORT__)
+#include "ccci_if.h"
+#endif
+#include "us_timer.h"
+#include "ex_public.h"
+
+#if defined(__MTK_TARGET__)
+#include "ostd_public.h"
+#endif
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+extern kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi);
+/*extern nvram_errno_enum nvram_read_data_item_multiple(
+                            nvram_ltable_entry_struct *ldi,
+                            kal_uint32 rec_index,
+                            kal_uint16 rec_amount,
+                            kal_uint8 *buffer,
+                            kal_uint32 buffer_size);
+*/
+
+extern nvram_drv_status_enum nvram_drv_fat_write_multRec(nvram_ltable_entry_struct *ldi,
+                                          kal_char   *nvramname,
+                                          nvram_folder_enum  nvram_folder,
+                                          kal_uint32 file_offset,
+                                          kal_uint16 rec_index,
+                                          kal_uint16 rec_amount,
+                                          kal_uint32 rec_size,
+                                          const kal_uint8 *buffer,
+                                          kal_bool initialize);
+
+extern kal_int32 nvram_get_defval_chksum_index(nvram_lid_enum LID);
+extern nvram_folder_enum nvram_query_folder_index_ex(nvram_category_enum category, kal_bool first_copy);
+extern void nvram_util_make_lid_filename(nvram_ltable_entry_struct *ldi, NVRAM_FILE_NAME nvramname, kal_bool first_copy);
+kal_uint8 const * nvram_get_lid_default_value_to_write(
+                                nvram_ltable_entry_struct *ldi, 
+                                kal_uint16 rec_index,
+                                kal_uint8 *buffer, 
+                                kal_uint32 buffer_size);
+
+extern module_type stack_get_active_module_id( void );
+
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+kal_bool g_nvram_cache_ready = KAL_FALSE;
+kal_bool g_nvram_cache_SHM_support = KAL_FALSE;
+
+
+kal_mutexid g_nvram_cache_mutex = NULL;
+
+static kal_int32 nvram_cache_last_err;
+static kal_uint32 nvram_cache_last_line;
+extern kal_bool bResetNvramData;
+
+kal_uint8* g_nvcache_base_address = NULL;
+kal_uint32 g_nvcache_memory_size = 0;
+
+#if ((!defined(__MTK_TARGET__)) && (!defined(__UE_SIMULATOR__)))
+ltable_type assgn_ltable = {0};
+nvram_ltable_entry_struct *assgn_logical_data_item_table = NULL;
+extern nvram_ltable_entry_struct _nvram_ltable_start;
+extern nvram_ltable_entry_struct the_nvram_ltable_end;
+#endif
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+
+/*****************************************************************************
+ * FUNCTION
+ *  get_lid_cache_index_item
+ * DESCRIPTION
+ *  get cache LID from cache table 
+ * PARAMETERS
+ *  ldi             [IN]
+ *  cache_ldi  [OUT]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool get_lid_cache_index_item(nvram_lid_enum LID, nvram_lid_cache_table_struct** cache_ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool ret_val = KAL_FALSE;
+    kal_uint32 low = 0;
+    kal_uint32 mid; 
+    kal_uint32 high = cache_info_header.cache_lid_num -1;
+    while (low<=high) {
+
+        mid = low + ((high - low)/2);
+        if(cache_info_table[mid].LID < LID) {
+            low = mid +1;
+        }else if(cache_info_table[mid].LID > LID) {
+            high = mid -1;
+        }else {
+            if (cache_ldi) {
+                *cache_ldi = &cache_info_table[mid];
+            }
+            ret_val = KAL_TRUE;
+            break;
+        }
+    }
+
+    return ret_val;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  get_lid_cache_base_address
+ * DESCRIPTION
+ *  get LID cache region base address
+ * PARAMETERS
+ *  ldi             [IN]
+ * RETURNS
+ *  address
+ *****************************************************************************/
+nvram_errno_enum get_lid_cache_base_address(nvram_ltable_entry_struct* ldi, kal_uint32* cache_offset)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_bool result = KAL_FALSE;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__,ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_1, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    *cache_offset = (kal_uint32)(g_nvcache_base_address + ((cache_info_header.cache_table_offset) + cache_ldi->cache_offset));
+    return NVRAM_IO_ERRNO_OK;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  get_lid_record_cache_offset
+ * DESCRIPTION
+ *  get LID record cache region address
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  section_size [IN]
+ * RETURNS
+ *  record cache address
+ *****************************************************************************/ 
+nvram_errno_enum get_lid_record_cache_offset(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint32 section_size, kal_uint32* cache_offset)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_bool result = KAL_FALSE;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x,attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s,fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X,attr:0x%08X\r\n",ldi->LID, ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s,fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_2, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    if (rec_index == 0) {
+        *cache_offset = (kal_uint32)(g_nvcache_base_address + ((cache_info_header.cache_table_offset) + cache_ldi->cache_offset));
+        return NVRAM_IO_ERRNO_OK;
+    }else{
+        *cache_offset = (kal_uint32)(g_nvcache_base_address + (((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + NVRAM_LDI_HEADER_SIZE) + (rec_index-1) * section_size));
+        return NVRAM_IO_ERRNO_OK;
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_data_to_cache
+ * DESCRIPTION
+ *  write data to cache
+ * PARAMETERS
+ *  ldi             [IN]
+ *  src_buffer  [IN]
+ *  size    [IN]
+ *  cache_offset    [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+nvram_errno_enum nvram_write_data_to_cache(nvram_ltable_entry_struct* ldi, void* src_buffer, kal_uint32 size, kal_uint32 cache_offset)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint8* dest_buffer = NULL;  
+    kal_bool result = KAL_FALSE;
+    kal_uint32 cache_temp_addr = 0;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_3, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    cache_temp_addr = (kal_uint32)(g_nvcache_base_address + (cache_info_header.cache_table_offset + cache_ldi->cache_offset + cache_ldi->file_length));
+    if(cache_temp_addr < (cache_offset + size))
+    {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+        kal_prompt_trace(MOD_NVRAM, "NVCACHE WRITE SHM CROSS BORDE:0x%x < 0x%x\n\r", cache_temp_addr, (cache_offset + size));
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)cache_temp_addr, NVRAM_ERROR_LOC_NVCACHE_WRITE_SHM_CROSS_BORDER, ldi->LID);
+    }
+    dest_buffer = (kal_uint8*)cache_offset;
+    kal_mem_cpy((void *)dest_buffer, src_buffer, size);
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return NVRAM_IO_ERRNO_OK;
+
+}
+ 
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_from_cache
+ * DESCRIPTION
+ *  read data from cache
+ * PARAMETERS
+ *  ldi             [IN]
+ *  nvram_param  [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/ 
+nvram_errno_enum nvram_read_data_from_cache(nvram_ltable_entry_struct* ldi, NVRAM_FS_PARAM_CMPT_T *nvram_param)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_bool result = KAL_FALSE;
+    kal_uint32 cache_temp_addr = 0;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table index\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X category:0x%08X, attr:0x%08X\r\n", ldi->LID, ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_4, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    cache_temp_addr = (kal_uint32)(g_nvcache_base_address + (cache_info_header.cache_table_offset + cache_ldi->cache_offset));
+    if((cache_temp_addr + cache_ldi->file_length) < (cache_temp_addr + nvram_param->Offset + nvram_param->Length))
+    {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+        kal_prompt_trace(MOD_NVRAM, "NVCACHE READ SHM CROSS BORDE:0x%x < 0x%x\n\r", (cache_temp_addr + cache_ldi->file_length), (cache_temp_addr + nvram_param->Offset + nvram_param->Length));
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)cache_temp_addr, NVRAM_ERROR_LOC_NVCACHE_READ_SHM_CROSS_BORDER, ldi->LID);
+    }
+    kal_mem_cpy((void *)nvram_param->DataPtr, (void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + nvram_param->Offset)), nvram_param->Length);
+    *(nvram_param->Read) = nvram_param->Length;
+    *(nvram_param->FileSize) = cache_ldi->file_length;
+    nvram_param->ret[0] = nvram_param->opid_map;
+    nvram_param->ret[1] = 0;
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_from_cache
+ * DESCRIPTION
+ *  read data from cache
+ * PARAMETERS
+ *  ldi             [IN]
+ *  nvram_param  [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/ 
+kal_bool nvram_read_header_from_cache(nvram_ltable_entry_struct* ldi, void* buffer, kal_uint32 buffer_size, kal_uint32 cache_offset)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint8* src_buffer = NULL;
+    kal_bool result = KAL_FALSE;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n", ldi->LID, ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_5, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    src_buffer = (kal_uint8*)cache_offset;
+    kal_mem_cpy((void *)buffer, (void *)src_buffer, buffer_size);
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+DECLARE_MIPS32
+static kal_uint16 nvram_cache_data_header_checksum(kal_uint8 *buf, kal_uint32 size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i;
+    kal_uint16 chksum = *(kal_uint16*)buf;
+    kal_uint8 *byte_chksum = (kal_uint8*)&chksum;
+    kal_uint8 value;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    for (i = 0; i < size; i++)
+    {
+        value = *(buf + i);
+        while(value) {
+            if(value & 0x1) {
+            #if defined(__MTK_TARGET__)
+                __asm__ __volatile__
+                (
+                "rol %0, %0, 1\r\n"
+                ::"r"(chksum)
+                );              
+            #else
+                __asm {ROL [chksum],1};
+            #endif
+            }
+            value >>= 1;
+        }
+    #if defined(__MTK_TARGET__)
+        __asm__ __volatile__
+        (
+        "rol %0, %0, 4\r\n"
+        ::"r"(chksum)
+        );              
+    #else
+        __asm {ROL [chksum],4};
+    #endif
+
+        *byte_chksum += *(buf + i);
+    }
+    
+    return chksum;
+}
+
+kal_uint32 nvram_cache_appendix_header_offset(nvram_ltable_entry_struct *ldi)
+{
+    kal_uint32 size = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if ((ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        || (ldi->attr & NVRAM_ATTR_MSP)
+        #endif
+    ){  /* 16 byte alignment */ 
+        size = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size) + ldi->size + nvram_chksum_size;
+    }
+    else {
+        size = (ldi->size + nvram_chksum_size);
+    }
+    size = size * ldi->total_records;
+    return (NVRAM_LDI_HEADER_SIZE + size);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_prepare_data
+ * DESCRIPTION
+ *  copy data into buffer
+ * PARAMETERS
+ *  source:             [IN]    source data
+ *  offset:             [IN]    offset in data
+ *  buffer:             [OUT]   buffer
+ *  buffer_size:        [IN]    size of buffer
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_cache_drv_fat_prepare_data(kal_uint8 *buffer, const kal_uint8 *source, kal_uint32 offset, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (source == NVRAM_EF_ZERO_DEFAULT)
+    {
+        nvram_memset(buffer, 0x00, buffer_size);
+    }
+    else if (source == NVRAM_EF_FF_DEFAULT)
+    {
+        nvram_memset(buffer, 0xFF, buffer_size);
+    }
+    else
+    {
+        kal_mem_cpy(buffer, source+offset, buffer_size);
+    }
+}
+
+kal_bool nvram_cache_prepare_ota_header(nvram_ldi_ota_header *ldi_ota_header, nvram_ltable_entry_struct *ldi)
+{
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    kal_int32 chksum_index;
+    #endif
+
+    memcpy(ldi_ota_header->header, "LDI", 4);
+    ldi_ota_header->LID = ldi->LID;
+    ldi_ota_header->ldi_attr = ldi->attr;
+    ldi_ota_header->ldi_category= ldi->category;
+    ldi_ota_header->record_size = ldi->size;
+    ldi_ota_header->total_records = ldi->total_records;
+    //check appendix header offset
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        ldi->append_offset = nvram_cache_appendix_header_offset(ldi);
+    }
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    chksum_index = nvram_get_defval_chksum_index(ldi->LID);
+    if(-1 != chksum_index)
+    {
+        kal_mem_cpy((char *)(ldi_ota_header->defval_chkrst_h), (const char*)(lid_default_value_chksum[chksum_index].chksum), RST_CHKSUM_SIZE-6);
+    }    
+    #endif
+    ldi_ota_header->checksum = nvram_cache_data_header_checksum((kal_uint8*)ldi_ota_header, (NVRAM_LDI_OTA_HEADER_SIZE - sizeof(ldi_ota_header->checksum)));
+    return KAL_TRUE;
+}
+
+kal_bool nvram_cache_prepare_debug_header(nvram_ldi_debug_header *ldi_debug_header, nvram_ltable_entry_struct *ldi)
+{
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    kal_int32 chksum_index;
+    #endif
+
+    ldi_debug_header->last_write_taskID = kal_get_current_task_index();
+    ldi_debug_header->last_write_time = kal_get_systicks();
+    ldi_debug_header->write_times += 1;
+    
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
+    chksum_index = nvram_get_structure_chksum_index(ldi->LID);
+    if(-1 != chksum_index)
+    {
+        kal_mem_cpy((char *)(ldi_debug_header->struct_chkrst), (const char*)(lid_structure_chksum[chksum_index].chksum), RST_CHKSUM_SIZE);
+    }
+    #endif
+
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    chksum_index = nvram_get_defval_chksum_index(ldi->LID);
+    if(-1 != chksum_index)
+    {
+        kal_mem_cpy((char *)(ldi_debug_header->defval_chkrst_l),(const char*)(&(lid_default_value_chksum[chksum_index].chksum[RST_CHKSUM_SIZE-6])), 6);
+    }    
+    #endif
+
+    return KAL_TRUE;
+}
+
+kal_bool nvram_cache_prepare_data_header(nvram_ltable_entry_struct *ldi,kal_uint8 *ldi_hd_buffer)
+{
+    nvram_ldi_ota_header *ldi_ota_header = (nvram_ldi_ota_header*)ldi_hd_buffer;
+    nvram_ldi_debug_header *ldi_debug_header = (nvram_ldi_debug_header*)(ldi_hd_buffer + NVRAM_LDI_OTA_HEADER_SIZE);
+
+    nvram_cache_prepare_ota_header(ldi_ota_header,ldi);
+    nvram_cache_prepare_debug_header(ldi_debug_header, ldi);
+
+    return KAL_TRUE;
+}
+
+kal_uint32 nvram_cache_prepare_appendix_header(nvram_appendix_type_enum type, nvram_ldi_appendix_header *ldi_append_header, nvram_ltable_entry_struct *ldi, kal_uint32 data_offset)
+{
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    memset(ldi_append_header, 0, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+    memcpy(ldi_append_header->header, "APDX", 4);
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if(type == NVRAM_APPEND_TYPE_CHKSUM) {
+        ldi_append_header->type = NVRAM_APPEND_TYPE_CHKSUM;
+        ldi_append_header->data_offset = data_offset;
+        //caculate next data start
+        data_offset = (data_offset + (ldi->total_records * (nvram_chksum_size)));
+        data_offset = NVRAM_MSP_ALIGNMENT_CEILING(data_offset);
+    }
+    else {
+        ldi_append_header->type = NVRAM_APPEND_TYPE_END;
+        data_offset = 0;
+    }
+    ldi_append_header->checksum = nvram_cache_data_header_checksum((kal_uint8*)ldi_append_header, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+    return data_offset;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_reset_header
+ * DESCRIPTION
+ *  reset one LID  header to default value
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/ 
+
+kal_bool nvram_cache_reset_header(nvram_ltable_entry_struct *ldi, nvram_header_section_enum section)
+{
+
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    kal_int32 result = FS_NO_ERROR;
+    kal_int32 backup_file_num = 1;
+    kal_bool mulpiple = KAL_FALSE;
+    kal_bool ret_val = KAL_TRUE;
+    nvram_ldi_header nv_header;
+    nvram_ldi_appendix_header nv_appendix_header;
+    nvram_ldi_ota_header *ldi_ota_header = NULL;
+    nvram_ldi_debug_header *ldi_debug_header = NULL;
+    nvram_ldi_appendix_header *ldi_append_header = &nv_appendix_header;
+    kal_uint32 ldi_hd_buffer_size = 0;
+    kal_uint32 ldi_hd_offset = 0;
+    kal_uint32 ldi_checksum_hd_offset = 0;
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+   
+    kal_mem_set(filename, 0x0, NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+    kal_mem_set(&nv_header, 0x0, sizeof(nv_header));
+    kal_mem_set(&nv_appendix_header, 0x0, sizeof(nv_appendix_header));
+
+    ldi_ota_header = &(nv_header.nv_ota_header);
+    ldi_debug_header = &(nv_header.nv_dbg_header);
+    
+    ldi_hd_buffer_size += NVRAM_LDI_HEADER_SIZE;
+ 
+
+    if(NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        mulpiple = KAL_TRUE;
+        backup_file_num = 2;
+    }
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start); //start timer
+    #endif
+    do {
+        NVRAM_FS_START_EX(FS_OP_OPEN, filename);
+        file_handle = FS_Open(filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE);
+        NVRAM_FS_END(FS_OP_OPEN,file_handle);
+        if (file_handle < FS_NO_ERROR) {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM write header open fail:0x%x\n\r", file_handle);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+            kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"NVRAM write header open fail:%d\r\n", file_handle);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n", ldi->LID, ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"fileprefix:%s,fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"section:%d\r\n", section);
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_ERROR_LOC_NVCACHE_OPEN_NV_FOLDER_FAIL_3, ldi->LID);
+            }
+            ret_val = KAL_FALSE;
+            goto CH_RESRET_FINAL;
+        }
+        if(ldi_hd_offset && (file_handle > FS_NO_ERROR)) {
+            NVRAM_FS_START(FS_OP_SEEK);
+            result = FS_Seek(file_handle, ldi_hd_offset, FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,result);
+        }
+
+        if(section & LDI_HEADER_DBG_SECTION) {
+            nvram_cache_prepare_debug_header(ldi_debug_header,ldi);
+        }
+        if(section & LDI_HEADER_OTA_SECTION) {
+            nvram_cache_prepare_ota_header(ldi_ota_header,ldi);
+        }
+        NVRAM_FS_START(FS_OP_WRITE);
+        result = FS_Write(file_handle, (void *)(&nv_header), ldi_hd_buffer_size, &ldi_hd_buffer_size);
+        NVRAM_FS_END(FS_OP_WRITE,result);
+        if (result < FS_NO_ERROR) {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM write header write fail:0x%x\n\r", result);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+            kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"NVRAM write header write fail:%d\r\n", file_handle);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n", ldi->LID, ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"section:%d\r\n", section);
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_FS_START(FS_OP_CLOSE);
+                result = FS_Close(file_handle);
+                NVRAM_FS_END(FS_OP_CLOSE,result);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_ERROR_LOC_NVCACHE_OPEN_NV_FOLDER_FAIL_2, ldi->LID, result);
+            }
+            ret_val = KAL_FALSE;
+            goto CH_RESRET_FINAL;
+        }
+        //write appendix header
+        ldi_checksum_hd_offset = nvram_cache_appendix_header_offset(ldi);
+        if((section == LDI_HEADER_ALL_SECTION) && (ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)) {
+            nvram_prepare_appendix_header(NVRAM_APPEND_TYPE_CHKSUM, ldi_append_header, ldi, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+            NVRAM_FS_START(FS_OP_SEEK);
+            result = FS_Seek(file_handle, ldi_checksum_hd_offset, FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,result);
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(file_handle, ldi_append_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, &ldi_hd_buffer_size);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (result < FS_NO_ERROR) {
+                kal_prompt_trace(MOD_NVRAM, "NVRAM appendix header write fail:0x%x\n\r", result);
+                kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+                NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"NVRAM write header write fail:%d\r\n", file_handle);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n", ldi->LID, ldi->category, ldi->attr);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"section:%d\r\n", section);
+                if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                    NVRAM_FS_START(FS_OP_CLOSE);
+                    result = FS_Close(file_handle);
+                    NVRAM_FS_END(FS_OP_CLOSE,result);
+                    NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_WRITE_FILE_FAIL_7, ldi->LID, result);
+                }
+                ret_val = KAL_FALSE;
+                goto CH_RESRET_FINAL;
+            }
+            
+        }
+        
+        CH_RESRET_FINAL:
+            
+        if(file_handle > FS_NO_ERROR) {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            result = FS_Close(file_handle);
+            NVRAM_FS_END(FS_OP_CLOSE,result);
+        }
+        backup_file_num --;
+        #if defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+        if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) {
+            // Don't write protect2
+            break;
+        }
+        #endif
+        if(!mulpiple)
+        {
+          break;  
+        }
+        nvram_folder = nvram_query_folder_index_ex(ldi->category,KAL_FALSE);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+    }while(backup_file_num > 0);
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+    
+    return ret_val;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_drv_fat_backup
+ * DESCRIPTION
+ *  To make a backup.
+ * PARAMETERS
+ *  prefix           [IN]         file prefix
+ *  verno            [IN]         file verno
+ *  a_to_b           [IN]         direction
+ * RETURNS
+ *  error code
+ *****************************************************************************/
+kal_int32 nvram_cache_drv_fat_backup(nvram_ltable_entry_struct *ldi, kal_bool a_to_b)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar src_path[NVRAM_MAX_PATH_LEN], dest_path[NVRAM_MAX_PATH_LEN];
+    NVRAM_FILE_NAME nvramname;
+	kal_int32 result = FS_NO_ERROR;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (a_to_b)
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);  // A
+        nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_TRUE), nvramname, src_path);
+
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            nvram_query_file_name(NVRAM_NVD_BAK, nvramname, dest_path);
+        }
+        else
+    #endif
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE); // B
+            nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_FALSE), nvramname, dest_path);
+        }
+    }
+    else
+    {
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            nvram_query_file_name(NVRAM_NVD_BAK, nvramname, src_path);
+        }
+        else
+    #endif
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);  // B
+            nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_FALSE), nvramname, src_path);
+
+        }
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);  // A
+        nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_TRUE), nvramname, dest_path);
+    }
+    NVRAM_FS_START_EX(FS_OP_DELETE, dest_path);
+    result = FS_Delete(dest_path);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+    NVRAM_FS_START_EX(FS_OP_MOVE, dest_path);
+    result = FS_Move(src_path, dest_path, FS_MOVE_COPY, NULL, NULL, 0);
+    NVRAM_FS_END(FS_OP_MOVE,result);
+    return result;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_data_item
+ * DESCRIPTION
+ *  This is nvram_cache_reset_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi                 [IN]        MUST be 1 ~ (total_LID - 1)
+ *  index               [IN]        MUST be 1 ~ total_records
+ *  data                [?]
+ *  is_init             [IN]
+ *  buffer_size(?)      [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2 Note that content of `data' could be changed due to encyrption!!
+ *  buffer(?)           [IN]        MUST be even-bytes aligned.
+ * RETURNS
+ *  NVRAM_IO_ERRNO_INVALID_LID
+ *  NVRAM_IO_ERRNO_INVALID_RECORD
+ *  NVRAM_IO_ERRNO_INVALID_SIZE
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+nvram_errno_enum nvram_cache_reset_data_item(kal_char   *nvramname,
+                                          nvram_folder_enum  nvram_folder,
+                                          kal_uint32 file_offset,
+                                          kal_uint16 rec_index,
+                                          kal_uint16 rec_amount,
+                                          kal_uint32 rec_size,
+                                          const kal_uint8 *buffer,
+                                          nvram_ltable_entry_struct *ldi,
+                                          kal_bool initialize)
+{
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_int32 result = FS_NO_ERROR;
+    nvram_ldi_ota_header ota_header;
+    kal_int32 ret = FS_NO_ERROR;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif    
+    kal_mem_set(filename, 0x0, NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+    #endif
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    
+    do 
+    {
+        /* translate record id to filename */
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+
+        openOption |= FS_CREATE;
+        if (initialize != KAL_TRUE) {  
+            #if !defined(_NAND_FLASH_BOOTING_) && !defined(__FS_SYSDRV_ON_NAND__)  && !defined(__EMMC_BOOTING__)                                  
+                openOption |= FS_PROTECTION_MODE;   /* boot from NAND and single bank NOR don't support this */        
+            #endif                                                                                                 
+        }
+
+        #if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+        if (ldi->attr & NVRAM_ATTR_COMMITTED) {
+            openOption |= FS_COMMITTED;
+        }
+        #endif
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        hFile = FS_Open((const kal_wchar*)filename, openOption);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+        if (hFile == FS_FILE_NOT_FOUND) {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail at %d,FS_FILE_NOT_FOUND\r\n",__FUNCTION__,nvramname,__LINE__);
+            result = NVRAM_DRV_EMPTY_RECORD;
+            nvram_cache_last_line = __LINE__;
+            break;
+        }
+        else if (hFile <= FS_NO_ERROR) {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,hFile=%d\r\n",__LINE__,hFile);
+            result = hFile;
+            nvram_cache_last_line = __LINE__;
+            break;
+        }
+
+        //Get appdenix header info
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+            ldi->append_buffer = get_ctrl_buffer(rec_amount * nvram_chksum_size);
+        }
+        if (file_offset) {
+            NVRAM_FS_START(FS_OP_SEEK);
+            result = FS_Seek(hFile, file_offset, FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,result);
+            if(FS_NO_ERROR > result){
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = hFile;
+                nvram_cache_last_line = __LINE__;
+                break;
+            }
+        }
+
+        result = nvram_drv_fat_write_section(hFile, buffer, rec_index, rec_amount, rec_size, ldi, file_offset);
+    }while(0);
+
+    //write-back appdenix header info
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        if(ldi->append_offset == 0) {            
+            if(KAL_TRUE == nvram_read_ota_header(hFile, &ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+           (ota_header.ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+            {
+                ldi->append_offset = nvram_appendix_header_offset(ldi);
+            }
+            else {
+                ldi->append_offset = -1;
+            }            
+        }
+        if(ldi->append_offset > 0) {
+            NVRAM_FS_START(FS_OP_SEEK);
+            ret = FS_Seek(hFile, (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size)), FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,ret);
+            NVRAM_FS_START(FS_OP_WRITE);
+            ret = FS_Write(hFile, ldi->append_buffer, (rec_amount * nvram_chksum_size), &len);
+            NVRAM_FS_END(FS_OP_WRITE,ret);
+        }
+        if(ldi->append_buffer) {
+            free_ctrl_buffer(ldi->append_buffer);
+            ldi->append_buffer = NULL;
+        }
+    }
+
+    if (hFile > FS_NO_ERROR) {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,ret);
+    }
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+            DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+    if (result < FS_NO_ERROR) {
+        nvram_cache_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_cache_last_err, nvram_cache_last_line);
+    }
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_write_data_item
+ * DESCRIPTION
+ *  This is nvram_cache_write_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi                 [IN]        MUST be 1 ~ (total_LID - 1)
+ *  index               [IN]        MUST be 1 ~ total_records
+ *  data                [?]
+ *  is_init             [IN]
+ *  buffer_size(?)      [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2 Note that content of `data' could be changed due to encyrption!!
+ *  buffer(?)           [IN]        MUST be even-bytes aligned.
+ * RETURNS
+ *  NVRAM_IO_ERRNO_INVALID_LID
+ *  NVRAM_IO_ERRNO_INVALID_RECORD
+ *  NVRAM_IO_ERRNO_INVALID_SIZE
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+nvram_errno_enum nvram_cache_write_data_item(nvram_ltable_entry_struct *ldi, kal_uint32 index, kal_uint8 *data, kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    nvram_drv_status_enum drv_status[2] = {NVRAM_DRV_OK, NVRAM_DRV_OK};
+
+    kal_uint32 record_ID =0;
+    NVRAM_FILE_NAME nvramname;    
+    kal_int32 recovery_status = NVRAM_DRV_OK;
+    kal_uint32 file_offset;
+    nvram_folder_enum folder_index;
+    kal_bool multiple = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        multiple = KAL_TRUE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+
+    file_offset = NVRAM_LDI_HEADER_SIZE;
+
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    for (record_ID = 0; record_ID < 2; record_ID++)
+    {
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+        if (record_ID == 1)
+        {
+            #ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+			extern kal_bool smu_is_write_protect2(nvram_lid_enum file_idx);
+			if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+			{       
+                // Aussme protect2 is always locked, acctually it only unlocked at first boot in factory
+                if (drv_status[0] == NVRAM_DRV_OK)
+                {
+                    if (smu_is_write_protect2(ldi->LID)) {
+                        // only trigger backup for specific LIDs when they are written legally (shoudn't be frequently)
+                        // trigger backup, this will write sync pattern in AP side
+                        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, 0xFFFF, 0x0001,__LINE__);
+                        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"LID 0x%04X write sync pattern to AP\r\n",ldi->LID);
+        		        ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xABC);
+                        
+                    } else {
+                       // Don't trigger backup.
+                       // think about this scenario: 
+                       // some LID will update at known time (every md bootup time)
+                       // this will leave sync pattern in AP if we trigger backup, 
+                       // then hacker can deleted all files on protect1 before reboot the phone
+                       // the SML data on protect2 will lost after phone reboot ...
+                    }
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+                    return NVRAM_IO_ERRNO_OK;
+                } 
+                else
+                {
+                    // don't trigger backup due to protect1 write failed
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+                    return NVRAM_IO_ERRNO_CHK;
+                } 
+			}
+	        #endif
+            folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+        }
+    #endif
+    // if LID == SYS_LID, file can be empty & index is the index of record needs to write (amount is 1)
+    // if is_init == TRUE, file can be empty & index is the # of record needs to write (index always 1)
+    // if is_init == FALSE, file should not be empty & index is the index of record needs to write (amount always 1)
+
+        if(is_init && NVRAM_EF_SYS_LID != ldi->LID)
+        {
+
+            drv_status[record_ID] = nvram_cache_reset_data_item(
+                            nvramname,
+                            folder_index,
+                            file_offset,
+                            1,
+                            index,
+                            ldi->size,
+                            data,
+                            ldi,
+                            is_init);
+
+        }
+        else
+        {
+            drv_status[record_ID] = nvram_cache_reset_data_item(
+                            nvramname,
+                            folder_index,
+                            file_offset,
+                            index,
+                            1,
+                            ldi->size,
+                            data,
+                            ldi,
+                            is_init);
+        }
+
+        /* Try to reset data if it is not a initial case */
+        if (drv_status[record_ID] != NVRAM_DRV_OK)
+        {
+            MD_TRC_IO_WRITE_DATA_ITEM_MULTIPLE(ldi->LID, drv_status, nvram_drv_fat_get_last_err(), __LINE__);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"drv_status[%d] =%d\r\n",record_ID,drv_status[record_ID]);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+            status = NVRAM_IO_ERRNO_CHK;
+        }
+
+        if (!multiple)
+        {
+            break;
+        }
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK && multiple == KAL_TRUE)
+    {
+        if (drv_status[0] != NVRAM_DRV_OK &&  drv_status[1] == NVRAM_DRV_OK)
+        {
+            recovery_status = nvram_cache_drv_fat_backup(ldi, KAL_FALSE);   /* A <-- B */
+        } 
+        else if (drv_status[0] == NVRAM_DRV_OK &&  drv_status[1] != NVRAM_DRV_OK)
+        {
+            recovery_status = nvram_cache_drv_fat_backup(ldi, KAL_TRUE);   /* A --> B */
+        }
+        else
+        {
+            // Both A&B write fail
+            recovery_status = drv_status[0];
+        }
+
+        if (recovery_status == NVRAM_DRV_OK) 
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+            return NVRAM_IO_ERRNO_OK;
+        }
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return status;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_multiple
+ * DESCRIPTION
+ *  write record(s) to FAT.
+ * PARAMETERS
+ *  hFile               [?]
+ *  buffer              [?]
+ *  rec_amount          [IN]
+ *  rec_size            [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_int32 nvram_cache_drv_fat_write_multiple(
+    FS_HANDLE hFile,
+    const kal_uint8 *buffer,
+    kal_uint16 rec_index,
+    kal_uint16 rec_amount,
+    kal_uint32 rec_size,
+    nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 len = 0, remainLen = 0;
+    kal_uint8 *chksum = NULL;
+    kal_uint32 max_rec_amount;
+    kal_uint32 section_size;
+    kal_uint32 working_buffer_size;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_DRV_OK;
+    kal_uint32 i;
+    kal_uint32 rec_in_block;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#endif
+
+    //16bytes alignment, limitation: msp data will be oversize 
+    section_size = rec_size + nvram_chksum_size + remainLen;
+    working_buffer_size = section_size * rec_amount;
+
+    if (rec_index > 1)
+    {
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, (rec_index - 1) * section_size, FS_FILE_CURRENT);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if (FS_NO_ERROR > result)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+            nvram_cache_last_line = __LINE__;
+            goto final;
+        }
+    }
+
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    max_rec_amount = working_buffer_size/section_size;
+    chksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+    if (!(ldi->attr & NVRAM_ATTR_MSP) && !(ldi->attr & NVRAM_ATTR_CONFIDENTIAL) &&
+        buffer != NVRAM_EF_ZERO_DEFAULT && buffer != NVRAM_EF_FF_DEFAULT)
+    {
+        for(i = 0; i < rec_amount; i++)
+        {
+            if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+            {
+                //rec_index start from 1
+                kal_mem_set(chksum, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, buffer + (i+rec_index-1)*rec_size, rec_size,chksum);
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size), buffer + (i+rec_index-1)*rec_size, rec_size);                
+                kal_mem_cpy(working_buffer + i*(rec_size+ nvram_chksum_size)+rec_size, chksum, nvram_chksum_size);
+            }
+            else
+            {
+                if (i==0)
+                {
+                    kal_mem_set(chksum, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, buffer, rec_size,chksum);
+                }
+                kal_mem_cpy(working_buffer + i*(rec_size+ nvram_chksum_size), buffer, rec_size);             
+                kal_mem_cpy(working_buffer + i*(rec_size+ nvram_chksum_size)+rec_size, chksum, nvram_chksum_size);
+            }
+
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i * nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+
+            if (i == (rec_amount - 1))
+            {
+                NVRAM_FS_START(FS_OP_WRITE);
+                result = FS_Write(hFile, working_buffer, section_size * rec_amount, &len);
+                NVRAM_FS_END(FS_OP_WRITE,result);
+                if (FS_NO_ERROR > result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    nvram_cache_last_line = __LINE__;
+                    goto final;
+                }
+            }           
+        }
+        goto final;
+    }
+
+    rec_in_block = 0;
+    max_rec_amount = working_buffer_size / section_size;
+    
+    for (i = 0; i < rec_amount; i ++)
+    {
+        nvram_cache_drv_fat_prepare_data(working_buffer + rec_in_block * section_size, buffer, (i+rec_index-1) * rec_size, rec_size);
+        kal_mem_set(chksum, 0, nvram_chksum_size);
+        nvram_util_caculate_checksum(ldi, working_buffer + rec_in_block * section_size, rec_size, chksum);
+
+        kal_mem_cpy(working_buffer + rec_in_block * section_size + rec_size, chksum, nvram_chksum_size);
+
+        //record integrated checksum
+        if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+            kal_mem_cpy((void *)(ldi->append_buffer + (i * nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+        }
+
+        if (remainLen)
+        {
+            kal_mem_set(working_buffer + rec_in_block * section_size + rec_size + nvram_chksum_size , 0x00, remainLen);
+        }
+        if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+        {
+            //custom_nvram_encrypt(nvram_ptr->secret_key, working_buffer + rec_in_block * section_size, rec_size, rec_size);
+        nvram_AES_encrypt(working_buffer + rec_in_block * section_size, section_size);
+        }
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        if (ldi->attr & NVRAM_ATTR_MSP)
+        {
+        /* this solution is only for work arround */
+        #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+            kal_uint8 *working_buffer2 = (kal_uint8*) get_ctrl_buffer(section_size);
+            kal_uint8 *working_buffer3 = (kal_uint8*) get_ctrl_buffer(section_size);
+            if (working_buffer2 == NULL)
+            {
+                if (working_buffer)
+                {
+                    free_ctrl_buffer(working_buffer);
+                    working_buffer = NULL;
+                }
+                kal_prompt_trace(MOD_NVRAM, "%s Can not get the memory from control buffer @line %d\n\r",__FUNCTION__,__LINE__);
+            }
+            if (working_buffer3 == NULL)
+            {
+                if (working_buffer)
+                {
+                    free_ctrl_buffer(working_buffer);
+                    working_buffer = NULL;
+                }
+                free_ctrl_buffer(working_buffer2);
+                working_buffer2 = NULL;
+                kal_prompt_trace(MOD_NVRAM, "%s Can not get the memory from control buffer @line %d\n\r",__FUNCTION__,__LINE__);
+            }
+            //copy the original data from working_buffer to working_buffer2
+            memcpy(working_buffer2, working_buffer + rec_in_block * section_size, section_size);
+
+            do
+            {
+                nvram_trace_to_file(__LINE__, 999, 0, 0, 0, 0);
+                nvram_trace_to_file(nvram_ptr->secret_key[0], nvram_ptr->secret_key[1], nvram_ptr->secret_key[2], nvram_ptr->secret_key[3], 0, 0);
+                nvram_trace_to_file(working_buffer[rec_in_block*section_size], working_buffer[rec_in_block*section_size + 1], working_buffer[rec_in_block*section_size + 2], working_buffer[rec_in_block*section_size + 3], 0, 0);
+
+                //encrypt working_buffer
+                SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+                nvram_trace_to_file(working_buffer[rec_in_block*section_size], working_buffer[rec_in_block*section_size + 1], working_buffer[rec_in_block*section_size + 2], working_buffer[rec_in_block*section_size + 3], 0, 0);
+
+                //copy the encrypted data from working_buffer to working_buffer3
+                memcpy(working_buffer3, working_buffer + rec_in_block * section_size, section_size);
+                //decrypt the working_buffer3
+                SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32)working_buffer3, section_size, nvram_ptr->secret_key, working_buffer3);
+
+                //compare the data between the working_buffer2 & working_buffer3
+                if (memcmp(working_buffer2, working_buffer3, section_size) == 0)
+                {
+                    //encrypt PASS
+                    break;
+                }
+                else
+                {
+                    //encrypt FAIL, try again, WTF
+                    memcpy(working_buffer + rec_in_block * section_size, working_buffer2, section_size);
+                }
+            }while(1);
+
+            free_ctrl_buffer(working_buffer2);
+            free_ctrl_buffer(working_buffer3);
+            working_buffer2 = NULL;
+            working_buffer3 = NULL;
+        #else
+            SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+
+        #endif
+        }
+    #endif
+
+        /* if this is not multi default, no need to prepare data anymore */
+        if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+        {
+            break;
+        }
+
+        rec_in_block ++;
+
+        if (rec_in_block == max_rec_amount || i == rec_amount - 1)
+        {
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, working_buffer, section_size * rec_in_block, &len);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (FS_NO_ERROR > result)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                nvram_cache_last_line = __LINE__;
+                goto final;
+            }
+            rec_in_block = 0;
+        }
+    }
+
+    /* special handling for not multi default */
+    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+    {
+        for (i = 0; i < rec_amount; i++)
+        {
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i * nvram_chksum_size)), (void *)(working_buffer+rec_size), nvram_chksum_size);
+            }
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, working_buffer, section_size, &len);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (FS_NO_ERROR > result)
+            {
+                nvram_cache_last_line = __LINE__;
+                goto final;
+            }
+        }
+    }
+
+final:
+
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+        working_buffer = NULL;
+    }
+
+    if (chksum)
+    {
+        free_ctrl_buffer(chksum);
+        chksum = NULL;
+    }
+
+    if (FS_NO_ERROR > result)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        nvram_cache_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_cache_last_err, nvram_cache_last_line);
+        return result;
+    }
+    
+    return NVRAM_DRV_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_multRec
+ * DESCRIPTION
+ *  write record(s) to FAT,now it only used at initiation stage
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  initialize          [IN]        true for reset, false for normal write.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_drv_status_enum nvram_cache_drv_fat_write_multRec(nvram_ltable_entry_struct *ldi,
+                                          kal_char   *nvramname,
+                                          nvram_folder_enum  nvram_folder,
+                                          kal_uint32 file_offset,
+                                          kal_uint16 rec_index,
+                                          kal_uint16 rec_amount,
+                                          kal_uint32 rec_size,
+                                          const kal_uint8 *buffer,
+                                          kal_bool initialize)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_int32 result = FS_NO_ERROR;
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    kal_uint32 len;
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+    nvram_ldi_ota_header ota_header;
+    kal_int32 ret = FS_NO_ERROR;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+       
+    kal_mem_set(filename, 0x0, NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+    #endif
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    do
+    {
+        if (rec_index < 1 || rec_amount < 1)
+        {
+            nvram_cache_last_line = __LINE__;
+            result = NVRAM_DRV_INVALID_RECORD_ID;
+            goto final;
+        }
+
+        /* translate record id to filename */
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+
+        /* set the attribute to empty before write data
+                sometime the files may be read only if the nvram lock is turn on
+                ex: software update when nvram lock is turned on
+                But it is not a good solution here, we should unlock it in io layer */
+
+        openOption |= FS_CREATE;
+
+        #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__)) && defined(__MTK_TARGET__)
+        if (ldi->attr & NVRAM_ATTR_COMMITTED)
+        {
+            openOption |= FS_COMMITTED;
+        }
+        #endif
+        //Get appdenix header info
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+        {
+            ldi->append_buffer = get_ctrl_buffer(rec_amount * nvram_chksum_size);
+        }
+
+        nvram_cache_reset_header(ldi, LDI_HEADER_ALL_SECTION);
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        hFile = FS_Open((const kal_wchar*)filename, openOption);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+        if (hFile == FS_FILE_NOT_FOUND)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail at %d,FS_FILE_NOT_FOUND\r\n",__FUNCTION__,nvramname,__LINE__);
+            nvram_cache_last_line = __LINE__;
+            result = NVRAM_DRV_EMPTY_RECORD;
+            goto final;
+        }
+        else if (hFile <= FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,hFile=%d\r\n",__LINE__,hFile);
+            nvram_cache_last_line = __LINE__;
+            result = hFile;
+            goto final;
+        }
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if(FS_NO_ERROR > result){
+            nvram_cache_last_line = __LINE__;
+            goto final;
+        }
+        result = nvram_cache_drv_fat_write_multiple(hFile, buffer, rec_index, rec_amount, rec_size, ldi);
+    }while(0);
+
+    //write-back appdenix header info
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        //Write appendix info
+        if(ldi->append_offset == 0) {
+            kal_mem_set(&ota_header, 0, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+            if(KAL_TRUE == nvram_read_ota_header(hFile, &ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+               (ota_header.ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+            {
+                ldi->append_offset = nvram_cache_appendix_header_offset(ldi);
+            }
+            else {
+                ldi->append_offset = -1;
+            }
+                
+        }        
+        if(ldi->append_offset > 0) {
+            NVRAM_FS_START(FS_OP_SEEK);
+            ret = FS_Seek(hFile, (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size)), FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,ret);
+            NVRAM_FS_START(FS_OP_WRITE);
+            ret = FS_Write(hFile, ldi->append_buffer, (rec_amount * nvram_chksum_size), &len);
+            NVRAM_FS_END(FS_OP_WRITE,ret);
+        }        
+        
+    }
+final:
+    if(ldi->append_buffer) {
+        free_ctrl_buffer(ldi->append_buffer);
+        ldi->append_buffer = NULL;
+    }
+    
+    if (hFile > FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,ret);
+    }    
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+        
+    /* Set the attribute back to original attribute */
+    if (result < FS_NO_ERROR)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        nvram_cache_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_cache_last_err, nvram_cache_last_line);
+    }
+
+    return result;
+}
+#if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram__cache_write_fs_data_item_multiple
+ * DESCRIPTION
+ *  This is nvram_write_data_item_multiple() function of NVRAM module.
+ * PARAMETERS
+ *  ldi             [?]
+ *  index           [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ *  is_init         [IN]
+ * RETURNS
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+static nvram_errno_enum nvram_cache_write_fs_data_item_multiple
+    (nvram_ltable_entry_struct *ldi, 
+    kal_uint16 index, 
+    kal_uint16 rec_mount, 
+    const kal_uint8 *buffer,
+    kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    nvram_drv_status_enum drv_status[2] = {NVRAM_DRV_OK, NVRAM_DRV_OK};
+    kal_uint32 record_ID;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint32 file_offset;
+    nvram_folder_enum folder_index;
+    kal_bool multiple = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        multiple = KAL_TRUE;
+    }
+
+    folder_index = nvram_query_folder_index(ldi->category);
+
+    file_offset = NVRAM_LDI_HEADER_SIZE;
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+    for (record_ID = 0; record_ID < 2; record_ID++)
+    {
+
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+        if (record_ID == 1)
+        {
+            #ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+            extern kal_bool smu_is_write_protect2(nvram_lid_enum file_idx);
+            if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+            {       
+                // Aussme protect2 is always locked, acctually it only unlocked at first boot in factory
+                if (drv_status[0] == NVRAM_DRV_OK)
+                {
+                    if (smu_is_write_protect2(ldi->LID)) {
+                        // only trigger backup for specific LIDs when they are written legally (shoudn't be frequently)
+                        // trigger backup, this will write sync pattern in AP side
+                        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, 0xFFFF, 0x0001,__LINE__);
+                        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X write sync pattern to AP\r\n",ldi->LID);
+                        ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xABC);
+                        
+                    } else {
+                       // Don't trigger backup.
+                       // think about this scenario: 
+                       // some LID will update at known time (every md bootup time)
+                       // this will leave sync pattern in AP if we trigger backup, 
+                       // then hacker can deleted all files on protect1 before reboot the phone
+                       // the SML data on protect2 will lost after phone reboot ...
+                    }
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+                    return NVRAM_IO_ERRNO_OK;
+                } 
+                else
+                {
+                    // don't trigger backup due to protect1 write failed
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+                    return NVRAM_IO_ERRNO_CHK;
+                } 
+            }
+            #endif
+            folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+        }
+    #endif
+       
+        drv_status[record_ID] = nvram_cache_drv_fat_write_multRec(
+                            ldi,
+                            nvramname,
+                            folder_index,
+                            file_offset,
+                            index,
+                            rec_mount,
+                            ldi->size,
+                            buffer,
+                            is_init);
+        
+        /* Try to reset data if it is not a initial case */
+        if (drv_status[record_ID] != NVRAM_DRV_OK)
+        {
+            MD_TRC_IO_WRITE_DATA_ITEM_MULTIPLE(ldi->LID, drv_status, nvram_drv_fat_get_last_err(), __LINE__);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP," drv_status[%d] =%d\r\n",record_ID,drv_status[record_ID]);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);            
+            status = NVRAM_IO_ERRNO_CHK;
+        }
+
+        if (!multiple)
+        {
+            break;
+        }        
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK && multiple == KAL_TRUE) 
+    {
+        kal_int32 recovery_status;
+        if (drv_status[0] != NVRAM_DRV_OK &&  drv_status[1] == NVRAM_DRV_OK)
+        {
+            recovery_status = nvram_drv_fat_backup(ldi, KAL_FALSE);   /* A <-- B */
+        } 
+        else if (drv_status[0] == NVRAM_DRV_OK &&  drv_status[1] != NVRAM_DRV_OK) 
+        {
+            recovery_status = nvram_drv_fat_backup(ldi, KAL_TRUE);   /* A --> B */
+        }
+        else
+        {
+            // Both A&B write fail
+            recovery_status = drv_status[0];
+        }
+
+        if (recovery_status == NVRAM_DRV_OK)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+            return NVRAM_IO_ERRNO_OK;
+        }
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return status;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_mutilpe_data_item
+ * DESCRIPTION
+ *  write data with lid size but not a record.Support write 1..amount records
+ *  one time if (lid->size+checksum) * amount < MAX_NVRAM_RECORD_SIZE
+ * PARAMETERS
+ *  ldi         [IN]    the data item to be write
+ *  rec_idnex   [IN]    the start record index will be write
+ *  rec_amount  [IN]    the amount of the records will be write 
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static nvram_errno_enum nvram_cache_write_default_data_item_mutilpe(nvram_ltable_entry_struct *ldi,
+                                        kal_uint16 rec_index,
+                                        kal_uint16 rec_amount)
+{
+    
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+        
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    MD_TRC_IO_WRITE_DATA_ITEM_START(ldi->LID, rec_index, rec_amount);
+    MD_TRC_INFO_NVRAM_DATA_ITEM(ldi->LID, ldi->size);
+
+    /******************************************************
+     *  Device Broken
+     ******************************************************/
+     NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    if (nvram_ptr->dev_broken)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_DRV_BROKEN, __LINE__, ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s NVRAM_IO_ERRNO_DRV_BROKEN\r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return status;
+    }
+    
+    /* prepare data */
+    if( ldi->default_value == NVRAM_EF_FF_DEFAULT || 
+        ldi->default_value == NVRAM_EF_ZERO_DEFAULT)
+    {
+        kal_uint8 const *default_value = ldi->default_value;
+        status = nvram_cache_write_fs_data_item_multiple(ldi,rec_index,rec_amount,default_value,KAL_TRUE);
+    }
+    else if(ldi->default_value == NULL)
+    {
+        kal_uint8 const *default_value = NVRAM_EF_FF_DEFAULT;
+        status = nvram_cache_write_fs_data_item_multiple(ldi,rec_index,rec_amount,default_value,KAL_TRUE);
+    }
+    else
+    {
+        kal_uint8 *default_value_buffer = NULL;
+        kal_uint32 i;
+        kal_uint8 *default_value_p;
+        kal_uint8 *def_buff;
+
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(ldi->size * rec_amount + NVRAM_BUFFER_TAIL_SIZE);
+        kal_mem_cpy((default_value_buffer + (ldi->size * rec_amount)), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE);
+            
+        if((ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT) && (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+        {
+            nvram_get_lid_default_value_to_write(ldi, 0, default_value_buffer, (ldi->size * rec_amount));
+        }
+        else
+        {
+            def_buff = (kal_uint8*) get_ctrl_buffer(ldi->size + NVRAM_BUFFER_TAIL_SIZE);
+            kal_mem_cpy((def_buff + ldi->size), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE);
+            for (i = 0; i < rec_amount; i++)
+            {
+                default_value_p = (kal_uint8*) nvram_get_lid_default_value_to_write(ldi, i, NULL, 0);        
+                if (default_value_p == NULL)
+                {
+                    nvram_get_lid_default_value_to_write(ldi, i, def_buff, ldi->size);
+                    default_value_p = def_buff;
+                }           
+                kal_mem_cpy(default_value_buffer + i*(ldi->size), default_value_p, ldi->size);
+                default_value_p = NULL;
+            }
+
+            if(kal_mem_cmp((def_buff + ldi->size), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE) != 0)
+            {
+                // Return default value is out of buffer. 
+                MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(ldi->LID, (ldi->size * rec_amount), __LINE__, 0,0);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (ldi->size * ldi->total_records), NVRAM_LOC_SPACE_NOT_ENOUGH_4, ldi->LID, free_ctrl_buffer(def_buff);free_ctrl_buffer(default_value_buffer));
+            }           
+            free_ctrl_buffer(def_buff);     
+        }
+
+        if(kal_mem_cmp((default_value_buffer + (ldi->size * rec_amount)), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE) != 0)
+        {
+            // Return default value is out of buffer. 
+            MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(ldi->LID, (ldi->size * rec_amount), __LINE__, 0,0);
+            NVRAM_EXT_ASSERT(KAL_FALSE, (ldi->size * ldi->total_records), NVRAM_LOC_SPACE_NOT_ENOUGH_3, ldi->LID, free_ctrl_buffer(default_value_buffer));
+        }
+        
+        status = nvram_cache_write_fs_data_item_multiple(ldi,rec_index,rec_amount,default_value_buffer,KAL_TRUE);
+        free_ctrl_buffer(default_value_buffer);
+    }
+    
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+        /* IMEI and SML */  
+        if ((NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)
+    #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+                || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+        #else
+            )
+        #endif
+    #else
+            )
+    #endif  
+            )
+        {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_ERROR_LOC_NVCACHE_WRITE_IMPORTANT_DATA_FAIL_1:%d\n\r", DISPLAY_ERROR(status));
+            kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM ASSERT ERROR NVRAM_ERROR_LOC_NVCACHE_WRITE_IMPORTANT_DATA_FAIL_1:%d\r\n", DISPLAY_ERROR(status));
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);            
+            NVRAM_EXT_ASSERT (KAL_FALSE, DISPLAY_ERROR(status),NVRAM_ERROR_LOC_NVCACHE_WRITE_IMPORTANT_DATA_FAIL_1 , ldi->LID);
+            return status;
+        }
+
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, KAL_TRUE);
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, KAL_TRUE);
+        kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_ERROR_LOC_NVCACGE_WRITE_AND_RESET_FAIL_1:%d\n\r", DISPLAY_ERROR(status));
+        kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_ERROR_LOC_NVCACGE_WRITE_AND_RESET_FAIL_1:%d\r\n", DISPLAY_ERROR(status));
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_ERROR_LOC_NVCACGE_WRITE_AND_RESET_FAIL_1, ldi->LID);
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return status;
+}
+#endif
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_reset_one_data_item
+ * DESCRIPTION
+ *  reset one LID to default value
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/ 
+nvram_errno_enum nvram_cache_reset_one_data_item(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint8 *default_value = NULL;
+    kal_uint32 i;
+    kal_uint32 start = rec_index;
+    kal_uint32 end = rec_amount;
+    kal_uint8 *default_value_buffer = NULL;
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+    kal_uint32 remainLen = 0;
+    #endif
+    kal_uint32 working_buffer_size = 0;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+    do
+    {
+        if (KAL_FALSE == bResetNvramData 
+            || KAL_FALSE == kal_query_systemInit()   //initiation
+            || (ldi->size + nvram_chksum_size) > MAX_NVRAM_RECORD_SIZE   //large record
+            || ldi->LID == NVRAM_EF_SYS_LID
+        #ifdef __NVRAM_OTP__        
+            || NVRAM_IS_CATEGORY_OTP(ldi->category)
+        #endif
+        #ifdef __NVRAM_CUSTOM_DISK__
+            || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category)
+        #endif
+        #ifdef __NVRAM_CRYPT_TEST__
+            || ldi->LID == NVRAM_EF_NVRAM_MSP_TEST_LID
+        #endif
+            )
+        {           
+            break;
+        }
+
+        // only support reset 1..total_records
+
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        if (ldi->attr & NVRAM_ATTR_MSP)
+        {
+            /* 4 byte alignment */
+            remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size);
+        }
+        #endif
+
+        working_buffer_size = (ldi->size + nvram_chksum_size + remainLen) * ldi->total_records;
+
+        if (working_buffer_size <= MAX_NVRAM_RECORD_SIZE)
+        {
+            result = nvram_cache_write_default_data_item_mutilpe(ldi,1,ldi->total_records);
+            goto final;
+        }
+        
+    }while(0);
+    #endif
+    working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    default_value_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    //nvram_debug_write_dump(ldi, 0x701, rec_index, rec_amount, NULL, ldi->size, NVRAM_IO_ERRNO_CHK);
+
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    nvram_cache_reset_header(ldi, LDI_HEADER_ALL_SECTION);
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+    for (i = start; i <= end; i++)
+    {
+        /* when ldi size too big, we cannot operator it on buffer,
+           use original default value pointer directly */
+
+        default_value = (kal_uint8*) nvram_get_default_value_to_write(ldi, i, NULL, 0);
+
+        /* the default_value is not assigned in table , ex: L1 LID */
+        if (default_value == NULL)
+        {
+            if((i == 1 && end == ldi->total_records) && (NVRAM_EF_SYS_LID != ldi->LID))
+            {
+                nvram_get_default_value_to_write(ldi, i, default_value_buffer, working_buffer_size);
+            }
+            else
+            {
+                nvram_memset(default_value_buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, working_buffer_size);
+                nvram_get_default_value_to_write(ldi, i, default_value_buffer, ldi->size);
+            }
+            
+            default_value = default_value_buffer;
+        }
+
+        /* initial case, we reset it directly to enhance performance*/
+        if(NVRAM_EF_SYS_LID == ldi->LID)
+        {
+            result = nvram_cache_write_data_item(ldi, i, default_value, KAL_TRUE);
+            if (result != NVRAM_IO_ERRNO_OK)
+            {
+                break;
+            }                
+        }
+        else
+        {
+            result = nvram_cache_write_data_item(ldi, ldi->total_records, default_value, KAL_TRUE);
+            break;
+        }
+    }
+#if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+final:
+#endif
+    if(default_value_buffer)
+    {
+        free_ctrl_buffer(default_value_buffer);
+        default_value_buffer = NULL;
+    }
+
+    if(result == NVRAM_IO_ERRNO_OK) {
+
+        unmask_valid_bit_by_ltable_entry(ldi, 0, (ldi->total_records + 1));
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  update_cache_header
+ * DESCRIPTION
+ *  update cache data for read
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * working_buffer [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+nvram_errno_enum update_cache_header(nvram_ltable_entry_struct* ldi, void* src_buffer, kal_uint32 ldi_hd_offset, kal_uint32 ldi_hd_buffer_size)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_bool result = KAL_FALSE;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_6, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    kal_mem_cpy((void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + ldi_hd_offset)), src_buffer, ldi_hd_buffer_size);
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  update_cache_data
+ * DESCRIPTION
+ *  update cache data for read
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * working_buffer [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+nvram_errno_enum update_cache_data(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount, NVRAM_FS_PARAM_CMPT_T* nvram_param, kal_bool is_only_chksum)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_bool result = KAL_FALSE;
+    kal_uint8* cache_data_boundary = NULL;
+    kal_uint32 remainLen = 0;
+    kal_uint32 section_size;
+    kal_uint16 temp_rec_index = rec_index;
+    kal_uint16 i, j;
+    kal_uint8* temp_dataPtr = (kal_uint8 *)(nvram_param->DataPtr);
+    kal_bool total_valid_bit = KAL_TRUE;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\n\r", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X,attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_7, ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size);
+    }
+    #else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size);
+    }
+    #endif
+    section_size = ldi->size+ nvram_chksum_size + remainLen;
+    
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    cache_data_boundary = g_nvcache_base_address + cache_info_header.cache_table_offset + cache_info_header.cache_table_size;
+    if((g_nvcache_base_address + cache_info_header.cache_table_offset + cache_ldi->cache_offset + nvram_param->Offset + (*(nvram_param->Read))) > cache_data_boundary)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)(g_nvcache_base_address + (cache_info_header.cache_table_offset + cache_ldi->cache_offset) + nvram_param->Offset + (*(nvram_param->Read))), NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_9, cache_ldi->LID);
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+    for(i = 0; i < rec_amount; i++)
+    {
+        if(is_only_chksum)
+        {
+            if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+            {
+                total_valid_bit = KAL_FALSE;
+                nvram_util_take_mutex(g_nvram_cache_mutex);
+                for(j = 0; j < nvram_chksum_size; j++)
+                {
+                    if(*((kal_uint8*)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + (nvram_param->Offset + (i* nvram_chksum_size)+ j)))) != 0)
+                    {
+                        total_valid_bit = KAL_TRUE;
+                        break;
+                    }
+                }
+                nvram_util_give_mutex(g_nvram_cache_mutex);
+                if (check_dirty_bit_by_cache_table(cache_ldi, temp_rec_index + i) && total_valid_bit)
+                {
+                    nvram_util_take_mutex(g_nvram_cache_mutex);
+                    kal_mem_cpy((void *)(temp_dataPtr + (i* nvram_chksum_size)), 
+                        (void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + (nvram_param->Offset + (i* nvram_chksum_size)))), nvram_chksum_size);
+                    nvram_util_give_mutex(g_nvram_cache_mutex);
+                }else if(!check_valid_bit_by_cache_table(cache_ldi, temp_rec_index + i) &&(total_valid_bit == KAL_FALSE))
+                {
+                    nvram_util_take_mutex(g_nvram_cache_mutex);
+                    kal_mem_cpy((void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + (nvram_param->Offset + (i* nvram_chksum_size)))),
+                        (void *)(temp_dataPtr + (i* nvram_chksum_size)), nvram_chksum_size);
+                    nvram_util_give_mutex(g_nvram_cache_mutex);
+                }
+            }else
+            {
+                nvram_util_take_mutex(g_nvram_cache_mutex);
+                kal_mem_cpy((void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + (nvram_param->Offset + (i* section_size)))),
+                    (void *)(temp_dataPtr + (i* nvram_chksum_size)), nvram_chksum_size);
+                nvram_util_give_mutex(g_nvram_cache_mutex);
+            }
+        }else
+        {
+            if (check_dirty_bit_by_cache_table(cache_ldi, temp_rec_index + i))
+            {
+                nvram_util_take_mutex(g_nvram_cache_mutex);
+                kal_mem_cpy((void *)(temp_dataPtr + (i* section_size)), (void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + (nvram_param->Offset + (i*section_size )))), section_size);
+                nvram_util_give_mutex(g_nvram_cache_mutex);
+            }else if(!check_valid_bit_by_cache_table(cache_ldi, temp_rec_index + i))
+            {
+                nvram_util_take_mutex(g_nvram_cache_mutex);
+                kal_mem_cpy((void *)(g_nvcache_base_address + ((cache_info_header.cache_table_offset + cache_ldi->cache_offset) + (nvram_param->Offset + (i* section_size)))), (void *)(temp_dataPtr + (i* section_size)), section_size);                
+                nvram_util_give_mutex(g_nvram_cache_mutex);
+                mask_valid_bit_by_cache_table(cache_ldi, temp_rec_index + i, 1);
+            }
+        }
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  get_cache_data
+ * DESCRIPTION
+ *  update cache data for read
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * working_buffer [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+nvram_errno_enum get_cache_data(kal_uint32 cache_address, void *dest_buffer, kal_uint32 working_buffer_size)
+{
+    kal_uint8* src_buffer = (kal_uint8*)cache_address;
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    kal_mem_set(dest_buffer,0,working_buffer_size);
+    kal_mem_cpy(dest_buffer, (void *)src_buffer, working_buffer_size);
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_flush_cache_data_to_file
+ * DESCRIPTION
+ *  nvram flush cache data to file
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * working_buffer [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+nvram_errno_enum nvram_flush_cache_data_to_file(nvram_cache_write_item *cache_queue_ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 len = 0;
+    kal_uint32 section_size = 0;
+    kal_uint32 working_buffer_size = 0;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_DRV_OK;
+    nvram_drv_status_enum drv_status[2] = {NVRAM_DRV_OK, NVRAM_DRV_OK};
+    kal_bool ret_val = KAL_FALSE;
+    kal_uint32 i, j;
+    kal_uint32 rec_size;
+    kal_uint16 rec_amount;
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32 start_record = 0;
+    kal_uint32 end_record = 0;
+    kal_int32 flush_length = 0;
+    kal_int32 flush_append_length = 0;
+    kal_uint32 file_offset = 0;
+    kal_uint32 file_append_offset = 0;
+    kal_uint32 temp_offset = 0;
+    kal_uint32 remainLen = 0;
+    kal_bool multiple = KAL_FALSE;
+    kal_uint32 multiple_ID = 0;
+
+    FS_HANDLE hFile = 0;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_wchar src_path[NVRAM_MAX_PATH_LEN];
+    kal_wchar dest_path[NVRAM_MAX_PATH_LEN];
+    NVRAM_FILE_NAME nvramname;
+    nvram_folder_enum  nvram_folder;    
+    kal_uint32 file_sz = 0;
+    kal_int32 ret = NVRAM_DRV_OK;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"LID 0x%04X cache_queue_ldi->rec_index=%d cache_queue_ldi->rec_amount=%d\r\n",cache_queue_ldi->ldi->LID,cache_queue_ldi->rec_index,cache_queue_ldi->rec_amount);
+    rec_size = cache_queue_ldi->ldi->size;
+    rec_amount = cache_queue_ldi->ldi->total_records;
+    openOption = cache_queue_ldi->openoption;
+    
+    kal_mem_set(filename, 0x0, NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(MD_CCCI_LIMIT_SIZE);
+    kal_mem_set(working_buffer, 0x0, MD_CCCI_LIMIT_SIZE);
+
+    nvram_get_lid_chksum_algo_info(cache_queue_ldi->ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((cache_queue_ldi->ldi->attr & NVRAM_ATTR_MSP)||(cache_queue_ldi->ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+    #else
+    if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+    #endif
+
+    section_size = rec_size + nvram_chksum_size + remainLen;
+
+    if (!(ret_val = get_lid_cache_index_item(cache_queue_ldi->ldi->LID , &cache_ldi))) {
+        if (working_buffer)
+        {
+            free_ctrl_buffer(working_buffer);
+            working_buffer = NULL;
+        }
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, cache_queue_ldi->ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", cache_queue_ldi->ldi->category, cache_queue_ldi->ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", cache_queue_ldi->ldi->fileprefix, cache_queue_ldi->ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s search LID 0x%04X failed from cache table index:\r\n",__FUNCTION__,cache_queue_ldi->ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"category:0x%08X, attr:0x%08X \r\n", cache_queue_ldi->ldi->category, cache_queue_ldi->ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\n\r", cache_queue_ldi->ldi->fileprefix, cache_queue_ldi->ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_8, cache_queue_ldi->ldi->LID);
+        result = NVRAM_IO_ERRNO_INVALID_LID;
+        nvram_cache_last_line = __LINE__;
+        goto final;
+    }
+    if (NVRAM_IS_ATTR_MULTIPLE(cache_queue_ldi->ldi->attr) || NVRAM_IS_ATTR_BACKUP_FAT(cache_queue_ldi->ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(cache_queue_ldi->ldi->category))
+    {
+        multiple = KAL_TRUE;
+    }
+
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+
+    nvram_folder = nvram_query_folder_index(cache_queue_ldi->ldi->category);
+    for (multiple_ID = 0; multiple_ID < 2; multiple_ID++)
+    {
+
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+        if (multiple_ID == 1)
+        {
+            #ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+			extern kal_bool smu_is_write_protect2(nvram_lid_enum file_idx);
+			if (NVRAM_IS_CATEGORY_IMPORTANT_L4(cache_queue_ldi->ldi->category))
+			{       
+                // Aussme protect2 is always locked, acctually it only unlocked at first boot in factory
+                if (drv_status[0] == NVRAM_DRV_OK)
+                {
+                    if (smu_is_write_protect2(cache_queue_ldi->ldi->LID)) {
+                        // only trigger backup for specific LIDs when they are written legally (shoudn't be frequently)
+                        // trigger backup, this will write sync pattern in AP side
+                        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(cache_queue_ldi->ldi->LID, 0xFFFF, 0x0001,__LINE__);
+                        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X write sync pattern to AP\r\n",cache_queue_ldi->ldi->LID);
+        		        ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xABC);
+                        
+                    } else {
+                       // Don't trigger backup.
+                       // think about this scenario: 
+                       // some LID will update at known time (every md bootup time)
+                       // this will leave sync pattern in AP if we trigger backup, 
+                       // then hacker can deleted all files on protect1 before reboot the phone
+                       // the SML data on protect2 will lost after phone reboot ...
+                    }
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+                    return NVRAM_IO_ERRNO_OK;
+                } 
+                else
+                {
+                    // don't trigger backup due to protect1 write failed
+                    return NVRAM_IO_ERRNO_CHK;
+                } 
+			}
+	        #endif
+            nvram_folder = nvram_query_folder_index_ex(cache_queue_ldi->ldi->category, KAL_FALSE);
+        }        
+        #endif
+
+        if (multiple_ID == 0)
+        {
+            nvram_util_make_lid_filename(cache_queue_ldi->ldi, nvramname, KAL_TRUE);
+        }else
+        {
+            nvram_util_make_lid_filename(cache_queue_ldi->ldi, nvramname, KAL_FALSE);
+        }
+
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        hFile = FS_Open((const kal_wchar*)filename, openOption);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+        if (hFile == FS_FILE_NOT_FOUND) {
+            drv_status[multiple_ID] = hFile;
+            nvram_cache_last_line = __LINE__;
+            goto FS_OP_ERROR;
+        } else if (hFile <= FS_NO_ERROR) {
+            drv_status[multiple_ID] = hFile;
+            nvram_cache_last_line = __LINE__;
+            goto FS_OP_ERROR;
+        }
+        NVRAM_FS_START(FS_OP_GETFILESIZE);
+        result = FS_GetFileSize(hFile, &file_sz);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+        if((cache_ldi->is_reset != 1) && (file_sz < NVRAM_LDI_HEADER_SIZE))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s->FS_GetFileSize fail at %d,result=%d file_sz =%d\r\n",__FUNCTION__,__LINE__,result,file_sz);
+            drv_status[multiple_ID] = FS_FILE_NOT_FOUND;
+            nvram_cache_last_line = __LINE__;
+             goto FS_OP_ERROR;
+        }
+        
+        for (i = 0; i <= rec_amount; i ++) {
+            if (check_dirty_bit_by_cache_table(cache_ldi, i)) {
+                start_record = i;
+                if(i == 0) {
+                    flush_length += NVRAM_LDI_HEADER_SIZE;
+                    if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+                        flush_append_length += NVRAM_LDI_APPENDIX_HEADER_SIZE;
+                    }
+                }else {
+                    flush_length += section_size;
+                    if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+                        flush_append_length += nvram_chksum_size;
+                    }
+                }
+                if(i < rec_amount)
+                {
+                    for (j = i+1; j <= rec_amount; j++)
+                    {
+                        if (check_dirty_bit_by_cache_table(cache_ldi, j)) {
+                            flush_length += section_size;
+                            if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+                                flush_append_length += nvram_chksum_size;
+                            }
+                            if(j == rec_amount) {
+                                end_record = j;
+                                i = j;
+                                break;
+                            }
+                        }else {
+                            end_record = j-1;
+                            i = j-1;
+                            break;
+                        }
+                    }
+                }
+                else         
+                {
+                    end_record = i;
+                }
+
+                if (start_record== 0) {
+        
+                    file_offset = 0;
+                    if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+                        file_append_offset = NVRAM_LDI_HEADER_SIZE + (section_size * rec_amount) ;
+                    }
+                }else{
+            
+                    file_offset = NVRAM_LDI_HEADER_SIZE + (start_record-1) * section_size;
+                    if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+                        file_append_offset = NVRAM_LDI_HEADER_SIZE + (section_size * rec_amount) + NVRAM_LDI_APPENDIX_HEADER_SIZE +((start_record-1) * nvram_chksum_size);
+                    }
+                }
+                if (file_offset) {
+                    NVRAM_FS_START(FS_OP_SEEK);
+                    drv_status[multiple_ID] = FS_Seek(hFile, file_offset, FS_FILE_BEGIN);
+                    NVRAM_FS_END(FS_OP_SEEK,drv_status[multiple_ID]);
+                    if (FS_NO_ERROR > drv_status[multiple_ID]){
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,drv_status[multiple_ID]);
+                        nvram_cache_last_line = __LINE__;
+                        goto FS_OP_ERROR;
+                    }
+                }
+
+                temp_offset = (kal_uint32)((g_nvcache_base_address + (cache_info_header.cache_table_offset + cache_ldi->cache_offset)) + file_offset);
+                len = 0;
+                NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"LID 0x%04X start_record=%d end_record=%d\r\n",cache_queue_ldi->ldi->LID,start_record,end_record);
+                while(flush_length > 0) {
+                    if(flush_length > MD_CCCI_LIMIT_SIZE) {
+                        working_buffer_size = MD_CCCI_LIMIT_SIZE;
+                    }else{
+                        working_buffer_size = flush_length;
+                    }
+
+                    get_cache_data(temp_offset, working_buffer, working_buffer_size);
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    drv_status[multiple_ID] = FS_Write(hFile, working_buffer, working_buffer_size, &len);
+                    NVRAM_FS_END(FS_OP_WRITE,drv_status[multiple_ID]);
+                    
+                    if (FS_NO_ERROR > drv_status[multiple_ID]) {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,drv_status[%d]=%d\r\n",__FUNCTION__,__LINE__,multiple_ID,drv_status[multiple_ID]);
+                        nvram_cache_last_line = __LINE__;
+                        goto FS_OP_ERROR;
+                    }
+
+                    temp_offset = temp_offset + len;
+                    flush_length = flush_length - len;
+                }
+
+                if (cache_queue_ldi->ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) 
+                {
+                    working_buffer_size = flush_append_length;
+                    NVRAM_FS_START(FS_OP_SEEK);
+                    drv_status[multiple_ID] = FS_Seek(hFile, file_append_offset, FS_FILE_BEGIN);
+                    NVRAM_FS_END(FS_OP_SEEK,drv_status[multiple_ID]);
+                    if (file_append_offset && FS_NO_ERROR > drv_status[multiple_ID]) {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        nvram_cache_last_line = __LINE__;
+                        goto FS_OP_ERROR;
+                    }
+
+                    temp_offset = (kal_uint32)((g_nvcache_base_address + (cache_info_header.cache_table_offset + cache_ldi->cache_offset)) + file_append_offset);
+                    len = 0;
+
+                    while(flush_append_length > 0) {
+
+                        if(flush_append_length > MD_CCCI_LIMIT_SIZE) {
+
+                            working_buffer_size = MD_CCCI_LIMIT_SIZE;
+                        }else{
+
+                            working_buffer_size = flush_append_length;
+                        }
+
+                        get_cache_data(temp_offset, working_buffer, working_buffer_size);
+                        NVRAM_FS_START(FS_OP_WRITE);
+                        drv_status[multiple_ID] = FS_Write(hFile, working_buffer, working_buffer_size, &len);
+                        NVRAM_FS_END(FS_OP_WRITE,drv_status[multiple_ID]);
+                        if (FS_NO_ERROR > drv_status[multiple_ID]) {
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                            nvram_cache_last_line = __LINE__;
+                            goto FS_OP_ERROR;
+                        }
+
+                        temp_offset = temp_offset + len;
+                        flush_append_length = flush_append_length - len;
+
+                    }
+                }
+
+                unmask_dirty_bit_by_cache_table(cache_ldi, start_record, (end_record - start_record)+1);
+                mask_valid_bit_by_cache_table(cache_ldi, start_record, (end_record - start_record)+1);
+            }
+
+        }
+
+FS_OP_ERROR:
+    
+        if(hFile > FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+        }
+
+        if(drv_status[multiple_ID] < FS_NO_ERROR)
+        {
+            if(!multiple)
+            {
+                result = drv_status[multiple_ID];
+                goto final;
+            }else
+            {
+                if(multiple_ID == 1)
+                {
+                    result = drv_status[multiple_ID];
+                    goto final;
+                }
+            }
+        }else
+        {
+            if(multiple)
+            {                
+                kal_mem_set(src_path, 0x0, NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));               
+                kal_mem_set(dest_path, 0x0, NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+                
+                if(multiple_ID == 0)
+                {
+                    nvram_util_make_lid_filename(cache_queue_ldi->ldi, nvramname, KAL_TRUE);  // A
+                    nvram_query_file_name(nvram_query_folder_index_ex(cache_queue_ldi->ldi->category, KAL_TRUE), nvramname, src_path);
+
+                    nvram_util_make_lid_filename(cache_queue_ldi->ldi, nvramname, KAL_FALSE); // B
+                    nvram_query_file_name(nvram_query_folder_index_ex(cache_queue_ldi->ldi->category, KAL_FALSE), nvramname, dest_path);
+                    NVRAM_FS_START_EX(FS_OP_MOVE, dest_path);
+                    ret = FS_Move(src_path, dest_path, FS_MOVE_COPY, NULL, NULL, 0); //A to B
+                    NVRAM_FS_END(FS_OP_MOVE,ret);
+                }else
+                {
+                    nvram_util_make_lid_filename(cache_queue_ldi->ldi, nvramname, KAL_FALSE);  // B
+                    nvram_query_file_name(nvram_query_folder_index_ex(cache_queue_ldi->ldi->category, KAL_FALSE), nvramname, src_path);
+
+                    nvram_util_make_lid_filename(cache_queue_ldi->ldi, nvramname, KAL_TRUE); // A
+                    nvram_query_file_name(nvram_query_folder_index_ex(cache_queue_ldi->ldi->category, KAL_TRUE), nvramname, dest_path);
+
+                    NVRAM_FS_START_EX(FS_OP_MOVE, dest_path);
+                    ret = FS_Move(src_path, dest_path, FS_MOVE_COPY, NULL, NULL, 0); //B to A
+                    NVRAM_FS_END(FS_OP_MOVE,ret);
+                }               
+                result = drv_status[multiple_ID];
+                goto final;
+
+            }else
+            {
+                result = drv_status[multiple_ID];
+                goto final;
+            }
+            
+        }
+    
+    }
+
+final:
+
+    nvram_util_give_mutex(g_nvram_fs_mutex);   
+    
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+    }
+    if (FS_NO_ERROR > result)
+    {
+        nvram_cache_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_cache_last_err, nvram_cache_last_line);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"Failed at %d,result=%d\r\n",__LINE__,result);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_ERRNO_FAIL;
+    }
+    
+    if(cache_ldi->is_reset == 1)
+    {
+        cache_ldi->is_reset = 0;
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return NVRAM_IO_ERRNO_OK;
+}
+
+#ifdef __NVRAM_UT_TEST__
+static kal_bool check_cache_lid_all_record_is_undirty_bit(nvram_ltable_entry_struct* ldi)
+{
+   kal_uint8 i;
+   for(i = 1; i <= ldi->total_records; i++)
+   {
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            return KAL_FALSE;
+        }
+   }
+   return KAL_TRUE;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_flush_cache_handler
+ * DESCRIPTION
+ *  nvram flush cache handler
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * working_buffer [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_flush_cache_handler(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_cache_write_item cache_queue_ldi;
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;    
+    nvram_ltable_entry_struct tmp_ldi;
+    FS_HANDLE hFile = 0;
+    kal_uint8 *filename = NULL;
+    mcf_ota_result_e mcf_ota_ret = MCF_OTA_R_SUCCESS;
+    kal_int32 result = FS_NO_ERROR;
+    #if defined(__MTK_TARGET__)
+    kal_uint32 temp_queue_length = 0;
+    ostd_ap_core_status_enum temp_ostd_status = OSTD_AP_CORE_UNKNOWN;
+    #endif
+    
+    kal_mem_set(&cache_queue_ldi, 0x0, sizeof(nvram_cache_write_item));
+    
+    do {
+
+        #if defined(__MTK_TARGET__)
+        if((temp_queue_length = nvram_cache_queue_usage_rates()) < CACHE_QUEUE_BOUNDARY_SIZE)
+        {
+            if((temp_ostd_status = OSTD_return_AP_status()) == OSTD_AP_CORE_SUSPEND)
+            {
+                kal_prompt_trace(MOD_NVRAM, "queue_length:%d, ostd_status:%d\n\r", temp_queue_length, temp_ostd_status);
+                MD_TRC_IO_WRITE_DATA_ITEM_RESULT(temp_queue_length, temp_ostd_status, __LINE__);
+                break;
+            }
+        }
+
+        kal_prompt_trace(MOD_NVRAM, "queue_length:%d, ostd_status:%d\n\r", temp_queue_length, temp_ostd_status);
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(temp_queue_length, temp_ostd_status, __LINE__);
+        #endif
+
+        if (!nvram_cache_dequeue(&cache_queue_ldi)) {
+
+            break;
+        }
+
+        #ifdef __NVRAM_UT_TEST__
+        if(check_cache_lid_all_record_is_undirty_bit(cache_queue_ldi.ldi))
+        {
+            continue;
+        }
+        if (NVRAM_FLUSH_CACHE_CHECK(cache_queue_ldi.ldi->LID))
+        {
+            kal_prompt_trace(MOD_NVRAM, "%s @%d NVCACHE flush bypass whilte list LID=%d\n\r",__FUNCTION__,__LINE__ , cache_queue_ldi.ldi->LID);
+            NVRAM_EXT_ASSERT(KAL_FALSE, __LINE__, NVRAM_LOC_INVALID_LID_5, cache_queue_ldi.ldi->LID);
+        }
+        #endif
+        status = nvram_flush_cache_data_to_file(&cache_queue_ldi);
+
+        /*
+           If write fail and the LID is located in NVRAM folder's subfolder,
+           first check the root folder is OK or not.
+           */
+
+        if(status != NVRAM_IO_ERRNO_OK) 
+        {
+                if(NVRAM_IS_CATEGORY_INTERNAL(cache_queue_ldi.ldi->category) || NVRAM_IS_CATEGORY_CALIBRAT(cache_queue_ldi.ldi->category) ||
+                    NVRAM_IS_CATEGORY_IMPORTANT(cache_queue_ldi.ldi->category) || (NVRAM_NVD_DATA == nvram_query_folder_index(cache_queue_ldi.ldi->category)))
+                {
+                    filename = (kal_uint8 *) get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+                   NVRAM_FS_MAKE_ROOT_PATH((kal_wchar*)filename);
+                   nvram_util_take_mutex(g_nvram_fs_mutex);
+                   NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+                   hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_DIR);
+                   NVRAM_FS_END(FS_OP_OPEN,hFile);
+                   free_ctrl_buffer(filename);
+                   filename = NULL;
+                   if(hFile >= FS_NO_ERROR)   /* Open NVRAM root folder Success */
+                   {
+                       NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s->FS_Open Success at %d,hFile=%d\r\n",__FUNCTION__,__LINE__,hFile);
+                       NVRAM_FS_START(FS_OP_CLOSE);
+                       result = FS_Close(hFile);
+                       NVRAM_FS_END(FS_OP_CLOSE,result);
+                   }
+                   else if (hFile == FS_FILE_NOT_FOUND || hFile == FS_PATH_NOT_FOUND)
+                   {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s NVRAM main folder lost\r\n",__FUNCTION__);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s NVRAM_ERROR_LOC_NVCACHE_OPEN_NV_FOLDER_FAIL_1\r\n",__FUNCTION__);
+                        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)hFile, NVRAM_ERROR_LOC_NVCACHE_OPEN_NV_FOLDER_FAIL_1, 0);
+                   }
+                   else
+                   {
+                       kal_prompt_trace(MOD_NVRAM, "Open NVRAM root folder result:%d\n\r", (kal_uint32)hFile);
+                       NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"Open NVRAM root folder result:%d\r\n",(kal_uint32)hFile);
+                   }
+                   nvram_util_give_mutex(g_nvram_fs_mutex);
+               }
+           }
+           
+            memcpy(&tmp_ldi,cache_queue_ldi.ldi,sizeof(nvram_ltable_entry_struct));
+            if (status != NVRAM_IO_ERRNO_OK)
+               {                
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+                   if (NVRAM_IS_CATEGORY_IN_BIN_REGION(cache_queue_ldi.ldi->category))
+                   {
+                       // try restore from bin region
+                       if (nvram_recover_data_item(cache_queue_ldi.ldi) == NVRAM_IO_ERRNO_OK)
+                       {
+                            if(nvram_ptr->state == NVRAM_STATE_READY)
+                           {
+                               mcf_ota_ret = mcf_do_ota_by_lid(cache_queue_ldi.ldi->LID,1, cache_queue_ldi.ldi->total_records,&tmp_ldi);
+                               kal_prompt_trace(MOD_NVRAM, "%s @%d mcr_ota_ret=%d\n\r",__FUNCTION__,__LINE__ , mcf_ota_ret);
+                               NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"mcf_do_ota_by_lid return %d\r\n",mcf_ota_ret);
+                           }
+                           status = nvram_flush_cache_data_to_file(&cache_queue_ldi);
+                           NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"nvram_flush_cache_data_to_file return %d\r\n",status); 
+                           if (status == NVRAM_IO_ERRNO_OK)
+                           {
+                               goto end;
+                           }
+                       }
+                   }
+#endif
+           
+                   /* IMEI and SML */
+                   if (NVRAM_IS_ATTR_FAULT_ASSERT(cache_queue_ldi.ldi->attr))
+                   {
+                       kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_ERROR_LOC_NVCACHE_WRITE_IMPORTANT_DATA_FAIL_2:%d\n\r", DISPLAY_ERROR(status));                      
+                       kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", cache_queue_ldi.ldi->LID, cache_queue_ldi.ldi->total_records, cache_queue_ldi.ldi->size);
+                       kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", cache_queue_ldi.ldi->category, cache_queue_ldi.ldi->attr);
+                       kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", cache_queue_ldi.ldi->fileprefix, cache_queue_ldi.ldi->fileverno);                        
+                       NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_ERROR_LOC_NVCACHE_WRITE_IMPORTANT_DATA_FAIL_2:%d\r\n", DISPLAY_ERROR(status));
+                       NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", cache_queue_ldi.ldi->LID, cache_queue_ldi.ldi->total_records, cache_queue_ldi.ldi->size);
+                       NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", cache_queue_ldi.ldi->category, cache_queue_ldi.ldi->attr);
+                       NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", cache_queue_ldi.ldi->fileprefix, cache_queue_ldi.ldi->fileverno);
+                       NVRAM_EXT_ASSERT (KAL_FALSE, DISPLAY_ERROR(status),NVRAM_ERROR_LOC_NVCACHE_WRITE_IMPORTANT_DATA_FAIL_2 , cache_queue_ldi.ldi->LID);                                              
+                       return status;
+                   }
+           
+           
+                   MD_TRC_IO_WRITE_DATA_ITEM_RESULT(cache_queue_ldi.ldi->LID, status, __LINE__);
+           
+                   if (KAL_TRUE
+        #ifdef __NVRAM_CUSTOM_DISK__
+                       && !NVRAM_IS_CATEGORY_CUSTOM_DISK(cache_queue_ldi.ldi->category)
+        #endif
+        #ifdef __NVRAM_OTP__
+                       && !NVRAM_IS_CATEGORY_OTP(cache_queue_ldi.ldi->category)
+        #endif
+                       )
+                   {
+                       /* Try to reset data if it is not a initial case */
+                       if ((status = nvram_cache_reset_one_data_item(cache_queue_ldi.ldi, 1, cache_queue_ldi.ldi->total_records)) == NVRAM_IO_ERRNO_OK)
+                       {
+                           MD_TRC_IO_WRITE_DATA_ITEM_RESULT(cache_queue_ldi.ldi->LID, status, __LINE__);
+                           NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s->nvram_cache_reset_one_data_item successfully\r\n",__FUNCTION__);                           
+                           if(nvram_ptr->state == NVRAM_STATE_READY)
+                           {
+                               mcf_ota_ret = mcf_do_ota_by_lid(cache_queue_ldi.ldi->LID,1, cache_queue_ldi.ldi->total_records,&tmp_ldi);
+                               kal_prompt_trace(MOD_NVRAM, "%s @%d mcr_ota_ret=%d\n\r",__FUNCTION__,__LINE__ , mcf_ota_ret);
+                               NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s->mcf_do_ota_by_lid return %d\r\n",__FUNCTION__,mcf_ota_ret);
+                           }                           
+                           status = nvram_flush_cache_data_to_file(&cache_queue_ldi);
+                           NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"nvram_flush_cache_data_to_file after reset status:%d\r\n",status);
+                           
+                       }
+                       //nvram_trace(TRACE_FUNC, IO_WRITE_DATA_ITEM_RESULT, ldi->LID, status, __LINE__, is_init);
+                   }
+               }
+           
+               if (status != NVRAM_IO_ERRNO_OK)
+               {
+                   MD_TRC_IO_WRITE_DATA_ITEM_RESULT(cache_queue_ldi.ldi->LID, status, __LINE__);
+                   kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_ERROR_LOC_NVCACGE_WRITE_AND_RESET_FAIL_2:%d\n\r", DISPLAY_ERROR(status));
+                   kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", cache_queue_ldi.ldi->LID, cache_queue_ldi.ldi->total_records, cache_queue_ldi.ldi->size);
+                   kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", cache_queue_ldi.ldi->category, cache_queue_ldi.ldi->attr);
+                   kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", cache_queue_ldi.ldi->fileprefix, cache_queue_ldi.ldi->fileverno);
+                   
+                   NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_ERROR_LOC_NVCACGE_WRITE_AND_RESET_FAIL_2:%d\r\n", DISPLAY_ERROR(status));
+                   NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", cache_queue_ldi.ldi->LID, cache_queue_ldi.ldi->total_records, cache_queue_ldi.ldi->size);
+                   NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", cache_queue_ldi.ldi->category, cache_queue_ldi.ldi->attr);
+                   NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", cache_queue_ldi.ldi->fileprefix, cache_queue_ldi.ldi->fileverno);
+                   NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_ERROR_LOC_NVCACGE_WRITE_AND_RESET_FAIL_2, cache_queue_ldi.ldi->LID);
+               }
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+           end:
+#endif
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+               if (status == NVRAM_IO_ERRNO_OK)
+               {
+                   nvram_util_post_write_lid(cache_queue_ldi.ldi);
+               }
+#endif
+    } while(1);
+    
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  mark_cache_task_ready
+ * DESCRIPTION
+ *  mark NVRAM cache task ready
+ * PARAMETERS
+ *  flag      [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool mark_nvram_cache_ready(void)
+{
+    g_nvram_cache_ready = KAL_TRUE;
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  unmark_nvram_cache_task_ready
+ * DESCRIPTION
+ *  unmark NVRAM cache task ready
+ * PARAMETERS
+ *  flag      [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool unmark_nvram_cache_ready(void)
+{
+    g_nvram_cache_ready = KAL_FALSE;
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  check_nvram_cache_task_ready
+ * DESCRIPTION
+ *  check NVRAM cache task whether ready
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  TRUE or FALSE
+ *****************************************************************************/
+kal_bool check_nvram_cache_ready(void)
+{
+    kal_bool ready = KAL_FALSE;
+    ready = ((g_nvram_cache_ready? KAL_TRUE : KAL_FALSE) && (KAL_FALSE == kal_query_systemInit())
+                && (kal_query_boot_mode() != FACTORY_BOOT) && (stack_get_active_module_id() != MOD_FT));
+    return ready;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  check_nvram_cache_initialized
+ * DESCRIPTION
+ *  check NVRAM cache task whether initialized 
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  TRUE or FALSE
+ *****************************************************************************/
+kal_bool check_nvram_cache_initialized(void)
+{
+    kal_bool initialzied = KAL_FALSE;
+    initialzied = ((g_nvram_cache_ready? KAL_TRUE : KAL_FALSE) && (kal_query_boot_mode() != FACTORY_BOOT) && (stack_get_active_module_id() != MOD_FT));
+    return initialzied;
+}
+
+#if ((!defined(__MTK_TARGET__)) && (!defined(__UE_SIMULATOR__)))
+
+static void nvcache_assgn_ltable(void)
+{
+    kal_uint32 i, offset = 0;
+    nvram_ltable_entry_struct *ltable_entry = NULL;
+    nvram_ltable_entry_struct *the_start = &_nvram_ltable_start;
+    kal_uint32 start_addr = (kal_uint32)the_start, end_addr = (kal_uint32)&the_nvram_ltable_end;
+
+  #if defined(_MSC_VER) && !defined(L1_SIM)
+    //skip session gap
+    for (offset = 0; offset < 0x1000; offset += 32) // __declspec(align(32))
+    {
+        ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[0] + offset);
+        if(ltable_entry->fileprefix[0]) {
+            break;
+        }
+    }
+  #endif
+
+    for (i = 0;(kal_uint32)ltable_entry <= end_addr; i++)
+    {
+        ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[i] + offset);
+        
+        if (assgn_logical_data_item_table == NULL && ltable_entry->fileprefix[0])
+        {
+            assgn_logical_data_item_table = ltable_entry;
+            assgn_ltable.table = &assgn_logical_data_item_table;
+        }
+
+        if (ltable_entry->fileprefix[0])
+        {
+            //printf("%03d: ltable[%d]:%x filename = %s\n", nvram_ptr->ltable.total_LID, ltable_entry->LID, ltable_entry, ltable_entry->fileprefix);
+            assgn_ltable.total_LID++;
+        }
+        else
+        {
+            ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[i] + offset + 32);
+            if (ltable_entry->fileprefix[0])
+            {
+                //printf("%03d: ltable[%d]:%x filename = %s\n", nvram_ptr->ltable.total_LID, ltable_entry->LID, ltable_entry, ltable_entry->fileprefix);
+                assgn_ltable.total_LID++;
+            }
+        }
+    }
+
+    assgn_ltable.area_size = (kal_uint32)ltable_entry - (kal_uint32)assgn_logical_data_item_table;
+
+}
+
+kal_bool nvcache_util_get_data_item(nvram_ltable_entry_struct **ldi, nvram_lid_enum LID)    
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i = 0, count = 0;
+    kal_uint32 end = (kal_uint32)assgn_logical_data_item_table + assgn_ltable.area_size;
+
+    do 
+    {
+        if (assgn_logical_data_item_table[i].fileprefix[0])
+        {
+            count++;
+
+            if (assgn_logical_data_item_table[i].LID == LID)
+            {
+                if (ldi) {
+                    *ldi = &assgn_logical_data_item_table[i];
+                }
+                return KAL_TRUE;
+            }
+        }
+        i++;
+    }while(count < assgn_ltable.total_LID && ((kal_uint32)&assgn_logical_data_item_table[i] < end));
+
+    if (ldi)
+        *ldi = NULL;
+
+    return KAL_FALSE;
+}
+
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_task_main
+ * DESCRIPTION
+ *  NVRAM cache task
+ * PARAMETERS
+ *  task_entry_ptr      [?]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_cache_main(task_entry_struct *task_entry_ptr)
+{
+
+    kal_uint32 count = 0; // for debg, CVD var error, can remove
+    //kal_uint32 retrieved_events = 0;
+    kal_status status;
+    if(g_nvram_cache_SHM_support == KAL_TRUE)
+    {
+        //kal_set_active_module_id();
+        while(1) {
+            count ++;
+            //wait for some events, then do something.
+            if((status = nvram_cache_retrieve_event()) == KAL_SUCCESS) {
+                nvram_flush_cache_handler();
+            }else {
+                //NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status),1,1,1);
+                break;
+            }
+            /**do your own things*/
+        }
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_task_init
+ * DESCRIPTION
+ *  This is init() function of NVRAM cache task of NVRAM module.
+ *  This function initialize all the context variables required for NVRAM cache task of NVRAM module
+ * PARAMETERS
+ *  task_indx       [IN]
+ * RETURNS
+ *  True if succeed.
+ *****************************************************************************/
+kal_bool nvram_cache_init(void)
+{
+    #if defined(__HIF_CCCI_SUPPORT__)
+    CCCI_RUNTIME_FEATURE_SUPPORT_T feature_support = {0};
+    CCCI_RUNTIME_SHARE_MEMORY_FORMAT_T shm = {0};
+    #endif
+
+    #if (!defined(__MTK_TARGET__)) && (!defined(__UE_SIMULATOR__))
+    kal_uint32 temp_offset = 0;
+    kal_int32  i;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 remainLen = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    #ifdef __NVRAM_UT_TEST__
+    extern nvram_checksum_config NVRAM_CHK_CONFIG;
+    #else
+    extern const nvram_checksum_config NVRAM_CHK_CONFIG;
+    #endif
+
+    nvcache_assgn_ltable();
+    
+    for(i = 0; i < cache_info_header.cache_lid_num; i++)
+    {
+        remainLen = 0;
+        if(nvcache_util_get_data_item(&ldi, cache_info_table[i].LID))
+        {
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if(NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(ldi->attr))
+            {
+                if(NVRAM_MD5 == NVRAM_CHK_CONFIG.enhance_algo_type)
+                {
+                    nvram_chksum_size = MD5_CHKSUM_LENGTH_8;
+                }else
+                {
+                     nvram_chksum_size = NVRAM_CHK_CONFIG.enhance_algo_size;   
+                }
+            }else
+            {
+                if(NVRAM_MD5 == NVRAM_CHK_CONFIG.default_algo_type)
+                {
+                    nvram_chksum_size = MD5_CHKSUM_LENGTH_8;
+                }else
+                {
+                     nvram_chksum_size = NVRAM_CHK_CONFIG.default_algo_size;   
+                }
+            }
+            #else
+            nvram_chksum_size = MD5_CHKSUM_LENGTH_8;
+            #endif
+
+             #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+             if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+             {
+                /* 16 byte alignment */
+                remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size);
+             }
+             #else
+             if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+             {
+                /* 16 byte alignment */
+                remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size);
+             }
+             #endif  
+             if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+             {
+                cache_info_table[i].file_length = nvram_cache_appendix_header_offset(ldi) + NVRAM_LDI_APPENDIX_HEADER_SIZE + (ldi->total_records * nvram_chksum_size);
+             }else
+             {
+                cache_info_table[i].file_length = NVRAM_LDI_HEADER_SIZE + ((ldi->size + nvram_chksum_size + remainLen) * ldi->total_records);
+             }
+             cache_info_table[i].cache_offset = temp_offset;
+             temp_offset = ((cache_info_table[i].file_length + temp_offset + (4 - 1)) & (~(4-1)));
+        }
+        else
+        {
+            cache_info_table[i].cache_offset = temp_offset;
+            temp_offset = ((cache_info_table[i].file_length + temp_offset + (4 - 1)) & (~(4-1)));
+            //return KAL_FALSE;
+        }
+    }
+    cache_info_header.cache_table_size = temp_offset;
+    #endif
+
+    #if defined(__MTK_TARGET__)
+
+    #if defined(__HIF_CCCI_SUPPORT__)
+    feature_support = ccci_runtime_data_query(AP_CCCI_RUNTIME_NVRAM_CACHE_SHARE_MEMORY, &shm, sizeof(CCCI_RUNTIME_SHARE_MEMORY_FORMAT_T));
+    if(feature_support.support_mask == CCCI_RUNTIME_FEATURE_MUST_SUPPORT)
+    {
+        g_nvcache_base_address = (kal_uint8 *)(shm.addr);
+        g_nvcache_memory_size = shm.size;
+        if ((cache_info_header.cache_table_offset + cache_info_header.cache_table_size) >= shm.size)
+        {
+            g_nvram_cache_SHM_support = KAL_FALSE;
+            MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(shm.addr, shm.size);
+            NVRAM_EXT_ASSERT (KAL_FALSE, shm.addr, shm.size, (cache_info_header.cache_table_offset + cache_info_header.cache_table_size));
+        }
+        kal_mem_set((void *)g_nvcache_base_address,0,shm.size);
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(shm.addr, shm.size);
+    }else
+    {
+        g_nvram_cache_SHM_support = KAL_FALSE;
+        unmark_nvram_cache_ready();
+        NVRAM_EXT_ASSERT (KAL_FALSE, feature_support.support_mask, NVRAM_ERROR_LOC_NVCACHE_ERRNO_SHM_GET_FAILED , __LINE__);
+        return KAL_TRUE;
+    }
+    #else
+        g_nvram_cache_SHM_support = KAL_FALSE;
+        unmark_nvram_cache_ready();
+        return KAL_TRUE;
+    #endif
+    kal_mem_cpy(g_nvcache_base_address, &cache_info_header,sizeof(nvram_lid_cache_header));
+    kal_mem_cpy((g_nvcache_base_address + cache_info_header.table_index_offset), cache_info_table, cache_info_header.table_index_size);
+    
+    #elif (!defined(__UE_SIMULATOR__))
+    g_nvcache_base_address =(kal_uint8 *) malloc(CACHE_SHARE_MEMORY_SIZE);
+    if(g_nvcache_base_address == NULL)
+    {
+        g_nvram_cache_SHM_support = KAL_FALSE;
+        unmark_nvram_cache_ready();
+        NVRAM_EXT_ASSERT (KAL_FALSE, KAL_FALSE, NVRAM_ERROR_LOC_NVCACHE_ERRNO_SHM_MALLOC_FAILED , __LINE__);
+        return KAL_TRUE;
+    }
+    kal_mem_set((void *)g_nvcache_base_address,0,CACHE_SHARE_MEMORY_SIZE);
+    kal_mem_cpy(g_nvcache_base_address, &cache_info_header,sizeof(nvram_lid_cache_header));
+    kal_mem_cpy((g_nvcache_base_address + cache_info_header.table_index_offset), cache_info_table, cache_info_header.table_index_size);    
+    #else
+        g_nvram_cache_SHM_support = KAL_FALSE;
+        unmark_nvram_cache_ready();
+        return KAL_TRUE;
+    #endif
+    
+    g_nvram_cache_SHM_support = KAL_TRUE;
+    g_nvram_cache_mutex = kal_create_mutex("NV_CACHE");
+    nvram_cache_event_init();
+    nvram_cache_queue_init();
+
+    mark_nvram_cache_ready();
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_task_reset
+ * DESCRIPTION
+ *  This is reset() function of NVRAM cache task of NVRAM module.
+ * PARAMETERS
+ *  task_indx       [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_bool nvram_cache_reset(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    g_nvram_cache_ready = KAL_FALSE;
+    #if defined (__NVRAM_UT_TEST__)
+    nvram_cache_queue_init();
+    
+    kal_mem_set(g_nvcache_base_address + cache_info_header.dirty_mapping_offset,0,cache_info_header.dirty_mapping_size);
+    kal_mem_set(g_nvcache_base_address + cache_info_header.valid_mapping_offset,0,cache_info_header.dirty_mapping_size);
+    #endif
+    return KAL_TRUE;
+}   /* end of nvram_reset function */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_task_create
+ * DESCRIPTION
+ *  NVRAM cache task create function
+ * PARAMETERS
+ *  handle      [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_cache_create(comptask_handler_struct **handle)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    static const comptask_handler_struct nvram_cache_task_handler_info =
+    {
+        nvram_cache_main,    /* task entry function */
+        nvram_cache_init,         /* task initialization function */
+        nvram_cache_reset        /* task reset handler */
+    };
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    *handle = (comptask_handler_struct*) & nvram_cache_task_handler_info;
+    return KAL_TRUE;
+}
+
diff --git a/mcu/service/nvram/src/nvram_cache_dirty_valid_mask.c b/mcu/service/nvram/src/nvram_cache_dirty_valid_mask.c
new file mode 100644
index 0000000..5e96765
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_cache_dirty_valid_mask.c
@@ -0,0 +1,597 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+#include "nvram_cache_interface.h"
+#include "us_timer.h"
+#include "ex_public.h"
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+extern kal_uint8 * g_nvcache_base_address;
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+extern module_type stack_get_active_module_id( void );
+
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+
+/*****************************************************************************
+ * FUNCTION
+ *  set_reset_flag_by_ltable_entry
+ * DESCRIPTION
+ *  mask LID to be reset for write LID to storage always
+ * PARAMETERS
+ *  ldi             [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool set_reset_flag_by_ltable_entry(nvram_ltable_entry_struct* ldi)
+{
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_bool result = KAL_FALSE;
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_9, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }    
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    cache_ldi->is_reset = 1;
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  mask_dirty_bit_by_ltable_entry
+ * DESCRIPTION
+ *  mask LID record to dirty, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool mask_dirty_bit_by_ltable_entry(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_dirty_adderss = NULL;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_bool result = KAL_FALSE;
+    kal_uint32* dirty_bit_boundary = NULL;
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_10, ldi->LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_dirty_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_ldi->dirty_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_dirty_adderss + ((rec_index + i)/32);
+        dirty_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > dirty_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_1, cache_ldi->LID);
+        }
+        *rec_index_offset |=  (1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  mask_dirty_bit_by_cache_table
+ * DESCRIPTION
+ *  mask LID record to dirty, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool mask_dirty_bit_by_cache_table(nvram_lid_cache_table_struct* cache_ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_dirty_adderss = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_uint32* dirty_bit_boundary = NULL;
+    
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_dirty_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_ldi->dirty_offset));
+    
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_dirty_adderss + ((rec_index + i)/32);
+        dirty_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > dirty_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_2, cache_ldi->LID);
+        }
+        *rec_index_offset |=  (1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  unmask_dirty_bit
+ * DESCRIPTION
+ *  unmask LID record to dirty, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool unmask_dirty_bit_by_ltable_entry(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_dirty_adderss = NULL;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_bool result = KAL_FALSE;
+    kal_uint32* dirty_bit_boundary = NULL;
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_11, ldi->LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_dirty_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_ldi->dirty_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_dirty_adderss + ((rec_index + i)/32);
+        dirty_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > dirty_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_3, cache_ldi->LID);
+        }
+        *rec_index_offset &=  ~(1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  unmask_dirty_bit_by_cache_table
+ * DESCRIPTION
+ *  unmask LID record to dirty, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool unmask_dirty_bit_by_cache_table(nvram_lid_cache_table_struct* cache_ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_dirty_adderss = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_uint32* dirty_bit_boundary = NULL;
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_dirty_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_ldi->dirty_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_dirty_adderss + ((rec_index + i)/32);
+        dirty_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > dirty_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_4, cache_ldi->LID);
+        }
+        *rec_index_offset &=  ~(1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  mask_valid_bit_by_ltable_entry
+ * DESCRIPTION
+ *  mask LID record to valid, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool mask_valid_bit_by_ltable_entry(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_valid_adderss = NULL;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_bool result = KAL_FALSE;
+    kal_uint32* valid_bit_boundary = NULL;
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_12, ldi->LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_valid_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_ldi->valid_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_valid_adderss + ((rec_index + i)/32);
+        valid_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > valid_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_5, cache_ldi->LID);
+        }
+        *rec_index_offset |=  (1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  mask_valid_bit_by_cache_table
+ * DESCRIPTION
+ *  mask LID record to valid, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool mask_valid_bit_by_cache_table(nvram_lid_cache_table_struct* cache_ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_valid_adderss = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_uint32* valid_bit_boundary = NULL;
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_valid_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_ldi->valid_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_valid_adderss + ((rec_index + i)/32);
+        valid_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > valid_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_6, cache_ldi->LID);
+        }
+        *rec_index_offset |=  (1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  unmask_valid_bit_by_ltable_entry
+ * DESCRIPTION
+ *  ummask LID record to valid, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool unmask_valid_bit_by_ltable_entry(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_valid_adderss = NULL;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_bool result = KAL_FALSE;
+    kal_uint32* valid_bit_boundary = NULL;
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID,ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_13, ldi->LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_valid_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_ldi->valid_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_valid_adderss + ((rec_index + i)/32);
+        valid_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > valid_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_7, cache_ldi->LID);
+        }
+        *rec_index_offset &=  ~(1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  unmask_valid_bit_by_cache_table
+ * DESCRIPTION
+ *  ummask LID record to valid, for update LID cache status
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool unmask_valid_bit_by_cache_table(nvram_lid_cache_table_struct * cache_ldi, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    kal_uint32* ldi_valid_adderss = NULL;
+    kal_uint32 i;
+    kal_uint32* rec_index_offset = NULL;
+    kal_uint32* valid_bit_boundary = NULL;
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_valid_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_ldi->valid_offset));
+
+    for(i = 0; i < rec_amount; i++) {
+        rec_index_offset = ldi_valid_adderss + ((rec_index + i)/32);
+        valid_bit_boundary = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_info_header.dirty_mapping_size));
+        if(rec_index_offset > valid_bit_boundary) 
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)rec_index_offset, NVRAM_ERROR_LOC_NVCACHE_ERRNO_BIT_BOUNDARY_8, cache_ldi->LID);
+        }
+        *rec_index_offset &=  ~(1 << ((rec_index + i)%32));
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  check_valid_bit_by_ltable_entry
+ * DESCRIPTION
+ *  check LID record whether valid
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool check_valid_bit_by_ltable_entry(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index)
+{
+    kal_uint32* ldi_valid_adderss = NULL;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32* rec_index_offset = NULL;
+    kal_bool result = KAL_FALSE;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID, ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_14, ldi->LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_valid_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_ldi->valid_offset));
+
+    rec_index_offset = ldi_valid_adderss + (rec_index/32);
+    if (((*rec_index_offset)>>(rec_index % 32)) & 0x1) {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+        return KAL_TRUE;
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_FALSE;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  check_valid_bit_by_cache_table
+ * DESCRIPTION
+ *  check LID record whether valid
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool check_valid_bit_by_cache_table(nvram_lid_cache_table_struct* cache_ldi, kal_uint16 rec_index)
+{
+    kal_uint32* ldi_valid_adderss = NULL;
+    kal_uint32* rec_index_offset = NULL;
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_valid_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.valid_mapping_offset + cache_ldi->valid_offset));
+
+    rec_index_offset = ldi_valid_adderss + (rec_index/32);
+    if (((*rec_index_offset)>>(rec_index % 32)) & 0x1) {
+
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+        return KAL_TRUE;
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_FALSE;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  check_dirty_bit_by_ltable_entry
+ * DESCRIPTION
+ *  mask LID record to dirty
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool check_dirty_bit_by_ltable_entry(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index)
+{
+    kal_uint32* ldi_dirty_adderss = NULL;
+    nvram_lid_cache_table_struct *cache_ldi = NULL;
+    kal_uint32* rec_index_offset = NULL;
+    kal_bool result = KAL_FALSE;
+
+    if (!(result = get_lid_cache_index_item(ldi->LID , &cache_ldi))) {
+        kal_prompt_trace(MOD_NVRAM, "[%s]search lid failed from cache table index: 0x%x\n\r", __FUNCTION__, ldi->LID);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][%s]search lid failed from cache table\r\n", __FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID, ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_INVALID_LID_15, ldi->LID);
+        return KAL_FALSE;
+    }
+
+    
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_dirty_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_ldi->dirty_offset));
+
+    rec_index_offset = ldi_dirty_adderss + (rec_index/32);
+    if (((*rec_index_offset)>>(rec_index % 32)) & 0x1) {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+        return KAL_TRUE;
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+    return KAL_FALSE;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  check_dirty_bit_by_cache_table
+ * DESCRIPTION
+ *  mask LID record to dirty
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool check_dirty_bit_by_cache_table(nvram_lid_cache_table_struct* cache_ldi, kal_uint16 rec_index)
+{
+    kal_uint32* ldi_dirty_adderss = NULL;
+    kal_uint32* rec_index_offset = NULL;
+
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    ldi_dirty_adderss = (kal_uint32*)(g_nvcache_base_address + (cache_info_header.dirty_mapping_offset + cache_ldi->dirty_offset));
+
+    rec_index_offset = ldi_dirty_adderss + (rec_index/32);
+    if (((*rec_index_offset)>>(rec_index % 32)) & 0x1) {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+        return KAL_TRUE;
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+
+    return KAL_FALSE;
+
+}
+
diff --git a/mcu/service/nvram/src/nvram_cache_event.c b/mcu/service/nvram/src/nvram_cache_event.c
new file mode 100644
index 0000000..20c06cf
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_cache_event.c
@@ -0,0 +1,140 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "svc_sap.h"
+	 
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+#include "nvram_cache_interface.h"
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+
+
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+/* For events handle */
+kal_eventgrpid g_nvram_cache_event = {0};
+#define NVRAM_CACHE_CTRL_RECEIVE_EVNET 0x00000001
+
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  send_event_to_nvram_cache
+ * DESCRIPTION
+ *  nvram main task send event nvram cache task
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  msg_id              [IN]        
+ *  local_param_ptr     [?]         
+ *  peer_buf_ptr        [?]         
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_status send_event_to_nvram_cache(void)
+{
+	return kal_set_eg_events(g_nvram_cache_event, NVRAM_CACHE_CTRL_RECEIVE_EVNET, KAL_OR);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_retrieve_event
+ * DESCRIPTION
+ *  nvram main task send event nvram cache task
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  msg_id              [IN]        
+ *  local_param_ptr     [?]         
+ *  peer_buf_ptr        [?]         
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_status nvram_cache_retrieve_event(void)
+{
+	kal_uint32 retrieved_events = 0;
+
+	return kal_retrieve_eg_events(g_nvram_cache_event, NVRAM_CACHE_CTRL_RECEIVE_EVNET, KAL_AND_CONSUME,  &retrieved_events, KAL_SUSPEND);
+	
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_event_init
+ * DESCRIPTION
+ *  nvram main task send event nvram cache task
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  msg_id              [IN]        
+ *  local_param_ptr     [?]         
+ *  peer_buf_ptr        [?]         
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_eventgrpid nvram_cache_event_init(void)
+{	
+	g_nvram_cache_event = kal_create_event_group("NV_CACHE_EVENT");
+	
+	return g_nvram_cache_event;
+}
+
diff --git a/mcu/service/nvram/src/nvram_cache_queue.c b/mcu/service/nvram/src/nvram_cache_queue.c
new file mode 100644
index 0000000..6d50d18
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_cache_queue.c
@@ -0,0 +1,266 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+
+#include "nvram_cache_interface.h"
+#include "nvram_cache_info.h"
+#include "us_timer.h"
+#include "ex_public.h"
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+ extern module_type stack_get_active_module_id( void );
+
+
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+nvram_cache_write_queue cache_write_queue;
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_queue_usage_rates
+ * DESCRIPTION
+ * get nvram cache queue usage rates
+ * PARAMETERS
+ *  cache_queue_ldi             [OUT]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_int32 nvram_cache_queue_usage_rates(void)
+{
+    kal_int32 length = 0;
+    
+    length = ((CACHE_QUEUE_SIZE + cache_write_queue.rear - cache_write_queue.front)% CACHE_QUEUE_SIZE);
+
+	return length;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_queue_full
+ * DESCRIPTION
+ * nvram cache queue whether full 
+ * PARAMETERS
+ *  cache_queue_ldi             [OUT]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_cache_queue_full(void)
+{
+    kal_bool full_flag = KAL_FALSE;
+
+    if((cache_write_queue.rear +1)%CACHE_QUEUE_SIZE == cache_write_queue.front) {
+        full_flag = KAL_TRUE;
+    }
+
+    return full_flag;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_queue_empty
+ * DESCRIPTION
+ * nvram cache queue whether empty 
+ * PARAMETERS
+ *  cache_queue_ldi             [OUT]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_cache_queue_empty(void)
+{
+    kal_bool empty_flag = KAL_FALSE;
+    
+    if(cache_write_queue.front == cache_write_queue.rear) {
+        empty_flag = KAL_TRUE;
+    }
+
+    return empty_flag;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_queue_search_lid
+ * DESCRIPTION
+ * nvram cache queue whether full 
+ * PARAMETERS
+ *  cache_queue_ldi             [OUT]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_cache_queue_search_lid(nvram_lid_enum LID)
+{
+    kal_uint16 front;
+    kal_bool search_flag = KAL_FALSE;
+
+    if(nvram_cache_queue_empty()) {     
+        return KAL_FALSE;
+    }
+
+    front = cache_write_queue.front;
+    while(front != cache_write_queue.rear) {
+        if(cache_write_queue.queue_array[front].ldi->LID == LID) {
+            search_flag = KAL_TRUE;
+            break;
+        }
+       front = (front+1)%CACHE_QUEUE_SIZE;
+    }
+
+    return search_flag;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_enqueue
+ * DESCRIPTION
+ *  NVRAM write option push to cache queue
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/ 
+kal_bool nvram_cache_enqueue(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint32 openOption)
+{
+    kal_bool result;
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    if ((cache_write_queue.rear +1)%CACHE_QUEUE_SIZE == cache_write_queue.front) {
+        if (!(result = nvram_cache_queue_search_lid(ldi->LID))) {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+            NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_QUEUE_FULL, ldi->LID);
+            return KAL_FALSE;//assert
+        }else {
+        nvram_util_give_mutex(g_nvram_cache_mutex);
+            return KAL_TRUE;
+        }
+    }
+
+    if (!nvram_cache_queue_search_lid(ldi->LID)) {
+
+        cache_write_queue.queue_array[cache_write_queue.rear].ldi = ldi;
+        cache_write_queue.queue_array[cache_write_queue.rear].rec_index = rec_index;
+        cache_write_queue.queue_array[cache_write_queue.rear].rec_amount = rec_amount;
+        cache_write_queue.queue_array[cache_write_queue.rear].openoption = openOption;
+        cache_write_queue.rear = (cache_write_queue.rear +1)%CACHE_QUEUE_SIZE;
+    }
+    nvram_util_give_mutex(g_nvram_cache_mutex);
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_dequeue
+ * DESCRIPTION
+ *  pop the write option for flsuh data to file 
+ * PARAMETERS
+ *  cache_queue_ldi             [OUT]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_cache_dequeue(nvram_cache_write_item *cache_queue_ldi)
+{
+    nvram_util_take_mutex(g_nvram_cache_mutex);
+    if(cache_write_queue.front == cache_write_queue.rear) {
+        nvram_util_give_mutex(g_nvram_cache_mutex);    
+            return KAL_FALSE;
+    }
+
+    cache_queue_ldi->ldi = cache_write_queue.queue_array[cache_write_queue.front].ldi;
+    cache_queue_ldi->rec_index = cache_write_queue.queue_array[cache_write_queue.front].rec_index;
+    cache_queue_ldi->rec_amount = cache_write_queue.queue_array[cache_write_queue.front].rec_amount;
+    cache_queue_ldi->openoption = cache_write_queue.queue_array[cache_write_queue.front].openoption;
+
+    cache_write_queue.front = (cache_write_queue.front+1)%CACHE_QUEUE_SIZE;
+    nvram_util_give_mutex(g_nvram_cache_mutex); 
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cache_queue_init
+ * DESCRIPTION
+ *  nvram cacge queue initialize
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index  [IN]
+ *  rec_amount [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_cache_queue_init(void)
+{
+    cache_write_queue.front = 0;
+    cache_write_queue.rear = 0;
+    cache_write_queue.count = 0;
+	#if defined (__NVRAM_UT_TEST__)
+    kal_mem_set(cache_write_queue.queue_array,0,sizeof(cache_write_queue.queue_array[0])*CACHE_QUEUE_SIZE);
+	#endif
+    return KAL_TRUE;
+}
+
diff --git a/mcu/service/nvram/src/nvram_cache_white_list.c b/mcu/service/nvram/src/nvram_cache_white_list.c
new file mode 100644
index 0000000..f9f8438
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_cache_white_list.c
@@ -0,0 +1,288 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+
+#include <string.h>
+    
+#include "kal_general_types.h"
+#include "kal_internal_api.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+#include "fs_type.h"                /* FS_HANDLE */
+#include "fs_func.h"                /* FS_Delete */
+#include "fs_errcode.h"             /* FS_NO_ERROR */
+#include "ex_item.h"                /* EX_LOG_T */
+
+#include "tst_msgid.h"
+#include "sbp_public_utility.h"
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+
+#include "nvram_cache_interface.h"
+
+
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+kal_uint32 pre_read_white_list[]= {
+    NVRAM_EF_SBP_MODEM_CONFIG_LID,
+    #if defined (__NVRAM_UT_TEST__)
+    NVRAM_EF_NVRAM_TEST_8_LID,
+    NVRAM_EF_NVRAM_TEST_9_LID,
+    NVRAM_EF_NVRAM_TEST_10_LID,
+    NVRAM_EF_NVRAM_TEST_11_LID,
+    NVRAM_EF_NVRAM_TEST_12_LID,
+    NVRAM_EF_INTERNAL_13_LID,
+    NVRAM_EF_INTERNAL_TEST_14_LID,
+    #endif
+};
+kal_uint16 preread_white_list_amount = sizeof(pre_read_white_list)/sizeof(kal_uint32);
+
+kal_uint32 pre_write_white_list[]= {
+    0,
+};
+kal_uint16 prewrite_white_list_amount = sizeof(pre_write_white_list)/sizeof(kal_uint32);
+
+kal_uint32 bypass_cache_w_list[]= {
+    60184,    /*NVRAM_EF_AST_TL1_TAS_CUSTOM_PARAMES_LID 0xEB18*/
+    1538,    /*NVRAM_EF_FAILURE_LIST_LID 0x602*/
+    1536,    /*NVRAM_EF_EPSLOCI_EPSNSC_TIN_LID 0x600*/
+    1539,    /*NVRAM_EF_T3402_INFO_LID 0x603*/
+    1349,    /*NVRAM_EF_HVOLTE_E911_LID 0x545*/
+    1537,    /*NVRAM_EF_LTE_PREFERENCE_LID 0x601*/
+    61217,    /*NVRAM_EF_RAC_PREFERENCE_LID 0xEF21*/
+    1351,    /*NVRAM_EF_IMS_PROVISIONING_PROFILE_LID 0x547*/
+    4,      /*NVRAM_EF_UMTS_START_HFN_TDD_LID*/
+    3,      /*NVRAM_EF_UMTS_START_HFN_FDD_LID*/
+    61219,  /*NVRAM_EF_SYSSEL_SETTING_LID 0xEF23*/
+    61226,    /*NVRAM_EF_PS_SIM_MAP_LID 0xEF2A*/
+    61203,    /*NVRAM_EF_MS_SECURITY_LID 0xEF13*/
+    61202,    /*NVRAM_EF_SIM_LOCK_LID 0xEF12*/
+    61231,    /*NVRAM_EF_SML_GBLOB_LID 0xEF2F*/
+    61201,    /*NVRAM_EF_SML_LID 0xEF11*/
+    61227,    /*NVRAM_EF_SML_NONCE_LID 0xEF2B*/
+    61233,    /*NVRAM_EF_SML_S_LID 0xEF31*/
+    61229,    /*NVRAM_EF_SML_SIGNATURE_LID 0xEF2D*/
+    61228,    /*NVRAM_EF_SML_UNLOCK_CODE_LID 0xEF2C*/
+    61224,    /*NVRAM_EF_SUBSIDY_LOCK_LID 0xEF28*/
+    61225,    /*NVRAM_EF_SUBSIDY_LOCK_ODM_DATA_LID 0xEF29*/
+    58413,    /*NVRAM_EF_C2K_MOBILE_ID_LID 0xE42D*/
+    61200,    /*NVRAM_EF_IMEI_IMEISV_LID 0xEF10*/
+    #if defined (__NVRAM_UT_TEST__)
+    61473,   /*NVRAM_EF_INTERNAL_TEST_17_LID 0xF021*/
+    #endif
+    61240,   /*NVRAM_EF_L4_ATT_SIM_LOCK_LID 0xEF38*/
+    61241,   /*NVRAM_EF_L4_SML_VZW_SIM_LOCK_LID 0xEF39*/
+    61242,   /*NVRAM_EF_L4_SML_VZW_SIM_LOCK_DEVICE_KEY_LID 0xEF3A*/
+    61243,   /*NVRAM_EF_L4_SML_VZW_RSU_DELAY_TIMER_LID 0xEF3B*/
+    61246,   /*NVRAM_EF_L4_SML_OP129_LID 0xEF3E*/
+    61248,   /*NVRAM_EF_L4_SML_TMO_MOVIAL_SIM_LOCK_LID 0xEF40*/
+    61249,   /*NVRAM_EF_L4_SML_TMO_MOVIAL_CORR_ID_LID 0xEF41*/
+    61252,   /*NVRAM_EF_L4_MS_SIM_BLACK_LIST_LID 0xEF44*/
+};
+
+kal_uint16 bypass_cache_w_list_amount = sizeof(bypass_cache_w_list)/sizeof(kal_uint32);
+
+#ifdef __NVRAM_PARTIAL_CACHE__
+/*You must synchronization modify the autogen_nvram_lid_noncache_list in /tools/NVRAMStatistic/src/nvram_gen_cache_table.c if you want to add or delete a member of below list.
+  *you can't use macro to wrapp the LID enum in below list.
+**/
+kal_uint32 nvram_lid_noncache_list[]= {
+    1245,   /*NVRAM_EF_MML1_RF_SELF_CAL_RX_TYPE1_LID*/
+    1248,   /*NVRAM_EF_MML1_RF_SELF_CAL_DET_TX_LID*/
+    1249,   /*NVRAM_EF_MML1_RF_SELF_CAL_TX_SB_LID*/
+    57346,  /*NVRAM_EF_NL1_TXCALDATA_BLOCK_LID*/
+    57348,  /*NVRAM_EF_NL1_RXSSIGAIN_TYPE1_BLOCK_LID*/
+    57350,  /*NVRAM_EF_NL1_RXSSIGAIN_TYPE2_BLOCK_LID*/
+    57356,  /*NVRAM_EF_NL1_DPD_CAL_DATABASE_LID*/
+    57365,  /*NVRAM_EF_NL1_ET_CAL_DATABASE_LID*/
+    60479,  /*NVRAM_EF_EL1_RF_SELF_CAL_RX_DC_IRR_LID*/
+    60481,  /*NVRAM_EF_EL1_RF_SELF_CAL_DET_TX_LID*/
+    60548,  /*NVRAM_EF_EL1_TXCALDATA_BLOCK_LID*/
+    60550,  /*NVRAM_EF_EL1_RXSSIGAIN_TYPE1_BLOCK_LID*/
+    60552,  /*NVRAM_EF_EL1_RXSSIGAIN_TYPE2_BLOCK_LID*/
+    60566,  /*NVRAM_EF_EL1_DPD_CAL_DATABASE_LID*/
+    60571,  /*NVRAM_EF_EL1_ET_CAL_DATABASE_LID*/
+    56832,  /*NVRAM_EF_MMRFC_RF_FAC_TABLE_LID*/
+    56833,  /*NVRAM_EF_MMRFC_RF_OTA_TABLE_LID*/
+    56834,  /*NVRAM_EF_MMRFC_RF_SELF_CAL_RX_TYPE1_OTA_LID*/
+    56835,  /*NVRAM_EF_MMRFC_RF_SELF_CAL_RX_TYPE2_OTA_LID*/
+    56836,  /*NVRAM_EF_MMRFC_RF_SELF_CAL_RX_TYPE2_OTA_LID*/
+    56837,  /*NVRAM_EF_MMRFC_RF_SELF_CAL_DET_TX_OTA_LID*/
+    56838,  /*NVRAM_EF_MMRFC_RF_SELF_CAL_TX_SB_OTA_LID*/
+    56839,  /*NVRAM_EF_MMRFC_RF_FAC_TABLE2_LID*/
+    56840,  /*NVRAM_EF_MMRFC_RF_OTA_TABLE2_LID*/
+};
+
+kal_uint16 nvram_lid_noncache_list_amount = sizeof(nvram_lid_noncache_list)/sizeof(kal_uint32);
+#endif
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+
+/*****************************************************************************
+  * FUNCTION
+  *  Is_in_preread_white_list
+  * DESCRIPTION
+  *  search lid in white list
+  * PARAMETERS
+  *  LDI             [IN]
+  * RETURNS
+  *  success or fail
+  *****************************************************************************/
+kal_bool Is_in_preread_white_list(nvram_lid_enum LID)
+{
+    
+    kal_bool ret = KAL_FALSE;
+    #ifdef __NVRAM_LID_PREREAD__
+    kal_uint32 idx;
+    for(idx = 0; idx < preread_white_list_amount; idx++)
+    {
+        if(pre_read_white_list[idx] == LID)
+        {
+            ret = KAL_TRUE;
+            break;
+        }
+    }
+    #endif
+    return ret;
+}
+
+/*****************************************************************************
+  * FUNCTION
+  *  Is_in_prewrite_white_list
+  * DESCRIPTION
+  *  search lid in white list
+  * PARAMETERS
+  *  LDI             [IN]
+  * RETURNS
+  *  success or fail
+  *****************************************************************************/
+kal_bool Is_in_prewrite_white_list(nvram_lid_enum LID)
+{
+    kal_bool ret = KAL_FALSE;
+    #ifdef __NVRAM_LID_PREREAD__
+    kal_uint32 idx;
+    for(idx = 0; idx < prewrite_white_list_amount; idx++)
+    {
+        if(pre_write_white_list[idx] == LID)
+        {
+            ret = KAL_TRUE;
+            break;
+        }
+    }
+    #endif
+    return ret;
+}
+
+/*****************************************************************************
+  * FUNCTION
+  *  Is_in_bypass_cache_w_list
+  * DESCRIPTION
+  *  NVRAM lid whether in bypass cache write list
+  * PARAMETERS
+  *  LDI             [IN]
+  * RETURNS
+  *  success or fail
+  *****************************************************************************/
+kal_bool Is_in_bypass_cache_w_list(nvram_lid_enum LID)
+{
+    kal_bool ret = KAL_FALSE;
+    #ifdef __NVRAM_CACHE_BYPASS_W_LIST__
+    kal_uint32 idx;
+    for(idx = 0; idx < bypass_cache_w_list_amount; idx++)
+    {
+        if(bypass_cache_w_list[idx] == LID)
+        {
+            ret = KAL_TRUE;
+            break;
+        }
+    }
+    #endif
+    return ret;
+}
+
+/*****************************************************************************
+  * FUNCTION
+  *  is_in_noncache_list
+  * DESCRIPTION
+  *  NVRAM lid whether in non-cache list
+  * PARAMETERS
+  *  LDI             [IN]
+  * RETURNS
+  *  success or fail
+  *You must synchronization modify the autogen_is_in_noncache_list in /tools/NVRAMStatistic/src/nvram_gen_cache_table.c if you want to add or delete a member of below list.
+  *****************************************************************************/
+kal_bool is_in_noncache_list(nvram_lid_enum LID)
+{
+    #ifdef __NVRAM_PARTIAL_CACHE__
+    kal_uint32 idx;
+    for(idx = 0; idx < nvram_lid_noncache_list_amount; idx++)
+    {
+        if(nvram_lid_noncache_list[idx] == LID)
+        {
+            return KAL_TRUE;
+        }
+    }
+    #endif
+    return KAL_FALSE;
+}
+
diff --git a/mcu/service/nvram/src/nvram_chksum_algorithm.c b/mcu/service/nvram/src/nvram_chksum_algorithm.c
new file mode 100644
index 0000000..e2c78fc
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_chksum_algorithm.c
@@ -0,0 +1,951 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+#include <string.h>
+    
+#include "kal_general_types.h"
+#include "kal_internal_api.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+    
+#include "syscomp_config.h"
+#include "task_config.h"
+#include "sysconf_statistics.h"     /* stack_statistics_struct */
+#include "custom_em.h"
+    /* Factory mode, should not send ADC calibration data to BMT  */
+#ifdef __MULTI_BOOT__
+#include "multiboot_config.h"
+#include "intrCtrl.h"               /* INT_BootMode */
+#endif /* __MULTI_BOOT__ */
+    
+#ifdef __CCCIFS_SUPPORT__
+#include "ccci.h"
+#endif
+    
+#if defined(__MTK_TARGET__)
+#include "SST_secure.h"
+#endif
+    
+#include "fs_type.h"                /* FS_HANDLE */
+#include "fs_func.h"                /* FS_Delete */
+#include "fs_errcode.h"             /* FS_NO_ERROR */
+#include "ex_item.h"                /* EX_LOG_T */
+
+#include "tst_msgid.h"
+#include "sbp_public_utility.h"
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+
+#if defined(__HIF_CCCI_SUPPORT__)
+#include "ccci_if.h"
+#endif
+#include "ex_public.h"
+#include "nvram_chksum_algorithm.h"
+#include "nvram_errcode.h"
+#include "nvram_data_items.h"
+#include "nvram_enums.h"
+#include "nvram_trc.h"
+#include "nvram_io.h"
+#include "nvram_ltable.h"
+#include "custom_nvram_sec.h"
+#include "nvram_sec.h"
+#include "nvram_util.h"
+#include "nvram_multi_folder.h"
+#include "nvram_main.h"
+#ifdef __NVRAM_LID_CACHE__
+#include "nvram_cache_interface.h"
+#endif
+
+
+
+
+
+
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+
+
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+nvram_algo_info chksum_algo;
+nvram_algo_info *chksum_algo_ptr = &chksum_algo;
+
+#ifdef __NVRAM_UT_TEST__
+extern nvram_checksum_config NVRAM_CHK_CONFIG;
+#else
+extern const nvram_checksum_config NVRAM_CHK_CONFIG;
+#endif
+
+extern kal_mutexid g_nvram_fs_mutex;
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+
+
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_cfg_crrnt_chksum_algo
+ * DESCRIPTION
+ *  Config currently NVRAM LID checksum algorithm 
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_cfg_crrnt_chksum_algo(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_mem_set(chksum_algo_ptr, 0, sizeof(nvram_algo_info));
+    chksum_algo_ptr->cur_algo.def_algo_length = NVRAM_CHK_CONFIG.default_algo_size;
+    chksum_algo_ptr->cur_algo.def_algo_type = NVRAM_CHK_CONFIG.default_algo_type;
+    chksum_algo_ptr->cur_algo.en_algo_length = NVRAM_CHK_CONFIG.enhance_algo_size;
+    chksum_algo_ptr->cur_algo.en_algo_type = NVRAM_CHK_CONFIG.enhance_algo_type;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_pre_chksum_algo
+ * DESCRIPTION
+ *  Config currently NVRAM LID checksum algorithm 
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_errno_enum nvram_get_pre_chksum_algo(nvram_algo_struct *nvram_chksum_algo)
+{    
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8* rec_buffer=NULL;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 rec_buffer_sz = 0;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+
+     /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if(NULL == nvram_chksum_algo)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM_LOC_LID_PTR_IS_NULL_6 %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_LID_PTR_IS_NULL_6,0, __LINE__);
+        return NVRAM_ERRNO_FAIL;
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_CHKSUM_INFO_LID);
+    if(!ldi)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM_LOC_LID_PTR_IS_NULL_7 %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_LID_PTR_IS_NULL_7,0, NVRAM_EF_CORE_CHKSUM_INFO_LID);
+        return NVRAM_ERRNO_FAIL;
+    }
+    rec_buffer = (kal_uint8*) get_ctrl_buffer(ldi->size);
+    rec_buffer_sz = ldi->size;
+    kal_mem_set(rec_buffer, 0, ldi->size);
+    result = nvram_read_data_item(ldi, 1, 1, rec_buffer, rec_buffer_sz);
+    if(result != NVRAM_IO_ERRNO_OK)
+    {
+        if (rec_buffer)
+        {
+            free_ctrl_buffer(rec_buffer);
+            rec_buffer = NULL;
+        }
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM_LOC_READ_IMPORTANT_DATA_FAIL_3 %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_READ_IMPORTANT_DATA_FAIL_3,0, NVRAM_EF_CORE_CHKSUM_INFO_LID);
+        return result;
+    }
+
+    kal_mem_cpy(nvram_chksum_algo, rec_buffer, rec_buffer_sz);
+
+    if (rec_buffer)
+    {
+        free_ctrl_buffer(rec_buffer);
+        rec_buffer = NULL;
+    }
+
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_assign_custpack_default_value
+ * DESCRIPTION
+ *  This function is assign
+ *      the point of default value from 3rd jump table to logical table
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_lid_chksum_algrthm_config_value(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if(buffer == NULL)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d)NVRAM_LOC_BUFFER_PTR_IS_NULL_41 NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NVRAM_LOC_BUFFER_PTR_IS_NULL_41 NULL %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_BUFFER_PTR_IS_NULL_41, 0, file_id);
+        return;
+    }
+
+    if(buffer_size < sizeof(chksum_algo_ptr->cur_algo))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d)NVRAM_LOC_BUFFER_SIZE_NOT_ENOUGH_6 NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NVRAM_LOC_BUFFER_SIZE_NOT_ENOUGH_6 NULL %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_BUFFER_SIZE_NOT_ENOUGH_6,0, file_id);
+        return;
+    }
+
+    switch (file_id)
+    {
+        case NVRAM_EF_CORE_CHKSUM_INFO_LID:
+        {
+            kal_mem_cpy(buffer, &(chksum_algo_ptr->cur_algo), sizeof(chksum_algo_ptr->cur_algo));
+        }
+        break;
+        case NVRAM_EF_CORE_BNRG_CHKSUM_ALGRTHM_LID:
+        {
+            kal_mem_cpy(buffer, &(chksum_algo_ptr->cur_algo), sizeof(chksum_algo_ptr->cur_algo));
+        }
+        break;
+        
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_chksum_def_algo_check
+ * DESCRIPTION
+ *  This function is double check NVRAM chksum default algorithm whether changed
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  KAL_TRUE NVRAM chksum default algorithm have not change, otherwise, it have changed.
+ *****************************************************************************/
+nvram_errno_enum nvram_chksum_def_algo_check(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+
+     /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/    
+
+    //kal_mem_set(&(chksum_algo_ptr->pre_algo), 0, sizeof(chksum_algo_ptr->pre_algo));
+    result = nvram_get_pre_chksum_algo(&(chksum_algo_ptr->pre_algo));
+
+    if(result != NVRAM_IO_ERRNO_OK)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM get pre chksum algo failed %d.\r\n", __FUNCTION__,__LINE__);
+        return NVRAM_ERRNO_FAIL;
+    }
+    if(chksum_algo_ptr->pre_algo.def_algo_type != chksum_algo_ptr->cur_algo.def_algo_type)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM def chksum algo changed %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_CHKSUM_DEF_ALGO_CHANGED,0, NVRAM_EF_CORE_CHKSUM_INFO_LID);
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_clone_lid_file
+ * DESCRIPTION
+ *  This function is clone a lid data to NVRAM_EF_CORE_INTERNAL_CLONE_LID
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_int32 nvram_clone_lid_file(nvram_ltable_entry_struct *ldi, nvram_ltable_entry_struct *clone_ldi, kal_bool first_copy)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_folder_enum ldi_folder_index, clone_ldi_folder_index;
+    NVRAM_FILE_NAME ldi_nvramname = {0};
+    kal_wchar ldi_filename[NVRAM_MAX_PATH_LEN];
+    NVRAM_FILE_NAME clone_ldi_nvramname = {0};
+    kal_wchar clone_ldi_filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 result = FS_NO_ERROR;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if((ldi == NULL) || (clone_ldi == NULL))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d) NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NULL %d.\r\n", __FUNCTION__,__LINE__);
+        return FS_PARAM_ERROR;
+    }
+
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    ldi_folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, ldi_nvramname, first_copy);
+    nvram_query_file_name(ldi_folder_index, ldi_nvramname, ldi_filename);
+
+    clone_ldi_folder_index = nvram_query_folder_index(clone_ldi->category);
+    nvram_util_make_lid_filename(clone_ldi, clone_ldi_nvramname, first_copy);
+    nvram_query_file_name(clone_ldi_folder_index, clone_ldi_nvramname, clone_ldi_filename);
+
+    NVRAM_FS_START_EX(FS_OP_MOVE,ldi_filename);
+    NVRAM_FS_START_EX(FS_OP_MOVE,clone_ldi_filename);
+    result = FS_Move(ldi_filename, clone_ldi_filename, FS_MOVE_COPY, NULL, NULL, 0);
+    NVRAM_FS_END(FS_OP_MOVE,result);
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+    return result;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_clone_lid_data
+ * DESCRIPTION
+ *  This function is clone a lid data to NVRAM_EF_CORE_INTERNAL_CLONE_LID
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_clone_lid_data(nvram_ltable_entry_struct *ldi, nvram_ltable_entry_struct *clone_ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool first_copy = KAL_TRUE;
+    kal_int32 drv_status[2] = {0, 0};
+
+     /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if((ldi == NULL) || (clone_ldi == NULL))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d) NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NULL %d.\r\n", __FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+
+    clone_ldi->total_records = ldi->total_records;
+    clone_ldi->size = ldi->size;
+    clone_ldi->default_value = ldi->default_value;
+    clone_ldi->category = ldi->category;
+    clone_ldi->attr = ldi->attr;
+    clone_ldi->attr |= NVRAM_ATTR_GEN_DEFAULT;
+
+    drv_status[0] = nvram_clone_lid_file(ldi, clone_ldi, first_copy);
+
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"clone_ldi->LID:0x%04x. ldi->LID:0x%04x drv_status[0]=%d\r\n",clone_ldi->LID,ldi->LID,drv_status[0]);
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+    {
+        first_copy = KAL_FALSE;
+        drv_status[1] = nvram_clone_lid_file(ldi, clone_ldi, first_copy);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"clone_ldi->LID:0x%04x. ldi->LID:0x%04x drv_status[0]=%d\r\n",clone_ldi->LID,ldi->LID,drv_status[0]);
+    }
+
+    if((drv_status[0] != 0) || (drv_status[1] != 0))
+    {
+        kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_CLONE_LID_FAIL:%d\n\r", drv_status[0]?drv_status[0]:drv_status[1]);
+        kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", clone_ldi->fileprefix, clone_ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM_LOC_CLONE_LID_FAIL:%d, 0x%x.\r\n", drv_status[0]?drv_status[0]:drv_status[1], NVRAM_LOC_CLONE_LID_FAIL);           
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID:0x%04X, total_records:%d, record_size:%d \r\n", ldi->LID, ldi->total_records, ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", clone_ldi->fileprefix, clone_ldi->fileverno);
+
+        return KAL_FALSE;
+    }
+
+    //mark file exist
+    nvram_util_take_mutex(nvram_bitmap_mutex);
+    nvram_util_lid_bimtap_set(nvram_bitmap_ptr, clone_ldi->LID);
+    nvram_util_give_mutex(nvram_bitmap_mutex);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_lid_chksum_algo
+ * DESCRIPTION
+ *  This function is reset LID checksum algorithm
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_reset_lid_chksum_algo(nvram_ltable_entry_struct *ldi, nvram_algo_info *backup_chksum_algo, nvram_chksum_change_enum chksum_change_enum, kal_bool reset_to_bf)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if((ldi == NULL) || (backup_chksum_algo == NULL))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d) NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NULL %d.\r\n", __FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+
+    if(chksum_change_enum == FROM_DEF_TO_ENHANCE)
+    {
+        if(reset_to_bf)
+        {
+            ldi->attr &=(~NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM);
+        }
+        else
+        {
+            ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+        }
+    }
+    else if(chksum_change_enum == FROM_ENHANCE_TO_DEF)
+    {
+        if(reset_to_bf)
+        {
+            ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+        }
+        else
+        {
+            ldi->attr &=(~NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM);
+        }
+    }
+    else if(chksum_change_enum == FROM_ENHANCE_A_TO_B)
+    {
+        if(reset_to_bf)
+        {
+            chksum_algo_ptr->cur_algo.en_algo_length =  backup_chksum_algo->pre_algo.en_algo_length;
+            chksum_algo_ptr->cur_algo.en_algo_type = backup_chksum_algo->pre_algo.en_algo_type;
+        }
+        else
+        {
+            chksum_algo_ptr->cur_algo.en_algo_length = backup_chksum_algo->cur_algo.en_algo_length;
+            chksum_algo_ptr->cur_algo.en_algo_type = backup_chksum_algo->cur_algo.en_algo_type;
+        }
+    }
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reconstruct_lid_file
+ * DESCRIPTION
+ *  Construct the files in certain folder to disk table
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_reconstruct_lid_file(nvram_ltable_entry_struct *ldi, nvram_ltable_entry_struct *pre_ldi, nvram_algo_info *backup_chksum_algo,nvram_chksum_change_enum chksum_change_enum)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 *lid_data_buffer = NULL;
+    kal_uint32 lid_data_buffer_size = 0;
+    kal_bool reset_to_bf = KAL_TRUE;
+    kal_bool result = KAL_TRUE;
+    nvram_ltable_entry_struct temp_ldi = {0};
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    kal_uint32 idx;
+    kal_int32 fs_result = FS_NO_ERROR;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if((ldi == NULL) || (backup_chksum_algo == NULL))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d) NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NULL %d.\r\n", __FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+
+    lid_data_buffer_size = ldi->total_records * ldi->size;
+    lid_data_buffer = (kal_uint8*) get_ctrl_buffer(lid_data_buffer_size);
+
+    kal_mem_cpy(&temp_ldi, ldi, sizeof(nvram_ltable_entry_struct));
+    nvram_reset_lid_chksum_algo(ldi, backup_chksum_algo, chksum_change_enum, reset_to_bf);
+    ldi->attr |= NVRAM_ATTR_GEN_DEFAULT;
+    status = nvram_read_data_item(ldi, 1, ldi->total_records, lid_data_buffer, lid_data_buffer_size);
+
+    if (status != NVRAM_IO_ERRNO_OK)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_read_data_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x nvram_read_data_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+        if (lid_data_buffer)
+        {
+            free_ctrl_buffer(lid_data_buffer);
+            lid_data_buffer = NULL;
+        }
+        return KAL_FALSE;
+    }
+
+    reset_to_bf = KAL_FALSE;
+    nvram_reset_lid_chksum_algo(ldi, backup_chksum_algo, chksum_change_enum, reset_to_bf);
+    kal_mem_cpy(ldi, &temp_ldi, sizeof(nvram_ltable_entry_struct));
+
+    for (idx = 0; idx < 2; idx++)
+    {
+        nvram_util_make_lid_filename(pre_ldi, nvramname, (idx==0));
+        folder_index = nvram_query_folder_index_ex(pre_ldi->category, (idx==0));
+        nvram_query_file_name(folder_index, nvramname, filename);
+        NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+        fs_result = FS_Delete(filename);
+        NVRAM_FS_END(FS_OP_DELETE,fs_result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Delete %s result=%d\r\n",__FUNCTION__,nvramname,fs_result);
+        if (!((pre_ldi->attr & NVRAM_ATTR_MULTIPLE) || NVRAM_IS_CATEGORY_IMPORTANT_L4(pre_ldi->category)))
+        {
+            break;
+        }
+    }
+
+    result = nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records);
+    if (!result)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_reset_data_items return %d\r\n",__FUNCTION__,ldi->LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x nvram_reset_data_items return %d\r\n",__FUNCTION__,ldi->LID,result);
+        if (lid_data_buffer)
+        {
+            free_ctrl_buffer(lid_data_buffer);
+            lid_data_buffer = NULL;
+        }
+        return KAL_FALSE;
+    }
+
+    status = nvram_write_data_item(ldi, ldi->total_records, lid_data_buffer, KAL_TRUE);
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_write_data_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x nvram_write_data_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+        if (lid_data_buffer)
+        {
+            free_ctrl_buffer(lid_data_buffer);
+            lid_data_buffer = NULL;
+        }
+        return KAL_FALSE;
+    }
+
+    if (lid_data_buffer)
+    {
+        free_ctrl_buffer(lid_data_buffer);
+        lid_data_buffer = NULL;
+    }
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reconstruct_lid_file
+ * DESCRIPTION
+ *  Construct the files in certain folder to disk table
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_reconstruct_lid_file_max(nvram_ltable_entry_struct *ldi, nvram_ltable_entry_struct *pre_ldi, nvram_algo_info *backup_chksum_algo, nvram_chksum_change_enum chksum_change_enum)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *clone_ldi = NULL;
+    nvram_ltable_entry_struct backup_clone_ldi = {0};
+    kal_uint8 *lid_data_buffer = NULL;
+    kal_uint32 lid_data_buffer_size = 0;
+    kal_bool reset_to_bf = KAL_TRUE;
+    kal_uint32 indx_j = 0;
+    kal_uint32 indx_i = 0;
+    kal_uint32 tmp_indx = 0;
+    kal_uint32 remainLen = 0;
+    kal_uint32 section_size = 0;
+    kal_bool result = KAL_TRUE;
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+    kal_uint32 idx;
+    kal_int32 fs_result = FS_NO_ERROR;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if((ldi == NULL) || (backup_chksum_algo == NULL))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d) NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NULL %d.\r\n", __FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&clone_ldi, NVRAM_EF_CORE_INTERNAL_CLONE_LID);
+    if(!clone_ldi)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d)clone_ldi NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NVRAM_LOC_INVALID_LID_SIZE_6 %d.\r\n", __FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+
+    kal_mem_cpy(&backup_clone_ldi, clone_ldi, sizeof(backup_clone_ldi));
+
+    result = nvram_clone_lid_data(ldi, clone_ldi);
+    if(!result)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d)nvram_clone_lid_data %d \r\n",__FUNCTION__, __LINE__, result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:nvram_clone_lid_data %d.\r\n", __FUNCTION__,__LINE__);
+        result = KAL_FALSE;
+        goto final;
+    }
+
+    for (idx = 0; idx < 2; idx++)
+    {
+        nvram_util_make_lid_filename(pre_ldi, nvramname, (idx==0));
+        folder_index = nvram_query_folder_index_ex(pre_ldi->category, (idx==0));
+        nvram_query_file_name(folder_index, nvramname, filename);
+        NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+        fs_result = FS_Delete(filename);
+        NVRAM_FS_END(FS_OP_DELETE,fs_result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Delete %s result=%d\r\n",__FUNCTION__,nvramname,fs_result);
+        if (!((pre_ldi->attr & NVRAM_ATTR_MULTIPLE) || NVRAM_IS_CATEGORY_IMPORTANT_L4(pre_ldi->category)))
+        {
+            break;
+        }
+    }
+
+    result = nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records);
+    if (!result)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_reset_data_items return %d\r\n",__FUNCTION__, ldi->LID, result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x nvram_reset_data_items return %d\r\n",__FUNCTION__, ldi->LID, result);
+        result = KAL_FALSE;
+        goto final;
+    }
+
+    for(indx_j = 1; indx_j <= clone_ldi->total_records; indx_j += tmp_indx)
+    {
+        reset_to_bf = KAL_TRUE;
+        nvram_reset_lid_chksum_algo(clone_ldi, backup_chksum_algo, chksum_change_enum, reset_to_bf);
+
+        nvram_get_lid_chksum_algo_info(clone_ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        if ((clone_ldi->attr & NVRAM_ATTR_MSP)||(clone_ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+        {
+            /* 16 byte alignment */
+            remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(clone_ldi->size + lid_chksum_info.algo_info.chksum_algo_length);
+        }
+        #else
+        if (clone_ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+        {
+            /* 16 byte alignment */
+            remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(clone_ldi->size + lid_chksum_info.algo_info.chksum_algo_length);
+        }
+        #endif
+
+        section_size = clone_ldi->size + lid_chksum_info.algo_info.chksum_algo_length + remainLen;
+
+        tmp_indx = MAX_NVRAM_RECORD_SIZE/section_size;
+        if((indx_j + tmp_indx) > clone_ldi->total_records)
+        {
+            tmp_indx = (clone_ldi->total_records - indx_j) + 1;
+        }
+
+        lid_data_buffer_size = tmp_indx * clone_ldi->size;
+        lid_data_buffer = (kal_uint8*) get_ctrl_buffer(lid_data_buffer_size);
+
+        status = nvram_read_data_item(clone_ldi, indx_j, tmp_indx, lid_data_buffer, lid_data_buffer_size);
+
+        if (status != NVRAM_IO_ERRNO_OK)
+        {                
+            kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_read_data_item return %d\r\n",__FUNCTION__,clone_ldi->LID,status);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item return %d\r\n",__FUNCTION__,clone_ldi->LID,status);
+            result = KAL_FALSE;
+            goto final;
+        }
+
+        reset_to_bf = KAL_FALSE;
+        nvram_reset_lid_chksum_algo(clone_ldi, backup_chksum_algo, chksum_change_enum, reset_to_bf);
+
+        for(indx_i = indx_j; indx_i < (indx_j + tmp_indx); indx_i++)
+        {
+            status = nvram_write_data_item(ldi, indx_i, lid_data_buffer +((indx_i - indx_j)* ldi->size) , KAL_FALSE);
+            if (status != NVRAM_IO_ERRNO_OK)
+            {
+                kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_write_data_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_write_data_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+                result = KAL_FALSE;
+                goto final;
+            }
+        }
+        if (lid_data_buffer)
+        {
+            free_ctrl_buffer(lid_data_buffer);
+            lid_data_buffer = NULL;
+        }
+    }
+
+final:
+
+    if (lid_data_buffer)
+    {
+        free_ctrl_buffer(lid_data_buffer);
+        lid_data_buffer = NULL;
+    }
+
+    nvram_util_mark_file_uncreated(clone_ldi);
+
+    for (idx = 0; idx < 2; idx++)
+    {
+        nvram_util_make_lid_filename(clone_ldi, nvramname, (idx==0));
+        folder_index = nvram_query_folder_index_ex(clone_ldi->category, (idx==0));
+        nvram_query_file_name(folder_index, nvramname, filename);
+        NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+        fs_result = FS_Delete(filename);
+        NVRAM_FS_END(FS_OP_DELETE,fs_result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Delete %s result=%d\r\n",__FUNCTION__,nvramname,fs_result);
+        if (!((clone_ldi->attr & NVRAM_ATTR_MULTIPLE) || NVRAM_IS_CATEGORY_IMPORTANT_L4(clone_ldi->category)))
+        {
+            break;
+        }
+    }
+
+    kal_mem_cpy(clone_ldi, &backup_clone_ldi, sizeof(backup_clone_ldi));
+
+    return result;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_construct_certain_disk_table
+ * DESCRIPTION
+ *  Construct the files in certain folder to disk table
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_reconstruct_lid_chksum_data(nvram_ltable_entry_struct *ldi, nvram_ldi_header *nv_header, nvram_chksum_change_enum chksum_change_enum)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_algo_info backup_chksum_algo = {0};
+    kal_bool result = KAL_TRUE;
+    nvram_ltable_entry_struct pre_ldi = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    kal_mem_cpy(&backup_chksum_algo, chksum_algo_ptr, sizeof(nvram_algo_info));
+    kal_mem_cpy(&pre_ldi, ldi, sizeof(nvram_ltable_entry_struct));
+    pre_ldi.attr = nv_header->nv_ota_header.ldi_attr;
+    pre_ldi.category = nv_header->nv_ota_header.ldi_category;
+
+    if((ldi->total_records * ldi->size) < MAX_NVRAM_RECORD_SIZE)
+    {
+        result = nvram_reconstruct_lid_file(ldi, &pre_ldi, &backup_chksum_algo, chksum_change_enum);
+
+        if (!result)
+        {                
+            kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_reconstruct_lid_file return %d\r\n",__FUNCTION__,ldi->LID,result);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_reconstruct_lid_file return %d\r\n",__FUNCTION__,ldi->LID,result);
+            return KAL_FALSE;
+        }
+        
+    }
+    else
+    {
+        result = nvram_reconstruct_lid_file_max(ldi, &pre_ldi, &backup_chksum_algo, chksum_change_enum);
+        if (!result)
+        {                
+            kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_reconstruct_lid_file_max return %d\r\n",__FUNCTION__,ldi->LID,result);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_reconstruct_lid_file_max return %d\r\n",__FUNCTION__,ldi->LID,result);
+            return KAL_FALSE;
+        }
+    }
+
+    return KAL_TRUE;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_ota_for_lid_chksum_algo
+ * DESCRIPTION
+ * This function is for OTA due to NVRAM lid cheksum algorithm change.
+ * PARAMETERS
+ *  *nv_header   [IN] lid file header
+ *  *ldi              [IN] lid entry table
+ * RETURNS
+ *  KAL_TRUE NVRAM LID ota success.
+ *****************************************************************************/
+nvram_errno_enum nvram_ota_for_lid_chksum_algo(nvram_ldi_header *nv_header, nvram_ltable_entry_struct *ldi)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool result = KAL_TRUE;
+    kal_bool handle_done = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if(nvram_util_has_file_created(ldi))
+    {        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x nvram_util_has_file_created ota_hd_attr(%x), ldi_attr(%x)\r\n",__FUNCTION__, ldi->LID, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+        return NVRAM_IO_ERRNO_OK;
+    }
+
+    if((nv_header->nv_ota_header.record_size != ldi->size) || (nv_header->nv_ota_header.total_records != ldi->total_records))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x lid size or records chancge ota_hd_attr(%x), ldi_attr(%x)\r\n",__FUNCTION__,ldi->LID,nv_header->nv_ota_header.ldi_attr,ldi->attr);
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    if(NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(nv_header->nv_ota_header.ldi_attr))
+    {
+        if(NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(ldi->attr))
+        {
+            if(chksum_algo_ptr->cur_algo.en_algo_type != chksum_algo_ptr->pre_algo.en_algo_type)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]ldi->LID(0x%x) Chksum algo from Enhance A(0x%08x) -> B(0x%08x)\r\n", ldi->LID, chksum_algo_ptr->pre_algo.en_algo_type, chksum_algo_ptr->cur_algo.en_algo_type);
+                NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_CALIBRAT(ldi->category), ldi->LID, NVRAM_LOC_CALIBRATION_CHKSUM_ALGO_CHANGED, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+                NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT(ldi->category), ldi->LID, NVRAM_LOC_IMPORTANT_CHKSUM_ALGO_CHANGED, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+                result = nvram_reconstruct_lid_chksum_data(ldi, nv_header, FROM_ENHANCE_A_TO_B);
+                handle_done = KAL_TRUE;
+            }
+        }
+        else
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]ldi->LID(0x%x) Chksum algo from Enhance(0x%08x) -> Default(0x%08x)\r\n", ldi->LID, chksum_algo_ptr->pre_algo.en_algo_type, chksum_algo_ptr->cur_algo.en_algo_type);
+            NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_CALIBRAT(ldi->category), ldi->LID, NVRAM_LOC_CALIBRATION_CHKSUM_ALGO_CHANGED, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+            NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT(ldi->category), ldi->LID, NVRAM_LOC_IMPORTANT_CHKSUM_ALGO_CHANGED, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+            result = nvram_reconstruct_lid_chksum_data(ldi, nv_header, FROM_ENHANCE_TO_DEF);
+            handle_done = KAL_TRUE;
+        }
+    }
+    else
+    {
+        if(NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(ldi->attr))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]ldi->LID(0x%x) Chksum algo from Default(0x%08x) -> Enhance(0x%08x)\r\n", ldi->LID, chksum_algo_ptr->pre_algo.en_algo_type, chksum_algo_ptr->cur_algo.en_algo_type);
+            NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_CALIBRAT(ldi->category), ldi->LID, NVRAM_LOC_CALIBRATION_CHKSUM_ALGO_CHANGED, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+            NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT(ldi->category), ldi->LID, NVRAM_LOC_IMPORTANT_CHKSUM_ALGO_CHANGED, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+            result = nvram_reconstruct_lid_chksum_data(ldi, nv_header, FROM_DEF_TO_ENHANCE);
+            handle_done = KAL_TRUE;
+        }
+    }
+
+    if (!result)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) NVRAM_LOC_RECONSTRUCT_LID_FAIL return %d\r\n",__FUNCTION__,ldi->LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x NVRAM_LOC_RECONSTRUCT_LID_FAIL return %d\r\n",__FUNCTION__,ldi->LID,result);
+        NVRAM_EXT_ASSERT(KAL_FALSE, ldi->LID, NVRAM_LOC_RECONSTRUCT_LID_FAIL, nv_header->nv_ota_header.ldi_attr, ldi->attr);
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    if(handle_done == KAL_FALSE)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04x NVRAM_chksum_algo_unhandle ota_hd_attr(%x), ldi_attr(%x)\r\n",__FUNCTION__,ldi->LID,nv_header->nv_ota_header.ldi_attr,ldi->attr);
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+
+}
+
diff --git a/mcu/service/nvram/src/nvram_cl1def.c b/mcu/service/nvram/src/nvram_cl1def.c
new file mode 100644
index 0000000..7845e57
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_cl1def.c
@@ -0,0 +1,364 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2016
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_cl1def.c
+ *
+ * Project:
+ * --------
+ * 93
+ *
+ * Description:
+ * ------------
+ * Interface Implementation provided to NVRAM.
+ *
+ *               
+ * Author:
+ * -------
+ * 
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *==============================================================================
+ *******************************************************************************/
+
+#include "kal_public_api.h"
+#include "cl1d_rf_common_defs.h"
+#include "nvram_enums.h"
+#include "cl1_nvram_def.h"
+#include "cl1cal_nvram_def.h"
+#include "nvram_cl1def.h"
+#include "cl1d_rf_cid.h"
+#include "cl1d_rf_error_check.h"
+
+/*** Need by getting default item info(lid, item index and size) ***/
+typedef struct
+{
+    nvram_lid_enum lid;
+    kal_uint16 rec_idx;
+    kal_uint16 rec_num;
+    kal_uint32 size;
+} CL1D_RF_CUST_DATA_LID_INFO_T;
+
+
+#undef NVRAM_ITEM_RF_CUST
+#undef NVRAM_ITEM_MIPI
+#undef NVRAM_ITEM_RF_CAL
+#undef NVRAM_ITEM_RF_POC
+#undef NVRAM_ITEM_RF_TAS_VAR
+#undef NVRAM_ITEM_RF_TAS_ARRAY
+#undef NVRAM_ITEM_ELNA_VAR
+#undef NVRAM_ITEM_TX_POWER_VAR
+#undef NVRAM_ITEM_RF_TAS_TST
+#define NVRAM_ITEM_RF_CUST(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)        {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_MIPI(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)           {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_RF_CAL(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)         {NVRAM_EF_CL1CAL_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_RF_POC(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)         {NVRAM_EF_CL1CAL_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_RF_TAS_VAR(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)     {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(C2K_CUSTOM_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_RF_TAS_ARRAY(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)   {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_ELNA_VAR(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)       {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_TX_POWER_VAR(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)   {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+#define NVRAM_ITEM_RF_TAS_TST(nAME, aFFIX, rECnUM, tYPE, tYPEnUM, fUNC)     {NVRAM_EF_CL1_##nAME##_LID, aFFIX##_IDX, rECnUM, sizeof(CL1D_RF_##tYPE)*(tYPEnUM)},
+
+const CL1D_RF_CUST_DATA_LID_INFO_T cl1d_rf_cust_data_lid_info[CL1D_RF_NVRAM_ITEM_MAX_NUM] =
+{
+    #include "cl1_nvram_id.h"
+};
+
+kal_uint16 setIndexDebug=5;
+#if (IS_C2K_DRDI_SUPPORT)
+static kal_bool cl1d_drdi_had_done = KAL_FALSE;
+#endif
+
+const static CL1D_RF_CUST_DATA_SET_INFO_T* set_info_ptr;
+
+#if defined(__MD97__)
+#else
+extern void CL1D_RF_POC_Data_Default(const kal_int8 rf_band,
+    const kal_int8 c2k_band,
+    CL1D_RF_POC_FINAL_T *data_out);
+#endif
+extern void CL1D_RF_DPD_Data_Default(const kal_int8 rf_band,
+    const kal_int8 c2k_band,
+    CL1D_RF_TX_DPD_AM_PM_LUT_DATA_T *data_out);
+extern kal_bool cl1_custom_drdi_enable;
+
+void nvram_CL1D_DrdiPointerInit(kal_uint16 setIdx)
+{
+    ///TODO: Check setIdx
+
+    set_info_ptr = c1ld_rf_cust_data_drdi_set_ptr[setIdx];
+}
+
+
+void nvram_CL1D_Drdi(void)
+{
+#if (IS_C2K_DRDI_SUPPORT)
+   if(!cl1d_drdi_had_done)
+   {
+   
+   #ifndef MTK_PLT_ON_PC /*This macro will be opened in modis */	
+      if(cl1_custom_drdi_enable)
+      {
+         kal_uint16 setIdx;
+         setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_C2K);
+		 setIndexDebug=setIdx;
+         /* set the pointer to RF custom data by set index */
+         nvram_CL1D_DrdiPointerInit(setIdx);
+      }
+      else
+      {
+         nvram_CL1D_DrdiPointerInit(0);
+      }
+   #else //Use default setting when in modis.
+      nvram_CL1D_DrdiPointerInit(0);
+   #endif
+   
+      cl1d_drdi_had_done = KAL_TRUE;
+   }
+#else
+      nvram_CL1D_DrdiPointerInit(0);
+#endif/*IS_3G_DRDI_SUPPORT*/
+}
+
+kal_uint32 nvram_CL1D_get_item_idx(nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16* rec_amount)
+{
+    kal_uint32 i;
+
+    for (i = 0; i < CL1D_RF_NVRAM_ITEM_MAX_NUM; i++)
+    {
+        if (cl1d_rf_cust_data_lid_info[i].lid == lid && cl1d_rf_cust_data_lid_info[i].rec_idx == rec_idx)
+        {
+            *rec_amount = cl1d_rf_cust_data_lid_info[i].rec_num;
+            break;
+        }
+    }
+
+    return i;
+}
+
+void nvram_get_cl1_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    kal_uint32 nvram_item_idx;
+    kal_uint32 nvram_item_size;
+    kal_uint16 rec_idx = 1;
+    kal_uint16 rec_num;
+    kal_uint16 last_rec_num;
+    kal_uint16 last_nvram_item_size;
+    kal_bool first_record = TRUE;
+    nvram_CL1D_Drdi();
+
+    do
+    {
+        nvram_item_idx = nvram_CL1D_get_item_idx(lid, rec_idx, &rec_num);
+#if defined(__MD93__)||defined(__MD95__)
+        EXT_ASSERT(rec_idx <= rec_num, lid, rec_idx, rec_num);
+#elif defined(__MD97__)
+        if(rec_idx > rec_num){ //check rec_idx valid
+#ifndef MTK_PLT_ON_PC /*This macro will be opened in modis */	
+            CL1D_ErrorCheck_NVRAM_check_record_index((kal_uint32)lid, (kal_uint32)rec_idx, (kal_uint32)rec_num);
+#endif
+        }
+#endif        
+        nvram_item_size = cl1d_rf_cust_data_lid_info[nvram_item_idx].size;
+        if(first_record)
+        {
+           first_record = FALSE;
+#if defined(__MD93__)||defined(__MD95__)
+           EXT_ASSERT(rec_num * nvram_item_size <= buffer_size, lid, buffer_size, nvram_item_size);
+#elif defined(__MD97__)
+           if(rec_num * nvram_item_size > buffer_size){ //check buffer size valid
+#ifndef MTK_PLT_ON_PC /*This macro will be opened in modis */
+                CL1D_ErrorCheck_NVRAM_check_buffer_size((kal_uint32)lid, (kal_uint32)buffer_size, (kal_uint32)nvram_item_size);
+#endif
+           }
+#endif 
+        }
+        else
+        {
+           /* Check second record data valid */
+#if defined(__MD93__)||defined(__MD95__)
+           EXT_ASSERT(last_rec_num == rec_num, lid, last_rec_num, rec_num);
+           EXT_ASSERT(last_nvram_item_size == nvram_item_size, lid, last_nvram_item_size, nvram_item_size);
+#elif defined(__MD97__)
+#ifndef MTK_PLT_ON_PC /*This macro will be opened in modis */
+           if(last_rec_num != rec_num){
+                CL1D_ErrorCheck_NVRAM_check_record_num_2nd((kal_uint32)lid, (kal_uint32)last_rec_num, (kal_uint32)rec_num);
+           }
+           
+           if(last_nvram_item_size != nvram_item_size){
+                CL1D_ErrorCheck_NVRAM_check_item_size_2nd((kal_uint32)lid, (kal_uint32)last_nvram_item_size, (kal_uint32)nvram_item_size);
+           }
+#endif
+#endif           
+        }
+
+        last_rec_num = rec_num;
+        last_nvram_item_size = nvram_item_size;
+        
+        kal_mem_cpy((kal_uint8*)buffer + (rec_idx - 1) * nvram_item_size, set_info_ptr[nvram_item_idx], nvram_item_size);
+
+    }while(rec_idx++ < rec_num);
+}
+
+kal_int32 nvram_get_cl1_default_band_idx_to_c2k_band(kal_int32 band_idx)
+{
+    kal_uint32 nvram_item_idx;
+    CL1D_RF_CUST_PARAM_T *param_ptr = NULL;
+    kal_int32 c2k_band = SYS_BAND_CLASS_NOT_USED;
+    kal_uint16 rec_num;
+#if defined(__MD93__)||defined(__MD95__)
+    ASSERT(band_idx < RF_CUST_SUPPORT_BAND_MAX_NUM);
+#elif defined(__MD97__)
+    DEBUG_ASSERT(band_idx < RF_CUST_SUPPORT_BAND_MAX_NUM);
+#endif
+
+    nvram_CL1D_Drdi();
+    nvram_item_idx = nvram_CL1D_get_item_idx(NVRAM_EF_CL1_CUST_PARAM_LID, 1, &rec_num);
+    param_ptr = (CL1D_RF_CUST_PARAM_T *)set_info_ptr[nvram_item_idx];
+
+    if (param_ptr->band_support[band_idx].is_supported)
+        c2k_band = param_ptr->band_support[band_idx].band_class;
+
+    if (c2k_band > SYS_BAND_CLASS_NOT_USED)
+        c2k_band = SYS_BAND_CLASS_NOT_USED;
+
+    return c2k_band;
+}
+
+#if defined(__MD97__)
+#else
+void nvram_get_cl1_poc_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+    kal_uint32 nvram_item_idx;
+    kal_int32 band_idx = 0;
+    kal_int32 c2k_band;
+    kal_uint16 rec_num, last_rec_num;
+    do
+    {
+        nvram_item_idx = nvram_CL1D_get_item_idx(NVRAM_EF_CL1CAL_POC_FINAL_LID, (band_idx + 1), &rec_num);
+        c2k_band = nvram_get_cl1_default_band_idx_to_c2k_band(band_idx);
+        CL1D_RF_POC_Data_Default(band_idx, c2k_band, set_info_ptr[nvram_item_idx]);
+
+        if(band_idx != 0)
+            EXT_ASSERT(last_rec_num == rec_num, band_idx, last_rec_num, rec_num);
+
+        last_rec_num = rec_num;
+        band_idx++;
+    }while(band_idx < rec_num);
+    nvram_get_cl1_default_value_to_write(lid, buffer, buffer_size);
+}
+#endif
+
+void nvram_get_cl1_1xrtt_dpd_am_pm_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    kal_uint32 nvram_item_idx;
+    kal_int32 band_idx = 0;
+    kal_int32 c2k_band;
+    kal_uint16 rec_num, last_rec_num;
+    do
+    {
+        nvram_item_idx = nvram_CL1D_get_item_idx(NVRAM_EF_CL1CAL_TX_DPD_AM_PM_COMP_1XRTT_LID, (band_idx + 1), &rec_num);
+        c2k_band = nvram_get_cl1_default_band_idx_to_c2k_band(band_idx);
+        CL1D_RF_DPD_Data_Default(band_idx, c2k_band, set_info_ptr[nvram_item_idx]);
+
+        
+#if defined(__MD93__)||defined(__MD95__)
+        if(band_idx != 0){
+            EXT_ASSERT(last_rec_num == rec_num, band_idx, last_rec_num, rec_num);
+        }
+#elif defined(__MD97__)
+#ifndef MTK_PLT_ON_PC /*This macro will be opened in modis */
+        if((band_idx != 0)&&(last_rec_num != rec_num)){
+            CL1D_ErrorCheck_NVRAM_check_dpd_1x_default_write((kal_uint32)band_idx, (kal_uint32)last_rec_num, (kal_uint32)rec_num);
+        }
+#endif
+#endif
+
+        last_rec_num = rec_num;
+        band_idx++;
+    }while(band_idx < rec_num);
+    nvram_get_cl1_default_value_to_write(lid, buffer, buffer_size);
+}
+
+void nvram_get_cl1_evdo_dpd_am_pm_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    kal_uint32 nvram_item_idx;
+    kal_int32 band_idx = 0;
+    kal_int32 c2k_band;
+    kal_uint16 rec_num, last_rec_num;
+    do
+    {
+        nvram_item_idx = nvram_CL1D_get_item_idx(NVRAM_EF_CL1CAL_TX_DPD_AM_PM_COMP_EVDO_LID, (band_idx + 1), &rec_num);
+        c2k_band = nvram_get_cl1_default_band_idx_to_c2k_band(band_idx);
+        CL1D_RF_DPD_Data_Default(band_idx, c2k_band, set_info_ptr[nvram_item_idx]);
+
+#if defined(__MD93__)||defined(__MD95__)
+            if(band_idx != 0){
+                EXT_ASSERT(last_rec_num == rec_num, band_idx, last_rec_num, rec_num);
+            }
+#elif defined(__MD97__)
+#ifndef MTK_PLT_ON_PC /*This macro will be opened in modis */
+            if((band_idx != 0)&&(last_rec_num != rec_num)){
+                CL1D_ErrorCheck_NVRAM_check_dpd_do_default_write((kal_uint32)band_idx, (kal_uint32)last_rec_num, (kal_uint32)rec_num);
+            }
+#endif
+#endif
+
+        last_rec_num = rec_num;
+        band_idx++;
+    }while(band_idx < rec_num);
+    nvram_get_cl1_default_value_to_write(lid, buffer, buffer_size);
+}
+
+
diff --git a/mcu/service/nvram/src/nvram_drval_fat.c b/mcu/service/nvram/src/nvram_drval_fat.c
new file mode 100644
index 0000000..b045b0d
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_drval_fat.c
@@ -0,0 +1,5632 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ * Filename:
+ * ---------
+ * nvram_drval_fat.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is Driver adaption level functions.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/***************************************************************************** 
+* Include
+*****************************************************************************/
+
+#include "stdio.h"
+#include "string.h"
+#include "stdarg.h"
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+
+#include "fs_type.h"
+#include "fs_func.h"
+#include "fs_errcode.h"
+
+#include "nvram_main.h"
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+
+#ifdef __NVRAM_LID_CACHE__
+#include "nvram_cache_interface.h"
+#endif
+
+
+#if defined(__MTK_TARGET__)
+#include "SST_secure.h"
+#endif
+#include "us_timer.h"
+#include "ex_public.h"
+
+/*****************************************************************************
+* Define
+*****************************************************************************/
+
+/*****************************************************************************
+* Global Variable
+*****************************************************************************/
+extern kal_mutexid g_nvram_fs_mutex;
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+extern DCL_HANDLE nvram_gpt_handle;
+#endif
+
+#ifdef __NVRAM_WRITE_WITH_FILE_SIZE__
+extern kal_bool bResetNvramData;
+#endif
+
+#ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+extern kal_bool Cali_filelist_found;
+extern kal_bool Imei_filelist_found;
+extern kal_bool is_nvram_in_ota_flow;
+extern kal_bool is_nvram_first_restore;
+extern kal_uint8 *CALI_FileListBuf;
+extern kal_uint8 *IMEI_FileListBuf;
+
+#endif
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+extern module_type stack_get_active_module_id( void );
+
+/*****************************************************************************
+* Local Variable
+*****************************************************************************/
+
+static kal_int32 nvram_fat_last_err;
+static kal_uint32 nvram_fat_last_line;
+static kal_uint8 g_chksum[128] = {0};
+
+#ifdef __NVRAM_CRYPT_TEST__
+extern kal_uint32 bWriteMsp;
+extern kal_uint32 bReadMsp;
+#define NVRAM_SWCHANGE_REPORT_MSP_ENCRYPT_FILE       "Z:\\NVRAM\\W_TST"
+#define NVRAM_SWCHANGE_REPORT_MSP_DENCRYPT_FILE      "Z:\\NVRAM\\R_TST"
+
+static kal_uint8 NVRAM_EF_MSP_TEST_W[NVRAM_MSP_TEST_LEN * 3];
+static kal_uint8 NVRAM_EF_MSP_TEST_R[NVRAM_MSP_TEST_LEN * 3];
+#endif
+
+#ifndef __MTK_TARGET__  /* Simulate by nvram on MODIS */
+void SST_Secure_Algo (kal_uint8 Direction, kal_uint32 ContentAddr,
+                             kal_uint32 ContentLen, kal_uint8 *CustomSeed,
+                             kal_uint8 *ResText)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 *source = (kal_uint8 *) ContentAddr;
+    kal_int32 i;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if ((ContentAddr & 0x03) != 0)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE, ContentAddr, NVRAM_LOC_ADDRESS_ALIGN_FAIL_1, 0);
+    }
+
+    if (NVRAM_MSP_ALIGNMENT_REMAINDER(ContentLen) != 0)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE,ContentLen , NVRAM_LOC_LENGTH_ALIGN_FAIL_1, 0);
+    }
+
+    for (i = 0 ;i < ContentLen; i ++)
+    {
+        *(ResText+i) = *(source+i) ^ i;
+    }
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_gpt_timeout_callback
+ * DESCRIPTION
+ *  if FS access timeout will trigger assert
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+void nvram_gpt_timeout_callback(void *data)
+{
+    //timeout assert
+    NVRAM_EXT_ASSERT(KAL_FALSE,0, NVRAM_LOC_ACCESS_TIMEOUT_1, 0);
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_fat_last_err
+ * DESCRIPTION
+ *  get the last error in nvram drv fat
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_get_last_err(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    return nvram_fat_last_err;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_fat_last_line
+ * DESCRIPTION
+ *  get the last error in nvram drv fat
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_uint32 nvram_drv_fat_get_last_line(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    return nvram_fat_last_line;
+}
+
+#ifdef __NVRAM_CRYPT_TEST__
+static kal_bool nvram_create_report_msp_file(kal_bool bWrite)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE handle;
+    kal_uint32 filelen = NVRAM_MSP_TEST_LEN*3;
+    kal_uint32 written;
+    kal_int32 result = FS_NO_ERROR;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if ( bWrite )
+    {
+        kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_MSP_ENCRYPT_FILE);
+        NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+        result = FS_GetAttributes(filename);
+        NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+        if (result >= FS_NO_ERROR)
+        {
+            NVRAM_FS_START_EX(FS_OP_DELETE, filename);
+            result = FS_Delete(filename);
+            NVRAM_FS_END(FS_OP_DELETE,result);
+        }
+    
+
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        handle = FS_Open(filename, FS_CREATE_ALWAYS | FS_READ_WRITE);
+        NVRAM_FS_END(FS_OP_OPEN,handle);
+        if (handle > FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(handle, &NVRAM_EF_MSP_TEST_W, filelen, &written);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (result != FS_NO_ERROR)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d \r\n",__FUNCTION__,__LINE__,result);
+                NVRAM_FS_START(FS_OP_CLOSE);
+                result = FS_Close(handle);
+                NVRAM_FS_END(FS_OP_CLOSE,result);
+                bWriteMsp = 0;
+                return KAL_FALSE;
+            }
+        }
+        else
+        {
+            return KAL_FALSE;
+        }
+
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        bWriteMsp = 0;
+    }
+    else
+    {
+        kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_MSP_DENCRYPT_FILE);
+        NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+        result = FS_GetAttributes(filename);
+        NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+        if (result >= FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_GetAttributes fail at %d,result=%d \r\n",__FUNCTION__,__LINE__,result);
+            NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+            result = FS_Delete(filename);
+            NVRAM_FS_END(FS_OP_DELETE,result);
+        }
+
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        handle = FS_Open(filename, FS_CREATE_ALWAYS | FS_READ_WRITE);
+        NVRAM_FS_END(FS_OP_OPEN,handle);
+        if (handle > FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(handle, &NVRAM_EF_MSP_TEST_R, filelen, &written);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (result != FS_NO_ERROR)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d \r\n",__FUNCTION__,__LINE__,result);
+                NVRAM_FS_START(FS_OP_CLOSE);
+                result = FS_Close(handle);
+                NVRAM_FS_END(FS_OP_CLOSE,result);
+                bReadMsp = 0;
+                return KAL_FALSE;
+            }
+        }
+        else
+        {
+            return KAL_FALSE;
+        }
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        bReadMsp = 0;
+    }
+    
+    return KAL_TRUE;    
+}
+#endif
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_init
+ * DESCRIPTION
+ *  This is nvram_drv_fat_init() function of NVRAM module.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  if NVRAM folder does not exist, it means the FAT is empty.
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_status(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile;
+    nvram_folder_enum i;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_START;        
+        nvram_ee_info->nvram_init_type = NVRAM_INIT_NORMAL_BOOT_UP;
+    }
+#if !(defined(_SIMULATION) || defined(__PALLADIUM__) || defined(__FPGA__))
+    if (nvram_check_first_bootup_log("FAT"))
+    {
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CHECK_DONE; 
+            nvram_ee_info->nvram_init_type = NVRAM_INIT_FIRST_BOOT_UP;
+        }
+        return NVRAM_DRV_UNFORMATTED;
+    }
+#endif
+
+    NVRAM_FS_MAKE_ROOT_PATH(filename);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if (hFile == FS_FILE_NOT_FOUND || hFile == FS_PATH_NOT_FOUND)
+    {
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CHECK_DONE;
+            nvram_ee_info->nvram_init_type = NVRAM_INIT_FIRST_BOOT_UP;
+        }
+        return NVRAM_DRV_UNFORMATTED;
+    }
+    else if (hFile == FS_FDM_USER_DRIVE_BROKEN ||
+             hFile == FS_FDM_SYS_DRIVE_BROKEN ||
+             hFile == FS_FDM_MULTIPLE_BROKEN)
+    {
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CHECK_DONE;
+            nvram_ee_info->nvram_init_context.dev_broken = KAL_TRUE;
+        }
+        return NVRAM_DRV_DRIVE_BROKEN;
+    }
+    else if (hFile == FS_FDM_VERSION_MISMATCH)
+    {
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CHECK_DONE;
+            nvram_ee_info->nvram_init_context.dev_broken = KAL_TRUE;
+        }
+        return NVRAM_DRV_DRIVE_VNOERR;
+    }
+    else if (hFile >= FS_NO_ERROR)   /* Success */
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+    }
+    else
+    {
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(hFile, __LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32) hFile, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_3, 0);
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CHECK_DONE;
+        }
+        return NVRAM_DRV_FATAL_ERROR;
+    }
+
+
+    for (i = NVRAM_FOLDER_BEGIN; i < NVRAM_FOLDER_TOTAL; i++)
+    {
+        kal_wsprintf(filename, "%s", nvram_query_work_path(i));
+        NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES, filename);
+        result = FS_GetAttributes(filename);
+        NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+        if (FS_NO_ERROR > result)
+        {
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_START;
+            }
+            return NVRAM_DRV_FOLDER_NOT_READY;
+        }
+    }
+ 
+    return NVRAM_DRV_OK;
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_init
+ * DESCRIPTION
+ *  This is nvram_drv_fat_init() function of NVRAM module.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  if NVRAM folder does not exist, it means the FAT is empty.
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_init_start(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 Ret = FS_NO_ERROR;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    Ret = NVRAM_FS_GET_FULL_PATH_LEN;
+
+    nvram_create_first_bootup_log("FAT");
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CREATE_FAT_FILE_DONE;
+    }
+    /* check nvram root folder, if not exist, create it! */
+    NVRAM_FS_MAKE_ROOT_PATH(filename);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES, filename);
+    Ret = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,Ret);
+    if(FS_NO_ERROR > Ret)
+    {
+        NVRAM_FS_START_EX(FS_OP_CREATEDIR,filename);
+        Ret = FS_CreateDir((const kal_wchar*)filename);
+        NVRAM_FS_END(FS_OP_CREATEDIR,Ret);
+       MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(Ret, __LINE__);
+    }
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CREATE_MAIN_FOLDER_DONE;
+    }
+    nvram_create_all_folder();
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_CREATE_ALL_FOLDER_DONE;
+        nvram_ee_info->nvram_init_time[2] = kal_get_systicks();
+    }
+    return NVRAM_DRV_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_init
+ * DESCRIPTION
+ *  This is nvram_drv_fat_init() function of NVRAM module.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  if NVRAM folder does not exist, it means the FAT is empty.
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_init_end(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_delete_first_bootup_log("FAT");
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_DELETE_FAT_FILE_DONE;
+    }
+    return NVRAM_DRV_OK;
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_format
+ * DESCRIPTION
+ *  Dummy format function.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_drv_fat_format(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* Folder is ready as init, nothing to do in format */
+    return;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_nvram_drv_fat_backup
+ * DESCRIPTION
+ *  To make a backup.
+ * PARAMETERS
+ *  prefix           [IN]         file prefix
+ *  verno            [IN]         file verno
+ *  a_to_b           [IN]         direction
+ * RETURNS
+ *  error code
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_backup(nvram_ltable_entry_struct *ldi, kal_bool a_to_b)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar src_path[NVRAM_MAX_PATH_LEN], dest_path[NVRAM_MAX_PATH_LEN];
+    NVRAM_FILE_NAME nvramname;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (a_to_b)
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);  // A
+        nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_TRUE), nvramname, src_path);
+
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            nvram_query_file_name(NVRAM_NVD_BAK, nvramname, dest_path);
+        }
+        else
+    #endif
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE); // B
+            nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_FALSE), nvramname, dest_path);
+        }
+    }
+    else
+    {
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            nvram_query_file_name(NVRAM_NVD_BAK, nvramname, src_path);
+        }
+        else
+    #endif
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);  // B
+            nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_FALSE), nvramname, src_path);
+
+        }
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);  // A
+        nvram_query_file_name(nvram_query_folder_index_ex(ldi->category, KAL_TRUE), nvramname, dest_path);
+    }
+
+#ifndef __LOW_COST_SUPPORT_ULC__
+
+//    FS_SetAttributes(dest_path, 0);
+    NVRAM_FS_START_EX(FS_OP_DELETE,dest_path);
+    result = FS_Delete(dest_path);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+    NVRAM_FS_START_EX(FS_OP_MOVE,src_path);
+    result = FS_Move(src_path, dest_path, FS_MOVE_COPY, NULL, NULL, 0);
+    NVRAM_FS_END(FS_OP_MOVE,result);
+#else
+    {
+        FS_HANDLE src, dest;
+        NVRAM_FS_START_EX(FS_OP_OPEN,src_path);
+        src = FS_Open(src_path, FS_READ_ONLY);
+        NVRAM_FS_END(FS_OP_OPEN,src);
+        NVRAM_FS_START_EX(FS_OP_OPEN,dest_path);
+        dest = FS_Open(dest_path, FS_READ_WRITE | FS_CREATE_ALWAYS);
+        NVRAM_FS_END(FS_OP_OPEN,dest);
+
+        if (src >= FS_NO_ERROR && dest >= FS_NO_ERROR)
+        {
+            kal_uint32 len;
+            kal_uint8 *buf = (kal_uint8 *)get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+            NVRAM_FS_START(FS_OP_READ);
+            result =  FS_Read(src, buf, MAX_NVRAM_RECORD_SIZE, &len);
+            NVRAM_FS_END(FS_OP_READ,result);
+            while ((ret == FS_NO_ERROR) &&
+                    result >= FS_NO_ERROR &&
+                   (len > 0))
+            {
+                NVRAM_FS_START(FS_OP_WRITE);
+                result = FS_Write(dest, buf, len, &len);
+                NVRAM_FS_END(FS_OP_WRITE,result);
+            }
+            nvram_fat_last_err = ret;
+            nvram_fat_last_line = __LINE__;
+            NVRAM_FS_START(FS_OP_CLOSE);
+            result = FS_Close(src);
+            NVRAM_FS_END(FS_OP_CLOSE,result);
+            NVRAM_FS_START(FS_OP_CLOSE);
+            result = FS_Close(dest);
+            NVRAM_FS_END(FS_OP_CLOSE,result);
+            free_ctrl_buffer(buf);
+            buf = NULL;
+        }
+        else
+        {
+            if (src < FS_NO_ERROR)
+                return src;
+            else
+                return dest;
+        }
+    }
+#endif
+
+    #ifdef __NVRAM_LID_CACHE__
+    if(result >= FS_NO_ERROR)
+    {
+        if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_RD_WITH_CACHE(ldi->LID))
+        {
+            unmask_valid_bit_by_ltable_entry(ldi, 0, (ldi->total_records + 1));
+        }
+    }
+    #endif
+
+    return result;
+}
+
+#if defined(__NVRAM_FS_OPERATION_COMPACT__) && defined(__NVRAM_FS_CMPT_SIMULATION__)
+/*****************************************************************************
+ * FUNCTION
+ *  FS_CMPT_Read
+ * DESCRIPTION
+ *  To simulate SP FS CMPT API
+ * RETURNS
+ *  error code
+ *****************************************************************************/
+kal_int32 FS_CMPT_Read(const WCHAR * FileName, NVRAM_FS_PARAM_CMPT_T* nvram_param)
+{
+    FS_HANDLE hFile;
+    int result;
+    kal_int32 ret = FS_NO_ERROR;    
+    if((nvram_param->opid_map & (NVRAM_FS_CMPT_OPEN)) == (NVRAM_FS_CMPT_OPEN)){
+        nvram_param->ret[0] |= NVRAM_FS_CMPT_OPEN;
+        NVRAM_FS_START_EX(FS_OP_OPEN,FileName);
+        hFile = FS_Open((const kal_wchar*)FileName, nvram_param->Flag);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+        if (hFile < FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open fail at %d,hFile=%d \r\n",__FUNCTION__,__LINE__,hFile);
+            nvram_param->ret[1] = hFile;
+            return hFile;
+        }
+    }
+    if((nvram_param->opid_map & (NVRAM_FS_CMPT_GETFILESIZE)) == (NVRAM_FS_CMPT_GETFILESIZE)){
+        nvram_param->ret[0] |= NVRAM_FS_CMPT_GETFILESIZE;
+        NVRAM_FS_START(FS_OP_GETFILESIZE);
+        result = FS_GetFileSize(hFile, nvram_param->FileSize);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+        if (result < FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_GetFileSize fail at %d,result=%d \r\n",__FUNCTION__,__LINE__,result);
+            nvram_param->ret[1] = result;
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+            return result;
+        }            
+    }    
+    if((nvram_param->opid_map & (NVRAM_FS_CMPT_SEEK)) == (NVRAM_FS_CMPT_SEEK)){
+        nvram_param->ret[0] |= NVRAM_FS_CMPT_SEEK;
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, nvram_param->Offset, nvram_param->Whence);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if (result < FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail at %d,result=%d \r\n",__FUNCTION__,__LINE__,result);
+            nvram_param->ret[1] = result;
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+            return result;
+        }            
+    }    
+    if((nvram_param->opid_map & (NVRAM_FS_CMPT_READ)) == (NVRAM_FS_CMPT_READ)){
+        nvram_param->ret[0] |= NVRAM_FS_CMPT_READ;
+        NVRAM_FS_START(FS_OP_READ);
+        result = FS_Read(hFile, nvram_param->DataPtr, nvram_param->Length, nvram_param->Read);
+        NVRAM_FS_END(FS_OP_READ,result);
+        if (result < FS_NO_ERROR)
+        {
+            nvram_param->ret[1] = result;
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+            return result;
+        }  
+    }
+    nvram_param->ret[0] |= NVRAM_FS_CMPT_CLOSE;
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+
+    return result;
+}
+#endif /* __NVRAM_FS_CMPT_SIMULATION__ */
+
+#if (defined(__NVRAM_FS_OPERATION_COMPACT__)&& defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_FS_CMPT_SIMULATION__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_read_section_cmpt
+ * DESCRIPTION
+ *  read record(s) from FAT.
+ * PARAMETERS
+ *  hFile               [IN]         file handle
+ *  rec_index           [IN]         which record to read (start)
+ *  rec_amount          [IN]         how many record to read at once
+ *  rec_size            [IN]         size of record
+ *  buffer              [IN/OUT]     buffer of check sum
+ *  type                [IN]         read content or checksum
+ *  ismsp               [IN]         to indicate that the records protected by hw
+ * RETURNS
+ *  = 0: success
+ *  > 0: NVRAM error code
+ *  < 0: FS error code
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_read_section_cmpt(
+            FS_HANDLE hFile,
+            kal_uint16 rec_index,
+            kal_uint16 rec_amount,
+            kal_uint32 rec_size,
+            kal_uint8 *buffer,
+            nvram_drv_read_type_enum type,
+            nvram_ltable_entry_struct *ldi,
+            kal_wchar *filename,
+            NVRAM_FS_PARAM_CMPT_T *nvram_param
+            )
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint16 chksum3 = 0;
+    kal_uint8 *chksum1 = NULL;
+    kal_uint8 *chksum2 = NULL;
+    kal_uint32 len = 0, remainLen = 0;
+    kal_uint32 section_size;
+    kal_uint32 working_buffer_size;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_DRV_OK;
+    kal_uint32 i,j;
+    kal_bool skip_verify = KAL_FALSE;
+    kal_uint32 file_offset = nvram_param->Offset;
+    nvram_ldi_ota_header *ota_header;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    #ifdef __NVRAM_LID_CACHE__
+    kal_bool is_valid_bit = KAL_TRUE;
+    kal_uint32 m, n;
+    kal_bool is_only_chksum = KAL_FALSE;
+    kal_uint32 max_cache_read_size = 0;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* read RAW data directly */
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_param->opid_map |= NVRAM_FS_CMPT_SEEK;
+        nvram_param->Whence = FS_FILE_CURRENT;
+        
+        nvram_param->opid_map |= NVRAM_FS_CMPT_READ;
+        nvram_param->DataPtr = buffer;
+        nvram_param->Length = rec_size;
+        nvram_param->Read = &len;                               
+        nvram_param->opid_map |= NVRAM_FS_CMPT_CLOSE;
+        NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+        result = FS_CMPT_Read(filename, nvram_param);
+        NVRAM_FS_END(FS_OP_CMPTREAD,result);
+        if (nvram_param->opid_map != nvram_param->ret[0])
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_CMPT_Read fail at %d \r\n",__FUNCTION__,__LINE__);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]nvram_param->opid_map(%d) != nvram_param->ret[0](%d) \r\n",nvram_param->opid_map,nvram_param->ret[0]);
+            nvram_fat_last_err = nvram_param->ret[1];
+            nvram_fat_last_line =  __LINE__;
+        }   
+        if (len==0)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s ->FS_CMPT_Read fail as len=0\r\n",__FUNCTION__);
+            result = FS_INVALID_FILE_POS;  // End of File
+            nvram_fat_last_line = __LINE__;    
+        }
+        goto END;
+    }
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#endif
+
+    section_size = rec_size + nvram_chksum_size + remainLen;
+
+    nvram_param->opid_map |= NVRAM_FS_CMPT_SEEK;
+    nvram_param->Offset += (rec_index - 1) * section_size;
+    nvram_param->Whence = FS_FILE_CURRENT;
+
+    /*
+    //working_buffer_size = MAX_NVRAM_RECORD_SIZE;        
+    //MAX_NVRAM_RECORD_SIZE = (NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * NVRAM_RECORD_SECTOR_SIZE)
+    //                      = (128 0r 16 or 4) * 512
+    */
+
+    working_buffer_size = section_size * rec_amount;
+    #ifdef __NVRAM_LID_CACHE__
+    if(working_buffer_size < MD_CCCI_LIMIT_SIZE)
+    {
+        max_cache_read_size = MD_CCCI_LIMIT_SIZE;
+    }
+    else
+    {
+        max_cache_read_size = ((working_buffer_size -1 )/MD_CCCI_LIMIT_SIZE + 1)* MD_CCCI_LIMIT_SIZE;
+    }
+    if(max_cache_read_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        max_cache_read_size = MAX_NVRAM_RECORD_SIZE;
+    }
+    #endif
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+    
+    // judge read checksum only
+    if ((type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY) || (type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B)) {
+        //Do not support read checksum only from encrypted
+        if(ldi->attr & (NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_MSP) || 
+           (rec_amount * nvram_chksum_size) > MAX_NVRAM_RECORD_SIZE ) {
+            type = (type==NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B)?NVRAM_DRV_READ_TYPE_CHKSUM_2B: NVRAM_DRV_READ_TYPE_CHKSUM;
+        }
+        else {
+            skip_verify = KAL_TRUE;
+            working_buffer_size = (rec_amount * nvram_chksum_size);
+            #ifdef __NVRAM_LID_CACHE__
+            is_only_chksum = KAL_TRUE;
+            #endif
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    working_buffer = (kal_uint8*) get_ctrl_buffer(max_cache_read_size);
+    #else
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    #endif
+    // return checksum only
+    if(skip_verify)
+    {
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+            //get appendix header
+            if(ldi->append_offset == 0) {
+                ota_header = (nvram_ldi_ota_header *)get_ctrl_buffer(NVRAM_LDI_OTA_HEADER_SIZE);
+                if(KAL_TRUE == nvram_read_data_header(filename, LDI_HEADER_OTA_SECTION, ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+                   (ota_header->ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+                {
+                    ldi->append_offset = nvram_appendix_header_offset(ldi);
+                }
+                else {
+                    ldi->append_offset = -1;
+                }
+                free_ctrl_buffer(ota_header);
+            }
+            if(ldi->append_offset > 0) {
+                nvram_param->opid_map |= NVRAM_FS_CMPT_READ;
+                nvram_param->Offset = (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size));
+                nvram_param->DataPtr = working_buffer;
+                nvram_param->Length = (rec_amount * nvram_chksum_size);
+                nvram_param->Read = &len;                               
+                nvram_param->opid_map |= NVRAM_FS_CMPT_CLOSE;
+
+                #ifdef __NVRAM_LID_CACHE__
+                if (NVRAM_RD_WITH_CACHE(ldi->LID))
+                {
+                    if (NVRAM_IO_ERRNO_OK != (result = nvram_read_data_from_cache(ldi, nvram_param)))
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s ->nvram_read_data_from_cache fail,result=%d\r\n",__FUNCTION__,result);
+                        result = FS_ERROR_RESERVED;
+                        nvram_fat_last_line = __LINE__;
+                    }
+                    
+                    for(m = 0; m < rec_amount; m++)
+                    {
+                        is_valid_bit = KAL_FALSE;   
+                        for(n = 0; n < nvram_chksum_size; n++)
+                        {
+                            if(*(((kal_uint8*)(nvram_param->DataPtr)) + (m * nvram_chksum_size + n)) != 0)
+                            {
+                                is_valid_bit = KAL_TRUE;
+                                break;
+                            }
+                        }
+                        if(is_valid_bit == KAL_FALSE)
+                        {
+                            break;
+                        }
+                    }
+
+                    if(is_valid_bit == KAL_FALSE)
+                    {
+                        NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+                        result = FS_CMPT_Read(filename, nvram_param);
+                        NVRAM_FS_END(FS_OP_CMPTREAD,result);
+                        if (result == FS_NO_ERROR) {
+                            update_cache_data(ldi, rec_index, rec_amount, nvram_param, is_only_chksum);                         
+                        }
+                    }
+                }else
+                #endif
+                {
+                    NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+                    result = FS_CMPT_Read(filename, nvram_param);
+                    NVRAM_FS_END(FS_OP_CMPTREAD,result);
+                }
+
+                if ((nvram_param->opid_map != nvram_param->ret[0]) || (len==0))
+                {
+                     //goto normal read flow when read appendix fail
+                     NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_CMPT_Read fail at %d\r\n",__FUNCTION__,__LINE__);
+                     NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]nvram_param->opid_map(%d) != nvram_param->ret[0](%d) or len==%d \r\n",nvram_param->opid_map,nvram_param->ret[0],len);
+                    goto NO_CHKSUM_INTEGRATE;
+                }   
+            }
+            else {
+                goto NO_CHKSUM_INTEGRATE;
+            }
+        }
+        else {
+            NO_CHKSUM_INTEGRATE:
+            for (j = 0; j < rec_amount; j++)
+            {
+                nvram_param->opid_map |= NVRAM_FS_CMPT_READ;
+                /*
+                1, will be a full process: fs_open() ==> fs_seek(, offsert) ==> fs_read() ==> fs_close()
+                2, offset should be right
+                */
+                nvram_param->Offset = file_offset + (rec_size + ((j + rec_index - 1) * section_size));
+                nvram_param->DataPtr = (working_buffer + (j* nvram_chksum_size));
+                nvram_param->Length = nvram_chksum_size;
+                nvram_param->Read = &len;                               
+                nvram_param->opid_map |= NVRAM_FS_CMPT_CLOSE;
+
+                #ifdef __NVRAM_LID_CACHE__
+                if (NVRAM_RD_WITH_CACHE(ldi->LID))
+				{
+                    result = nvram_read_data_from_cache(ldi, nvram_param);
+                    is_valid_bit = KAL_FALSE;
+                    for(n = 0; n < nvram_chksum_size; n++)
+                    {
+                        if(*(((kal_uint8*)(nvram_param->DataPtr)) + n) != 0)
+                        {
+                            is_valid_bit = KAL_TRUE;
+                            break;
+                        }
+                    }
+                    if (is_valid_bit == KAL_FALSE)
+                    {
+                        NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+                        result = FS_CMPT_Read(filename, nvram_param);
+                        NVRAM_FS_END(FS_OP_CMPTREAD,result);
+                        if (result == FS_NO_ERROR) {
+                            update_cache_data(ldi, rec_index+j, 1, nvram_param, is_only_chksum);
+                        }
+                    }
+                }else
+                #endif
+                {
+                    NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+                    result = FS_CMPT_Read(filename, nvram_param);
+                    NVRAM_FS_END(FS_OP_CMPTREAD,result);
+                }
+
+                if (nvram_param->opid_map != nvram_param->ret[0])
+                {
+                    nvram_fat_last_err = nvram_param->ret[1];
+                    nvram_fat_last_line =  __LINE__;
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_CMPT_Read fail at %d\r\n",__FUNCTION__,__LINE__);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]nvram_param->opid_map(%d) != nvram_param->ret[0](%d)\r\n",nvram_param->opid_map,nvram_param->ret[0]);
+                    goto final;
+                }   
+                if (len==0)
+                {
+                    result = FS_INVALID_FILE_POS;  // End of File
+                    nvram_fat_last_line = __LINE__;
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_CMPT_Read fail at %d,len=0\r\n",__FUNCTION__,__LINE__);
+                    goto final;
+                }   
+            }
+        }
+        //Caculate checksum
+        if(type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B) {
+            for (j = 0; j < rec_amount; j++) {
+                chksum3 = nvram_util_md5_checksum_convert((working_buffer + (j* nvram_chksum_size)), NULL, KAL_TRUE);
+                kal_mem_cpy(buffer + (NVRAM_CHKSUM_SIZE_2B* j), &chksum3, NVRAM_CHKSUM_SIZE_2B);
+            }
+        }
+        else {
+            kal_mem_cpy(buffer, working_buffer, (rec_amount * nvram_chksum_size));
+        }
+    }
+    else
+    {
+        kal_int32 rec_in_block = working_buffer_size / section_size;
+        
+        #ifdef __NVRAM_LID_CACHE__
+        kal_uint32 rec_cnt_for_cache_read = 0;
+        kal_uint32 rec_index_for_cache_read = 0;
+        kal_uint32 cache_read_length = 0;
+        kal_int32 rec_in_block_for_cache_read = max_cache_read_size / section_size;
+        kal_uint32 nvram_param_offset_temp = 0;
+        void *DataPtr_temp = NULL;
+        #endif
+        chksum1 = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+        for (i = 0 ; i < rec_amount; )
+        {
+            kal_uint32 total_read = section_size * rec_in_block;
+            kal_uint32 working_buffer_sub_index = 0;
+            
+            
+            nvram_param->Offset = file_offset + (rec_index - 1) * section_size;
+            nvram_param->Offset += (i*section_size);
+            #ifdef __NVRAM_LID_CACHE__
+            is_valid_bit = KAL_TRUE;
+            #endif
+
+            /* last read */
+            if (rec_in_block > rec_amount - i)
+            {
+                rec_in_block = rec_amount - i;
+                total_read = section_size * rec_in_block;
+            }
+            len = 0;
+            do 
+            {
+                nvram_param->opid_map |= NVRAM_FS_CMPT_READ;
+                /*
+                1, will be a full process: fs_open() ==> fs_seek(, offsert) ==> fs_read() ==> fs_close()
+                2, offset should be right
+                */
+                nvram_param->Offset += len;
+                nvram_param->DataPtr = (working_buffer + working_buffer_sub_index);
+                nvram_param->Length = total_read;
+                nvram_param->Read = &len;                               
+                nvram_param->opid_map |= NVRAM_FS_CMPT_CLOSE;
+                
+                #ifdef __NVRAM_LID_CACHE__
+				is_valid_bit = KAL_TRUE;
+                nvram_param_offset_temp = nvram_param->Offset;
+                //DataPtr_temp = nvram_param->DataPtr;
+                cache_read_length = total_read;
+
+                if (NVRAM_RD_WITH_CACHE(ldi->LID))
+                {
+                    int n;
+                    rec_cnt_for_cache_read = rec_in_block_for_cache_read;
+                    for( n = 0; n < rec_in_block; n++) 
+                    {
+                        if (!check_valid_bit_by_ltable_entry(ldi, rec_index+i+n))
+                        {
+                            rec_index_for_cache_read = rec_index +i+n; 
+                            if(rec_index+i+n + rec_in_block_for_cache_read > ldi->total_records)
+                            {
+                                rec_cnt_for_cache_read = ldi->total_records - (rec_index+i+n )+1;
+                            }                            
+                            is_valid_bit = KAL_FALSE;
+                            break;
+                        }
+                    }
+                    if(!is_valid_bit)
+                    {
+                         DataPtr_temp = (kal_uint8*) get_ctrl_buffer(rec_cnt_for_cache_read * section_size);
+                         nvram_param->Offset +=  ((rec_index_for_cache_read- rec_index- i) * (section_size));
+                         nvram_param->DataPtr = DataPtr_temp;
+                         nvram_param->Length = rec_cnt_for_cache_read * section_size;
+                         NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+                         result = FS_CMPT_Read(filename,nvram_param);
+                         NVRAM_FS_END(FS_OP_CMPTREAD,result);
+                         if (nvram_param->opid_map != nvram_param->ret[0])
+                         {
+                            free_ctrl_buffer(DataPtr_temp);
+                            DataPtr_temp = NULL;
+                            nvram_fat_last_err = nvram_param->ret[1];
+                            nvram_fat_last_line =  __LINE__;
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_CMPT_Read fail at %d\r\n",__FUNCTION__,__LINE__);
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]nvram_param->opid_map(%d) != nvram_param->ret[0](%d)\r\n",nvram_param->opid_map,nvram_param->ret[0]);
+                            goto final;
+                         }                        
+                         if (len != nvram_param->Length)
+                         {
+                            free_ctrl_buffer(DataPtr_temp);
+                            DataPtr_temp = NULL;
+                            result = FS_INVALID_FILE_POS;  // End of File
+                            nvram_fat_last_line = __LINE__;
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_CMPT_Read fail at %d\r\n",__FUNCTION__,__LINE__);
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]len(%d) != %d\r\n",len, nvram_param->Length);
+                            goto final;
+                          }
+                         update_cache_data(ldi, rec_index_for_cache_read, rec_cnt_for_cache_read, nvram_param, is_only_chksum);
+                         mask_valid_bit_by_ltable_entry(ldi, rec_index_for_cache_read, rec_cnt_for_cache_read);
+                         free_ctrl_buffer(DataPtr_temp);
+                         DataPtr_temp = NULL;
+                    }
+                    nvram_param->Offset = nvram_param_offset_temp;
+                    nvram_param->DataPtr = (working_buffer + working_buffer_sub_index);
+                    nvram_param->Length = cache_read_length;
+                    len = total_read;
+                    nvram_read_data_from_cache(ldi, nvram_param);
+                }
+                else
+                #endif
+                {
+                    NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+                    result = FS_CMPT_Read(filename, nvram_param);
+                    NVRAM_FS_END(FS_OP_CMPTREAD,result);
+                    if (nvram_param->opid_map != nvram_param->ret[0])
+                    {
+                        nvram_fat_last_err = nvram_param->ret[1];
+                        nvram_fat_last_line =  __LINE__;
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_CMPT_Read fail at %d\r\n",__FUNCTION__,__LINE__);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]nvram_param->opid_map(%d) != nvram_param->ret[0](%d)\r\n",nvram_param->opid_map,nvram_param->ret[0]);
+                        goto final;
+                    }   
+            
+                    if (len == 0)
+                    {
+                        result = FS_INVALID_FILE_POS;  // End of File
+                        nvram_fat_last_line = __LINE__;
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_CMPT_Read fail at %d,len=0\r\n",__FUNCTION__,__LINE__);
+                        goto final;
+                    }
+                }                 
+                total_read -= len;
+                working_buffer_sub_index += len;
+                
+            }while(total_read > 0);
+
+        #ifdef __NVRAM_CRYPT_TEST__
+            if (bReadMsp == 1)
+            {
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_R, working_buffer, NVRAM_MSP_TEST_LEN);
+            }
+        #endif
+
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+
+            if (ldi->attr & NVRAM_ATTR_MSP)
+            {
+                for (j = 0; j < rec_in_block; j++)
+                {
+                    /* work arround solution for hw.. sej is not stable */
+                #ifdef __CCCIFS_SUPPORT__
+                    kal_uint8 *working_buffer2 = (kal_uint8*) get_ctrl_buffer(section_size);
+                    kal_uint8 *working_buffer3 = (kal_uint8*) get_ctrl_buffer(section_size);
+
+                    //copy the encrypted data from working_buffer to working_buffer2
+                    memcpy(working_buffer2, working_buffer + section_size * j, section_size);
+
+                    do
+                    {
+                        nvram_trace_to_file(__LINE__, 999, 1, 0, 0 ,0);
+                        nvram_trace_to_file(nvram_ptr->secret_key[0], nvram_ptr->secret_key[1], nvram_ptr->secret_key[2], nvram_ptr->secret_key[3], 0, 0);
+                        nvram_trace_to_file(working_buffer[j*section_size], working_buffer[j*section_size + 1], working_buffer[j*section_size + 2], working_buffer[j*section_size + 3], 0, 0);
+                        //decrypt the working_buffer
+                        SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32) (working_buffer + section_size * j), section_size, nvram_ptr->secret_key, working_buffer + section_size * j);
+                        nvram_trace_to_file(working_buffer[j*section_size], working_buffer[j*section_size + 1], working_buffer[j*section_size + 2], working_buffer[j*section_size + 3], 0, 0);
+
+                        //copy decrypted data from working_buffer to working_buffer3
+                        memcpy(working_buffer3, working_buffer + section_size * j, section_size);
+                        //encrypt the working_buffer3
+                        SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer3, section_size, nvram_ptr->secret_key, working_buffer3);
+
+                        //compare the working_buffer2 & working_buffer3
+                        if (memcmp(working_buffer2, working_buffer3, section_size) == 0)
+                        {
+                            //decrypt PASS
+                            break;
+                        }
+                        else
+                        {
+                            //decrypt FAIL, try again
+                            memcpy(working_buffer + section_size * j, working_buffer2, section_size);
+                        }
+                    }while(1);
+
+                    free_ctrl_buffer(working_buffer2);
+                    free_ctrl_buffer(working_buffer3);
+                    working_buffer2 = NULL;
+                    working_buffer3 = NULL;
+                #else
+                    SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32) (working_buffer + section_size * j), section_size, nvram_ptr->secret_key, working_buffer + section_size * j);
+                #endif
+                }
+            }
+        #endif
+
+        #ifdef __NVRAM_CRYPT_TEST__
+            if (bReadMsp == 1)
+            {
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_R[NVRAM_MSP_TEST_LEN],working_buffer,NVRAM_MSP_TEST_LEN);
+            }
+        #endif
+
+            /* Handle multi-record reading */
+            for (j = 0; j < rec_in_block; j++)
+            {
+             if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+             {
+                   // custom_nvram_decrypt(nvram_ptr->secret_key, working_buffer + section_size * j, rec_size, rec_size);
+                   nvram_AES_decrypt(working_buffer + section_size * j, section_size);
+             }
+            //get checksum from the working buffer
+            chksum2  = (kal_uint8*) (working_buffer + section_size * j + rec_size);
+
+            //calculate the checksum from the content
+            /* checksum from content */
+            kal_mem_set(chksum1, 0, nvram_chksum_size);
+            nvram_util_caculate_checksum(ldi, working_buffer + (section_size * j), rec_size, chksum1);
+
+            if (kal_mem_cmp(chksum1, chksum2, nvram_chksum_size)!=0)
+            {
+                nvram_ptr->sw_status &= NVRAM_SW_SOME_CORRUPT;
+                if(nvram_ee_info != NULL){
+                    nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+                }
+                #ifdef __NVRAM_LID_CACHE__
+                if (NVRAM_RD_WITH_CACHE(ldi->LID))
+                {
+                    unmask_valid_bit_by_ltable_entry(ldi, 0, (ldi->total_records + 1));
+                }
+                #endif
+                nvram_fat_last_line = __LINE__;
+                result = NVRAM_DRV_CHECKSUM_ERROR;
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Checksum error at %d\r\n",__FUNCTION__,__LINE__);
+                goto final;
+            }            
+            //seems no need to calculate checksum3, and buffer for NVRAM_DRV_READ_TYPE_CHKSUM_2B is useless if we do not verify the checksum?
+            //if we want to compare the checksum between A & B, we need another buffer to use memcmp
+            /* checksum after decrypt */
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if(lid_chksum_info.algo_info.chksum_algo_type == NVRAM_MD5)
+            {
+                kal_mem_set(chksum1, 0, nvram_chksum_size);
+                chksum3 = nvram_util_caculate_checksum(ldi, working_buffer + (section_size * j), rec_size, chksum1);
+            }
+            #else
+            chksum3 = nvram_util_caculate_checksum(ldi, working_buffer + (section_size * j), rec_size, chksum1);
+            #endif
+            if (type == NVRAM_DRV_READ_TYPE_DATA)
+            {
+                 kal_mem_cpy(buffer + (rec_size * (i + j)), working_buffer + (section_size * j), rec_size);
+            }
+            else if  ((type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)||(type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B))
+            {
+                kal_mem_cpy(buffer + (NVRAM_CHKSUM_SIZE_2B * (i + j)), &chksum3, NVRAM_CHKSUM_SIZE_2B);
+            }
+            else if ((type == NVRAM_DRV_READ_TYPE_CHKSUM)||(type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY))
+            {
+                kal_mem_cpy(buffer + (nvram_chksum_size * (i + j)), chksum2, nvram_chksum_size);
+            }
+        }
+        #ifdef __NVRAM_CRYPT_TEST__
+            if (bReadMsp == 1)
+            {
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_R[NVRAM_MSP_TEST_LEN*2],working_buffer,NVRAM_MSP_TEST_LEN);
+                nvram_create_report_msp_file(KAL_FALSE);
+            }
+        #endif
+            
+            i += rec_in_block;
+        }
+
+    }
+final:
+
+    if(chksum1)
+    {
+        free_ctrl_buffer(chksum1);            
+        chksum1 = NULL;
+    }
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+        working_buffer = NULL;
+    }
+    
+END:
+    if (FS_NO_ERROR > result)
+    {
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d status %d\r\n",__FUNCTION__,nvram_fat_last_line,nvram_fat_last_err);
+    }
+
+    return result;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_read_aux
+ * DESCRIPTION
+ *  read record(s) from FAT.
+ * PARAMETERS
+ *  hFile               [IN]         file handle
+ *  rec_index           [IN]         which record to read (start)
+ *  rec_amount          [IN]         how many record to read at once
+ *  rec_size            [IN]         size of record
+ *  buffer              [IN/OUT]     buffer of check sum
+ *  type                [IN]         read content or checksum
+ *  ismsp               [IN]         to indicate that the records protected by hw
+ * RETURNS
+ *  = 0: success
+ *  > 0: NVRAM error code
+ *  < 0: FS error code
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_read_section(
+            FS_HANDLE hFile,
+            kal_uint16 rec_index,
+            kal_uint16 rec_amount,
+            kal_uint32 rec_size,
+            kal_uint8 *buffer,
+            nvram_drv_read_type_enum type,
+            nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint16 chksum3 = 0;
+    kal_uint8 *chksum1 = NULL;
+    kal_uint8 *chksum2 = NULL;
+    kal_uint32 len = 0, remainLen = 0;
+    kal_uint32 section_size;
+    kal_uint32 working_buffer_size;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_DRV_OK;
+    kal_uint32 i,j;
+    kal_bool skip_verify = KAL_FALSE;
+    nvram_ldi_ota_header *ota_header;
+    kal_uint32 seek_offset = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* read RAW data directly */
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        NVRAM_FS_START(FS_OP_READ);
+        result = FS_Read(hFile, buffer, rec_size, &len);
+        NVRAM_FS_END(FS_OP_READ,result);
+        if (FS_NO_ERROR > result)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Read error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+            nvram_fat_last_line = __LINE__;
+        }
+        goto ERROR;
+    }
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#endif
+
+    section_size = rec_size + nvram_chksum_size + remainLen;
+
+
+    /* seek to the record start */
+    NVRAM_FS_START(FS_OP_SEEK);
+    result = FS_Seek(hFile, (rec_index - 1) * section_size, FS_FILE_CURRENT);
+    NVRAM_FS_END(FS_OP_SEEK,result);
+    if (FS_NO_ERROR > result)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Seek error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        nvram_fat_last_line = __LINE__;
+        goto ERROR;
+    }
+
+    //working_buffer_size = MAX_NVRAM_RECORD_SIZE;        
+    //MAX_NVRAM_RECORD_SIZE = (NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * NVRAM_RECORD_SECTOR_SIZE)
+    //                                                    = (16 or 4) * 512
+    working_buffer_size = section_size * rec_amount;
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+    // judge read checksum only
+    if ((type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY) || (type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B)) {
+        //Do not support read checksum only from encrypted
+        if(ldi->attr & (NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_MSP) || 
+           (rec_amount * nvram_chksum_size) > MAX_NVRAM_RECORD_SIZE ) {
+            type = (type==NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B)?NVRAM_DRV_READ_TYPE_CHKSUM_2B: NVRAM_DRV_READ_TYPE_CHKSUM;
+        }
+        else {
+            skip_verify = KAL_TRUE;
+            working_buffer_size = (rec_amount * nvram_chksum_size);
+        }
+    }    
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    if(skip_verify)
+    {
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+            //get appendix header
+            if(ldi->append_offset == 0) {
+                NVRAM_FS_START(FS_OP_SEEK);
+                seek_offset = FS_Seek(hFile, 0, FS_FILE_CURRENT); //backup FS offset
+                NVRAM_FS_END(FS_OP_SEEK,seek_offset);
+                ota_header = (nvram_ldi_ota_header *)get_ctrl_buffer(NVRAM_LDI_OTA_HEADER_SIZE);
+                if(KAL_TRUE == nvram_read_ota_header(hFile, ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+                   (ota_header->ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+                {
+                    ldi->append_offset =  nvram_appendix_header_offset(ldi);
+                }
+                else {
+                    ldi->append_offset = -1;
+                }
+                free_ctrl_buffer(ota_header);
+                ota_header = NULL;
+            }
+            if(ldi->append_offset > 0) {
+                if(!seek_offset) {
+                    //backup FS offset
+                    NVRAM_FS_START(FS_OP_SEEK);
+                    seek_offset = FS_Seek(hFile, 0, FS_FILE_CURRENT);
+                    NVRAM_FS_END(FS_OP_SEEK,seek_offset);
+                }
+                NVRAM_FS_START(FS_OP_SEEK);
+                result = FS_Seek(hFile, (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size)), FS_FILE_BEGIN);
+                NVRAM_FS_END(FS_OP_SEEK,result);
+                if(FS_NO_ERROR > result)
+                {
+                    //goto normal read flow when read appendix fail
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    goto NO_CHKSUM_INTEGRATE;            
+                }
+                NVRAM_FS_START(FS_OP_READ);
+                result = FS_Read(hFile, working_buffer, (rec_amount * nvram_chksum_size), &len);
+                NVRAM_FS_END(FS_OP_READ,result);
+                if (FS_NO_ERROR > result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Read error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    goto NO_CHKSUM_INTEGRATE;            
+                }
+            }
+            else {
+                goto NO_CHKSUM_INTEGRATE;            
+            }
+        }
+        else {
+            NO_CHKSUM_INTEGRATE:
+            if(seek_offset) {
+                //Restore FS ptr
+                NVRAM_FS_START(FS_OP_SEEK);
+                result = FS_Seek(hFile, seek_offset, FS_FILE_BEGIN);
+                NVRAM_FS_END(FS_OP_SEEK,result);
+            }
+            for (j = 0; j < rec_amount; j++)
+            {
+                /* seek to the record checksum */
+                NVRAM_FS_START(FS_OP_SEEK);
+                result = FS_Seek(hFile, rec_size, FS_FILE_CURRENT);
+                NVRAM_FS_END(FS_OP_SEEK,result);
+                if(FS_NO_ERROR > result)
+                {
+                    nvram_fat_last_line = __LINE__;
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    goto ERROR;
+                }
+
+                NVRAM_FS_START(FS_OP_READ);
+                result = FS_Read(hFile, (working_buffer + (j* nvram_chksum_size)), nvram_chksum_size, &len);
+                NVRAM_FS_END(FS_OP_READ,result);
+                if (FS_NO_ERROR > result)
+                {
+                    nvram_fat_last_line = __LINE__;
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Read error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    goto final;
+                }
+            }
+        }
+        //Caculate checksum
+        if(type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B) {
+            for (j = 0; j < rec_amount; j++) {
+                chksum3 = nvram_util_md5_checksum_convert((working_buffer + (j* nvram_chksum_size)), NULL, KAL_TRUE);
+                kal_mem_cpy(buffer + (NVRAM_CHKSUM_SIZE_2B* j), &chksum3, NVRAM_CHKSUM_SIZE_2B);
+            }
+        }
+        else {
+            kal_mem_cpy(buffer, working_buffer, (rec_amount * nvram_chksum_size));
+        }
+        
+    }
+    else
+    {
+        kal_int32 rec_in_block = working_buffer_size / section_size;
+
+        chksum1 = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+        for (i = 0 ; i < rec_amount; )
+        {
+            kal_uint32 total_read = section_size * rec_in_block;
+            kal_uint32 working_buffer_sub_index = 0;
+
+            /* last read */
+            if (rec_in_block > rec_amount - i)
+            {
+                rec_in_block = rec_amount - i;
+            }
+            
+            #define NVRAM_MAX_READ_LEN (3*1024)
+            
+            do 
+            {
+                kal_uint32 this_read = total_read;
+                
+                if (total_read >= NVRAM_MAX_READ_LEN)
+                {
+                    this_read = NVRAM_MAX_READ_LEN;
+                }
+                NVRAM_FS_START(FS_OP_READ);
+                result = FS_Read(hFile, working_buffer + working_buffer_sub_index, this_read, &len);
+                NVRAM_FS_END(FS_OP_READ,result);
+                if (FS_NO_ERROR > result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Read error at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+                
+                if (len==0)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Read error at %d,len=0\r\n",__FUNCTION__,__LINE__);
+                    result = FS_INVALID_FILE_POS;  // End of File
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+
+                total_read -= len;
+                working_buffer_sub_index += len;
+                
+            }while(total_read > 0);
+
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+
+            if (ldi->attr & NVRAM_ATTR_MSP)
+            {
+                for (j = 0; j < rec_in_block; j++)
+                {
+                    /* work arround solution for hw.. sej is not stable */
+                #ifdef __CCCIFS_SUPPORT__
+                    kal_uint8 *working_buffer2 = (kal_uint8*) get_ctrl_buffer(section_size);
+                    kal_uint8 *working_buffer3 = (kal_uint8*) get_ctrl_buffer(section_size);
+
+                    //copy the encrypted data from working_buffer to working_buffer2
+                    memcpy(working_buffer2, working_buffer + section_size * j, section_size);
+
+                    do
+                    {
+                        nvram_trace_to_file(__LINE__, 999, 1, 0, 0 ,0);
+                        nvram_trace_to_file(nvram_ptr->secret_key[0], nvram_ptr->secret_key[1], nvram_ptr->secret_key[2], nvram_ptr->secret_key[3], 0, 0);
+                        nvram_trace_to_file(working_buffer[j*section_size], working_buffer[j*section_size + 1], working_buffer[j*section_size + 2], working_buffer[j*section_size + 3], 0, 0);
+                        //decrypt the working_buffer
+                        SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32) (working_buffer + section_size * j), section_size, nvram_ptr->secret_key, working_buffer + section_size * j);
+                        nvram_trace_to_file(working_buffer[j*section_size], working_buffer[j*section_size + 1], working_buffer[j*section_size + 2], working_buffer[j*section_size + 3], 0, 0);
+
+                        //copy decrypted data from working_buffer to working_buffer3
+                        memcpy(working_buffer3, working_buffer + section_size * j, section_size);
+                        //encrypt the working_buffer3
+                        SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer3, section_size, nvram_ptr->secret_key, working_buffer3);
+
+                        //compare the working_buffer2 & working_buffer3
+                        if (memcmp(working_buffer2, working_buffer3, section_size) == 0)
+                        {
+                            //decrypt PASS
+                            break;
+                        }
+                        else
+                        {
+                            //decrypt FAIL, try again
+                            memcpy(working_buffer + section_size * j, working_buffer2, section_size);
+                        }
+                    }while(1);
+
+                    free_ctrl_buffer(working_buffer2);
+                    free_ctrl_buffer(working_buffer3);
+                    working_buffer2 = NULL;
+                    working_buffer3 = NULL;
+                #else
+                    SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32) (working_buffer + section_size * j), section_size, nvram_ptr->secret_key, working_buffer + section_size * j);
+                #endif
+                }
+            }
+        #endif
+
+
+            /* Handle multi-record reading */
+            for (j = 0; j < rec_in_block; j++)
+            {
+
+                if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+                {
+                   // custom_nvram_decrypt(nvram_ptr->secret_key, working_buffer + section_size * j, rec_size, rec_size);
+                   nvram_AES_decrypt(working_buffer + section_size * j, section_size);
+                }
+                //verify checksum one at once
+
+                //get checksum from the working buffer
+                chksum2  = (kal_uint8*) (working_buffer + section_size * j + rec_size);
+
+                //calculate the checksum from the content
+                /* checksum from content */
+                kal_mem_set(chksum1, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, working_buffer + (section_size * j), rec_size,chksum1);
+
+                if (kal_mem_cmp(chksum1, chksum2, nvram_chksum_size)!=0)
+                {
+                    nvram_ptr->sw_status &= NVRAM_SW_SOME_CORRUPT;
+                    if(nvram_ee_info != NULL){
+                        nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+                    }
+                    nvram_fat_last_line = __LINE__;
+                    result = NVRAM_DRV_CHECKSUM_ERROR;
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Checksum error at %d\r\n",__FUNCTION__,__LINE__);
+                    goto final;
+                }
+            
+
+                //seems no need to calculate checksum3, and buffer for NVRAM_DRV_READ_TYPE_CHKSUM_2B is useless if we do not verify the checksum?
+                //if we want to compare the checksum between A & B, we need another buffer to use memcmp
+                /* checksum after decrypt */
+                #ifdef __NV_CHKSUM_ENHANCE__
+                if(lid_chksum_info.algo_info.chksum_algo_type== NVRAM_MD5)
+                {
+                    kal_mem_set(chksum1, 0, nvram_chksum_size);
+                    chksum3 = nvram_util_caculate_checksum(ldi, working_buffer + (section_size * j), rec_size,chksum1);
+                }
+                #else
+                chksum3 = nvram_util_caculate_checksum(ldi, working_buffer + (section_size * j), rec_size,chksum1);
+                #endif
+                if (type == NVRAM_DRV_READ_TYPE_DATA)
+                {
+                    kal_mem_cpy(buffer + (rec_size * (i + j)), working_buffer + (section_size * j), rec_size);
+                }
+                else if((type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)||(type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B))
+                {
+                    kal_mem_cpy(buffer + (NVRAM_CHKSUM_SIZE_2B * (i + j)), &chksum3, NVRAM_CHKSUM_SIZE_2B);
+                }
+                else if ((type == NVRAM_DRV_READ_TYPE_CHKSUM)||(type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY))
+                {
+                    kal_mem_cpy(buffer + (nvram_chksum_size * (i + j)), chksum1, nvram_chksum_size);
+                }
+            }
+            i += rec_in_block;
+        }
+
+    }
+
+final:
+
+    if(chksum1)
+    {
+        free_ctrl_buffer(chksum1);            
+        chksum1 = NULL;
+    }
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+        working_buffer = NULL;
+    }
+
+ERROR:
+    if (FS_NO_ERROR > result)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+    }
+
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_read_aux
+ * DESCRIPTION
+ *  read record(s) from FAT.
+ * PARAMETERS
+ *  filename            [IN]         full path of the data item
+ *  rec_index           [IN]         which record to read (start)
+ *  rec_amount          [IN]         how many record to read at once
+ *  rec_size            [IN]         size of record
+ *  buffer              [IN/OUT]     buffer of check sum
+ *  type                [IN]         read content or checksum
+ *  ismsp               [IN]         to indicate that the records protected by hw
+ * RETURNS
+ *  = 0: success
+ *  > 0: NVRAM error code
+ *  < 0: FS error code
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_read(
+            kal_char *nvramname,
+            nvram_folder_enum nvram_folder,      /* folder index */
+            kal_uint32 file_offset,
+            kal_uint16 rec_index,
+            kal_uint16 rec_amount,
+            kal_uint32 rec_size,
+            kal_uint8 *buffer,
+            nvram_drv_read_type_enum type,
+            nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_int32 result = 0;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+#if (defined(__NVRAM_FS_OPERATION_COMPACT__) && defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_FS_CMPT_SIMULATION__)
+    NVRAM_FS_PARAM_CMPT_T nvram_param = {0};
+#else
+    kal_int32 ret = 0;
+#endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_READ_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start); //start timer
+    #endif
+    
+    do
+    {
+        if (rec_index < 1)
+        {
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_INVALID_RECORD_ID;
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error] invalid record index(%d) \r\n",rec_index);
+            break;
+        }
+
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+
+#if !defined(__NVRAM_FS_OPERATION_COMPACT__) || defined(__NVRAM_PSEUDO_MERGE__) || !((defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_FS_CMPT_SIMULATION__))
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+        if (hFile == FS_FILE_NOT_FOUND)
+        {
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_EMPTY_RECORD;
+            break;
+        }
+        else if (hFile <= FS_NO_ERROR)
+        {
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_FATAL_ERROR;
+            break;
+        }
+
+        /* check if a empty record */
+        NVRAM_FS_START(FS_OP_GETFILESIZE);
+        result = FS_GetFileSize(hFile, &len);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+        if ((result == FS_NO_ERROR) && (len == 0))
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_EMPTY_RECORD;
+            break;
+        }
+
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, file_offset, FS_FILE_BEGIN);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if (FS_NO_ERROR > result)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+            nvram_fat_last_line = __LINE__;
+            break;
+        }
+
+        result = nvram_drv_fat_read_section(hFile, rec_index, rec_amount, rec_size, buffer, type, ldi);
+        if (hFile > FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+        }
+#else
+        nvram_param.opid_map = 0;
+        nvram_param.ret[0] = 0;
+        nvram_param.ret[1] = 0;
+        
+        nvram_param.Flag = (FS_READ_ONLY | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+        nvram_param.opid_map |= NVRAM_FS_CMPT_OPEN;
+        nvram_param.opid_map |= NVRAM_FS_CMPT_GETFILESIZE;
+        nvram_param.FileSize = &len;
+        nvram_param.Offset = file_offset;
+        result = nvram_drv_fat_read_section_cmpt(hFile, rec_index, rec_amount, rec_size, buffer, type, ldi,(kal_wchar*)filename, &nvram_param);
+#endif
+    }while(0);
+    
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+    
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+#if !defined(__NVRAM_FS_OPERATION_COMPACT__) || defined(__NVRAM_PSEUDO_MERGE__) || !((defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_FS_CMPT_SIMULATION__))
+    if (result < FS_NO_ERROR)
+    {
+        nvram_fat_last_err = result;
+        nvram_fat_last_line =  __LINE__;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d\r\n",__FUNCTION__,__LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]result = %d ,last_err=%d,last_line=%d\r\n",result,nvram_fat_last_err,nvram_fat_last_line);
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+    }
+#else   
+    if (nvram_param.opid_map != nvram_param.ret[0])
+    {
+        nvram_fat_last_err = nvram_param.ret[1] || result;
+        nvram_fat_last_line =  __LINE__;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d\r\n",__FUNCTION__,__LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]result = %d last_err=%d,last_line=%d\r\n",result,nvram_fat_last_err,nvram_fat_last_line);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]nvram_param.opid_map(%d) != nvram_param.ret[0](%d)\r\n",nvram_param.opid_map,nvram_param.ret[0]);
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+
+    }
+#endif
+    
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_exception_item
+ * DESCRIPTION
+ *  read exception record from FAT.
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  readsize            [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_read_exception_item(kal_uint8 *buffer,
+                                                        kal_char *nvramname,
+                                                        kal_uint16 section_number,
+                                                        kal_uint32 size,
+                                                        kal_uint32 readsize)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_int32 Ret;
+    kal_uint32 nvram_chksum_size = 0;
+    kal_char cfilename[NVRAM_FILE_LEN + 1] = {0};
+    kal_wchar wcfilename[NVRAM_FILE_LEN + 1] = {0};    
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (section_number < 1)
+    {
+        /* kal_print("Nvram write: section_number < 1 !"); */
+        return NVRAM_DRV_INVALID_RECORD_ID;
+    }
+
+    /* translate record id to filename */
+    nvram_query_file_name(NVRAM_NVD_DATA, nvramname, filename);
+
+    nvram_query_file_name_by_path((kal_wchar *)filename, wcfilename);
+    kal_dchar2char((WCHAR *)wcfilename, cfilename);
+    nvram_util_get_data_item_by_fileprefix(&ldi, cfilename);
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    /* open NV_RCD.(RCD#) file */
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_NO_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open %s fail \r\n",__FUNCTION__,nvramname);
+        return NVRAM_DRV_EMPTY_RECORD;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        /* kal_print("Nvram read: FS_Open return error!"); */
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open %s fail \r\n",__FUNCTION__,nvramname);
+        return NVRAM_DRV_FATAL_ERROR;
+    }
+
+    /* check if a empty record */
+    NVRAM_FS_START(FS_OP_GETFILESIZE);
+    Ret = FS_GetFileSize(hFile, &len);
+    NVRAM_FS_END(FS_OP_GETFILESIZE,Ret);
+    if ((Ret == FS_NO_ERROR) && (len == 0))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_GetFileSize fail,result=%d \r\n",__FUNCTION__,Ret);
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return NVRAM_DRV_EMPTY_RECORD;
+    }
+
+    /* seek to the record start */
+    NVRAM_FS_START(FS_OP_SEEK);
+    Ret = FS_Seek(hFile, (NVRAM_LDI_HEADER_SIZE + ((section_number - 1) * (size + nvram_chksum_size))), FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,Ret);
+    if (Ret >= FS_NO_ERROR)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail,result=%d \r\n",__FUNCTION__,Ret);
+        NVRAM_FS_START(FS_OP_READ);
+        Ret = FS_Read(hFile, buffer, (kal_uint32) readsize, &len);
+        NVRAM_FS_END(FS_OP_READ,Ret);
+    }
+
+    if (Ret != FS_NO_ERROR)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Read fail,result=%d \r\n",__FUNCTION__,Ret);
+        /* kal_print("Nvram read: Read error!"); */
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return NVRAM_DRV_CHECKSUM_ERROR;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    Ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,Ret);
+    return NVRAM_DRV_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_prepare_data
+ * DESCRIPTION
+ *  copy data into buffer
+ * PARAMETERS
+ *  source:             [IN]    source data
+ *  offset:             [IN]    offset in data
+ *  buffer:             [OUT]   buffer
+ *  buffer_size:        [IN]    size of buffer
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_drv_fat_prepare_data(kal_uint8 *buffer, const kal_uint8 *source, kal_uint32 offset, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (source == NVRAM_EF_ZERO_DEFAULT)
+    {
+        nvram_memset(buffer, 0x00, buffer_size);
+    }
+    else if (source == NVRAM_EF_FF_DEFAULT)
+    {
+        nvram_memset(buffer, 0xFF, buffer_size);
+    }
+    else
+    {
+        kal_mem_cpy(buffer, source+offset, buffer_size);
+    }
+}
+
+#ifdef __NVRAM_WRITE_WITH_FILE_SIZE__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_multiple
+ * DESCRIPTION
+ *  write record(s) to FAT.
+ * PARAMETERS
+ *  hFile               [?]
+ *  buffer              [?]
+ *  rec_amount          [IN]
+ *  rec_size            [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_write_multiple(
+    FS_HANDLE hFile,
+    const kal_uint8 *buffer,
+    kal_uint16 rec_index,
+    kal_uint16 rec_amount,
+    kal_uint32 rec_size,
+    nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 len = 0, remainLen = 0;
+    kal_uint8 *chksum = NULL;
+    kal_uint32 max_rec_amount;
+    kal_uint32 section_size;
+    kal_uint32 working_buffer_size;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_DRV_OK;
+    kal_uint32 i;
+    kal_uint32 rec_in_block;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    #ifdef __NVRAM_LID_CACHE__
+    kal_uint32 cache_offset = 0;
+    kal_uint32 temp_cache_offset = 0;
+    kal_uint16 temp_rec_index = rec_index;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[NVUT_UTIL_CAL]%s():%d NVRAM chksize %d \n\r", __FUNCTION__, __LINE__,nvram_chksum_size);
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+#endif
+
+    //16bytes alignment, limitation: msp data will be oversize 
+    section_size = rec_size + nvram_chksum_size + remainLen;
+    working_buffer_size = section_size * rec_amount;
+
+    if (rec_index > 1)
+    {
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, (rec_index - 1) * section_size, FS_FILE_CURRENT);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if (FS_NO_ERROR > result)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail,result=%d\r\n",__FUNCTION__,result);
+            nvram_fat_last_line = __LINE__;
+            goto final;
+        }
+    }
+
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    max_rec_amount = working_buffer_size/section_size;
+    chksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+    
+    #ifdef __NVRAM_LID_CACHE__
+        cache_offset = 0;
+        if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+        {
+            if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset)))
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->get_lid_record_cache_offset fail,result=%d\r\n",__FUNCTION__,result);
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+        }
+        temp_cache_offset = cache_offset;
+    #endif
+        
+    if (!(ldi->attr & NVRAM_ATTR_MSP) && !(ldi->attr & NVRAM_ATTR_CONFIDENTIAL) &&
+        buffer != NVRAM_EF_ZERO_DEFAULT && buffer != NVRAM_EF_FF_DEFAULT)
+    {
+        for(i = 0; i < rec_amount; i++)
+        {
+            if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+            {
+                //rec_index start from 1
+                kal_mem_set(chksum, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, buffer + (i+rec_index-1)*rec_size, rec_size,chksum);
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size), buffer + (i+rec_index-1)*rec_size, rec_size);                
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size)+rec_size, chksum, nvram_chksum_size);
+            }
+            else
+            {
+                if (i==0)
+                {
+                    kal_mem_set(chksum, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, buffer, rec_size,chksum);
+                }
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size), buffer, rec_size);             
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size)+rec_size, chksum, nvram_chksum_size);
+            }
+
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+
+            if (i == (rec_amount - 1))
+            {
+                NVRAM_FS_START(FS_OP_WRITE);
+                result = FS_Write(hFile, working_buffer, section_size * rec_amount, &len);
+                NVRAM_FS_END(FS_OP_WRITE,result);
+                if (FS_NO_ERROR > result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail,result=%d\r\n",__FUNCTION__,result);
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+                #ifdef __NVRAM_LID_CACHE__
+                if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                {
+                    nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_amount, cache_offset);
+                    mask_valid_bit_by_ltable_entry(ldi, rec_index, rec_amount);
+                }
+                #endif
+            }
+        }
+        goto final;
+    }
+
+    rec_in_block = 0;
+    max_rec_amount = working_buffer_size / section_size;
+    
+    for (i = 0; i < rec_amount; i ++)
+    {
+        nvram_drv_fat_prepare_data(working_buffer + rec_in_block * section_size, buffer, (i+rec_index-1) * rec_size, rec_size);
+        kal_mem_set(chksum, 0, nvram_chksum_size);
+        nvram_util_caculate_checksum(ldi, working_buffer + rec_in_block * section_size, rec_size, chksum);
+
+        kal_mem_cpy(working_buffer + rec_in_block * section_size + rec_size, chksum, nvram_chksum_size);
+
+        //record integrated checksum
+        if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+            kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+        }
+
+        if (remainLen)
+        {
+            kal_mem_set(working_buffer + rec_in_block * section_size + rec_size + nvram_chksum_size , 0x00, remainLen);
+        }
+        if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+        {
+            //custom_nvram_encrypt(nvram_ptr->secret_key, working_buffer + rec_in_block * section_size, rec_size, rec_size);
+        nvram_AES_encrypt(working_buffer + rec_in_block * section_size, section_size);
+        }
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        if (ldi->attr & NVRAM_ATTR_MSP)
+        {
+        /* this solution is only for work arround */
+        #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+            kal_uint8 *working_buffer2 = (kal_uint8*) get_ctrl_buffer(section_size);
+            kal_uint8 *working_buffer3 = (kal_uint8*) get_ctrl_buffer(section_size);
+
+            //copy the original data from working_buffer to working_buffer2
+            memcpy(working_buffer2, working_buffer + rec_in_block * section_size, section_size);
+
+            do
+            {
+                nvram_trace_to_file(__LINE__, 999, 0, 0, 0, 0);
+                nvram_trace_to_file(nvram_ptr->secret_key[0], nvram_ptr->secret_key[1], nvram_ptr->secret_key[2], nvram_ptr->secret_key[3], 0, 0);
+                nvram_trace_to_file(working_buffer[rec_in_block*section_size], working_buffer[rec_in_block*section_size + 1], working_buffer[rec_in_block*section_size + 2], working_buffer[rec_in_block*section_size + 3], 0, 0);
+
+                //encrypt working_buffer
+                SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+                nvram_trace_to_file(working_buffer[rec_in_block*section_size], working_buffer[rec_in_block*section_size + 1], working_buffer[rec_in_block*section_size + 2], working_buffer[rec_in_block*section_size + 3], 0, 0);
+
+                //copy the encrypted data from working_buffer to working_buffer3
+                memcpy(working_buffer3, working_buffer + rec_in_block * section_size, section_size);
+                //decrypt the working_buffer3
+                SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32)working_buffer3, section_size, nvram_ptr->secret_key, working_buffer3);
+
+                //compare the data between the working_buffer2 & working_buffer3
+                if (memcmp(working_buffer2, working_buffer3, section_size) == 0)
+                {
+                    //encrypt PASS
+                    break;
+                }
+                else
+                {
+                    //encrypt FAIL, try again, WTF
+                    memcpy(working_buffer + rec_in_block * section_size, working_buffer2, section_size);
+                }
+            }while(1);
+
+            free_ctrl_buffer(working_buffer2);
+            free_ctrl_buffer(working_buffer3);
+            working_buffer2 = NULL;
+            working_buffer3 = NULL;
+        #else
+            SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+
+        #endif
+        }
+    #endif
+
+        /* if this is not multi default, no need to prepare data anymore */
+        if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+        {
+            break;
+        }
+
+        rec_in_block ++;
+
+        if (rec_in_block == max_rec_amount || i == rec_amount - 1)
+        {
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, working_buffer, section_size * rec_in_block, &len);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (FS_NO_ERROR > result)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail,result=%d\r\n",__FUNCTION__,result);
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            #ifdef __NVRAM_LID_CACHE__
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_in_block, temp_cache_offset);
+                mask_valid_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+
+                temp_cache_offset += section_size * rec_in_block;
+                temp_rec_index += rec_in_block;
+            }
+            #endif
+
+            rec_in_block = 0;
+        }
+    }
+
+    /* special handling for not multi default */
+    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+    {
+        for (i = 0; i < rec_amount; i++)
+        {
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer)
+            {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)(working_buffer+rec_size), nvram_chksum_size);
+            }
+
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, working_buffer, section_size, &len);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (FS_NO_ERROR > result)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail,result=%d\r\n",__FUNCTION__,result);
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            #ifdef __NVRAM_LID_CACHE__
+            temp_cache_offset = cache_offset + section_size * i;
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                nvram_write_data_to_cache(ldi, working_buffer, section_size, temp_cache_offset);
+                mask_valid_bit_by_ltable_entry(ldi, rec_index+i, 1);
+            }
+            #endif
+        }
+    }
+
+final:
+
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+        working_buffer = NULL;
+    }
+
+    if (chksum)
+    {
+        free_ctrl_buffer(chksum);
+        chksum = NULL;
+    }
+
+    if (FS_NO_ERROR > result)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+        return result;
+    }
+    
+    return NVRAM_DRV_OK;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_section
+ * DESCRIPTION
+ *  write record(s) to FAT.
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  initialize          [IN]        true for reset, false for normal write.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_write_section(
+    FS_HANDLE hFile,
+    const kal_uint8 *buffer,
+    kal_uint16 rec_index,
+    kal_uint16 rec_amount,
+    kal_uint32 rec_size,
+    nvram_ltable_entry_struct *ldi,
+    kal_uint32 filesize)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 len = 0, remainLen = 0;
+    kal_uint8  *chksum = NULL;
+    kal_uint32 max_rec_amount;
+    kal_uint32 section_size;
+    kal_uint32 working_buffer_size;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_DRV_OK;
+    kal_bool encrypt_data = KAL_FALSE;
+    kal_uint32 i;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    #ifdef __NVRAM_LID_CACHE__
+    kal_uint32 cache_offset = 0;
+    kal_uint32 temp_cache_offset = 0;
+    kal_uint16 temp_rec_index = rec_index;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+        encrypt_data = KAL_TRUE;
+    }
+#else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+        encrypt_data = KAL_TRUE;
+    }
+#endif
+
+    section_size = rec_size + nvram_chksum_size + remainLen;
+    working_buffer_size = section_size * rec_amount;
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    chksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+    if (rec_index > 1 && rec_amount == 1)
+    {
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, (rec_index - 1) * section_size, FS_FILE_CURRENT);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if (FS_NO_ERROR > result)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+            nvram_fat_last_line = __LINE__;
+            goto final;
+        }
+    }
+
+    /* we can write data into FS directly, we don't need another buffer*/
+    if (!(ldi->attr & NVRAM_ATTR_MSP) && !(ldi->attr & NVRAM_ATTR_CONFIDENTIAL) &&
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+          !(ldi->attr & NVRAM_ATTR_COMMITTED) && 
+      #endif  
+        buffer != NVRAM_EF_ZERO_DEFAULT && buffer != NVRAM_EF_FF_DEFAULT)
+    {
+        #ifdef __NVRAM_LID_CACHE__
+        cache_offset = 0;
+        if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+        {            
+            if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset)))
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->get_lid_record_cache_offset fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+        }
+        #endif
+        for(i = 0;i < rec_amount;i++)
+        {
+            nvram_memset(working_buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, working_buffer_size);
+            if ((i == 0 || (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)) && 
+                !NVRAM_IS_ATTR_RAW_DATA(ldi->attr) )
+            {
+                kal_mem_set(chksum, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, buffer + i * rec_size, rec_size, chksum);
+            }
+
+            if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+            {
+                if (NVRAM_IS_ATTR_RAW_DATA(ldi->attr))
+                {
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Write(hFile, (void *)(buffer + i * rec_size), rec_size, &len);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                    if (FS_NO_ERROR > result)
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        nvram_fat_last_line = __LINE__;
+                        goto final;
+                    }
+                }
+                else
+                {
+                    kal_mem_cpy(working_buffer, (void *)(buffer + i * rec_size), rec_size);
+                }    
+            }
+            else
+            {
+                if (NVRAM_IS_ATTR_RAW_DATA(ldi->attr))
+                {
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Write(hFile, (void *)buffer, rec_size, &len);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                    if (FS_NO_ERROR > result)
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        nvram_fat_last_line = __LINE__;
+                        goto final;
+                    }
+                }
+                else
+                {
+                    kal_mem_cpy(working_buffer, (void *)buffer, rec_size);
+                }  
+            }
+            if (NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+                goto final;
+            }
+            //write data & checksum
+            kal_mem_cpy((void *)(working_buffer + rec_size), (void *)chksum, nvram_chksum_size);
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, working_buffer, section_size, &len);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (FS_NO_ERROR > result)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            #ifdef __NVRAM_LID_CACHE__
+            if(NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                nvram_write_data_to_cache(ldi, working_buffer, section_size, (cache_offset + i * section_size));
+                mask_valid_bit_by_ltable_entry(ldi, rec_index + i, 1);
+            }
+            #endif
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+        }
+        goto final;
+    }
+
+    //working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    //MAX_NVRAM_RECORD_SIZE = (NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * NVRAM_RECORD_SECTOR_SIZE)
+    //                                                    = (16 or 4) * 512
+
+#ifdef __NVRAM_LARGE_RECORD_SIZE__
+    /* size too large , we need to operate block by block */
+    if (section_size > working_buffer_size)
+    {
+        /* we need to prepare extra working buffer;
+           and due to msp need 16-bytes alignment, therefore
+           we set the working buffer to 16-bytes alignment also */
+        kal_uint8 *tmpchksum = NULL;
+
+        kal_int32 j,cs_idx;
+
+        working_buffer_size = NVRAM_MSP_ALIGNMENT_FLOOR(working_buffer_size) - NVRAM_MSP_ALIGNMENT;
+        tmpchksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+        #ifdef __NVRAM_LID_CACHE__
+        cache_offset = 0;
+        temp_cache_offset = 0;
+        if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+        {
+            if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset)))
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->get_lid_record_cache_offset fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                nvram_fat_last_line = __LINE__;
+                if (tmpchksum)
+                {
+                    free_ctrl_buffer(tmpchksum);
+                    tmpchksum = NULL;
+                }
+                goto final;
+            }
+        }
+        #endif
+
+        for (i = 0 ; i < rec_amount; i++)
+        {
+            #ifdef __NVRAM_LID_CACHE__
+            temp_cache_offset = cache_offset + i*section_size;
+            #endif
+            for (j = 0; j < rec_size; j += working_buffer_size)
+            {
+                kal_int32 byte_in_block = rec_size - j;
+                kal_bool last_block = KAL_FALSE;
+
+                if (byte_in_block > working_buffer_size)
+                {
+                    byte_in_block = working_buffer_size;
+                    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+                    {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, j, byte_in_block);
+                    }
+                    else
+                    {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, i * rec_size + j, byte_in_block);
+                    }
+                }
+                else    /* last block */
+                {
+                    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+                    {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, j, byte_in_block);
+                    }
+                    else
+                    {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, i * rec_size + j, byte_in_block);
+                    }
+                    last_block = KAL_TRUE;
+                }
+
+                if (i == 0 || ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+                {
+                    if (j == 0)
+                    {
+                        kal_mem_set(chksum, 0, nvram_chksum_size);
+                    }
+                    kal_mem_set(tmpchksum, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, working_buffer, byte_in_block, tmpchksum);
+                    for(cs_idx= 0; cs_idx < nvram_chksum_size;cs_idx++){
+                        chksum[cs_idx]  += tmpchksum[cs_idx];
+                    }
+                }
+
+                /* last block */
+                if (last_block)
+                {
+                    kal_mem_cpy(working_buffer + byte_in_block, chksum, nvram_chksum_size);
+                    kal_mem_set(working_buffer + byte_in_block + nvram_chksum_size, 0, remainLen);
+                    byte_in_block += (nvram_chksum_size + remainLen);
+                }
+                if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+                {
+                    //custom_nvram_encrypt(nvram_ptr->secret_key, working_buffer, byte_in_block, rec_size);
+                    nvram_AES_encrypt(working_buffer, byte_in_block);
+                }
+
+            #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+                if (ldi->attr & NVRAM_ATTR_MSP)
+                {
+
+                    SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer, byte_in_block, nvram_ptr->secret_key, working_buffer);
+                }
+            #endif
+
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Write(hFile, working_buffer, byte_in_block, &len);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                    if (FS_NO_ERROR > result)
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        nvram_fat_last_line = __LINE__;
+                        if (tmpchksum)
+                        {
+                            free_ctrl_buffer(tmpchksum);
+                            tmpchksum = NULL;
+                        }
+                        goto final;
+                    }
+                #ifdef __NVRAM_LID_CACHE__
+                if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                {
+                    nvram_write_data_to_cache(ldi, working_buffer, byte_in_block, temp_cache_offset);
+                    temp_cache_offset = temp_cache_offset + byte_in_block;
+                }
+                #endif
+            }
+
+            #ifdef __NVRAM_LID_CACHE__
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                mask_valid_bit_by_ltable_entry(ldi, rec_index + i, 1);
+            }
+            #endif
+
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+        }
+        if (tmpchksum)
+        {
+            free_ctrl_buffer(tmpchksum);
+            tmpchksum = NULL;
+        }
+    }
+    else
+#endif
+    {
+        kal_uint32 rec_in_block = 0;
+
+        max_rec_amount = working_buffer_size / section_size;
+
+        #ifdef __NVRAM_LID_CACHE__
+            cache_offset = 0;
+            temp_cache_offset = 0;
+            temp_rec_index = rec_index;
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset)))
+                {
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+            }
+        #endif
+
+        for (i = 0; i < rec_amount ; i ++)
+        {
+            /*
+             * Write several record at once to reduce io Write
+             *   case a: all remain record
+             *               section_number - i
+             *   case b: max record we can write in one time
+             *               max_rec_amount
+             *   check which case is smaller
+             */
+
+            nvram_drv_fat_prepare_data(working_buffer + rec_in_block * section_size, buffer, i * rec_size, rec_size);
+            kal_mem_set(chksum, 0, nvram_chksum_size);
+            nvram_util_caculate_checksum(ldi, working_buffer + rec_in_block * section_size, rec_size, chksum);
+
+            kal_mem_cpy(working_buffer + rec_in_block * section_size + rec_size, chksum, nvram_chksum_size);
+
+            if (remainLen)
+            {
+                kal_mem_set(working_buffer + rec_in_block * section_size + rec_size + nvram_chksum_size , 0x00, remainLen);
+            }
+
+            if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+            {
+        #ifdef __NVRAM_CRYPT_TEST__
+            if (bWriteMsp == 1){
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_W,working_buffer,NVRAM_MSP_TEST_LEN);
+            }
+        #endif
+                nvram_AES_encrypt(working_buffer + rec_in_block * section_size, section_size);
+                
+            #ifdef __NVRAM_CRYPT_TEST__
+            if (bWriteMsp == 1){
+                 kal_mem_cpy(&NVRAM_EF_MSP_TEST_W[NVRAM_MSP_TEST_LEN],working_buffer,NVRAM_MSP_TEST_LEN);
+            }
+            #endif
+            }
+
+
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+            if (ldi->attr & NVRAM_ATTR_MSP)
+            {
+              SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+            }
+        #endif
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+
+            /* if this is not multi default, no need to prepare data anymore */
+            if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+            {
+                break;
+            }
+            rec_in_block ++;
+
+            if (rec_in_block == max_rec_amount || i == rec_amount - 1)
+            {
+                NVRAM_FS_START(FS_OP_WRITE);
+                result = FS_Write(hFile, working_buffer, section_size * rec_in_block, &len);
+                NVRAM_FS_END(FS_OP_WRITE,result);
+                if (FS_NO_ERROR > result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+                #ifdef __NVRAM_LID_CACHE__
+                if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                {
+                    nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_in_block, cache_offset);
+                    mask_valid_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+
+                    cache_offset += section_size * rec_in_block;
+                    temp_rec_index += rec_in_block;
+                }
+                #endif
+
+                rec_in_block = 0;
+            }
+        }
+
+
+        /* special handling for not multi default */
+        if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+        {
+            /* special handling for NVRAM_EF_ZERO_DEFAULT write speed up*/
+            if((buffer == NVRAM_EF_ZERO_DEFAULT) &&
+                (filesize <= NVRAM_LDI_HEADER_SIZE) &&
+                !encrypt_data )
+            {
+                #ifdef __NVRAM_LID_CACHE__
+                    temp_rec_index = rec_index;
+                    if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                    {
+                        get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset);
+                    }
+                #endif
+            
+                for(i = 0; i < rec_amount; i++) {
+                    NVRAM_FS_START(FS_OP_SEEK);	
+                    result = FS_Seek(hFile, rec_size, FS_FILE_CURRENT);
+                    NVRAM_FS_END(FS_OP_SEEK,result);	
+                    if(FS_NO_ERROR > result)
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        nvram_fat_last_line = __LINE__;
+                        goto final;
+                    }
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Write(hFile, (working_buffer + rec_size), nvram_chksum_size, &len);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                    if (FS_NO_ERROR > result)
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        nvram_fat_last_line = __LINE__;
+                        goto final;
+                    }
+                    #ifdef __NVRAM_LID_CACHE__
+                    if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                    {
+                        temp_cache_offset = cache_offset + i* section_size;                    
+                        nvram_write_data_to_cache(ldi, working_buffer, section_size, temp_cache_offset);                       
+                        mask_valid_bit_by_ltable_entry(ldi, rec_index + i, 1);
+                    }
+                    #endif
+
+                    //record integrated checksum
+                    if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                        kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)(working_buffer + rec_size), nvram_chksum_size);
+                    }                    
+                }
+                goto final;
+            }
+                
+            if (rec_amount > 1)
+            {
+                for (i = 1; i < max_rec_amount && i < rec_amount; i++)
+                {
+                    kal_mem_cpy(working_buffer + section_size * i, working_buffer, section_size);
+                    //record integrated checksum
+                    if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                        kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)(working_buffer+rec_size), nvram_chksum_size);
+                    }                    
+                }
+            }
+
+    #ifdef __NVRAM_CRYPT_TEST__
+            if (bWriteMsp == 1)
+            {
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_W[NVRAM_MSP_TEST_LEN*2],working_buffer,NVRAM_MSP_TEST_LEN);  
+                nvram_create_report_msp_file(KAL_TRUE);
+            }
+    #endif
+            #ifdef __NVRAM_LID_CACHE__
+                temp_rec_index = rec_index;
+                if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                {
+                    get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset);
+                }
+                temp_cache_offset = cache_offset;
+            #endif
+            
+            for (i = 0 ; i < rec_amount ; i += max_rec_amount)
+            {   
+                rec_in_block = (rec_amount - i) > max_rec_amount ? max_rec_amount: (rec_amount - i);
+
+                 NVRAM_FS_START(FS_OP_WRITE);
+                 result = FS_Write(hFile, working_buffer, section_size * rec_in_block, &len);
+                 NVRAM_FS_END(FS_OP_WRITE,result);
+                 if (FS_NO_ERROR > result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+                #ifdef __NVRAM_LID_CACHE__
+                if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                {
+                    nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_in_block, temp_cache_offset);                   
+                    mask_valid_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+
+                    temp_rec_index = temp_rec_index + rec_in_block;
+                    temp_cache_offset = cache_offset + section_size * rec_in_block;
+                }
+                #endif
+            }
+        }
+
+    }
+
+
+
+
+final:
+
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+    }
+
+    if (chksum)
+    {
+        free_ctrl_buffer(chksum);
+        chksum = NULL;
+    }
+
+    if (FS_NO_ERROR > result)
+    {
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+        return result;
+    }
+    
+    return NVRAM_DRV_OK;
+}
+
+#ifdef __NVRAM_WRITE_WITH_FILE_SIZE__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_multRec
+ * DESCRIPTION
+ *  write record(s) to FAT,now it only used at initiation stage
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  initialize          [IN]        true for reset, false for normal write.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_write_multRec(nvram_ltable_entry_struct *ldi,
+                                          kal_char   *nvramname,
+                                          nvram_folder_enum  nvram_folder,
+                                          kal_uint32 file_offset,
+                                          kal_uint16 rec_index,
+                                          kal_uint16 rec_amount,
+                                          kal_uint32 rec_size,
+                                          const kal_uint8 *buffer,
+                                          kal_bool initialize)
+{
+    kal_int32 result = FS_NO_ERROR;
+    kal_int32 ret = FS_NO_ERROR;
+    #ifdef __NVRAM_LID_CACHE__
+    if(NVRAM_WR_WITH_CACHE(ldi->LID) && (!(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))))
+    {
+        result = nvram_drv_fat_write_multiRec_to_cache(buffer, rec_index, rec_amount, rec_size, ldi);
+    }
+    else
+    #endif
+    {
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+      
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    kal_uint32 len;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+    nvram_ldi_ota_header ota_header;
+
+    #ifdef __NVRAM_LID_CACHE__
+    kal_uint32 cache_offset = 0;
+    #endif
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+    #endif
+    
+    do
+    {
+        if (rec_index < 1 || rec_amount < 1)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d\r\n",__FUNCTION__,__LINE__);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index=%d,rec_amount=%d\r\n",rec_index,rec_amount);
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_INVALID_RECORD_ID;
+            break;
+        }
+
+        /* translate record id to filename */
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+
+        /* set the attribute to empty before write data
+           sometime the files may be read only if the nvram lock is turn on
+           ex: software update when nvram lock is turned on
+           But it is not a good solution here, we should unlock it in io layer */
+
+
+        openOption |= FS_CREATE;
+#if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__)) && defined(__MTK_TARGET__)
+        if (ldi->attr & NVRAM_ATTR_COMMITTED)
+        {
+            openOption |= FS_COMMITTED;
+        }
+#endif
+        //Get appdenix header info
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+            ldi->append_buffer = get_ctrl_buffer(rec_amount * nvram_chksum_size);
+        }
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        hFile = FS_Open((const kal_wchar*)filename, openOption);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+        if (hFile == FS_FILE_NOT_FOUND)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,FS_FILE_NOT_FOUND result=%d\r\n",__LINE__,hFile);
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_EMPTY_RECORD;
+            break;
+        }
+        else if (hFile <= FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,result=%d\r\n",__LINE__,hFile);
+            nvram_fat_last_line = __LINE__;
+            result = hFile;
+            break;
+        }
+        if (!nvram_util_has_file_created(ldi))
+        {
+            kal_uint32 ldi_hd_buffer_size = 0;            
+            kal_uint8 ldi_hd_buffer[NVRAM_LDI_HEADER_SIZE] = {0};
+            //prepare header data and write header
+            nvram_prepare_data_header(ldi, ldi_hd_buffer);
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, ldi_hd_buffer, NVRAM_LDI_HEADER_SIZE, &ldi_hd_buffer_size);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            if (result < FS_NO_ERROR)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                nvram_fat_last_line = __LINE__;
+                break;
+            }
+            #ifdef __NVRAM_LID_CACHE__
+            cache_offset = 0;
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                get_lid_cache_base_address(ldi, &cache_offset);
+                nvram_write_data_to_cache(ldi, (void *)ldi_hd_buffer, NVRAM_LDI_HEADER_SIZE, cache_offset);
+                mask_valid_bit_by_ltable_entry(ldi, 0, 1);
+            }
+            #endif
+        }
+        else
+        {
+            NVRAM_FS_START(FS_OP_SEEK);
+            result = FS_Seek(hFile, file_offset, FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,result);
+            if (file_offset && FS_NO_ERROR > result)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                nvram_fat_last_line = __LINE__;
+                break;
+            }
+        }
+        result = nvram_drv_fat_write_multiple(hFile, buffer, rec_index, rec_amount, rec_size, ldi);
+    }while(0);
+
+    //write-back appdenix header info
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        //Write appendix header
+        kal_mem_set(&ota_header, 0, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+        nvram_prepare_appendix_header(NVRAM_APPEND_TYPE_CHKSUM, (nvram_ldi_appendix_header*)(&ota_header), ldi, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, ldi->append_offset, FS_FILE_BEGIN);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        NVRAM_FS_START(FS_OP_WRITE);
+        result = FS_Write(hFile, &ota_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, &len);
+        NVRAM_FS_END(FS_OP_WRITE,result);
+        if (result < FS_NO_ERROR) {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM appendix header write fail:0x%x\n\r", result);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM appendix header write fail:0x%x\r\n", result);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID 0x%04X,category:0x%08X, attr:0x%08X\r\n",ldi->LID, ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                if(ldi->append_buffer) {
+                    free_ctrl_buffer(ldi->append_buffer);
+                    ldi->append_buffer = NULL;
+                }
+                NVRAM_FS_START(FS_OP_CLOSE);
+                result = FS_Close(hFile);
+                NVRAM_FS_END(FS_OP_CLOSE,result);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)hFile, NVRAM_LOC_WRITE_FILE_FAIL_4, ldi->LID, result);
+            }
+        }
+        #ifdef __NVRAM_LID_CACHE__
+        else
+        {
+            cache_offset = 0;
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                get_lid_cache_base_address(ldi, &cache_offset);
+                cache_offset = cache_offset + ldi->append_offset;
+                nvram_write_data_to_cache(ldi, (void *)&ota_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, cache_offset);
+            }
+        }
+        #endif
+        
+        //Write appendix info
+        if(ldi->append_offset == 0) {
+            kal_mem_set(&ota_header, 0, NVRAM_LDI_OTA_HEADER_SIZE);
+            #if defined(__NVRAM_LID_CACHE__) && (defined(__NVRAM_LID_PREREAD__) || defined(__NVRAM_CACHE_BYPASS_W_LIST__))
+            if(KAL_TRUE == nvram_cache_read_ota_header(filename, hFile, &ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+               (ota_header.ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+            #else
+            if(KAL_TRUE == nvram_read_ota_header(hFile, &ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+               (ota_header.ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+            #endif
+            {
+                ldi->append_offset = nvram_appendix_header_offset(ldi);
+            }
+            else {
+                ldi->append_offset = -1;
+            }
+        }
+        if(ldi->append_offset > 0) {
+            NVRAM_FS_START(FS_OP_SEEK);
+            ret = FS_Seek(hFile, (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size)), FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,ret);
+            NVRAM_FS_START(FS_OP_WRITE);
+            ret = FS_Write(hFile, ldi->append_buffer, (rec_amount * nvram_chksum_size), &len);
+            NVRAM_FS_END(FS_OP_WRITE,ret);
+            #ifdef __NVRAM_LID_CACHE__
+            cache_offset = 0;
+            if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+            {
+                get_lid_cache_base_address(ldi, &cache_offset);
+                cache_offset = cache_offset + (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size));
+                nvram_write_data_to_cache(ldi, (kal_uint8*)ldi->append_buffer, (rec_amount * nvram_chksum_size), cache_offset);
+            }
+            #endif
+        }
+        if(ldi->append_buffer) {
+            free_ctrl_buffer(ldi->append_buffer);
+            ldi->append_buffer = NULL;
+        }
+    }
+    
+    if (hFile > FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,ret);
+    }
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+    
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+    
+    /* Set the attribute back to original attribute */
+    if (result < FS_NO_ERROR)
+    {
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+    }    
+    }
+    return result;
+}   
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write
+ * DESCRIPTION
+ *  write record(s) to FAT.
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  initialize          [IN]        true for reset, false for normal write.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_write(kal_char   *nvramname,
+                                          nvram_folder_enum  nvram_folder,
+                                          kal_uint32 file_offset,
+                                          kal_uint16 rec_index,
+                                          kal_uint16 rec_amount,
+                                          kal_uint32 rec_size,
+                                          const kal_uint8 *buffer,
+                                          nvram_ltable_entry_struct *ldi,
+                                          kal_bool initialize)
+{
+    
+    kal_int32 result = FS_NO_ERROR;
+    kal_int32 Ret = FS_NO_ERROR;
+    #ifdef __NVRAM_LID_CACHE__
+    if(NVRAM_WR_WITH_CACHE(ldi->LID) && (!(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))))
+    {
+        result = nvram_drv_fat_write_cache_section(buffer, rec_index, rec_amount, rec_size, ldi);
+    }
+    else
+    #endif    
+    {
+    
+        /*----------------------------------------------------------------*/
+        /* Local Variables                                                */
+        /*----------------------------------------------------------------*/
+        kal_wchar filename[NVRAM_MAX_PATH_LEN];
+        FS_HANDLE hFile = 0;
+        kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+        kal_uint32 len;
+        kal_uint32 nvram_chksum_size = 0;
+        nvram_lid_chksum_info lid_chksum_info = {0};
+
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        SGPT_CTRL_START_T start;
+        #endif
+        nvram_ldi_ota_header ota_header;
+
+        /*----------------------------------------------------------------*/
+        /* Code Body                                                      */
+        /*----------------------------------------------------------------*/
+
+        /* NVRAM GPT timeout assert start timer */
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+        start.pfCallback=nvram_gpt_timeout_callback;
+        start.vPara=NULL;
+        #endif
+
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+
+        nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+        nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+        #endif
+        
+        do
+        {
+            if (rec_index < 1 || rec_amount < 1)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,\r\n",__FUNCTION__,__LINE__);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index=%d,rec_amount=%d\r\n",rec_index,rec_amount);
+                nvram_fat_last_line = __LINE__;
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                break;
+            }
+
+            /* translate record id to filename */
+            nvram_query_file_name(nvram_folder, nvramname, filename);
+
+            /* set the attribute to empty before write data
+               sometime the files may be read only if the nvram lock is turn on
+               ex: software update when nvram lock is turned on
+               But it is not a good solution here, we should unlock it in io layer */
+
+
+            openOption |= FS_CREATE;
+            if (initialize != KAL_TRUE)
+            {  
+            #if !defined(_NAND_FLASH_BOOTING_) && !defined(__FS_SYSDRV_ON_NAND__)  && !defined(__EMMC_BOOTING__)                                  
+                openOption |= FS_PROTECTION_MODE;   /* boot from NAND and single bank NOR don't support this */        
+            #endif                                                                                                 
+            }
+
+        #if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+            if (ldi->attr & NVRAM_ATTR_COMMITTED)
+            {
+                openOption |= FS_COMMITTED;
+            }
+        #endif
+            NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+            hFile = FS_Open((const kal_wchar*)filename, openOption);
+            NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+            if (hFile == FS_FILE_NOT_FOUND)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,FS_FILE_NOT_FOUND hFile=%d\r\n",__LINE__,hFile);
+                nvram_fat_last_line = __LINE__;
+                result = NVRAM_DRV_EMPTY_RECORD;
+                break;
+            }
+            else if (hFile <= FS_NO_ERROR)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open %s fail \r\n",__FUNCTION__,nvramname);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,hFile=%d\r\n",__LINE__,hFile);
+                nvram_fat_last_line = __LINE__;
+                result = hFile;
+                break;
+            }
+
+            //Get appdenix header info
+            if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+                ldi->append_buffer = get_ctrl_buffer(rec_amount * nvram_chksum_size);
+            }
+
+            if (file_offset)
+            {
+                NVRAM_FS_START(FS_OP_SEEK);
+                result = FS_Seek(hFile, file_offset, FS_FILE_BEGIN);
+                NVRAM_FS_END(FS_OP_SEEK,result);
+                if(FS_NO_ERROR > result){
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    nvram_fat_last_line = __LINE__;
+                    break;
+                }
+            }
+
+            /* try to write one record in file, but found the file size is zero. strange ! */
+            if (!(ldi->attr & NVRAM_ATTR_BACKUP_RAW) && 
+                !NVRAM_IS_ATTR_RAW_DATA(ldi->attr) &&
+                !initialize 
+                ) //only have header, fill content is NULL
+            {
+                NVRAM_FS_START(FS_OP_GETFILESIZE);
+                result = FS_GetFileSize(hFile, &len);
+                NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+                if( result == FS_NO_ERROR && (len <= NVRAM_LDI_HEADER_SIZE)){
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_GetFileSize fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    nvram_fat_last_line = __LINE__;
+                    result = NVRAM_DRV_EMPTY_RECORD;
+                    #if defined(__NVRAM_WRITE_PROTECT_ENABLE__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+                    if(nvram_folder != NVRAM_NVD_IMPNT2)
+                    {
+                        // Permit to write Y: as the important_l4 data is maybe deleted manualy
+                        break;
+                    }
+                    #else
+                    break;
+                    #endif
+                }
+            }
+
+            /* Fast reset need to know whether file be written */
+            if (!(ldi->attr & NVRAM_ATTR_BACKUP_RAW) && 
+                !NVRAM_IS_ATTR_RAW_DATA(ldi->attr) &&
+                initialize && 
+                (buffer == NVRAM_EF_ZERO_DEFAULT))
+            {
+                NVRAM_FS_START(FS_OP_GETFILESIZE);
+                result = FS_GetFileSize(hFile, &len);
+                NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+            }
+
+            result = nvram_drv_fat_write_section(hFile, buffer, rec_index, rec_amount, rec_size, ldi, len);
+        }while(0);
+
+        //write-back appdenix header info
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+            if(ldi->append_offset == 0) {
+                #if defined(__NVRAM_LID_CACHE__) && (defined(__NVRAM_LID_PREREAD__) || defined(__NVRAM_CACHE_BYPASS_W_LIST__))
+                if(KAL_TRUE == nvram_cache_read_ota_header(filename, hFile, &ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+                (ota_header.ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+                #else
+                if(KAL_TRUE == nvram_read_ota_header(hFile, &ota_header, NVRAM_LDI_OTA_HEADER_SIZE) &&
+                (ota_header.ldi_attr & NVRAM_ATTR_CHKSUM_INTEGRATE) )
+                #endif
+                {
+                    ldi->append_offset = nvram_appendix_header_offset(ldi);
+                }
+                else {
+                    ldi->append_offset = -1;
+                }
+            }
+            if(ldi->append_offset > 0) {
+                 NVRAM_FS_START(FS_OP_SEEK);
+                 result = FS_Seek(hFile, (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size)), FS_FILE_BEGIN);
+                 NVRAM_FS_END(FS_OP_SEEK,result);
+                 NVRAM_FS_START(FS_OP_WRITE);
+                 result = FS_Write(hFile, ldi->append_buffer, (rec_amount * nvram_chksum_size), &len);
+                 NVRAM_FS_END(FS_OP_WRITE,result);
+                #if defined(__NVRAM_LID_CACHE__)
+                kal_uint32 cache_offset = 0;
+                if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                {
+                    get_lid_cache_base_address(ldi, &cache_offset);
+                    cache_offset = cache_offset + (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size));
+                    nvram_write_data_to_cache(ldi, (kal_uint8*)ldi->append_buffer, (rec_amount * nvram_chksum_size), cache_offset);                        
+                }
+
+                #endif
+            }
+
+            if(ldi->append_buffer) {
+                free_ctrl_buffer(ldi->append_buffer);
+                ldi->append_buffer = NULL;
+            }
+        }
+        
+        if (hFile > FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            Ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        }
+
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+        #endif
+
+        nvram_util_give_mutex(g_nvram_fs_mutex);
+        
+        /* Set the attribute back to original attribute */
+
+
+        if (result < FS_NO_ERROR)
+        {
+            nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+        }    
+    }
+    
+    return result;
+}
+
+nvram_drv_status_enum nvram_drv_fat_write_exception_item(kal_uint8 *buffer,
+                                                                kal_char *nvramname,
+                                                                kal_uint16 section_number,
+                                                                kal_uint32 size,
+                                                                kal_uint32 writesize)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_char cfilename[NVRAM_FILE_LEN + 1] = {0};
+    kal_wchar wcfilename[NVRAM_FILE_LEN + 1] = {0}; 
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_uint32 offset = 0;
+    kal_int32 Ret = FS_NO_ERROR;
+    kal_uint32 nvram_chksum_size = 0;    
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (section_number < 1)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,section_number=%d\r\n",__FUNCTION__,__LINE__,section_number);
+        /* kal_print("Nvram write: section_number < 1 !"); */
+        return NVRAM_DRV_INVALID_RECORD_ID;
+    }
+
+    /* translate record id to filename */
+    nvram_query_file_name(NVRAM_NVD_DATA, nvramname, filename);
+
+    nvram_query_file_name_by_path((kal_wchar *)filename, wcfilename);
+    kal_dchar2char((WCHAR *)wcfilename, cfilename);
+    nvram_util_get_data_item_by_fileprefix(&ldi, cfilename);
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if(nvram_chksum_size > sizeof(g_chksum))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s-> %d nvram_chksum_size > chksum array size.\r\n",__FUNCTION__, __LINE__);
+    }
+
+    /* open NV_RCD.(RCD#) file */
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_CREATE | FS_READ_WRITE | FS_OPEN_NO_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,FS_FILE_NOT_FOUND hFile=%d\r\n",__LINE__,hFile);
+        return NVRAM_DRV_EMPTY_RECORD;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open %s fail\r\n",__FUNCTION__,nvramname);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Fail at %d,hFile=%d\r\n",__LINE__,hFile);
+        /* kal_print("Nvram write: FS_Open return error!"); */
+        return NVRAM_DRV_FATAL_ERROR;
+    }
+
+    /* seek to the record start */
+    offset = NVRAM_LDI_HEADER_SIZE;
+    offset += (section_number - 1) * (size + nvram_chksum_size);
+    NVRAM_FS_START(FS_OP_SEEK);
+    Ret = FS_Seek(hFile, offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,Ret);
+    if (Ret == offset)
+    {
+        NVRAM_FS_START(FS_OP_WRITE);
+        Ret = FS_Write(hFile, buffer, (kal_uint32) writesize, &len);
+        NVRAM_FS_END(FS_OP_WRITE,Ret);
+        if (Ret == FS_NO_ERROR)
+        {   
+            nvram_util_caculate_checksum(ldi, buffer, writesize,g_chksum);
+            NVRAM_FS_START(FS_OP_WRITE);
+            Ret = FS_Write(hFile, g_chksum, nvram_chksum_size, &len);
+            NVRAM_FS_END(FS_OP_WRITE,Ret);
+        }
+    }
+
+    if (Ret != FS_NO_ERROR)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,Ret);
+        /* kal_print("Nvram write: Read error!"); */
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return NVRAM_DRV_CHECKSUM_ERROR;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    Ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,Ret);
+
+    return NVRAM_DRV_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_get_record_size
+ * DESCRIPTION
+ *  get the record size.
+ * PARAMETERS
+ *  nvramname       [?]
+ *  Hint            [?]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_get_record_size(kal_char *nvramname, void *Hint, nvram_folder_enum nvram_folder)
+{
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_uint32 size = 0;     
+    kal_int32 Ret = FS_NO_ERROR;
+#if !defined(__NVRAM_FS_OPERATION_COMPACT__) || !(defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__))
+    FS_HANDLE hFile;    
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    NVRAM_FS_START_EX(FS_OP_OPENHINT,filename);
+    hFile = FS_OpenHint(filename, FS_READ_ONLY, (FS_FileOpenHint*) Hint);
+    NVRAM_FS_END(FS_OP_OPENHINT,hFile);
+    if ( hFile > 0)
+    {
+        NVRAM_FS_START(FS_OP_GETFILESIZE);
+        Ret = FS_GetFileSize(hFile, &size);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,Ret);
+        if (Ret != FS_NO_ERROR)
+        {
+            size = 0;
+        }
+
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        nvram_util_give_mutex(g_nvram_fs_mutex); 
+        return (size - NVRAM_LDI_HEADER_SIZE);
+    }
+    else
+    {
+        nvram_util_give_mutex(g_nvram_fs_mutex); 
+        return hFile;
+    }
+#else
+    NVRAM_FS_PARAM_CMPT_T nvram_param;
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+    nvram_query_file_name(nvram_folder, nvramname, filename);       
+    /* Add NVRAM GPT timeout assert start timer*/
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_READ_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+    #endif
+
+    nvram_param.opid_map = 0;
+    nvram_param.ret[0] = 0;
+    nvram_param.ret[1] = 0;
+
+    //FS_Open
+    nvram_param.opid_map |= NVRAM_FS_CMPT_OPEN;
+    nvram_param.Flag = FS_READ_ONLY;
+    //FS_GetFileSize
+    nvram_param.opid_map |= NVRAM_FS_CMPT_GETFILESIZE;
+    nvram_param.FileSize = &size;
+    nvram_param.DataPtr = NULL;
+    nvram_param.Read = NULL;
+    //FS_Close
+    nvram_param.opid_map |= NVRAM_FS_CMPT_CLOSE;
+    NVRAM_FS_START_EX(FS_OP_CMPTREAD,filename);
+    Ret = FS_CMPT_Read(filename, &nvram_param);
+    NVRAM_FS_END(FS_OP_CMPTREAD,Ret);
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+    
+    nvram_util_give_mutex(g_nvram_fs_mutex);    
+
+    if (nvram_param.opid_map == nvram_param.ret[0])
+    {
+        return (size - NVRAM_LDI_HEADER_SIZE);
+    }
+    else
+    {
+        return nvram_param.ret[1];
+    }
+#endif
+}
+
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+
+#ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+
+static kal_int32 nvram_drv_fat_read_file(const kal_wchar* filename, void *DataPtr, kal_uint32 *Readlen)
+{
+    kal_int32 result = 0;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    kal_int32 Ret = 0;
+    do
+    {
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        hFile = FS_Open(filename, FS_READ_ONLY | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+        NVRAM_FS_END(FS_OP_OPEN,hFile);
+        if (hFile == FS_FILE_NOT_FOUND)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open fail at %d,hFile=%d\r\n",__FUNCTION__,__LINE__,hFile);
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_EMPTY_RECORD;
+            break;
+        }
+        else if (hFile <= FS_NO_ERROR)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Open fail at %d,hFile=%d\r\n",__FUNCTION__,__LINE__,hFile);
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_FATAL_ERROR;
+            break;
+        }
+
+        /* check if a empty record */
+        NVRAM_FS_START(FS_OP_GETFILESIZE);
+        result = FS_GetFileSize(hFile, &len);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+        if ((result == FS_NO_ERROR) && (len == 0))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_GetFileSize fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+            NVRAM_FS_START(FS_OP_CLOSE);
+            Ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,Ret);
+            nvram_fat_last_line = __LINE__;
+            result = NVRAM_DRV_EMPTY_RECORD;
+            break;
+        }
+        NVRAM_FS_START(FS_OP_SEEK);
+        result = FS_Seek(hFile, 0, FS_FILE_BEGIN);
+        NVRAM_FS_END(FS_OP_SEEK,result);
+        if (FS_NO_ERROR > result)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s ->FS_Seek fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+            NVRAM_FS_START(FS_OP_CLOSE);
+            Ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,Ret);
+            nvram_fat_last_line = __LINE__;
+            break;
+        }
+        NVRAM_FS_START(FS_OP_READ);
+        result = FS_Read(hFile, DataPtr, len, Readlen);
+        NVRAM_FS_END(FS_OP_READ,result);
+        if (hFile > FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            Ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        }
+    }while(0);
+
+    return result;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_auto_recover
+ * DESCRIPTION
+ *  file auto-recover, only for smart phone.
+ * PARAMETERS
+ *  filename            [IN]         full path of the data item
+ *  rec_index           [IN]         which record to read (start)
+ *  rec_amount          [IN]         how many record to read at once
+ *  rec_size            [IN]         size of record
+ *  buffer              [IN/OUT]     buffer of check sum
+ *  type                [IN]         read content or checksum
+ *  ismsp               [IN]         to indicate that the records protected by hw
+ * RETURNS
+ *  = 0: success
+ *  > 0: NVRAM error code
+ *  < 0: FS error code
+ *****************************************************************************/
+kal_int32 nvram_drv_fat_auto_recover(
+            kal_char *nvramname,
+            nvram_folder_enum nvram_folder      /* folder index */
+            )
+            
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 result = 0;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_char cfilename[NVRAM_FILE_LEN + 1];
+    kal_wchar wcfilename[NVRAM_FILE_LEN + 1];
+    void *dummy_ptr = (void*)&result;
+    FS_HANDLE fhdl = FS_INVALID_FILE_HANDLE;
+    #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+    kal_wchar *Cali_filelistname = NULL;
+    kal_wchar *Imei_filelistname = NULL;
+    nvram_folder_enum folder_index;
+    kal_uint32 len = 0;
+    kal_int32 temp_count = 0;
+    #endif
+    nvram_ldi_header nv_header;
+    kal_uint32 header_buffer_size = 0;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 ret = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    nvram_query_file_name(nvram_folder, nvramname, filename);    
+  #if defined(__NVRAM_BIN_REGION_SIMULATION__)
+    {
+        kal_wchar *s_filename = (kal_wchar *)get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+        kal_wsprintf(s_filename, "%s\\%s", "Z:\\BIN_REGION", nvramname);
+        NVRAM_FS_START_EX(FS_OP_MOVE,s_filename);
+        result = FS_Move(s_filename, filename, (FS_MOVE_COPY | FS_MOVE_OVERWRITE), NULL, NULL, 0);
+        NVRAM_FS_END(FS_OP_MOVE,result);
+        free_ctrl_buffer(s_filename);
+        s_filename = NULL;
+    }while(0);
+  #else
+    #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+    if(is_nvram_in_ota_flow)
+    {
+        if(is_nvram_first_restore)
+        {
+            Cali_filelistname = (kal_wchar *)get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+            Imei_filelistname = (kal_wchar *)get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+            if(Cali_filelistname == NULL)
+            {
+                kal_prompt_trace(MOD_NVRAM, "%s Can not get the memory from control buffer @line %d\n\r",__FUNCTION__,__LINE__);
+            }
+            if(Imei_filelistname == NULL)
+            {
+                kal_prompt_trace(MOD_NVRAM, "%s Can not get the memory from control buffer @line %d\n\r",__FUNCTION__,__LINE__);
+            }
+            folder_index = nvram_query_folder_index(NVRAM_CATEGORY_CALIBRAT);
+            nvram_query_file_name(folder_index, "FILELIST", Cali_filelistname);
+            
+            folder_index = nvram_query_folder_index(NVRAM_CATEGORY_IMPORTANT);
+            nvram_query_file_name(folder_index, "FILELIST", Imei_filelistname);
+            
+            //delete FILELIST in Calibrate and IMEI folder
+            NVRAM_FS_START_EX(FS_OP_XDELETE,Cali_filelistname);
+            ret = MD_FS_Delete((const kal_wchar*)Cali_filelistname);
+            NVRAM_FS_END(FS_OP_XDELETE,ret);
+            NVRAM_FS_START_EX(FS_OP_XDELETE, Imei_filelistname);
+            ret = MD_FS_Delete((const kal_wchar*)Imei_filelistname);
+            NVRAM_FS_END(FS_OP_XDELETE,ret);
+            
+            //Restore FILELIST from bin region
+            NVRAM_FS_START_EX(FS_OP_RESTORE,Cali_filelistname);
+            result = MD_FS_Restore((const kal_wchar*)Cali_filelistname, dummy_ptr, 4);
+            NVRAM_FS_END(FS_OP_RESTORE,result);
+            if(result >= 0)
+            {
+                //read filelist from bin region to buf
+                result = nvram_drv_fat_read_file((const kal_wchar* )Cali_filelistname, (void *)CALI_FileListBuf,&len);
+                if(result == 0)
+                {
+                    Cali_filelist_found = KAL_TRUE;
+                    for(temp_count = 0; temp_count < len; temp_count++)
+                    {
+                        if(CALI_FileListBuf[temp_count] == 0x00)
+                        {
+                            CALI_FileListBuf[temp_count] = 0xd;
+                        }
+                    }
+                }
+            }
+            NVRAM_FS_START_EX(FS_OP_RESTORE, Imei_filelistname);
+            result = MD_FS_Restore((const kal_wchar*)Imei_filelistname, dummy_ptr, 4);
+            NVRAM_FS_END(FS_OP_RESTORE,result);
+            if(result >= 0)
+            {
+                //read filelist from bin region to buf
+                result = nvram_drv_fat_read_file((const kal_wchar* )Imei_filelistname, (void *)IMEI_FileListBuf,&len);
+                if(result == 0)
+                {
+                    Imei_filelist_found = KAL_TRUE;
+
+                    for(temp_count = 0; temp_count < len; temp_count++)
+                    {
+                        if(IMEI_FileListBuf[temp_count] == 0x00)
+                        {
+                            IMEI_FileListBuf[temp_count] = 0xd;
+                        }
+                    }
+                }
+            }
+            is_nvram_first_restore = KAL_FALSE;
+            free_ctrl_buffer(Cali_filelistname);
+            free_ctrl_buffer(Imei_filelistname);
+            Cali_filelistname = NULL;
+            Imei_filelistname = NULL;
+        }
+        if((NVRAM_NVD_IMPT == nvram_folder) &&(Imei_filelist_found == KAL_TRUE))
+        {
+            if(NULL != strstr((const char *)IMEI_FileListBuf,(const char *)nvramname))
+            {
+                NVRAM_FS_START_EX(FS_OP_RESTORE, filename);
+                result = MD_FS_Restore((const kal_wchar*)filename, dummy_ptr, 4);
+                NVRAM_FS_END(FS_OP_RESTORE,result);
+            }
+            else
+            {
+                result =  NVRAM_DRV_FATAL_ERROR;
+            }
+        }
+        else if((NVRAM_NVD_CALI == nvram_folder)&&(Cali_filelist_found == KAL_TRUE))
+        {
+            if(NULL != strstr((const char *)CALI_FileListBuf,(const char *)nvramname))
+            {
+                NVRAM_FS_START_EX(FS_OP_RESTORE, filename);
+                result = MD_FS_Restore((const kal_wchar*)filename, dummy_ptr, 4);
+                NVRAM_FS_END(FS_OP_RESTORE,result);
+            }
+            else
+            {
+                result =  NVRAM_DRV_FATAL_ERROR;
+            }
+        }
+        else   
+        {
+            result =  NVRAM_DRV_FATAL_ERROR;
+        }
+    }
+    else
+    {
+        NVRAM_FS_START_EX(FS_OP_RESTORE, filename);
+        result = MD_FS_Restore((const kal_wchar*)filename, dummy_ptr, 4);
+        NVRAM_FS_END(FS_OP_RESTORE,result);
+    }
+    #else
+    NVRAM_FS_START_EX(FS_OP_RESTORE, filename);
+    result = MD_FS_Restore((const kal_wchar*)filename, dummy_ptr, 4);
+    NVRAM_FS_END(FS_OP_RESTORE,result);
+    #endif
+    kal_mem_set(&nv_header, 0x0, sizeof(nv_header));
+    if(result == NVRAM_DRV_OK)
+    {
+        NVRAM_FS_START_EX(FS_OP_OPEN, filename);
+        fhdl = FS_Open(filename, FS_READ_ONLY | FS_OPEN_SHARED |FS_OPEN_NO_DIR);
+        NVRAM_FS_END(FS_OP_OPEN,result);
+        if(fhdl > FS_NO_ERROR)
+        {
+          NVRAM_FS_START(FS_OP_READ);
+          result = FS_Read(fhdl, &nv_header, NVRAM_LDI_HEADER_SIZE, &header_buffer_size);
+          NVRAM_FS_END(FS_OP_READ,result);
+        }
+
+        if((fhdl > FS_NO_ERROR) && (result == NVRAM_DRV_OK))
+        {
+            NVRAM_FS_START(FS_OP_SEEK);
+            ret = FS_Seek(fhdl, 0, FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,result);
+        } 
+        if((fhdl > FS_NO_ERROR) && (strcmp(nv_header.nv_ota_header.header,"LDI"))){                
+                ldi = NULL;
+                kal_mem_set(cfilename,0,NVRAM_FILE_LEN + 1);
+                kal_mem_set(wcfilename,0,(NVRAM_FILE_LEN + 1)*sizeof(kal_wchar));
+                nvram_query_file_name_by_path((kal_wchar *)filename, wcfilename);
+                kal_dchar2char((WCHAR *)wcfilename, cfilename);
+                nvram_util_get_data_item_by_fileprefix(&ldi, cfilename);  
+                if(ldi != NULL)
+                {
+                    nvram_prepare_data_header(ldi, (kal_uint8 *)(&nv_header));
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Write(fhdl, (void *)(&nv_header), NVRAM_LDI_HEADER_SIZE, &header_buffer_size);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                }
+            }
+        if(fhdl > FS_NO_ERROR) {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            ret = FS_Close(fhdl);
+            NVRAM_FS_END(FS_OP_CLOSE,ret);
+        }
+    }
+  #endif
+
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+    #ifdef __NVRAM_LID_CACHE__
+    {                        
+        ldi = NULL;
+        kal_mem_set(cfilename,0,NVRAM_FILE_LEN + 1);
+        kal_mem_set(wcfilename,0,(NVRAM_FILE_LEN + 1)*sizeof(kal_wchar));
+        
+        nvram_query_file_name_by_path((kal_wchar *)filename, wcfilename);
+        kal_dchar2char((WCHAR *)wcfilename, cfilename);
+        nvram_util_get_data_item_by_fileprefix(&ldi, cfilename);
+        
+        if(ldi == NULL)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]Can't find LID entry for %s in the LID table\r\n",cfilename);
+            if(nvram_ptr->state == NVRAM_STATE_READY)
+            {
+                kal_prompt_trace(MOD_NVRAM, "cfilename:%s\n\r", cfilename);
+                kal_prompt_trace(MOD_NVRAM, "Can't find LID entry in the LID table:\n\r");                
+                NVRAM_EXT_ASSERT(KAL_FALSE,0 , NVRAM_LOC_LID_PTR_IS_NULL_3, ldi);
+            }else
+            {
+                kal_prompt_trace(MOD_NVRAM, "cfilename:%s\n\r", cfilename);                
+                return NVRAM_DRV_FATAL_ERROR;
+            }
+        }
+
+        if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_RD_WITH_CACHE(ldi->LID))
+        {
+            unmask_valid_bit_by_ltable_entry(ldi, 0, (ldi->total_records + 1));
+        }
+    }
+    #endif    
+    return result;
+}
+#endif
+
+#ifdef __NVRAM_LID_CACHE__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_cache_section
+ * DESCRIPTION
+ *  write record(s) to FAT.
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  initialize          [IN]        true for reset, false for normal write.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_write_cache_section(
+    const kal_uint8 *buffer,
+    kal_uint16 rec_index,
+    kal_uint16 rec_amount,
+    kal_uint32 rec_size,
+    nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    kal_uint32 remainLen = 0;
+    kal_uint8  *chksum = NULL;
+    kal_uint32 max_rec_amount = 0;
+    kal_uint32 section_size = 0;
+    kal_uint32 working_buffer_size = 0;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_IO_ERRNO_OK;
+    kal_bool encrypt_data = KAL_FALSE;
+    kal_uint32 i = 0;
+    kal_uint16 temp_rec_index = rec_index;
+    kal_uint32 cache_offset = 0;
+    kal_uint32 temp_cache_offset = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+
+    //nvram_util_take_mutex(g_nvram_fs_mutex);
+    
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+    #endif
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    /* set the attribute to empty before write data
+           sometime the files may be read only if the nvram lock is turn on
+           ex: software update when nvram lock is turned on
+           But it is not a good solution here, we should unlock it in io layer */
+
+
+    openOption |= FS_CREATE;
+    #if !defined(_NAND_FLASH_BOOTING_) && !defined(__FS_SYSDRV_ON_NAND__)  && !defined(__EMMC_BOOTING__)                                  
+        openOption |= FS_PROTECTION_MODE;   /* boot from NAND and single bank NOR don't support this */        
+    #endif                                                                                                 
+
+    #if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+    if (ldi->attr & NVRAM_ATTR_COMMITTED) {
+        openOption |= FS_COMMITTED;
+    }
+    #endif
+
+    //Get appdenix header info
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        ldi->append_buffer = get_ctrl_buffer(rec_amount * nvram_chksum_size);
+    }
+
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL)) {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+        encrypt_data = KAL_TRUE;
+    }
+    #else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL) {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+        encrypt_data = KAL_TRUE;
+    }
+    #endif
+
+    section_size = rec_size + nvram_chksum_size + remainLen;
+    working_buffer_size = section_size * rec_amount;
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE) {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    chksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+    
+    /* we can write data into FS directly, we don't need another buffer*/
+    if (!(ldi->attr & NVRAM_ATTR_MSP) && !(ldi->attr & NVRAM_ATTR_CONFIDENTIAL) &&
+       #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+              !(ldi->attr & NVRAM_ATTR_COMMITTED) && 
+      #endif  
+            buffer != NVRAM_EF_ZERO_DEFAULT && buffer != NVRAM_EF_FF_DEFAULT)
+        {
+            if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset))) {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->get_lid_record_cache_offset fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            for(i = 0;i < rec_amount;i++)
+            {
+                nvram_memset(working_buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, working_buffer_size);
+                if ((i == 0) || (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+                {
+                    kal_mem_set(chksum, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, buffer + i * rec_size, rec_size, chksum);
+                }
+    
+                if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+                {
+                        kal_mem_cpy(working_buffer, (void *)(buffer + i * rec_size), rec_size);
+                }else 
+                {
+                        kal_mem_cpy(working_buffer, (void *)buffer, rec_size);
+                }
+
+                //write data & checksum
+                kal_mem_cpy((void *)(working_buffer + rec_size), (void *)chksum, nvram_chksum_size);
+
+                if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, working_buffer, section_size, (cache_offset + i * section_size)))) {                  
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+
+                mask_dirty_bit_by_ltable_entry(ldi, rec_index + i, 1);
+                mask_valid_bit_by_ltable_entry(ldi, rec_index + i, 1);
+
+                //record integrated checksum
+                if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                    kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+                }
+            }
+            goto final;
+        }
+    
+        //working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+        //MAX_NVRAM_RECORD_SIZE = (NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM * NVRAM_RECORD_SECTOR_SIZE)
+        //                                                = (16 or 4) * 512
+
+#ifdef __NVRAM_LARGE_RECORD_SIZE__
+    /* size too large , we need to operate block by block */
+    if (section_size > working_buffer_size)
+    {
+        /* we need to prepare extra working buffer;
+           and due to msp need 16-bytes alignment, therefore
+           we set the working buffer to 16-bytes alignment also */
+        kal_uint8 *tmpchksum = NULL;
+        kal_int32 j,cs_idx;
+
+        working_buffer_size = NVRAM_MSP_ALIGNMENT_FLOOR(working_buffer_size) - NVRAM_MSP_ALIGNMENT;
+        tmpchksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+        if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset))) {           
+            result = NVRAM_DRV_INVALID_RECORD_ID;
+            nvram_fat_last_line = __LINE__;
+            if (tmpchksum)
+            {
+                free_ctrl_buffer(tmpchksum);
+                tmpchksum = NULL;
+            }
+            goto final;
+        }
+
+        for (i = 0 ; i < rec_amount; i++)
+        {
+            temp_cache_offset = cache_offset + i*section_size;
+            for (j = 0; j < rec_size; j += working_buffer_size)
+            {
+                kal_int32 byte_in_block = rec_size - j;
+                kal_bool last_block = KAL_FALSE;
+
+                if (byte_in_block > working_buffer_size) {
+                    byte_in_block = working_buffer_size;
+                    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)) {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, j, byte_in_block);
+                    }
+                    else {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, i * rec_size + j, byte_in_block);
+                    }
+                }
+                else    /* last block */
+                {
+                    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)) {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, j, byte_in_block);
+                    }
+                    else {
+                        nvram_drv_fat_prepare_data(working_buffer, buffer, i * rec_size + j, byte_in_block);
+                    }
+                    last_block = KAL_TRUE;
+                }
+
+                if (i == 0 || ldi->attr & NVRAM_ATTR_MULTI_DEFAULT) {
+                    if (j == 0) {
+                        kal_mem_set(chksum, 0, nvram_chksum_size);
+                    }
+                    kal_mem_set(tmpchksum, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, working_buffer, byte_in_block, tmpchksum);
+                    for(cs_idx= 0; cs_idx < nvram_chksum_size;cs_idx++) {
+                        chksum[cs_idx]  += tmpchksum[cs_idx];
+                    }
+                }
+
+                /* last block */
+                if (last_block) {
+                    kal_mem_cpy(working_buffer + byte_in_block, chksum, nvram_chksum_size);
+                    kal_mem_set(working_buffer + byte_in_block + nvram_chksum_size, 0, remainLen);
+                    byte_in_block += (nvram_chksum_size + remainLen);
+                }
+                if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL) {
+                    //custom_nvram_encrypt(nvram_ptr->secret_key, working_buffer, byte_in_block, rec_size);
+                    nvram_AES_encrypt(working_buffer, byte_in_block);
+                }
+
+            #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+                if (ldi->attr & NVRAM_ATTR_MSP) {
+
+                    SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer, byte_in_block, nvram_ptr->secret_key, working_buffer);
+                }
+            #endif
+
+                if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, working_buffer, byte_in_block, temp_cache_offset))) {                  
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    if (tmpchksum)
+                    {
+                        free_ctrl_buffer(tmpchksum);
+                        tmpchksum = NULL;
+                    }
+                    goto final;
+                }
+
+                temp_cache_offset = temp_cache_offset + byte_in_block;
+            }
+
+            mask_dirty_bit_by_ltable_entry(ldi, rec_index + i, 1);
+            mask_valid_bit_by_ltable_entry(ldi, rec_index + i, 1);
+
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+        }
+        if (tmpchksum)
+        {
+            free_ctrl_buffer(tmpchksum);
+            tmpchksum = NULL;
+        }
+    }
+    else
+#endif
+    {
+        kal_uint32 rec_in_block = 0;
+        max_rec_amount = working_buffer_size / section_size;
+        temp_rec_index = rec_index;
+
+        if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset))) {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->get_lid_record_cache_offset fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+            result = NVRAM_DRV_INVALID_RECORD_ID;
+            nvram_fat_last_line = __LINE__;
+            goto final;
+        }
+
+        for (i = 0; i < rec_amount ; i ++) {
+            /*
+             * Write several record at once to reduce io Write
+             *   case a: all remain record
+             *               section_number - i
+             *   case b: max record we can write in one time
+             *               max_rec_amount
+             *   check which case is smaller
+             */
+
+            nvram_drv_fat_prepare_data(working_buffer + rec_in_block * section_size, buffer, i * rec_size, rec_size);
+            kal_mem_set(chksum, 0, nvram_chksum_size);
+            nvram_util_caculate_checksum(ldi, working_buffer + rec_in_block * section_size, rec_size, chksum);
+
+            kal_mem_cpy(working_buffer + rec_in_block * section_size + rec_size, chksum, nvram_chksum_size);
+
+            if (remainLen) {
+                kal_mem_set(working_buffer + rec_in_block * section_size + rec_size + nvram_chksum_size , 0x00, remainLen);
+            }
+
+            if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL) {
+        #ifdef __NVRAM_CRYPT_TEST__
+            if (bWriteMsp == 1) {
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_W,working_buffer,NVRAM_MSP_TEST_LEN);
+            }
+        #endif
+                nvram_AES_encrypt(working_buffer + rec_in_block * section_size, section_size);
+                
+            #ifdef __NVRAM_CRYPT_TEST__
+            if (bWriteMsp == 1){
+                 kal_mem_cpy(&NVRAM_EF_MSP_TEST_W[NVRAM_MSP_TEST_LEN],working_buffer,NVRAM_MSP_TEST_LEN);
+            }
+            #endif
+            }
+
+
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+            if (ldi->attr & NVRAM_ATTR_MSP) {
+              SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+            }
+        #endif
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+
+            /* if this is not multi default, no need to prepare data anymore */
+            if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)) {
+                break;
+            }
+            rec_in_block ++;
+
+            if (rec_in_block == max_rec_amount || i == rec_amount - 1)
+            {
+      
+                result = nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_in_block, cache_offset);
+
+                if (NVRAM_IO_ERRNO_OK != result)
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+                mask_dirty_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+                mask_valid_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+                cache_offset += section_size * rec_in_block;
+                temp_rec_index += rec_in_block;
+
+                rec_in_block = 0;
+            }
+        }
+
+
+        /* special handling for not multi default */
+        if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)) {
+            /* special handling for NVRAM_EF_ZERO_DEFAULT write speed up*/
+            if((buffer == NVRAM_EF_ZERO_DEFAULT) &&
+                !encrypt_data )
+            {
+                if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset))) {                   
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->get_lid_record_cache_offset fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+
+                for(i = 0; i < rec_amount; i++) {
+                    temp_cache_offset = cache_offset + i* section_size;                    
+                    if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, working_buffer, section_size, temp_cache_offset))) {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        result = NVRAM_DRV_INVALID_RECORD_ID;
+                        nvram_fat_last_line = __LINE__;
+                        goto final;
+                    }
+
+                    mask_dirty_bit_by_ltable_entry(ldi, rec_index + i, 1);
+                    mask_valid_bit_by_ltable_entry(ldi, rec_index + i, 1);
+
+                    //record integrated checksum
+                    if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                        kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)(working_buffer + rec_size), nvram_chksum_size);
+                    }                    
+                }
+                goto final;
+            }
+                
+            if (rec_amount > 1) {
+                for (i = 1; i < max_rec_amount && i < rec_amount; i++) {
+                    kal_mem_cpy(working_buffer + section_size * i, working_buffer, section_size);
+                    //record integrated checksum
+                    if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                        kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)(working_buffer+rec_size), nvram_chksum_size);
+                    }                    
+                }
+            }
+
+    #ifdef __NVRAM_CRYPT_TEST__
+            if (bWriteMsp == 1) {
+                kal_mem_cpy(&NVRAM_EF_MSP_TEST_W[NVRAM_MSP_TEST_LEN*2],working_buffer,NVRAM_MSP_TEST_LEN);  
+                nvram_create_report_msp_file(KAL_TRUE);
+            }
+    #endif
+            if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset))) {
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            temp_rec_index = rec_index;            
+            temp_cache_offset = cache_offset;
+            for (i = 0 ; i < rec_amount ; i += max_rec_amount) {
+                rec_in_block = (rec_amount - i) > max_rec_amount ? max_rec_amount: (rec_amount - i);
+
+                if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_in_block, temp_cache_offset))) {                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+                mask_dirty_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+                mask_valid_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+
+
+                temp_rec_index = temp_rec_index + rec_in_block;
+                temp_cache_offset = cache_offset + section_size * rec_in_block;
+            }
+        }
+
+    }
+
+final:
+
+    if(result == NVRAM_IO_ERRNO_OK)
+    {
+        do
+        {
+            //write-back appdenix header info
+            if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+            {
+                if(ldi->append_offset == 0) {
+                    ldi->append_offset = nvram_appendix_header_offset(ldi);             
+                }
+
+                if(ldi->append_offset > 0) {
+
+                    if(NVRAM_IO_ERRNO_OK != (result = get_lid_cache_base_address(ldi, &cache_offset))) {                
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->get_lid_cache_base_address fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        result = NVRAM_DRV_INVALID_RECORD_ID;
+                        nvram_fat_last_line = __LINE__;
+                        break;
+                    }
+
+                    cache_offset = cache_offset + (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size));
+                    if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, (kal_uint8*)ldi->append_buffer, (rec_amount * nvram_chksum_size), cache_offset))) {               
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        result = NVRAM_DRV_INVALID_RECORD_ID;
+                        nvram_fat_last_line = __LINE__;
+                        break;
+                    }
+                }
+
+           }
+        }while(0);
+    }
+
+    if(ldi->append_buffer) {
+        free_ctrl_buffer(ldi->append_buffer);
+        ldi->append_buffer = NULL;
+    }
+
+    if (working_buffer) {
+        free_ctrl_buffer(working_buffer);
+        working_buffer = NULL;
+    }
+
+    if (chksum)
+    {
+        free_ctrl_buffer(chksum);
+        chksum = NULL;
+    }
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+
+    if (NVRAM_IO_ERRNO_OK != result) {
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+        return result;
+    }
+
+    nvram_cache_enqueue(ldi, rec_index, rec_amount, openOption);
+
+    send_event_to_nvram_cache();
+
+    return NVRAM_DRV_OK;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_fat_write_multiRec_to_cache
+ * DESCRIPTION
+ *  write record(s) to FAT.
+ * PARAMETERS
+ *  buffer              [?]
+ *  nvramname           [?]
+ *  section_number      [IN]
+ *  size                [IN]
+ *  initialize          [IN]        true for reset, false for normal write.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+nvram_drv_status_enum nvram_drv_fat_write_multiRec_to_cache(
+    const kal_uint8 *buffer,
+    kal_uint16 rec_index,
+    kal_uint16 rec_amount,
+    kal_uint32 rec_size,
+    nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    kal_uint32 remainLen = 0;
+    kal_uint8  *chksum = NULL;
+    kal_uint32 max_rec_amount;
+    kal_uint32 section_size;
+    kal_uint32 working_buffer_size;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 i;
+    kal_uint32 cache_offset = 0;
+    kal_uint32 temp_cache_offset = 0;
+    kal_uint16 temp_rec_index = rec_index;
+    kal_uint32 rec_in_block = 0;
+    nvram_ldi_ota_header ota_header;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+
+    //nvram_util_take_mutex(g_nvram_fs_mutex);
+    
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start);    //start timer
+    #endif
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    /* set the attribute to empty before write data
+           sometime the files may be read only if the nvram lock is turn on
+           ex: software update when nvram lock is turned on
+           But it is not a good solution here, we should unlock it in io layer */
+
+
+    openOption |= FS_CREATE;
+    #if !defined(_NAND_FLASH_BOOTING_) && !defined(__FS_SYSDRV_ON_NAND__)  && !defined(__EMMC_BOOTING__)                                  
+        openOption |= FS_PROTECTION_MODE;   /* boot from NAND and single bank NOR don't support this */        
+    #endif                                                                                                 
+
+    #if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+    if (ldi->attr & NVRAM_ATTR_COMMITTED) {
+        openOption |= FS_COMMITTED;
+    }
+    #endif
+
+    if (!nvram_util_has_file_created(ldi))
+    {
+            //prepare header data and write header
+            //nvram_prepare_data_header(ldi, ldi_hd_buffer);
+            if (KAL_FALSE == nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION))
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_header fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = NVRAM_ERROR_LOC_NVCACHE_ERRNO_WRITE_HEADER_FAIL;
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+    }
+
+    //Get appdenix header info
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        ldi->append_buffer = get_ctrl_buffer(rec_amount * nvram_chksum_size);
+    }
+
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL)) {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+    #else
+    if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL) {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(rec_size + nvram_chksum_size);
+    }
+    #endif
+
+    section_size = rec_size + nvram_chksum_size + remainLen;
+    working_buffer_size = section_size * rec_amount;
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE) {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    chksum = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+    if(NVRAM_IO_ERRNO_OK !=(result = get_lid_record_cache_offset(ldi, rec_index, section_size, &cache_offset)))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->get_lid_record_cache_offset fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        result = NVRAM_DRV_INVALID_RECORD_ID;
+        nvram_fat_last_line = __LINE__;
+        goto final;
+    }
+    temp_cache_offset = cache_offset;
+
+    if (!(ldi->attr & NVRAM_ATTR_MSP) && !(ldi->attr & NVRAM_ATTR_CONFIDENTIAL) &&
+            buffer != NVRAM_EF_ZERO_DEFAULT && buffer != NVRAM_EF_FF_DEFAULT)
+    {
+
+        for(i = 0; i < rec_amount; i++)
+        {
+            if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+            {
+                //rec_index start from 1
+                kal_mem_set(chksum, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, buffer + (i+rec_index-1)*rec_size, rec_size,chksum);
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size), buffer + (i+rec_index-1)*rec_size, rec_size);                
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size)+rec_size, chksum, nvram_chksum_size);
+            }
+            else
+            {
+                if (i==0)
+                {
+                    kal_mem_set(chksum, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, buffer, rec_size,chksum);
+                }
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size), buffer, rec_size);             
+                kal_mem_cpy(working_buffer + i*(rec_size + nvram_chksum_size)+rec_size, chksum, nvram_chksum_size);
+            }
+    
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+            }
+
+            if (i == (rec_amount - 1))
+            {
+                if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_amount, cache_offset)))
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    goto final;
+                }
+
+                mask_dirty_bit_by_ltable_entry(ldi, rec_index, rec_amount);
+                mask_valid_bit_by_ltable_entry(ldi, rec_index, rec_amount);
+
+            }
+        }
+        goto final;
+    }
+
+    rec_in_block = 0;
+    max_rec_amount = working_buffer_size / section_size;
+
+    for (i = 0; i < rec_amount; i ++)
+    {
+        nvram_drv_fat_prepare_data(working_buffer + rec_in_block * section_size, buffer, (i+rec_index-1) * rec_size, rec_size);
+        kal_mem_set(chksum, 0, nvram_chksum_size);
+        nvram_util_caculate_checksum(ldi, working_buffer + rec_in_block * section_size, rec_size, chksum);
+
+        kal_mem_cpy(working_buffer + rec_in_block * section_size + rec_size, chksum, nvram_chksum_size);
+
+        //record integrated checksum
+        if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+            kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)chksum, nvram_chksum_size);
+        }
+
+        if (remainLen)
+        {
+            kal_mem_set(working_buffer + rec_in_block * section_size + rec_size + nvram_chksum_size , 0x00, remainLen);
+        }
+        if (ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+        {
+            //custom_nvram_encrypt(nvram_ptr->secret_key, working_buffer + rec_in_block * section_size, rec_size, rec_size);
+        nvram_AES_encrypt(working_buffer + rec_in_block * section_size, section_size);
+        }
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        if (ldi->attr & NVRAM_ATTR_MSP)
+        {
+        /* this solution is only for work arround */
+    #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+            kal_uint8 *working_buffer2 = (kal_uint8*) get_ctrl_buffer(section_size);
+            kal_uint8 *working_buffer3 = (kal_uint8*) get_ctrl_buffer(section_size);
+            //copy the original data from working_buffer to working_buffer2
+            memcpy(working_buffer2, working_buffer + rec_in_block * section_size, section_size);
+
+            do
+            {
+                nvram_trace_to_file(__LINE__, 999, 0, 0, 0, 0);
+                nvram_trace_to_file(nvram_ptr->secret_key[0], nvram_ptr->secret_key[1], nvram_ptr->secret_key[2], nvram_ptr->secret_key[3], 0, 0);
+                nvram_trace_to_file(working_buffer[rec_in_block*section_size], working_buffer[rec_in_block*section_size + 1], working_buffer[rec_in_block*section_size + 2], working_buffer[rec_in_block*section_size + 3], 0, 0);
+
+                //encrypt working_buffer
+                SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+                nvram_trace_to_file(working_buffer[rec_in_block*section_size], working_buffer[rec_in_block*section_size + 1], working_buffer[rec_in_block*section_size + 2], working_buffer[rec_in_block*section_size + 3], 0, 0);
+
+                //copy the encrypted data from working_buffer to working_buffer3
+                memcpy(working_buffer3, working_buffer + rec_in_block * section_size, section_size);
+                //decrypt the working_buffer3
+                SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32)working_buffer3, section_size, nvram_ptr->secret_key, working_buffer3);
+
+                //compare the data between the working_buffer2 & working_buffer3
+                if (memcmp(working_buffer2, working_buffer3, section_size) == 0)
+                {
+                    //encrypt PASS
+                    break;
+                }
+                else
+                {
+                    //encrypt FAIL, try again, WTF
+                    memcpy(working_buffer + rec_in_block * section_size, working_buffer2, section_size);
+                }
+            }while(1);
+
+            free_ctrl_buffer(working_buffer2);
+            free_ctrl_buffer(working_buffer3);
+            working_buffer2 = NULL;
+            working_buffer3 = NULL;
+    #else
+            SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer + rec_in_block * section_size, section_size, nvram_ptr->secret_key, working_buffer + rec_in_block * section_size);
+
+    #endif
+        }
+#endif
+
+        /* if this is not multi default, no need to prepare data anymore */
+        if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+        {
+            break;
+        }
+
+        rec_in_block ++;
+
+        if (rec_in_block == max_rec_amount || i == rec_amount - 1)
+        {
+            result = nvram_write_data_to_cache(ldi, working_buffer, section_size * rec_in_block, temp_cache_offset);
+            if (NVRAM_IO_ERRNO_OK != result)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->vram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            
+            mask_dirty_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+            mask_valid_bit_by_ltable_entry(ldi, temp_rec_index, rec_in_block);
+            temp_cache_offset += section_size * rec_in_block;
+            temp_rec_index += rec_in_block;
+
+            rec_in_block = 0;
+        }
+    }
+
+    /* special handling for not multi default */
+    if (!(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+    {
+        for (i = 0; i < rec_amount; i++)
+        {
+            //record integrated checksum
+            if((ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) && ldi->append_buffer) {
+                kal_mem_cpy((void *)(ldi->append_buffer + (i* nvram_chksum_size)), (void *)(working_buffer+rec_size), nvram_chksum_size);
+            }
+            temp_cache_offset = cache_offset + section_size * i;
+            if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, working_buffer, section_size, temp_cache_offset)))
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                result = NVRAM_DRV_INVALID_RECORD_ID;
+                nvram_fat_last_line = __LINE__;
+                goto final;
+            }
+            mask_dirty_bit_by_ltable_entry(ldi, rec_index+i, 1);
+            mask_valid_bit_by_ltable_entry(ldi, rec_index+i, 1);
+        }
+    }
+
+final:
+
+    if(result == NVRAM_IO_ERRNO_OK)
+    {
+        do
+        {
+            //write-back appdenix header info
+            if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+            {
+                //Write appendix header                
+                nvram_prepare_appendix_header(NVRAM_APPEND_TYPE_CHKSUM, (nvram_ldi_appendix_header*)(&ota_header), ldi, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+
+                if(NVRAM_IO_ERRNO_OK != (result = get_lid_cache_base_address(ldi, &cache_offset)))
+                {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->get_lid_cache_base_address fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    result = NVRAM_DRV_INVALID_RECORD_ID;
+                    nvram_fat_last_line = __LINE__;
+                    break;
+                }
+
+                if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, &ota_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, (cache_offset + ldi->append_offset))))
+                {
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM appendix header write fail:0x%x\n\r", result);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);                
+                    kal_prompt_trace(MOD_NVRAM, "cache_offset:%d\n\r", cache_offset);
+                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM appendix header write fail:0x%x\r\n", result);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);                
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"cache_offset:%d\r\n", cache_offset);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                    if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr))
+                    {
+                        if(ldi->append_buffer)
+                        {
+                                free_ctrl_buffer(ldi->append_buffer);
+                                ldi->append_buffer = NULL;
+                        }                        
+                        if (working_buffer)
+                        {
+                            free_ctrl_buffer(working_buffer);
+                            working_buffer = NULL;
+                        }
+                        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_WRITE_HEADER_FAIL, ldi->LID);
+                    }
+                }
+                
+                //write-back appdenix header info
+                if(ldi->append_offset == 0)
+                {
+                    ldi->append_offset = nvram_appendix_header_offset(ldi);             
+                }
+
+                if(ldi->append_offset > 0)
+                {
+
+                    cache_offset = cache_offset + (ldi->append_offset + NVRAM_LDI_APPENDIX_HEADER_SIZE + ((rec_index - 1) * nvram_chksum_size));
+
+                    if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, (kal_uint8*)ldi->append_buffer, (rec_amount * nvram_chksum_size), cache_offset)))
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_write_data_to_cache fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+                        result = NVRAM_DRV_INVALID_RECORD_ID;
+                        nvram_fat_last_line = __LINE__;
+                        break;
+                    }
+                }
+
+            }
+        }while(0);
+    }
+    
+    if(ldi->append_buffer)
+    {
+            free_ctrl_buffer(ldi->append_buffer);
+            ldi->append_buffer = NULL;
+    }
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+        working_buffer = NULL;
+    }
+
+    if (chksum)
+    {
+        free_ctrl_buffer(chksum);
+        chksum = NULL;
+    }
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+
+    if (NVRAM_IO_ERRNO_OK != result) {
+        nvram_fat_last_err = result;
+        MD_TRC_FUNC_NVRAM_DRV_FAT_THROW_EXCEPTION(nvram_fat_last_err, nvram_fat_last_line);
+        return result;
+    }
+
+    nvram_cache_enqueue(ldi, rec_index, rec_amount, openOption);
+
+    send_event_to_nvram_cache();
+
+    return NVRAM_DRV_OK;
+}
+#endif
+
diff --git a/mcu/service/nvram/src/nvram_el1def.c b/mcu/service/nvram/src/nvram_el1def.c
new file mode 100644
index 0000000..596929f
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_el1def.c
@@ -0,0 +1,40 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_el1def.c
+ *
+ * Project:
+ * --------
+ *   
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+#if (defined __MD93__)  
+#include "nvram_el1def_md93.c"
+#elif (defined __MD95__)
+#include "nvram_el1def_md95.c"
+#elif (defined __MD97__)
+#include "nvram_el1def_md97.c"
+#else
+#error "Should define at least a kind of BB being used."
+#endif
diff --git a/mcu/service/nvram/src/nvram_el1def_md93.c b/mcu/service/nvram/src/nvram_el1def_md93.c
new file mode 100644
index 0000000..43e7936
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_el1def_md93.c
@@ -0,0 +1,1376 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_el1def_md93.c
+ *
+ * Project:
+ * --------
+ *   
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+#include "el1_nvram_def.h"
+
+#if defined(__LTE_RAT__)
+#include "el1d_rf_custom_data.h"
+#include "el1d_rf_dpd_custom_data.h"
+#include "el1d_rf_drdi.h"
+#include "mml1_dpd_def.h"
+
+
+void nvram_get_eL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+
+   kal_uint32 i;
+   
+   /** DRDI */
+   EL1D_RF_CUSTOM_DynamicInit();
+   EL1D_RF_CUSTOM_DynamicInitMipi();
+
+   EL1D_RF_UpdateDatabaseTable();
+
+   switch (lid)
+   {
+      /** EL1 RF Calibration */
+      case NVRAM_EF_EL1_FREQADJTBL_LID:
+      {
+         if (buffer != (kal_uint8 *)&FreqAdjustTbl_SetDefault)
+         {
+            kal_mem_cpy(buffer, &FreqAdjustTbl_SetDefault, sizeof(LTE_FreqAdjustTable));
+         }
+      }
+      break;
+      
+      case NVRAM_EF_EL1_RX_POWER_OFFSET_SWITCH_LID:
+      {
+#if IS_4G_RX_POWER_OFFSET_SUPPORT
+         if (buffer != (kal_uint8 *)&LTE_RX_POWER_OFFSET_SWITCH_SetDefault)
+         {
+            kal_mem_cpy(buffer, &LTE_RX_POWER_OFFSET_SWITCH_SetDefault, NVRAM_EF_EL1_RX_POWER_OFFSET_SWITCH_SIZE);
+         }
+#endif
+      }
+      break;
+
+      /** EL1D RF General Parammeters */
+      case NVRAM_EF_EL1_MPRADJTBL_LID:
+      {
+#if 0 /* Temporary disabled by jaska 10-Nov-2015 
+       * => LTE_MPRAdjustTbl commented out in lrfcustomdata.c to be fixed by RFSW */ 
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_AMPRADJTBL_LID:
+      {
+#if 0 /* Temporary disabled by jaska 10-Nov-2015 
+       * => LTE_AMPRAdjustTbl commented out in lrfcustomdata.c to be fixed by RFSW */ 
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+      }
+      break;
+
+      /** EL1D RF Customization data */
+      case NVRAM_EF_EL1_BAND_INDICATOR_LID:
+      {
+         if (buffer != (kal_uint8 *)lteBandIndArray)
+         {
+            kal_mem_cpy(buffer, lteBandIndArray, NVRAM_EF_EL1_BAND_INDICATOR_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_FE_CA_LINKAGE_DATABASE_LID:
+      {
+#if IS_LTE_RF_DL_CA_SUPPORT || IS_LTE_RF_UL_CA_SUPPORT
+         if (buffer != (kal_uint8 *)(&(LTE_FE_CA_LINKAGE_DATABASE_SetDefault)))
+         {
+            kal_mem_cpy(buffer, &(LTE_FE_CA_LINKAGE_DATABASE_SetDefault), NVRAM_EF_EL1_FE_CA_LINKAGE_DATABASE_SIZE);
+         }
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_EVT_TIME_OFST_TABLE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&(ERF_EVT_TIME_OFST_TABLE.lteBpiOfst)))
+         {
+            kal_mem_cpy(buffer, &(ERF_EVT_TIME_OFST_TABLE.lteBpiOfst), NVRAM_EF_EL1_EVT_TIME_OFST_TABLE_SIZE);
+         }
+      }
+      break;
+
+      /* LTE Antenna tuner setting*/
+      case NVRAM_EF_EL1_OLAT_FEATURE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_OLAT_ENABLE))
+         {
+            kal_mem_cpy(buffer, &LTE_OLAT_ENABLE, NVRAM_EF_EL1_OLAT_FEATURE_SIZE);
+         }
+      }
+      break;
+
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+      
+      case NVRAM_EF_EL1_ANT_PDATABASE_LID:
+      case NVRAM_EF_EL1_ANT_CA_LINKAGE_DATABASE_LID:
+      break;
+      
+      case NVRAM_EF_EL1_ANT_ROUTE_DATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&(LTE_ANT_FE_ROUTE_DATABASE_SetDefault)))
+         {
+            kal_mem_cpy(buffer, &(LTE_ANT_FE_ROUTE_DATABASE_SetDefault), NVRAM_EF_EL1_ANT_ROUTE_DATABASE_SIZE);
+         }
+      }
+      break;
+
+      /* DAT Feature */
+      case NVRAM_EF_EL1_DAT_FEATURE_ENABLE_LID:
+      {
+   #if __IS_EL1D_RF_DAT_SUPPORT__
+         if (buffer != (kal_uint8 *)(&(LTE_DAT_FEATURE_ENABLE)))
+         {
+            kal_mem_cpy(buffer, &(LTE_DAT_FEATURE_ENABLE), NVRAM_EF_EL1_DAT_FEATURE_ENABLE_SIZE);
+         }
+   #endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_DAT_ROUTE_DATABASE_LID:
+      {
+   #if __IS_EL1D_RF_DAT_SUPPORT__
+         if (buffer != (kal_uint8 *)(&(LTE_DAT_FE_ROUTE_DATABASE_SetDefault)))
+         {
+            kal_mem_cpy(buffer, &(LTE_DAT_FE_ROUTE_DATABASE_SetDefault), NVRAM_EF_EL1_DAT_ROUTE_DATABASE_SIZE);
+         }
+   #endif
+      }
+      break;
+#else
+      case NVRAM_EF_EL1_ANT_PDATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&(LTE_ANT_ROUTE_DATABASE_SetDefault)))
+         {
+            kal_mem_cpy(buffer, &(LTE_ANT_ROUTE_DATABASE_SetDefault), NVRAM_EF_EL1_ANT_PDATABASE_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_ANT_CA_LINKAGE_DATABASE_LID:
+      {
+   #if IS_LTE_RF_DL_CA_SUPPORT || IS_LTE_RF_UL_CA_SUPPORT
+         if (buffer != (kal_uint8 *)(&(LTE_ANT_CA_LINKAGE_DATABASE_SetDefault)))
+         {
+            kal_mem_cpy(buffer, &(LTE_ANT_CA_LINKAGE_DATABASE_SetDefault), NVRAM_EF_EL1_ANT_CA_LINKAGE_DATABASE_SIZE);
+         }
+   #endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_ANT_ROUTE_DATABASE_LID:
+      case NVRAM_EF_EL1_DAT_FEATURE_ENABLE_LID:
+      case NVRAM_EF_EL1_DAT_ROUTE_DATABASE_LID:
+      break;
+
+#endif
+      
+      case NVRAM_EF_EL1_VPA_CONFIG_DATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&(LTE_VPA_SOURCE_CONFIG_DATABASE)))
+         {
+            kal_mem_cpy(buffer, &(LTE_VPA_SOURCE_CONFIG_DATABASE), NVRAM_EF_EL1_VPA_CONFIG_DATABASE_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_TAS_FORCE_PARAMETER_LID:
+      {
+         if (buffer != (kal_uint8 *)(&(ERF_TAS_FORCE_PARAMETER)))
+         {
+            kal_mem_cpy(buffer, &(ERF_TAS_FORCE_PARAMETER), NVRAM_EF_EL1_TAS_FORCE_PARAMETER_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_TAS_FEATURE_BY_RAT_LID:
+      {
+         if (buffer != (kal_uint8 *)(&(ERF_TAS_FEATURE_BY_RAT_SetDefault)))
+         {
+            kal_mem_cpy(buffer, &(ERF_TAS_FEATURE_BY_RAT_SetDefault), NVRAM_EF_EL1_TAS_FEATURE_BY_RAT_SIZE);
+         }
+      }
+      break;
+      
+      case NVRAM_EF_EL1_TAS_FEATURE_ENABLE_LID:
+      {
+         kal_uint32 i;
+
+         for (i=0;i<LTE_TAS_MAX_FE_ROUTE_NUM;i++)
+         {
+            kal_mem_cpy(&(ERF_TAS_FEATURE_ENABLE[i]), 
+                        &(LTE_TAS_FE_ROUTE_DATABASE_SetDefault.lte_tas_fe_route_db[i].tas_feature_enable), 
+                        sizeof(LTE_CUSTOM_TAS_FEATURE_ENABLE_T));
+         }
+
+         if (buffer != (kal_uint8 *)ERF_TAS_FEATURE_ENABLE)
+         {
+            kal_mem_cpy(buffer, ERF_TAS_FEATURE_ENABLE, NVRAM_EF_EL1_TAS_FEATURE_ENABLE_SIZE);
+         }
+      }
+      break;
+    
+      /* Dynamic Radio-setting Dedicated Image (DRDI) */
+      case NVRAM_EF_EL1_CUSTOM_DYNAMIC_INIT_DEBUG_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_DRDI_DEBUG_INFO))
+         {
+            kal_mem_cpy(buffer, &LTE_DRDI_DEBUG_INFO, NVRAM_EF_EL1_CUSTOM_DYNAMIC_INIT_DEBUG_SIZE);
+         }
+      }
+      break;
+
+      /* Single ANT Feature */
+      case NVRAM_EF_EL1_RF_RX_PATH_CONFIG_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_RF_RX_PATH_CONFIG_DEFAULT))
+         {
+            kal_mem_cpy(buffer, &LTE_RF_RX_PATH_CONFIG_DEFAULT, NVRAM_EF_EL1_RF_RX_PATH_CONFIG_SIZE);
+         }
+      }
+      break;
+
+      /* MIPI Feature */
+      case NVRAM_EF_EL1_MIPI_FEATURE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_MIPI_ENABLE))
+         {
+            kal_mem_cpy(buffer, &LTE_MIPI_ENABLE, NVRAM_EF_EL1_MIPI_FEATURE_SIZE);
+         }
+      }
+      break;
+
+
+      /* Filter Database removed, part of FE Tx Database now; NVRAM functionality TBDL */
+      /*** MIPI BYPASS Feature ***/
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_0THBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_1STBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_2NDBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_3RDBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_4THBAND_LID:
+      {
+         //kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_SIZE);
+         //kal_mem_cpy(buffer,
+         //LTE_MIPI_FILTER_TX_DATA_TABLE_SetDefault[lid-NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_START],
+         //LTE_MIPI_FILTER_TX_DATA_SIZE_TABLE_SetDefault[lid-NVRAM_EF_EL1_MIPI_BYPASS_TX_DATA_START]);
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_0THBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_1STBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_2NDBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_3RDBAND_LID:
+      case NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_4THBAND_LID:
+      {
+         //kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_SIZE);
+         //kal_mem_cpy(buffer,
+         //LTE_MIPI_FILTER_TX_EVENT_TABLE_SetDefault[lid-NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_START],
+         //LTE_MIPI_FILTER_TX_EVENT_SIZE_TABLE_SetDefault[lid-NVRAM_EF_EL1_MIPI_BYPASS_TX_EVENT_START]);
+      }
+      break;
+
+      case NVRAM_EF_EL1_TX_POWER_BACKOFF_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_POWER_BACKOFF)
+         {
+            kal_mem_cpy(buffer, ERF_TX_POWER_BACKOFF, sizeof(ERF_TX_POWER_BACKOFF_PARAM_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+
+#if IS_EL1D_RF_MT6177M
+      case NVRAM_EF_EL1_TX_POWER_BACKOFF_CONDITION_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_POWER_BACKOFF_CONDITION)
+         {
+            kal_mem_cpy(buffer, ERF_TX_POWER_BACKOFF_CONDITION, sizeof(ERF_TX_POWER_BACKOFF_CONDITION_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_TX_POWER_CONDITIONAL_BACKOFF_TABLE_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_POWER_CONDITIONAL_BACKOFF_TABLE)
+         {
+            kal_mem_cpy(buffer, ERF_TX_POWER_CONDITIONAL_BACKOFF_TABLE, sizeof(ERF_TX_POWER_CONDITIONAL_BACKOFF_TABLE_T)*LTE_TX_CONDI_BF_TBL_CNT);
+         }
+      }
+      break;
+#else
+      case NVRAM_EF_EL1_TX_POWER_BACKOFF_CONDITION_LID:
+      case NVRAM_EF_EL1_TX_POWER_CONDITIONAL_BACKOFF_TABLE_LID:
+      {
+         //bypass
+      }
+      break;
+#endif
+
+#if (IS_EL1D_RF_MT6177M) && (IS_LTE_RF_UL_CA_SUPPORT)
+      case NVRAM_EF_EL1_TX_POWER_BACKOFF_CONDITION_CCA_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_POWER_BACKOFF_CONDITION_CCA)
+         {
+            kal_mem_cpy(buffer, ERF_TX_POWER_BACKOFF_CONDITION_CCA, sizeof(ERF_TX_POWER_BACKOFF_CONDITION_CCA_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_TX_POWER_CONDITIONAL_BACKOFF_TABLE_CCA_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_POWER_CONDITIONAL_BACKOFF_TABLE_CCA)
+         {
+            kal_mem_cpy(buffer, ERF_TX_POWER_CONDITIONAL_BACKOFF_TABLE_CCA, sizeof(ERF_TX_POWER_CONDITIONAL_BACKOFF_TABLE_CCA_T)*LTE_TX_CONDI_BF_CCA_TBL_CNT);
+         }
+      }
+      break;
+#else
+      case NVRAM_EF_EL1_TX_POWER_BACKOFF_CONDITION_CCA_LID:
+      case NVRAM_EF_EL1_TX_POWER_CONDITIONAL_BACKOFF_TABLE_CCA_LID:
+      {
+         //bypass
+      }
+      break;
+#endif
+
+      case NVRAM_EF_EL1_TX_MC_VCC_IDX_OFS_LID:
+      {
+      }
+      break;
+      
+      case NVRAM_EF_EL1_TX_MC_POW_BF_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_MC_POW_BF)
+         {
+            kal_mem_cpy(buffer, ERF_TX_MC_POW_BF, sizeof(ERF_TX_MULTI_CLUSTER_POW_BF_PARAM_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+      
+#if (IS_EL1D_RF_MT6177M) && (IS_LTE_RF_UL_CA_SUPPORT)
+      /*CCA cases, also NS0~2 cases*/
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_MC_POW_BF_CCA)
+         {
+            kal_mem_cpy(buffer, ERF_TX_MC_POW_BF_CCA, sizeof(ERF_TX_MULTI_CLUSTER_POW_BF_CCA_PARAM_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_0_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_MC_POW_BF_CCA_0)
+         {
+            kal_mem_cpy(buffer, ERF_TX_MC_POW_BF_CCA_0, sizeof(ERF_TX_MULTI_CLUSTER_POW_BF_CCA_0_PARAM_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_1_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_MC_POW_BF_CCA_1)
+         {
+            kal_mem_cpy(buffer, ERF_TX_MC_POW_BF_CCA_1, sizeof(ERF_TX_MULTI_CLUSTER_POW_BF_CCA_1_PARAM_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_2_LID:
+      {
+         if (buffer != (kal_uint8 *)ERF_TX_MC_POW_BF_CCA_2)
+         {
+            kal_mem_cpy(buffer, ERF_TX_MC_POW_BF_CCA_2, sizeof(ERF_TX_MULTI_CLUSTER_POW_BF_CCA_2_PARAM_T)*LTE_TARGET_MAX_SUPPORT_BAND_NUM);
+         }
+      }
+      break;
+#else
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_LID:
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_0_LID:
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_1_LID:
+      case NVRAM_EF_EL1_TX_MC_POW_BF_CCA_2_LID:
+      {
+         //bypass
+      }
+      break;
+#endif
+
+      /* Split Band Feature */
+      case NVRAM_EF_EL1_SPLIT_BAND_DATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&ERF_SPLIT_BAND_DATABASE))
+         {
+            kal_mem_cpy(buffer, &ERF_SPLIT_BAND_DATABASE, NVRAM_EF_EL1_SPLIT_BAND_DATABASE_SIZE);
+         }
+      }
+      break;
+
+      /* Bypass Mode Feature */
+      case NVRAM_EF_EL1_FILTER_MODE_DATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&ERF_RF_FILTER_MODE_DATABASE))
+         {
+            kal_mem_cpy(buffer, &ERF_RF_FILTER_MODE_DATABASE, NVRAM_EF_EL1_FILTER_MODE_DATABASE_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_BAND_IND_CCA_SUPPORT_LID:
+      {
+         if (buffer != lteBandIndArrayCCASupport)
+         {
+            kal_mem_cpy(buffer, lteBandIndArrayCCASupport, NVRAM_EF_EL1_BAND_IND_CCA_SUPPORT_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_BAND_IND_FLT_CCA_SUPPORT_LID:
+      {
+         if (buffer != lteBandIndArrayFilterCCASupport)
+         {
+            kal_mem_cpy(buffer, lteBandIndArrayFilterCCASupport, NVRAM_EF_EL1_BAND_IND_FLT_CCA_SUPPORT_SIZE);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_DPD_PCFE_OTFC_CUSTOM_PARA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         #if   __IS_4G_PCFE_SA_TUNE_PARA_SUPPORT__  
+         kal_mem_cpy(buffer, p_LTE_PCFE_DPD_OTFC_CUSTOM_PARA_SetDefault, NVRAM_EF_EL1_DPD_PCFE_OTFC_CUSTOM_PARA_SIZE);
+         #endif
+         #endif
+      }
+      break;  
+      
+      case NVRAM_EF_EL1_DPD_PCFE_OTFC_NONCUSTOM_PARA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         #if   __IS_4G_PCFE_SA_TUNE_PARA_SUPPORT__  
+         kal_mem_cpy(buffer, p_LTE_PCFE_DPD_OTFC_NONCUSTOM_PARA, NVRAM_EF_EL1_DPD_PCFE_OTFC_NONCUSTOM_PARA_SIZE);
+         #endif
+         #endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_FE_RX_ROUTE_DATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_FRONT_END_RX_ROUTE_DATABASE_SetDefault))
+         {
+            kal_mem_cpy(buffer, &LTE_FRONT_END_RX_ROUTE_DATABASE_SetDefault, buffer_size);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_FE_TX_ROUTE_DATABASE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_FRONT_END_TX_ROUTE_DATABASE_SetDefault))
+         {
+            kal_mem_cpy(buffer, &LTE_FRONT_END_TX_ROUTE_DATABASE_SetDefault, buffer_size);
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_RX_EVENT_LID:
+      {        
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_RX_EVENT_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_RX_EVENT_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {            
+               if (LTE_MIPI_RX_EVENT_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_RX_EVENT_SIZE)), LTE_MIPI_RX_EVENT_TABLE_SetDefault[i], LTE_MIPI_RX_EVENT_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_TX_EVENT_LID:
+      {        
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_TX_EVENT_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_TX_EVENT_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {           
+               if (LTE_MIPI_TX_EVENT_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_TX_EVENT_SIZE)), LTE_MIPI_TX_EVENT_TABLE_SetDefault[i], LTE_MIPI_TX_EVENT_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_RX_DATA_LID:
+      {        
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_RX_DATA_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_RX_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {    
+               if (LTE_MIPI_RX_DATA_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_RX_DATA_SIZE)), LTE_MIPI_RX_DATA_TABLE_SetDefault[i], LTE_MIPI_RX_DATA_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }         
+      }
+      break;
+     
+      case NVRAM_EF_EL1_MIPI_TX_DATA_LID:
+      {        
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_TX_DATA_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_TX_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {    
+               if (LTE_MIPI_TX_DATA_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_TX_DATA_SIZE)), LTE_MIPI_TX_DATA_TABLE_SetDefault[i], LTE_MIPI_TX_DATA_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_ANTRX_EVENT_LID:
+      {        
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else         
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_ANTRX_EVENT_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_ANTRX_EVENT_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {               
+               if (LTE_MIPI_ANTRX_EVENT_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_ANTRX_EVENT_SIZE)), LTE_MIPI_ANTRX_EVENT_TABLE_SetDefault[i], LTE_MIPI_ANTRX_EVENT_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         } 
+#endif         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_ANTTX_EVENT_LID:
+      {  
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else         
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_ANTTX_EVENT_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_ANTTX_EVENT_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {       
+               if (LTE_MIPI_ANTTX_EVENT_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_ANTTX_EVENT_SIZE)), LTE_MIPI_ANTTX_EVENT_TABLE_SetDefault[i], LTE_MIPI_ANTTX_EVENT_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }
+#endif         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_ANTRX_DATA_LID:
+      {       
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else         
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_ANTRX_DATA_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_ANTRX_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {        
+               if (LTE_MIPI_ANTRX_DATA_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_ANTRX_DATA_SIZE)), LTE_MIPI_ANTRX_DATA_TABLE_SetDefault[i], LTE_MIPI_ANTRX_DATA_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }
+#endif         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_ANTTX_DATA_LID:
+      { 
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else         
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_ANTTX_DATA_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_ANTTX_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {             
+               if (LTE_MIPI_ANTTX_DATA_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_ANTTX_DATA_SIZE)), LTE_MIPI_ANTTX_DATA_TABLE_SetDefault[i], LTE_MIPI_ANTTX_DATA_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         } 
+#endif         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_TPC_EVENT_LID:
+      {        
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_TPC_EVENT_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_TPC_EVENT_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {          
+               if (LTE_MIPI_TPC_EVENT_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_TPC_EVENT_SIZE)), LTE_MIPI_TPC_EVENT_TABLE_SetDefault[i], LTE_MIPI_TPC_EVENT_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_PA_TPC_SECTION_DATA_LID:
+      {                             
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[0].set_default_single_carrier))
+         {
+            LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE tmp_data_buffer;
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_PA_TPC_SECTION_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {        
+               if ((LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier != NULL) &&
+                   (LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca != NULL))
+               {
+                  kal_mem_cpy(&tmp_data_buffer.single_carrier, LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier, LTE_MIPI_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  kal_mem_cpy(&tmp_data_buffer.cca, LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca, LTE_MIPI_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  tmp_data_buffer.txcca = LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[i].is_txcca;
+                  
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_PA_TPC_SECTION_DATA_SIZE)), &tmp_data_buffer, NVRAM_EF_EL1_MIPI_PA_TPC_SECTION_DATA_SIZE);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_FILTER_TPC_EVENT_LID:
+      {        
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_FILTER_TPC_EVENT_TABLE_SetDefault[0]))
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_FILTER_TPC_EVENT_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {       
+               if (LTE_MIPI_FILTER_TPC_EVENT_TABLE_SetDefault[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_FILTER_TPC_EVENT_SIZE)), LTE_MIPI_FILTER_TPC_EVENT_TABLE_SetDefault[i], LTE_MIPI_FILTER_TPC_EVENT_SIZE_TABLE_SetDefault[i]);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_FILTER_PA_TPC_SECTION_DATA_LID:
+      {                   
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[0].set_default_single_carrier))
+         {
+            LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE tmp_data_buffer;
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {     
+               if ((LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier != NULL) &&
+                   (LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca != NULL))
+               {
+                  kal_mem_cpy(&tmp_data_buffer.single_carrier, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  kal_mem_cpy(&tmp_data_buffer.cca, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  tmp_data_buffer.txcca = LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[i].is_txcca;
+                  
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE)), &tmp_data_buffer, NVRAM_EF_EL1_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE);
+               }
+            }
+         }         
+      }
+      break;
+
+      case NVRAM_EF_EL1_SAR_TX_POWER_OFFSET_LID:
+      { 
+#if IS_4G_SAR_TX_POWER_OFFSET_SUPPORT
+         if (buffer != (kal_uint8 *)LTE_SAR_TX_POWER_OFFSET_TABLE[0])
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_SAR_TX_POWER_OFFSET_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {               
+               if (LTE_SAR_TX_POWER_OFFSET_TABLE[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_SAR_TX_POWER_OFFSET_SIZE)), LTE_SAR_TX_POWER_OFFSET_TABLE[i], NVRAM_EF_EL1_SAR_TX_POWER_OFFSET_SIZE);
+               }
+            }
+         }  
+#endif         
+      }
+      break; 
+
+      case NVRAM_EF_EL1_SWTP_TX_POWER_OFFSET_LID:
+      { 
+#if IS_4G_SAR_TX_POWER_OFFSET_SUPPORT || IS_4G_TX_POWER_OFFSET_SUPPORT
+         if (buffer != (kal_uint8 *)LTE_SWTP_TX_POWER_OFFSET_TABLE[0])
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_SWTP_TX_POWER_OFFSET_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {           
+               if (LTE_SWTP_TX_POWER_OFFSET_TABLE[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_SWTP_TX_POWER_OFFSET_SIZE)), LTE_SWTP_TX_POWER_OFFSET_TABLE[i], NVRAM_EF_EL1_SWTP_TX_POWER_OFFSET_SIZE);
+               }
+            }
+         }  
+#endif         
+      }
+      break;       
+
+      case NVRAM_EF_EL1_RX_POWER_OFFSET_LID:
+      {
+#if IS_4G_RX_POWER_OFFSET_SUPPORT         
+         if (buffer != (kal_uint8 *)LTE_RX_POWER_OFFSET_TABLE[0])
+         {
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_RX_POWER_OFFSET_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {
+               if (LTE_RX_POWER_OFFSET_TABLE[i] != NULL)
+               {
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_RX_POWER_OFFSET_SIZE)), LTE_RX_POWER_OFFSET_TABLE[i], NVRAM_EF_EL1_RX_POWER_OFFSET_SIZE);
+               }
+            }
+         }
+#endif          
+      }
+      break;
+
+	  // DPD mipi
+      case NVRAM_EF_EL1_DPD_MIPI_PA_TPC_SECTION_DATA_LID:
+      {      
+	  	 #if __IS_EL1D_DPD_SUPPORT__
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[0].set_default_single_carrier))
+         {
+            LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE tmp_data_buffer;
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_DPD_MIPI_PA_TPC_SECTION_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {        
+               if ((LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier != NULL) &&
+                   (LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca != NULL))
+               {
+                  kal_mem_cpy(&tmp_data_buffer.single_carrier, LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier, LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  kal_mem_cpy(&tmp_data_buffer.cca, LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca, LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  tmp_data_buffer.txcca = LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[i].is_txcca;
+                  
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_DPD_MIPI_PA_TPC_SECTION_DATA_SIZE)), &tmp_data_buffer, NVRAM_EF_EL1_DPD_MIPI_PA_TPC_SECTION_DATA_SIZE);
+               }
+            }
+         }         
+         #endif
+	  }
+      break;
+
+	  case NVRAM_EF_EL1_DPD_MIPI_FILTER_PA_TPC_SECTION_DATA_LID:
+      {
+	     #if __IS_EL1D_DPD_SUPPORT__
+         if ((LTE_MIPI_ENABLE == 1) && (buffer != (kal_uint8 *)LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[0].set_default_single_carrier))
+         {
+            LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE tmp_data_buffer;
+            kal_uint32 record_size = buffer_size/NVRAM_EF_EL1_DPD_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE;
+            kal_mem_set(buffer, 0, buffer_size);
+            for (i=0 ; i<record_size ; i++)
+            {        
+               if ((LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier != NULL) &&
+                   (LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca != NULL))
+               {
+                  kal_mem_cpy(&tmp_data_buffer.single_carrier, LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_single_carrier, LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  kal_mem_cpy(&tmp_data_buffer.cca, LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[i].set_default_cca, LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[i]);
+                  tmp_data_buffer.txcca = LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[i].is_txcca;
+                  
+                  kal_mem_cpy((buffer + (i*NVRAM_EF_EL1_DPD_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE)), &tmp_data_buffer, NVRAM_EF_EL1_DPD_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE);
+               }
+            }
+         }         
+         #endif
+	  }
+	  break;
+
+      default:
+         ASSERT(KAL_FALSE);
+      break;
+   }
+}
+
+void nvram_get_eL1_default_value_to_write_with_record(nvram_lid_core_enum lid, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+   kal_uint32 index_select = rec_index-1;
+
+   /** DRDI */
+   EL1D_RF_CUSTOM_DynamicInit();
+   EL1D_RF_CUSTOM_DynamicInitMipi();
+
+   EL1D_RF_UpdateDatabaseTable();
+
+   switch (lid)
+   {
+      /** EL1D RF RX RSSI Table */
+      case NVRAM_EF_EL1_RSSIGAINTBL_TYPE1_LID:
+      {
+         if (LTE_RSSIGainTblType1_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(buffer, LTE_RSSIGainTblType1_SetDefault[index_select], sizeof(LTE_RX_PL_ROUTE_TYPE1_T));
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_RSSIGAINTBL_TYPE2_LID:
+      {
+#if IS_LTE_RF_DL_CA_SUPPORT
+         if (LTE_RSSIGainTblType2_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(buffer, LTE_RSSIGainTblType2_SetDefault[index_select], sizeof(LTE_RX_PL_ROUTE_TYPE2_T));
+         }
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_RX_POWER_OFFSET_LID:
+      {
+#if IS_4G_RX_POWER_OFFSET_SUPPORT
+         if (LTE_RX_POWER_OFFSET_TABLE[index_select] != 0)
+         {
+            kal_mem_cpy(buffer, LTE_RX_POWER_OFFSET_TABLE[index_select], NVRAM_EF_EL1_RX_POWER_OFFSET_SIZE);
+         }
+#endif
+      }
+      break;
+      
+      /** EL1D RF Tx DAC */
+      case NVRAM_EF_EL1_TXDAC_LID:
+      {
+         if (LTE_RampData_SetDefault[index_select].set_default_single_carrier != 0)
+         {
+            kal_mem_cpy(buffer, LTE_RampData_SetDefault[index_select].set_default_single_carrier, sizeof(LTE_sRAMPDATA));
+            buffer += sizeof(LTE_sRAMPDATA);
+
+            kal_mem_cpy(buffer, LTE_RampData_SetDefault[index_select].set_default_cca, sizeof(LTE_sRAMPDATA));
+            buffer += sizeof(LTE_sRAMPDATA);
+
+            kal_mem_cpy(buffer, &(LTE_RampData_SetDefault[index_select].is_txcca), sizeof(kal_uint8));
+         }
+      }
+      break;
+
+      /** EL1D RF Tx PA OCT level */
+      case NVRAM_EF_EL1_TXPAOCTLEV_LID:
+      {
+         if (LTE_PaOctLevTable_SetDefault[index_select].set_default_single_carrier != 0)
+         {
+            kal_mem_cpy(buffer, LTE_PaOctLevTable_SetDefault[index_select].set_default_single_carrier, sizeof(LTE_sPAOCTLVLSETTING));
+            buffer += sizeof(LTE_sPAOCTLVLSETTING);
+
+            kal_mem_cpy(buffer, LTE_PaOctLevTable_SetDefault[index_select].set_default_cca, sizeof(LTE_sPAOCTLVLSETTING));
+            buffer += sizeof(LTE_sPAOCTLVLSETTING);
+
+            kal_mem_cpy(buffer, &(LTE_PaOctLevTable_SetDefault[index_select].is_txcca), sizeof(kal_uint8));
+         }
+      }
+      break;
+
+      /*** EL1D RF TX DAC (Ramp) filter ***/
+      case NVRAM_EF_EL1_FILTER_TXDAC_LID:
+      {
+         if (LTE_FILTER_RampData_SetDefault[index_select].set_default_single_carrier != 0)
+         {
+            kal_mem_cpy(buffer, LTE_FILTER_RampData_SetDefault[index_select].set_default_single_carrier, sizeof(LTE_sRAMPDATA));
+            buffer += sizeof(LTE_sRAMPDATA);
+
+            kal_mem_cpy(buffer, LTE_FILTER_RampData_SetDefault[index_select].set_default_cca, sizeof(LTE_sRAMPDATA));
+            buffer += sizeof(LTE_sRAMPDATA);
+
+            kal_mem_cpy(buffer, &(LTE_FILTER_RampData_SetDefault[index_select].is_txcca), sizeof(kal_uint8));
+         }
+      }
+      break;
+
+      /*** EL1D RF Tx PA OCT level filter  ***/
+      case NVRAM_EF_EL1_FILTER_TXPAOCTLEV_LID:
+      {
+         if (LTE_FILTER_PaOctLevTable_SetDefault[index_select].set_default_single_carrier != 0)
+         {
+            kal_mem_cpy(buffer, LTE_FILTER_PaOctLevTable_SetDefault[index_select].set_default_single_carrier, sizeof(LTE_sPAOCTLVLSETTING));
+            buffer += sizeof(LTE_sPAOCTLVLSETTING);
+
+            kal_mem_cpy(buffer, LTE_FILTER_PaOctLevTable_SetDefault[index_select].set_default_cca, sizeof(LTE_sPAOCTLVLSETTING));
+            buffer += sizeof(LTE_sPAOCTLVLSETTING);
+
+            kal_mem_cpy(buffer, &(LTE_FILTER_PaOctLevTable_SetDefault[index_select].is_txcca), sizeof(kal_uint8));
+         }
+      }
+      break;
+      
+      /** POWER CAL Related NVRAM Lid */        
+      case NVRAM_EF_EL1_RF_SELF_CAL_RX_DC_IRR_LID:
+      {
+         if(1/*need to check src is not empty*/)
+         {
+            kal_mem_set(buffer, 0, sizeof(LTE_RF_POC_RX_DC_IRR_COMP_PER_ROUTE_T));
+            //kal_mem_cpy(buffer, 0, sizeof(LTE_RF_POC_RX_DC_IRR_COMP_PER_ROUTE_T));
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_RF_SELF_CAL_RX_IIP2_LID:
+      {
+         if(1/*need to check src is not empty*/)
+         {
+            kal_mem_set(buffer, 0, sizeof(LTE_RF_POC_RX_IIP2_COMP_PER_ROUTE_T) );
+            //kal_mem_cpy(buffer, 0, sizeof(LTE_RF_POC_RX_IIP2_COMP_PER_ROUTE_T) );
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_RF_SELF_CAL_DET_TX_LID:
+      {
+         if(1/*need to check src is not empty*/)
+         {
+            kal_mem_set(buffer, 0, sizeof(LTE_RF_POC_DET_TX_COMP_CAL_DATA_ELEMENT_T) );
+            //kal_mem_cpy(buffer, 0, sizeof(LTE_RF_POC_DET_TX_COMP_CAL_DATA_ELEMENT_T) );
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_RF_SELF_CAL_TX_SB_LID:
+      {
+         if(1/*need to check src is not empty*/)
+         {
+            kal_mem_set(buffer, 0, sizeof(LTE_RF_POC_TX_SB_COMP_CAL_DATA_PER_BAND_T) );
+            //kal_mem_cpy(buffer, 0, sizeof(LTE_RF_POC_TX_SB_COMP_CAL_DATA_PER_BAND_T) );
+         }
+      }
+      break;
+
+      /*** LTE_FRONT_END_RX_ROUTE_DATABASE ***/
+      case NVRAM_EF_EL1_FE_RX_ROUTE_DATABASE_LID:
+      {
+         if (&(LTE_FRONT_END_RX_ROUTE_DATABASE_SetDefault.lte_rx_front_end_route_table[index_select]) != 0)
+         {
+            kal_mem_cpy(buffer, &(LTE_FRONT_END_RX_ROUTE_DATABASE_SetDefault.lte_rx_front_end_route_table[index_select]), sizeof(LTE_FE_RX_ROUTE_TABLE_T));
+         }
+      }
+      break;
+
+      /*** LTE_FRONT_END_TX_ROUTE_DATABASE ***/
+      case NVRAM_EF_EL1_FE_TX_ROUTE_DATABASE_LID:
+      {
+         if (&(LTE_FRONT_END_TX_ROUTE_DATABASE_SetDefault.lte_tx_front_end_route_table[index_select]) != 0)
+         {
+            kal_mem_cpy(buffer, &(LTE_FRONT_END_TX_ROUTE_DATABASE_SetDefault.lte_tx_front_end_route_table[index_select]), sizeof(LTE_FE_TX_ROUTE_TABLE_T));
+         }
+      }
+      break;
+
+      /*** LTE MIPI RX EVT TABLE ***/
+      case NVRAM_EF_EL1_MIPI_RX_EVENT_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_RX_EVENT_TABLE_SetDefault[index_select] != 0 )
+            {
+               kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_RX_EVENT_SIZE);
+               kal_mem_cpy(buffer,
+                           LTE_MIPI_RX_EVENT_TABLE_SetDefault[index_select],
+                           LTE_MIPI_RX_EVENT_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+      }
+      break;
+
+      /*** LTE MIPI TX EVT TABLE ***/
+      case NVRAM_EF_EL1_MIPI_TX_EVENT_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_TX_EVENT_TABLE_SetDefault[index_select] != 0 )
+            {
+               kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_TX_EVENT_SIZE);
+               kal_mem_cpy(buffer,
+                           LTE_MIPI_TX_EVENT_TABLE_SetDefault[index_select],
+                           LTE_MIPI_TX_EVENT_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+      }
+      break;
+
+      /*** LTE MIPI RX DATA TABLE ***/
+      case NVRAM_EF_EL1_MIPI_RX_DATA_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_RX_DATA_TABLE_SetDefault[index_select] != 0 )
+            {
+               kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_RX_DATA_SIZE);
+               kal_mem_cpy(buffer,
+                           LTE_MIPI_RX_DATA_TABLE_SetDefault[index_select],
+                           LTE_MIPI_RX_DATA_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+      }
+      break;
+
+      /*** LTE MIPI TX DATA TABLE ***/
+      case NVRAM_EF_EL1_MIPI_TX_DATA_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_TX_DATA_TABLE_SetDefault[index_select] != 0 )
+            {
+               kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_TX_DATA_SIZE);
+               kal_mem_cpy(buffer,
+                           LTE_MIPI_TX_DATA_TABLE_SetDefault[index_select],
+                           LTE_MIPI_TX_DATA_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_TPC_EVENT_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_TPC_EVENT_TABLE_SetDefault[index_select] != 0)
+            {
+               kal_mem_cpy(buffer, LTE_MIPI_TPC_EVENT_TABLE_SetDefault[index_select], LTE_MIPI_TPC_EVENT_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_PA_TPC_SECTION_DATA_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier != 0)
+            {
+               kal_mem_cpy(buffer, LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier, LTE_MIPI_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               buffer += LTE_MIPI_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select];
+
+               kal_mem_cpy(buffer, LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_cca, LTE_MIPI_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               buffer += LTE_MIPI_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select];
+
+               kal_mem_cpy(buffer, &(LTE_MIPI_PA_TPC_SECTION_DATA_SetDefault[index_select].is_txcca), sizeof(kal_uint8));
+            }
+         }
+      }
+	  break;
+
+      case NVRAM_EF_EL1_MIPI_FILTER_TPC_EVENT_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_FILTER_TPC_EVENT_TABLE_SetDefault[index_select] != 0)
+            {
+               kal_mem_cpy(buffer, LTE_MIPI_FILTER_TPC_EVENT_TABLE_SetDefault[index_select], LTE_MIPI_FILTER_TPC_EVENT_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_MIPI_FILTER_PA_TPC_SECTION_DATA_LID:
+      {
+         if(LTE_MIPI_ENABLE == 1)
+         {   
+            if (LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier != 0)
+            {
+               kal_mem_cpy(buffer, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               buffer += LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select];
+
+               kal_mem_cpy(buffer, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_cca, LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               buffer += LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select];
+
+               kal_mem_cpy(buffer, &(LTE_MIPI_FILTER_PA_TPC_SECTION_DATA_SetDefault[index_select].is_txcca), sizeof(kal_uint8));
+            }
+         }
+      }
+      break;
+
+      case NVRAM_EF_EL1_SAR_TX_POWER_OFFSET_LID:
+      {
+#if IS_4G_SAR_TX_POWER_OFFSET_SUPPORT
+         if (LTE_SAR_TX_POWER_OFFSET_TABLE[index_select] != 0)
+         {
+            kal_mem_cpy(buffer, LTE_SAR_TX_POWER_OFFSET_TABLE[index_select], sizeof(LTE_SAR_TX_POWER_OFFSET_DATA_T));
+         }
+#endif
+      }
+      break;
+      case NVRAM_EF_EL1_SWTP_TX_POWER_OFFSET_LID:
+      {
+#if IS_4G_SAR_TX_POWER_OFFSET_SUPPORT || IS_4G_TX_POWER_OFFSET_SUPPORT
+         if (LTE_SWTP_TX_POWER_OFFSET_TABLE[index_select] != 0)
+         {
+            kal_mem_cpy(buffer, LTE_SWTP_TX_POWER_OFFSET_TABLE[index_select], sizeof(LTE_SWTP_TX_POWER_OFFSET_DATA_T));
+         }
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_TX_POWER_OFFSET_LID:
+      {
+         /*Since SWTP is using new LID: NVRAM_EF_EL1_SWTP_TX_POWER_OFFSET_LID, it's need to be remove in 95*/
+      }
+
+      break;
+
+       /*** LTE MIPI ANTRX EVT TABLE ***/
+      case NVRAM_EF_EL1_MIPI_ANTRX_EVENT_LID:
+      {
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_ANTRX_EVENT_TABLE_SetDefault[index_select] != 0 )
+            {
+               kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_ANTRX_EVENT_SIZE);
+               kal_mem_cpy(buffer,
+                           LTE_MIPI_ANTRX_EVENT_TABLE_SetDefault[index_select],
+                           LTE_MIPI_ANTRX_EVENT_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+#endif
+       }
+       break;
+      
+       /*** LTE MIPI ANTTX EVT TABLE ***/
+       case NVRAM_EF_EL1_MIPI_ANTTX_EVENT_LID:
+       {
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else
+          if(LTE_MIPI_ENABLE == 1)
+          {
+             if (LTE_MIPI_ANTTX_EVENT_TABLE_SetDefault[index_select] != 0 )
+             {
+                kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_ANTTX_EVENT_SIZE);
+                kal_mem_cpy(buffer,
+                            LTE_MIPI_ANTTX_EVENT_TABLE_SetDefault[index_select],
+                            LTE_MIPI_ANTTX_EVENT_SIZE_TABLE_SetDefault[index_select]);
+             }
+          }
+#endif
+       }
+       break;
+      
+       /*** LTE MIPI ANTRX DATA TABLE ***/
+       case NVRAM_EF_EL1_MIPI_ANTRX_DATA_LID:
+       {
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else
+          if(LTE_MIPI_ENABLE == 1)
+          {
+             if (LTE_MIPI_ANTRX_DATA_TABLE_SetDefault[index_select] != 0 )
+             {
+                kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_ANTRX_DATA_SIZE);
+                kal_mem_cpy(buffer,
+                            LTE_MIPI_ANTRX_DATA_TABLE_SetDefault[index_select],
+                            LTE_MIPI_ANTRX_DATA_SIZE_TABLE_SetDefault[index_select]);
+             }
+          }
+#endif
+       }
+       break;
+      
+      /*** LTE MIPI ANTTX DATA TABLE ***/
+      case NVRAM_EF_EL1_MIPI_ANTTX_DATA_LID:
+      {
+#if __IS_EL1D_RF_ANT_MERGE_SUPPORT__
+#else
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_ANTTX_DATA_TABLE_SetDefault[index_select] != 0 )
+            {
+               kal_mem_set(buffer, 0, NVRAM_EF_EL1_MIPI_ANTTX_DATA_SIZE);
+               kal_mem_cpy(buffer,
+                           LTE_MIPI_ANTTX_DATA_TABLE_SetDefault[index_select],
+                           LTE_MIPI_ANTTX_DATA_SIZE_TABLE_SetDefault[index_select]);
+            }
+         }
+#endif
+      }
+      break;
+     
+      /** EL1D DPD Factory Calibration Data */
+      case NVRAM_EF_EL1_DPD_FACTORY_CAL_DATA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         LTE_DPD_GROUP_CAL_DEFAULT_SIZE *p_buffer = (LTE_DPD_GROUP_CAL_DEFAULT_SIZE*)buffer;
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_ramp_data), 0, sizeof(LTE_sRAMPDATA));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_ramp_data),            0, sizeof(LTE_sRAMPDATA));
+         kal_mem_set(&(p_buffer->txcca),                            0, sizeof(kal_uint8));
+         
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_pa_oct_lev_tbl), 0, sizeof(LTE_sPAOCTLVLSETTING));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_pa_oct_lev_tbl),            0, sizeof(LTE_sPAOCTLVLSETTING));
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_common_cal), 0, sizeof(LTE_DPD_COMMON_CAL_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_common_cal),            0, sizeof(LTE_DPD_COMMON_CAL_T));
+         
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_am_lut_perband), 0, sizeof(LTE_DPD_AMLUT_PERBAND_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_am_lut_perband),            0, sizeof(LTE_DPD_AMLUT_PERBAND_T));
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_pm_lut_perband), 0, sizeof(LTE_DPD_PMLUT_PERBAND_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_pm_lut_perband), 0, sizeof(LTE_DPD_PMLUT_PERBAND_T));
+         #endif
+      }
+      break;
+      
+      /** EL1D FILTER DPD Factory Calibration Data */
+      case NVRAM_EF_EL1_DPD_FILTER_FACTORY_CAL_DATA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         LTE_DPD_GROUP_CAL_DEFAULT_SIZE *p_buffer = (LTE_DPD_GROUP_CAL_DEFAULT_SIZE*)buffer;
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_ramp_data), 0, sizeof(LTE_sRAMPDATA));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_ramp_data),            0, sizeof(LTE_sRAMPDATA));
+         kal_mem_set(&(p_buffer->txcca),                            0, sizeof(kal_uint8));
+         
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_pa_oct_lev_tbl), 0, sizeof(LTE_sPAOCTLVLSETTING));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_pa_oct_lev_tbl),            0, sizeof(LTE_sPAOCTLVLSETTING));
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_common_cal), 0, sizeof(LTE_DPD_COMMON_CAL_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_common_cal),            0, sizeof(LTE_DPD_COMMON_CAL_T));
+         
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_am_lut_perband), 0, sizeof(LTE_DPD_AMLUT_PERBAND_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_am_lut_perband),            0, sizeof(LTE_DPD_AMLUT_PERBAND_T));
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_pm_lut_perband), 0, sizeof(LTE_DPD_PMLUT_PERBAND_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_pm_lut_perband),            0, sizeof(LTE_DPD_PMLUT_PERBAND_T));
+         #endif
+      }
+      break;
+
+      /** EL1D DPD Factory Calibration Data */
+      case NVRAM_EF_EL1_DPD_COMMON_CTRL_DATA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         if (LTE_DPD_FacCommonData_Table_SetDefault[index_select].single_carrier  != 0)
+         {
+            LTE_DPD_COMMON_CTRL_DEFAULT_SIZE *p_buffer = (LTE_DPD_COMMON_CTRL_DEFAULT_SIZE*)buffer;
+            
+            kal_mem_cpy(&(p_buffer->single_carrier), LTE_DPD_FacCommonData_Table_SetDefault[index_select].single_carrier, sizeof(LTE_DPD_COMMON_CTRL_T));
+            kal_mem_cpy(&(p_buffer->cca),            LTE_DPD_FacCommonData_Table_SetDefault[index_select].cca,            sizeof(LTE_DPD_COMMON_CTRL_T));
+            kal_mem_cpy(&(p_buffer->txcca),        &(LTE_DPD_FacCommonData_Table_SetDefault[index_select].txcca),         sizeof(kal_uint8));
+         }
+         #endif
+      }
+      break;
+      
+      /** EL1D FILTER DPD Factory Calibration Data */
+      case NVRAM_EF_EL1_DPD_FILTER_COMMON_CTRL_DATA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         if (LTE_FILTER_DPD_FacCommonData_Table_SetDefault[index_select].single_carrier  != 0)
+         {
+            LTE_DPD_COMMON_CTRL_DEFAULT_SIZE *p_buffer = (LTE_DPD_COMMON_CTRL_DEFAULT_SIZE*)buffer;
+            
+            kal_mem_cpy(&(p_buffer->single_carrier), LTE_FILTER_DPD_FacCommonData_Table_SetDefault[index_select].single_carrier, sizeof(LTE_DPD_COMMON_CTRL_T));
+            kal_mem_cpy(&(p_buffer->cca),            LTE_FILTER_DPD_FacCommonData_Table_SetDefault[index_select].cca,            sizeof(LTE_DPD_COMMON_CTRL_T));
+            kal_mem_cpy(&(p_buffer->txcca),        &(LTE_FILTER_DPD_FacCommonData_Table_SetDefault[index_select].txcca),         sizeof(kal_uint8));
+         }
+         #endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_DPD_MIPI_PA_TPC_SECTION_DATA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier != 0 )
+            {
+               LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE *p_buffer = (LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE*)buffer;
+               
+               kal_mem_cpy(&(p_buffer->single_carrier), LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier, LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               kal_mem_cpy(&(p_buffer->cca),            LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_cca,            LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               kal_mem_cpy(&(p_buffer->txcca),        &(LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].is_txcca),                  sizeof(kal_uint8));
+            }          
+         }
+         #endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_DPD_MIPI_FILTER_PA_TPC_SECTION_DATA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         if(LTE_MIPI_ENABLE == 1)
+         {
+            if (LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier != 0 )
+            {
+               LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE *p_buffer = (LTE_MIPI_TPC_SECTION_TABLE_DEFAULT_SIZE*)buffer;
+               
+               kal_mem_cpy(&(p_buffer->single_carrier), LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_single_carrier, LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               kal_mem_cpy(&(p_buffer->cca),            LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].set_default_cca,            LTE_MIPI_DPD_PA_TPC_SECTION_DATA_SIZE_SetDefault[index_select]);
+               kal_mem_cpy(&(p_buffer->txcca),        &(LTE_MIPI_FILTER_DPD_PA_TPC_SECTION_DATA_SetDefault[index_select].is_txcca),                  sizeof(kal_uint8));
+            }            
+         }
+         #endif
+      }
+      break;
+
+      default:
+      {
+         ASSERT(KAL_FALSE);
+      }
+      break;
+   }
+}
+
+#endif  // end of #if defined(__LTE_RAT__)
diff --git a/mcu/service/nvram/src/nvram_el1def_md95.c b/mcu/service/nvram/src/nvram_el1def_md95.c
new file mode 100644
index 0000000..6758d16
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_el1def_md95.c
@@ -0,0 +1,462 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_el1def_md95.c
+ *
+ * Project:
+ * --------
+ *   
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+#include "el1d_rf_custom_data_et.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+#include "lte_custom_rf_dpd.h"
+//#include "lte_custom_mipi_dpd.h"
+#include "el1d_rf_dpd_custom_data_md95.h"
+#include "el1d_rf_custom_data_md95.h"
+
+#include "el1_nvram_def.h"
+
+#if defined(__LTE_RAT__)
+#include "el1d_rf_custom_data.h"
+#include "el1d_rf_drdi.h"
+#include "el1d_rf_cid.h"
+#include "el1d_rf_custom_data_md95.h"
+#include "mml1_dpd_def.h"
+//#include "lrfcustomdata_dpd.h"
+
+
+void nvram_get_eL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+   switch (lid)
+   {
+
+      /** EL1D RF General Parammeters */
+      case NVRAM_EF_EL1_MPRADJTBL_LID:
+      {
+#if 0 /* Temporary disabled by jaska 10-Nov-2015 
+       * => LTE_MPRAdjustTbl commented out in lrfcustomdata.c to be fixed by RFSW */ 
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_AMPRADJTBL_LID:
+      {
+#if 0 /* Temporary disabled by jaska 10-Nov-2015 
+       * => LTE_AMPRAdjustTbl commented out in lrfcustomdata.c to be fixed by RFSW */ 
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+      }
+      break;
+
+      /* Single ANT Feature */
+      case NVRAM_EF_EL1_RF_RX_PATH_CONFIG_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_RF_RX_PATH_CONFIG_DEFAULT))
+         {
+            kal_mem_cpy(buffer, &LTE_RF_RX_PATH_CONFIG_DEFAULT, NVRAM_EF_EL1_RF_RX_PATH_CONFIG_SIZE);
+         }
+      }
+      break;
+
+      /* MIPI Feature */
+      case NVRAM_EF_EL1_MIPI_FEATURE_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_MIPI_ENABLE))
+         {
+            kal_mem_cpy(buffer, &LTE_MIPI_ENABLE, NVRAM_EF_EL1_MIPI_FEATURE_SIZE);
+         }
+      }
+      break;
+
+      default:
+         ASSERT(KAL_FALSE);
+      break;
+   }
+}
+
+
+void nvram_get_eL1_default_value_to_write_with_record(nvram_lid_core_enum lid, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+   #if __IS_EL1D_ET_SUPPORT__
+   kal_uint32 index_select = rec_index-1;
+   #endif
+
+//   /** DRDI */
+     EL1D_RF_CUSTOM_DynamicInit();
+//   EL1D_RF_CUSTOM_DynamicInitMipi();
+//
+//   EL1D_RF_UpdateDatabaseTable();
+
+   switch (lid)
+   {
+   
+     /** EL1D ET RF Feature*/  
+      // CAL DATA
+      case NVRAM_EF_EL1_LTE_ET_CAL_DATA_LID:
+      {
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_NVRAM_CANNOT_OTA_T *p_buffer = (LTE_ET_NVRAM_CANNOT_OTA_T*)buffer;
+
+         kal_mem_set(&(p_buffer->band),          0, sizeof(kal_uint16));
+         kal_mem_set(&(p_buffer->total_route),   0, sizeof(kal_uint16));
+         kal_mem_set(&(p_buffer->comp_route),    0, sizeof(kal_uint16));
+         kal_mem_set(&(p_buffer->EtCalDoneFlag), 0, sizeof(kal_uint32));
+         kal_mem_set(&(p_buffer->cal_info),      0, sizeof(LTE_ET_FAC_PARAMETER_NVRAM_INI_T));
+         kal_mem_set(&(p_buffer->cal_lab),       0, sizeof(LTE_ET_GAINIDX_LABK_NVRAM_INI_T));
+         kal_mem_set(&(p_buffer->cal_data),      0, sizeof(LTE_ET_FAC_CALDATA_NVRAM_T));
+
+         if (LTE_ET_DRIVER_PARA_SetDefault[index_select]!= 0)
+         {
+            kal_mem_cpy(&(p_buffer->pa_para), LTE_ET_DRIVER_PARA_SetDefault[index_select], sizeof(LTE_ET_DRIVER_PARAMETER_NVRAM_CUSTOM_T));
+         }
+         else
+         {
+            //kal_mem_cpy(&(p_buffer->pa_para), &LTE_BandNone_ET_DRIVER_PARA_SetDefault, sizeof(LTE_ET_DRIVER_PARAMETER_NVRAM_CUSTOM_T));
+         }
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_LTE_ET_CAL_DATA_CCA_LID:
+      {
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_NVRAM_CANNOT_OTA_T *p_buffer = (LTE_ET_NVRAM_CANNOT_OTA_T*)buffer;
+
+         kal_mem_set(&(p_buffer->band),          0, sizeof(kal_uint16));
+         kal_mem_set(&(p_buffer->total_route),   0, sizeof(kal_uint16));
+         kal_mem_set(&(p_buffer->comp_route),    0, sizeof(kal_uint16));
+         kal_mem_set(&(p_buffer->EtCalDoneFlag), 0, sizeof(kal_uint32));
+         kal_mem_set(&(p_buffer->cal_info),      0, sizeof(LTE_ET_FAC_PARAMETER_NVRAM_INI_T));
+         kal_mem_set(&(p_buffer->cal_lab),       0, sizeof(LTE_ET_GAINIDX_LABK_NVRAM_INI_T));
+         kal_mem_set(&(p_buffer->cal_data),      0, sizeof(LTE_ET_FAC_CALDATA_NVRAM_T));
+
+         if (LTE_ET_CCA_DRIVER_PARA_SetDefault[index_select]!= 0)
+         {
+            kal_mem_cpy(&(p_buffer->pa_para), LTE_ET_CCA_DRIVER_PARA_SetDefault[index_select], sizeof(LTE_ET_DRIVER_PARAMETER_NVRAM_CUSTOM_T));
+         }
+         else
+         {
+            //kal_mem_cpy(&(p_buffer->pa_para), &LTE_BandNone_CCA_ET_DRIVER_PARA_SetDefault, sizeof(LTE_ET_DRIVER_PARAMETER_NVRAM_CUSTOM_T));
+         }
+#endif
+      }
+      break;
+      
+      //MANUAL PARAMETER
+      case NVRAM_EF_EL1_LTE_ET_MANUAL_PARAMETER_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T *p_buffer = (LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T*)buffer;
+
+         if (LTE_ET_MANUAL_PARA_SetDefault[index_select]!= 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ET_MANUAL_PARA_SetDefault[index_select], sizeof(LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_ET_MANUAL_PARA_SetDefault, sizeof(LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T));
+         }
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_LTE_ET_MANUAL_PARAMETER_CCA_LID:
+      {
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T *p_buffer = (LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T*)buffer;
+
+         if (LTE_CCA_ET_MANUAL_PARA_SetDefault[index_select]!= 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_CCA_ET_MANUAL_PARA_SetDefault[index_select], sizeof(LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_CCA_ET_MANUAL_PARA_SetDefault, sizeof(LTE_ET_MANUAL_PARAMETER_NVRAM_CUSTOM_T));
+         }
+#endif
+      }
+      break;
+
+      /** EL1D ET MIPI Feature*/   
+      //SUBBAND FREQ
+      case NVRAM_EF_EL1_LTE_ET_BAND_FREQ_LID:
+      {
+#if __IS_EL1D_ET_SUPPORT__
+         kal_uint16 *p_buffer = (kal_uint16*)buffer;
+
+         if(LTE_ET_BAND_FREQ_TABLE_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ET_BAND_FREQ_TABLE_SetDefault[index_select], (sizeof(kal_uint16)*LTE_ET_SUBBAND_FREQ_NUM));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_FREQ_SetDefault, (sizeof(kal_uint16)*LTE_ET_SUBBAND_FREQ_NUM));
+         }
+#endif
+      }
+      break;
+      //TX EVENT
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_EVENT_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_EVENT_TABLE_T *p_buffer = (LTE_ET_EVENT_TABLE_T*)buffer;
+
+         if(LTE_ET_TX_EVENT_TABLE_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ET_TX_EVENT_TABLE_SetDefault[index_select], (sizeof(LTE_ET_EVENT_TABLE_T)*LTE_ET_TX_EVENT_NUM));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_ET_TX_EVENT_SetDefault, (sizeof(LTE_ET_EVENT_TABLE_T)*LTE_ET_TX_EVENT_NUM));
+         }
+#endif
+      }
+      break;
+
+      //TX DATA
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_DATA_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_DATA_SUBBAND_TABLE_T *p_buffer = (LTE_ET_DATA_SUBBAND_TABLE_T*)buffer;
+
+         if(LTE_ET_TX_DATA_TABLE_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ET_TX_DATA_TABLE_SetDefault[index_select], (sizeof(LTE_ET_DATA_SUBBAND_TABLE_T)*LTE_ET_TX_DATA_NUM));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_ET_TX_DATA_SetDefault, (sizeof(LTE_ET_DATA_SUBBAND_TABLE_T)*LTE_ET_TX_DATA_NUM));
+         }
+#endif
+      }
+      break;
+
+      //TX TPC EVENT
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_TPC_EVENT_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_EVENT_TABLE_T *p_buffer = (LTE_ET_EVENT_TABLE_T*)buffer;
+
+         if(LTE_ET_TPC_EVENT_TABLE_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ET_TPC_EVENT_TABLE_SetDefault[index_select], (sizeof(LTE_ET_EVENT_TABLE_T)*LTE_ET_TPC_EVENT_NUM));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_ET_TPC_EVENT_SetDefault, (sizeof(LTE_ET_EVENT_TABLE_T)*LTE_ET_TPC_EVENT_NUM));
+         }
+#endif
+      }
+      break;
+
+      //TX TPC DATA
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_TPC_DATA_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_DATA_TABLE_T *p_buffer = (LTE_ET_DATA_TABLE_T*)buffer;
+
+         if(LTE_ET_TPC_DATA_TABLE_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ET_TPC_DATA_TABLE_SetDefault[index_select], (sizeof(LTE_ET_DATA_TABLE_T)*LTE_ET_TPC_DATA_NUM));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_ET_TPC_DATA_SetDefault, (sizeof(LTE_ET_DATA_TABLE_T)*LTE_ET_TPC_DATA_NUM));
+         }
+#endif
+      }
+      break;
+
+      //TX BW SWITCH SECTION DATA
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_BW_SWITCH_SECTION_DATA_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_BW_SWITCH_SECTION_TABLE_DEFAULT_SIZE *p_buffer = (LTE_ET_BW_SWITCH_SECTION_TABLE_DEFAULT_SIZE*)buffer;
+
+         if(LTE_ET_BW_SWITCH_SECTION_DATA_TABLE_SetDefault[index_select].set_default_single_carrier != 0)
+         {
+            kal_mem_cpy(&(p_buffer->single_carrier), LTE_ET_BW_SWITCH_SECTION_DATA_TABLE_SetDefault[index_select].set_default_single_carrier, sizeof(LTE_ET_BW_SWITCH_SECTION_SIZE));
+         }
+         else
+         {
+            //kal_mem_cpy(&(p_buffer->single_carrier), &LTE_BandNone_ET_BW_SWITCH_SECTION_DATA_SetDefault, sizeof(LTE_ET_BW_SWITCH_SECTION_SIZE));
+         }
+
+         if(LTE_ET_BW_SWITCH_SECTION_DATA_TABLE_SetDefault[index_select].set_default_cca != 0)
+         {
+            kal_mem_cpy(&(p_buffer->cca), LTE_ET_BW_SWITCH_SECTION_DATA_TABLE_SetDefault[index_select].set_default_cca, sizeof(LTE_ET_BW_SWITCH_SECTION_SIZE));
+         }
+         else
+         {
+            //kal_mem_cpy(&(p_buffer->cca), &LTE_BandNone_ET_BW_SWITCH_CCA_SECTION_DATA_SetDefault, sizeof(LTE_ET_BW_SWITCH_SECTION_SIZE));
+         }
+#endif                                                                                     
+      }
+      break;
+
+      //TX ET MODE SETTING DATA
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_ET_MODE_SETTING_DATA_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_MIPI_adda_DATA_EXPAND_SIZE *p_buffer = (LTE_MIPI_adda_DATA_EXPAND_SIZE*)buffer;
+
+         if(LTE_ETM_MODE_SETTING_DATA_TABLE_SetDefault[index_select] != 0)
+         {
+            kal_mem_cpy(p_buffer, LTE_ETM_MODE_SETTING_DATA_TABLE_SetDefault[index_select], sizeof(LTE_MIPI_adda_DATA_EXPAND_SIZE));
+         }
+         else
+         {
+            //kal_mem_cpy(p_buffer, &LTE_BandNone_ET_MODE_SETTING_DATA_SetDefault, sizeof(LTE_MIPI_adda_DATA_EXPAND_SIZE));
+         }
+#endif
+      }
+      break;
+
+      //TX PA SECTION DATA
+      case NVRAM_EF_EL1_LTE_ET_MIPI_TX_ET_PA_SECTION_DATA_LID:
+      { 
+#if __IS_EL1D_ET_SUPPORT__
+         LTE_ET_TPC_PA_SECTION_TABLE_DEFAULT_SIZE *p_buffer = (LTE_ET_TPC_PA_SECTION_TABLE_DEFAULT_SIZE*)buffer;
+
+         if(LTE_ET_PA_TPC_SECTION_DATA_TABLE_SetDefault[index_select].set_default_single_carrier != 0)
+         {
+            kal_mem_cpy(&(p_buffer->single_carrier), LTE_ET_PA_TPC_SECTION_DATA_TABLE_SetDefault[index_select].set_default_single_carrier, sizeof(LTE_ET_TPC_PA_SECTION_DATA_MD95_T));
+         }
+         else
+         {
+            //kal_mem_cpy(&(p_buffer->single_carrier), &LTE_BandNone_ET_MIPI_PA_SECTION_DATA_SetDefault, sizeof(LTE_ET_TPC_PA_SECTION_DATA_MD95_T));
+         }
+
+         if(LTE_ET_PA_TPC_SECTION_DATA_TABLE_SetDefault[index_select].set_default_cca != 0)
+         {
+            kal_mem_cpy(&(p_buffer->cca), LTE_ET_PA_TPC_SECTION_DATA_TABLE_SetDefault[index_select].set_default_cca, sizeof(LTE_ET_TPC_PA_SECTION_DATA_MD95_T));
+         }
+         else
+         {
+            //kal_mem_cpy(&(p_buffer->cca), &LTE_BandNone_ET_MIPI_PA_CCA_SECTION_DATA_SetDefault, sizeof(LTE_ET_TPC_PA_SECTION_DATA_MD95_T));
+         }
+#endif
+      }
+      break;
+
+      /** EL1D DPD Factory Calibration Data */
+      case NVRAM_EF_EL1_DPD_FACTORY_CAL_DATA_LID:
+      {
+         #if MMDPD_DUMMY_CHK(__IS_EL1D_DPD_SUPPORT__)
+         LTE_DPD_GROUP_CAL_DEFAULT_SIZE *p_buffer = (LTE_DPD_GROUP_CAL_DEFAULT_SIZE*)buffer;
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_ramp_data),      0, sizeof(LTE_sRAMPDATA));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_ramp_data),                 0, sizeof(LTE_sRAMPDATA));
+         
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_pa_oct_lev_tbl), 0, sizeof(LTE_sPAOCTLVLSETTING));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_pa_oct_lev_tbl),            0, sizeof(LTE_sPAOCTLVLSETTING));
+
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_common_cal),     0, sizeof(LTE_DPD_COMMON_CAL_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_common_cal),                0, sizeof(LTE_DPD_COMMON_CAL_T));
+         
+         kal_mem_set(&(p_buffer->single_carrier.lte_dpd_lut_perband),    0, sizeof(LTE_DPD_LUT_PERBAND_T));
+         kal_mem_set(&(p_buffer->cca.lte_dpd_lut_perband),               0, sizeof(LTE_DPD_LUT_PERBAND_T));
+
+         #endif
+		 
+      }
+      break;
+
+	  /*** TX DPD RF ***/
+      //Common Control
+      case NVRAM_EF_EL1_DPD_COMMON_CTRL_LID:
+      { 	
+         #if MMDPD_DUMMY_CHK(__IS_EL1D_DPD_SUPPORT__)
+            //LTE_DPD_COMMON_CTRL_DEFAULT_SIZE *p_buffer = (LTE_DPD_COMMON_CTRL_DEFAULT_SIZE*)buffer;
+		    //if (LTE_DPD_FacCommonData_Table_SetDefault[index_select]!= 0)
+            //{
+	        //   kal_mem_cpy(&(p_buffer->single_carrier), LTE_DPD_FacCommonData_Table_SetDefault[index_select],     sizeof(LTE_DPD_COMMON_CTRL_T));
+		    //}
+		    //if (LTE_CCA_DPD_FacCommonData_Table_SetDefault[index_select]!= 0)
+            //{
+		    //   kal_mem_cpy(&(p_buffer->cca),            LTE_CCA_DPD_FacCommonData_Table_SetDefault[index_select], sizeof(LTE_DPD_COMMON_CTRL_T));
+			//}
+		 #endif
+      }
+      break;	
+
+      //PCFE custom parameter
+      case NVRAM_EF_EL1_DPD_PCFE_CUSTOM_PARA_LID:
+      { 	
+         #if MMDPD_DUMMY_CHK(__IS_EL1D_DPD_SUPPORT__)
+         //LTE_PCFE_CUSTOM_PARA_T *p_buffer = (LTE_PCFE_CUSTOM_PARA_T*)buffer;
+	     //kal_mem_cpy(p_buffer, &LTE_PCFE_DPD_OTFC_CUSTOM_PARA_SetDefault, sizeof(LTE_PCFE_CUSTOM_PARA_T));
+		 #endif
+      }
+      break;
+	  
+	  //PCFE non-custom parameter
+	  case NVRAM_EF_EL1_DPD_PCFE_NONCUSTOM_PARA_LID:
+      { 	
+         #if MMDPD_DUMMY_CHK(__IS_EL1D_DPD_SUPPORT__)            
+         //LTE_PCFE_NONCUSTOM_PARA_T *p_buffer = (LTE_PCFE_NONCUSTOM_PARA_T*)buffer;
+	     //kal_mem_cpy(p_buffer, &LTE_PCFE_NONCUSTOM_PARA, sizeof(LTE_PCFE_NONCUSTOM_PARA_T));
+		 #endif
+      }
+     break;
+	  
+      //normal mode and otfc custom parameter
+      case NVRAM_EF_EL1_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_LID:
+      { 	
+         #if MMDPD_DUMMY_CHK(__IS_EL1D_DPD_SUPPORT__)
+         //LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T *p_buffer = (LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T*)buffer;
+	     //kal_mem_cpy(p_buffer, &LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_SetDefault, sizeof(LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T));
+		 #endif
+      }
+      break;
+
+      //normal mode and otfc non-custom parameter
+      case NVRAM_EF_EL1_DPD_NORMAL_MODE_AND_OTFC_NONCUSTOM_PARA_LID:
+      { 	
+         #if MMDPD_DUMMY_CHK(__IS_EL1D_DPD_SUPPORT__)
+         //LTE_DPD_NORMAL_MODE_AND_OTFC_NONCUSTOM_PARA_T *p_buffer = (LTE_DPD_NORMAL_MODE_AND_OTFC_NONCUSTOM_PARA_T*)buffer;
+	     //kal_mem_cpy(p_buffer, &LTE_DPD_NORMAL_MODE_AND_OTFC_NONCUSTOM_PARA, sizeof(LTE_DPD_NORMAL_MODE_AND_OTFC_NONCUSTOM_PARA_T));
+		 #endif
+      }
+      break;
+
+      default:
+      {
+         ASSERT(KAL_FALSE);
+      }
+      break;
+
+   }
+}
+
+
+#endif  // end of #if defined(__LTE_RAT__)
diff --git a/mcu/service/nvram/src/nvram_el1def_md97.c b/mcu/service/nvram/src/nvram_el1def_md97.c
new file mode 100644
index 0000000..51ec8b1
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_el1def_md97.c
@@ -0,0 +1,271 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_el1def_md97.c
+ *
+ * Project:
+ * --------
+ *   
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+#include "mml1_dpd_def.h"
+#include "el1d_rf_custom_data_et.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+#include "el1_nvram_def.h"
+#include "mml1_tpc_custom_data.h"
+#include "el1d_rf_dpd_custom_data.h"
+#include "lrfcustomdata_dpd.h"
+
+#if defined(__LTE_RAT__)
+#include "el1d_rf_custom_data.h"
+#include "el1d_rf_drdi.h"
+//#include "TrcMod_el1d.h"
+
+void nvram_get_eL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+   switch (lid)
+   {
+
+      /** EL1D RF General Parammeters */
+      case NVRAM_EF_EL1_MPRADJTBL_LID:
+      {
+#if 0 /* Temporary disabled by jaska 10-Nov-2015 
+       * => LTE_MPRAdjustTbl commented out in lrfcustomdata.c to be fixed by RFSW */ 
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+      }
+      break;
+
+      case NVRAM_EF_EL1_AMPRADJTBL_LID:
+      {
+#if 0 /* Temporary disabled by jaska 10-Nov-2015 
+       * => LTE_AMPRAdjustTbl commented out in lrfcustomdata.c to be fixed by RFSW */ 
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+      }
+      break;
+
+      /* Single ANT Feature */
+      case NVRAM_EF_EL1_RF_RX_PATH_CONFIG_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_RF_RX_PATH_CONFIG_DEFAULT))
+         {
+            kal_mem_cpy(buffer, &LTE_RF_RX_PATH_CONFIG_DEFAULT, NVRAM_EF_EL1_RF_RX_PATH_CONFIG_SIZE);
+         }
+      }
+      break;
+
+      /*Addl MPR for B30/48*/
+      case NVRAM_EF_EL1_MPR_CTRL_CONFIG_LID:
+      {
+         if (buffer != (kal_uint8 *)(&LTE_MPR_CTRL_CONFIG_DEFAULT))
+         {
+            kal_mem_cpy(buffer, &LTE_MPR_CTRL_CONFIG_DEFAULT, NVRAM_EF_EL1_MPR_CTRL_CONFIG_SIZE);
+         }
+      }
+      break;
+
+      default:
+         ASSERT(KAL_FALSE);
+      break;
+   }
+}
+
+
+
+void nvram_get_eL1_default_value_to_write_with_record(nvram_lid_core_enum lid, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+   kal_int32 i,j;
+
+   switch (lid)
+   {
+      /** EL1D DPD K data(MMDPD_CAL_DATABASE_T) set to default zero*/
+      case NVRAM_EF_EL1_DPD_CAL_DATABASE_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+
+         MMDPD_CAL_DATABASE_T *p_buffer = (MMDPD_CAL_DATABASE_T*)buffer;
+         kal_mem_set(&(p_buffer->cal_result),  0, sizeof(MMDPD_NVRAM_DATA_T));
+
+         #endif /* __IS_EL1D_DPD_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D DPD K data(MML1_RFFE_CAL_TX_DEFAULT_TBL_T) zero init*/
+      case NVRAM_EF_EL1_DPD_CAL_TX_DEFAULT_TBL_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+
+         MML1_RFFE_CAL_TX_DEFAULT_TBL_T *p_buffer = (MML1_RFFE_CAL_TX_DEFAULT_TBL_T*)buffer;
+         kal_mem_set(&(p_buffer->band_ind),  0, sizeof(MMRF_COMMON_BAND_IDX_E));
+
+         for(i=0; i<MMRF_CAL_MAX_BLOCK_PER_COMP_ROUTE; i++)
+         {
+            for(j=0; j<MML1_RFFE_CAL_TX_BW_NUM; j++)
+            {
+               kal_mem_set(&(p_buffer->mapping_tbl[i].block_id_bw[j]),  0, sizeof(kal_uint16));
+            }
+         }
+
+         #endif /* __IS_EL1D_DPD_SUPPORT__ */
+      }
+      break;  
+
+      //normal mode and otfc custom parameter
+      case NVRAM_EF_EL1_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+         LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T *p_buffer = (LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T*)buffer;
+         kal_mem_cpy(p_buffer, p_LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_SetDefault, sizeof(LTE_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T));
+         //EL1D_TRC_ET_DBG21(789,0,0);
+         #endif
+      }
+      break;
+
+      /** EL1D DPD DEBUG PARA*/ 
+      case NVRAM_EF_EL1_DPD_DEBUG_PARA_LID:
+      {
+         #if __IS_EL1D_DPD_SUPPORT__
+
+         MMDPD_DBG_T *p_buffer = (MMDPD_DBG_T*)buffer;
+         kal_mem_cpy(&p_buffer->normal_otfc, p_LTE_DPD_NORMAL_MODE_AND_OTFC_DBG_PARA, sizeof(MMDPD_NORMAL_MODE_AND_OTFC_DBG_T));
+         kal_mem_set(&p_buffer->factory, 0, sizeof(MMDPD_FAC_DBG_T));
+
+         #endif /* __IS_EL1D_DPD_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D ET RF Feature*/  
+
+/*******************************************************************************
+* ET part GEN97
+******************************************************************************/
+      /** EL1D ET K data(MMET_CAL_DATABASE_T) set to default zero*/
+      case NVRAM_EF_EL1_ET_CAL_DATABASE_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         MMET_CAL_DATABASE_T *p_buffer = (MMET_CAL_DATABASE_T*)buffer;
+         kal_mem_set(&(p_buffer->cal_result),  0, sizeof(MMET_NVRAM_DATA_T));
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break; 
+
+      /** EL1D ET K detrough(MMET_DETROUGH_T) set to default zero*/
+      case NVRAM_EF_EL1_ET_CAL_DETROUGH_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         MMET_DETROUGH_T *p_buffer = (MMET_DETROUGH_T*)buffer;
+         kal_mem_set(p_buffer,  0, sizeof(MMET_DETROUGH_T));
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D ET K pa gain subband(MMET_PA_GAIN_COMPENSATION_T) set to default zero*/
+      case NVRAM_EF_EL1_ET_CAL_PA_SUB_COMP_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         MMET_PA_GAIN_COMPENSATION_T *p_buffer = (MMET_PA_GAIN_COMPENSATION_T*)buffer;
+         kal_mem_set(p_buffer,  0, sizeof(MMET_PA_GAIN_COMPENSATION_T));
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D ET K data(MML1_RFFE_CAL_TX_DEFAULT_TBL_T) zero init*/
+      case NVRAM_EF_EL1_ET_CAL_TX_DEFAULT_TBL_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         MML1_RFFE_CAL_TX_DEFAULT_TBL_T *p_buffer = (MML1_RFFE_CAL_TX_DEFAULT_TBL_T*)buffer;
+         kal_mem_set(&(p_buffer->band_ind),  0, sizeof(MMRF_COMMON_BAND_IDX_E));
+
+         for(i=0; i<MMRF_CAL_MAX_BLOCK_PER_COMP_ROUTE; i++)
+         {
+            for(j=0; j<MML1_RFFE_CAL_TX_BW_NUM; j++)
+            {
+               kal_mem_set(&(p_buffer->mapping_tbl[i].block_id_bw[j]),  0, sizeof(kal_uint16));
+            }
+         }
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D ET CMEAS PARA*/  
+      case NVRAM_EF_EL1_ET_CMEAS_PARA_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         LTE_ET_CMEAS_PARA_T *p_buffer = (LTE_ET_CMEAS_PARA_T*)buffer;
+         kal_mem_cpy(p_buffer, p_LTE_ET_CMEAS_PARA_SetDefault, sizeof(LTE_ET_CMEAS_PARA_T));
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D ET NORMAL MODE AND OTFC CUSTOM PARA*/  
+      case NVRAM_EF_EL1_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         LTE_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_II_T *p_buffer = (LTE_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_II_T*)buffer;
+         kal_mem_cpy(p_buffer, p_LTE_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_II_SetDefault, sizeof(LTE_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_II_T));
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break;
+
+      /** EL1D ET NORMAL MODE AND OTFC NONCUSTOM PARA*/ 
+      case NVRAM_EF_EL1_ET_DEBUG_PARA_LID:
+      {
+         #if __IS_EL1D_ET_SUPPORT__
+
+         MMET_DBG_T *p_buffer = (MMET_DBG_T*)buffer;
+         kal_mem_cpy(&p_buffer->normal_otfc, p_LTE_ET_NORMAL_MODE_AND_OTFC_DBG_PARA, sizeof(MMET_NORMAL_MODE_AND_OTFC_DBG_T));
+         kal_mem_set(&p_buffer->factory, 0, sizeof(MMET_FAC_DBG_T));
+
+         #endif /* __IS_EL1D_ET_SUPPORT__ */
+      }
+      break;
+
+      default:
+      {
+         ASSERT(KAL_FALSE);
+      }
+      break;
+   }
+}
+
+#endif  // end of #if defined(__LTE_RAT__)
diff --git a/mcu/service/nvram/src/nvram_ex_io.c b/mcu/service/nvram/src/nvram_ex_io.c
new file mode 100644
index 0000000..62446a8
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ex_io.c
@@ -0,0 +1,3168 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ex_io.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *
+ * Author:
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#include "kal_public_api.h" //MSBB change #include "kal_release.h"        /* Basic data type */
+
+#include "kal_public_defs.h" //MSBB change #include "stack_common.h"
+//MSBB remove #include "app_buff_alloc.h"     /* Declaration of buffer management API */
+
+#include "nvram_main.h"
+#include "nvram_io.h"
+
+/* For FAT */
+#include "fs_gprot.h"
+#include "fs_iprot.h"
+#include "us_timer.h"
+#include "ex_public.h"
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+extern module_type stack_get_active_module_id( void );
+
+#ifdef __NVRAM_OTP__
+#ifndef __MTK_TARGET__
+
+nvram_ltable_entry_struct ldi_otp =
+{
+    NVRAM_EF_RESERVED_LID - 1,
+    256,
+    1,
+    NVRAM_EF_ZERO_DEFAULT,
+    NVRAM_CATEGORY_USER,
+    NVRAM_ATTR_AVERAGE,    
+    "CT05",
+    "000",
+    "Fake OTP\0"
+};
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  OTP_Read_FAKE
+ * DESCRIPTION
+ * PARAMETERS
+ *  Offset          [IN]
+ *  BufferPtr       [?]
+ *  Length          [IN]
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+int OTP_Read_FAKE(kal_uint32 Offset, void *BufferPtr, kal_uint32 Length)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_int32 Ret = FS_FLASH_OTP_UNKNOWERR;
+    kal_uint16 chksum1 = 0, chksum2 = 0;
+    kal_uint32 i;
+    NVRAM_FILE_NAME nvramname;
+    nvram_ltable_entry_struct *ldi = &ldi_otp;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_EXT_ASSERT(BufferPtr != NULL,(kal_uint32)BufferPtr, NVRAM_LOC_BUFFER_PTR_IS_NULL_1, 0);
+
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+    /* translate record id to filename */
+    nvram_query_file_name(NVRAM_NVD_DATA, nvramname, filename);
+
+    /* open NV_RCD.(RCD#) file */
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const WCHAR*)filename, FS_READ_WRITE | FS_CREATE);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return FS_FLASH_OTP_UNKNOWERR;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret =FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return FS_FLASH_OTP_UNKNOWERR;
+    }
+
+    len = 256;
+    if ((Offset + Length) > len)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return FS_FLASH_OTP_OVERSCOPE;
+    }
+
+    /* check if a empty record */
+    NVRAM_FS_START(FS_OP_GETFILESIZE);
+    Ret = FS_GetFileSize(hFile, &len);
+    NVRAM_FS_END(FS_OP_GETFILESIZE,Ret);
+    if ((Ret == FS_NO_ERROR) && (len == 0))
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return FS_FLASH_OTP_UNKNOWERR;
+    }
+
+    /* seek to the record start */
+    NVRAM_FS_START(FS_OP_SEEK);
+    Ret = FS_Seek(hFile, Offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,Ret);
+    if (Ret >= FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_READ);
+        Ret = FS_Read(hFile, BufferPtr, Length, &len);
+        NVRAM_FS_END(FS_OP_READ,Ret);
+    }
+
+    if (Ret != FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        return FS_FLASH_OTP_UNKNOWERR;
+    }
+
+    NVRAM_FS_START(FS_OP_CLOSE);
+    Ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,Ret);
+    return FS_NO_ERROR;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  OTP_Write_FAKE
+ * DESCRIPTION
+ * PARAMETERS
+ *  Offset          [IN]
+ *  BufferPtr       [?]
+ *  Length          [IN]
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+int OTP_Write_FAKE(kal_uint32 Offset, void *BufferPtr, kal_uint32 Length)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_int32 Ret = FS_FLASH_OTP_UNKNOWERR;
+    kal_int32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR;
+    kal_uint16 chksum = 0;
+    kal_uint8 *buffer_with_chksum;
+    NVRAM_FILE_NAME nvramname;
+    nvram_ltable_entry_struct *ldi = &ldi_otp;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+    /* translate record id to filename */
+    nvram_query_file_name(NVRAM_NVD_DATA, nvramname, filename);
+
+    openOption |= FS_CREATE;
+#if !defined(_NAND_FLASH_BOOTING_) && !defined(__FS_SYSDRV_ON_NAND__)
+    openOption |= FS_PROTECTION_MODE;
+#endif
+    openOption |= FS_READ_WRITE;
+
+    MD_TRC_OTP_FAKE_WRITE(Offset, Offset + Length - 1);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const WCHAR*)filename, openOption);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        if (nvram_ptr->state != NVRAM_STATE_READY)
+        {
+            MD_TRC_OTP_INIT();
+            /* Reinitialize, Create always, No committed */
+            openOption |= FS_CREATE_ALWAYS;
+            NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+            hFile = FS_Open((const WCHAR*)filename, openOption);
+            NVRAM_FS_END(FS_OP_OPEN,hFile);
+            if (hFile >= FS_NO_ERROR)
+            {
+                buffer_with_chksum = (kal_uint8*) get_ctrl_buffer(Length);
+                NVRAM_EXT_ASSERT(buffer_with_chksum != NULL,(kal_uint32)buffer_with_chksum, NVRAM_LOC_BUFFER_PTR_IS_NULL_2, 0, FS_Close(hFile));
+                memset(buffer_with_chksum, 0x00, Length);
+                /* init fake OTP file */
+                NVRAM_FS_START(FS_OP_WRITE);
+                Ret = FS_Write(hFile, buffer_with_chksum, ldi->size, &len);
+                NVRAM_FS_END(FS_OP_WRITE,Ret);
+                NVRAM_EXT_ASSERT(Ret >= FS_NO_ERROR,Ret, NVRAM_LOC_WRITE_FILE_FAIL_1, 0);
+                free_ctrl_buffer(buffer_with_chksum);
+                NVRAM_FS_START(FS_OP_CLOSE);
+                Ret = FS_Close(hFile);
+                NVRAM_FS_END(FS_OP_CLOSE,Ret);
+                return FS_NO_ERROR;
+            }
+        }
+        else
+            return FS_FLASH_OTP_WRITEFAIL;
+    }
+    NVRAM_EXT_ASSERT(hFile >= FS_NO_ERROR,(kal_uint32)hFile, NVRAM_LOC_CREAT_FILE_FAIL_1, 0);
+
+    /* start write */
+
+    /* Update one of the sections if linear-fixed */
+    NVRAM_FS_START(FS_OP_GETFILESIZE);
+    Ret = FS_GetFileSize(hFile, &len);
+    NVRAM_FS_END(FS_OP_GETFILESIZE,Ret);
+    if ((Ret == FS_NO_ERROR) && (len == 0))
+    {
+        if (nvram_ptr->state != NVRAM_STATE_READY)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            Ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,Ret);
+
+            MD_TRC_OTP_INIT();
+            /* Reinitialize, Create always, No committed */
+            openOption |= FS_CREATE_ALWAYS;
+            NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+            hFile = FS_Open((const WCHAR*)filename, openOption);
+            NVRAM_FS_END(FS_OP_OPEN,hFile);
+            if (hFile >= FS_NO_ERROR)
+            {
+                buffer_with_chksum = (kal_uint8*) get_ctrl_buffer(Length);
+                NVRAM_EXT_ASSERT(buffer_with_chksum != NULL,(kal_uint32)buffer_with_chksum, NVRAM_LOC_BUFFER_PTR_IS_NULL_3, 0, FS_Close(hFile));
+                memset(buffer_with_chksum, 0x00, Length);
+                /* init fake OTP file */
+                NVRAM_FS_START(FS_OP_WRITE);
+                Ret = FS_Write(hFile, buffer_with_chksum, ldi->size, &len);
+                NVRAM_FS_END(FS_OP_WRITE,Ret);
+                NVRAM_EXT_ASSERT(Ret >= FS_NO_ERROR,Ret, NVRAM_LOC_WRITE_FILE_FAIL_2, 0, FS_Close(hFile));
+                free_ctrl_buffer(buffer_with_chksum);
+                NVRAM_FS_START(FS_OP_CLOSE);
+                Ret = FS_Close(hFile);
+                NVRAM_FS_END(FS_OP_CLOSE,Ret);
+                return FS_NO_ERROR;
+            }
+        }
+        else
+            return FS_FLASH_OTP_WRITEFAIL;
+
+    }
+
+    /* seek to the section start in this record */
+    NVRAM_FS_START(FS_OP_SEEK);
+    Ret = FS_Seek(hFile, Offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,Ret);
+    if (Ret >= FS_NO_ERROR)
+    {
+        kal_uint8 i = 0;
+
+        MD_TRC_OTP_AREA_ALLOW(Ret, Ret + Length - 1);
+        buffer_with_chksum = (kal_uint8*) get_ctrl_buffer(Length);
+        NVRAM_EXT_ASSERT(buffer_with_chksum != NULL,(kal_uint32)buffer_with_chksum, NVRAM_LOC_BUFFER_PTR_IS_NULL_4, 0);
+        NVRAM_FS_START(FS_OP_READ);
+        Ret = FS_Read(hFile, buffer_with_chksum, Length, &len);
+        NVRAM_FS_END(FS_OP_READ,Ret);
+        for (i = 0; i < Length; ++i)
+        {
+            if (buffer_with_chksum[i])
+            {
+                MD_TRC_OTP_PROGRAM_TWICE(Offset, Offset + Length - 1);
+                free_ctrl_buffer(buffer_with_chksum);
+                NVRAM_FS_START(FS_OP_CLOSE);
+                Ret = FS_Close(hFile);
+                NVRAM_FS_END(FS_OP_CLOSE,Ret);
+                return FS_FLASH_OTP_WRITEFAIL;
+            }
+        }
+
+        kal_mem_cpy(buffer_with_chksum, BufferPtr, Length);
+        NVRAM_FS_START(FS_OP_SEEK);
+        Ret = FS_Seek(hFile, Offset, FS_FILE_BEGIN);
+        NVRAM_FS_END(FS_OP_SEEK,Ret);
+        NVRAM_FS_START(FS_OP_WRITE);
+        Ret = FS_Write(hFile, buffer_with_chksum, Length, &len);
+        NVRAM_FS_END(FS_OP_WRITE,Ret);
+        NVRAM_EXT_ASSERT(Ret == FS_NO_ERROR,Ret, NVRAM_LOC_WRITE_FILE_FAIL_3, 0, FS_Close(hFile));
+        if (Ret != FS_NO_ERROR)
+        {
+            free_ctrl_buffer(buffer_with_chksum);
+            NVRAM_FS_START(FS_OP_CLOSE);
+            Ret = FS_Close(hFile);
+            NVRAM_FS_END(FS_OP_CLOSE,Ret);
+            return Ret;
+        }
+        free_ctrl_buffer(buffer_with_chksum);
+    }
+    else
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        Ret = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,Ret);
+        MD_TRC_OTP_OVERSCOPE(Offset, Offset + Length - 1);
+        return FS_FLASH_OTP_OVERSCOPE;
+    }
+
+    NVRAM_FS_START(FS_OP_CLOSE);
+    Ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,Ret);
+    return FS_NO_ERROR;
+}
+#endif /* __MTK_TARGET__ */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_otp_data_item
+ * DESCRIPTION
+ * PARAMETERS
+ *  ldi             [?]
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+nvram_errno_enum nvram_read_otp_data_item(
+                    nvram_ltable_entry_struct *ldi,
+                    kal_uint16 rec_index,
+                    kal_uint16 rec_amount,
+                    kal_uint8 *buffer,
+                    kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 offset = 0;
+    kal_int32 result;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (!NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    if (ldi->size * rec_amount > buffer_size)
+    {
+        return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+
+    offset = nvram_get_otp_offset(ldi->LID);
+
+    offset += (rec_index - 1) * ldi->size;
+
+#ifndef __MTK_TARGET__
+    result = OTP_Read_FAKE(offset, buffer, ldi->size * rec_amount);
+#else
+    NVRAM_FS_START(FS_OP_OTPREAD);
+    result = FS_OTPRead(FS_DEVICE_TYPE_UNKNOWN, offset, buffer, ldi->size * rec_amount);
+    NVRAM_FS_END(FS_OP_OTPREAD,result);
+#endif
+
+    MD_TRC_OTP_READ_RESULT(result, offset, offset + ldi->size - 1);
+
+    if (result < FS_NO_ERROR)
+    {
+        return NVRAM_ERRNO_FAIL;
+    }
+    else
+    {
+        return NVRAM_ERRNO_SUCCESS;
+    }
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_otp_data_item
+ * DESCRIPTION
+ * PARAMETERS
+ *  ldi             [?]
+ *  index           [IN]
+ *  data            [?]
+ *  buffer_size     [IN]
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+
+static kal_int32 nvram_translate_otp_error_code(kal_int32 fs_err_code)
+{
+    // NVRAM_LOG1(TRACE_FUNC, OTP_WRITE_RESULT, fs_err_code);
+
+    switch (fs_err_code)
+    {
+        case FS_FLASH_OTP_UNKNOWERR:    /* -123 */
+            return NVRAM_ERRNO_OTP_UNKNOW;
+        case FS_FLASH_OTP_OVERSCOPE:    /* -124 */
+            return NVRAM_ERRNO_OTP_OVERSCOPE;
+        case FS_FLASH_OTP_WRITEFAIL:    /* -125 */
+            return NVRAM_ERRNO_OTP_WRITEFAIL;
+        default:
+            if (fs_err_code < FS_NO_ERROR)
+                return NVRAM_ERRNO_FAIL;
+            else
+                return NVRAM_ERRNO_SUCCESS;
+
+    }
+    return NVRAM_IO_ERRNO_OK;
+}
+
+nvram_errno_enum nvram_write_otp_data_item(
+                    nvram_ltable_entry_struct *ldi,
+                    kal_uint16 index,
+                    kal_uint8 *data,
+                    kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 offset;
+    nvram_errno_enum result=NVRAM_IO_ERRNO_OK;
+    kal_uint32 fs_otp_size;
+    #ifdef __MTK_TARGET__
+    kal_int32 ret= FS_NO_ERROR;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (!NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    offset = nvram_get_otp_offset(ldi->LID);
+    offset += (index - 1) * ldi->size;
+
+#ifdef __MTK_TARGET__
+    NVRAM_FS_START(FS_OP_OTPQUERYLENGTH);
+    ret = FS_OTPQueryLength(FS_DEVICE_TYPE_UNKNOWN, &fs_otp_size);
+    NVRAM_FS_END(FS_OP_OTPQUERYLENGTH,ret);
+
+#else
+    fs_otp_size = 256;
+#endif
+
+    if ((offset + ldi->size) > fs_otp_size)
+    {
+        return NVRAM_ERRNO_OTP_INVALID_RANGE;
+    }
+
+#ifndef __MTK_TARGET__
+    result = OTP_Write_FAKE(offset, data, ldi->size);
+#else /* __MTK_TARGET__ */
+    {
+        kal_uint8 *buffer = (kal_uint8*) get_ctrl_buffer(ldi->size);
+        NVRAM_EXT_ASSERT(buffer != NULL,(kal_uint32)buffer, NVRAM_LOC_BUFFER_PTR_IS_NULL_5, 0);
+
+        do {
+            kal_uint32 i = 0;
+            kal_uint8 is_empty = 1;
+            kal_int32 fs_result = FS_NO_ERROR;
+            NVRAM_FS_START(FS_OP_OTPREAD);
+            ret = FS_OTPRead(FS_DEVICE_TYPE_UNKNOWN, offset, buffer, ldi->size);
+            NVRAM_FS_END(FS_OP_OTPREAD,ret);
+
+            for (; i < ldi->size; i++)
+            {
+                if ((buffer[i] != 0xFF && buffer[i] != 0x00) || (buffer[i] != buffer[0]))
+                {
+                    //NVRAM_LOG2(TRACE_FUNC, OTP_PROGRAM_TWICE, offset, offset + ldi->size - 1);
+                    result = NVRAM_ERRNO_OTP_WRITETWICE;
+                    goto error_return;
+                }
+
+                if ((data[i] != 0xFF && data[i] != 0x00) || data[i] != data[0])
+                {
+                    is_empty = 0;
+                }
+            }
+
+            if (is_empty)
+            {
+                result = NVRAM_ERRNO_OTP_INVALID_INPUT;
+                break;
+            }
+            NVRAM_FS_START(FS_OP_OTPWRITE);
+            fs_result = FS_OTPWrite(FS_DEVICE_TYPE_UNKNOWN, offset, data, ldi->size);
+            NVRAM_FS_END(FS_OP_OTPWRITE,fs_result);
+
+            if (fs_result < 0)
+            {
+                result = nvram_translate_otp_error_code(fs_result);
+                break;
+            }
+
+            NVRAM_FS_START(FS_OP_OTPREAD);
+            ret = FS_OTPRead(FS_DEVICE_TYPE_UNKNOWN, offset, buffer, ldi->size);
+            NVRAM_FS_END(FS_OP_OTPREAD,ret);
+
+            if (kal_mem_cmp(data, buffer, ldi->size) != 0)
+            {
+                result=NVRAM_ERRNO_OTP_WRITEFAIL;
+                break;
+            }
+
+        } while(0);
+
+error_return:
+        free_ctrl_buffer(buffer);
+    }
+#endif /* __MTK_TARGET__ */
+
+    return result;
+}
+
+#endif /* __NVRAM_OTP__ */
+
+#if defined(__TC01__) && defined (__MTK_TARGET__) && defined(LGE_FW_COMMON)
+#include "lge_fw_factory_data.h"
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_raw_disk
+ * DESCRIPTION
+ * PARAMETERS
+ *  ldi             [?]
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+nvram_errno_enum nvram_read_custom_disk(
+                    nvram_ltable_entry_struct *ldi,
+                    kal_uint16 rec_index,
+                    kal_uint16 rec_amount,
+                    kal_uint8 *buffer,
+                    kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 imei[NVRAM_EF_IMEI_IMEI_SIZE << 1];
+    kal_int32 i, j;
+    kal_bool result = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/    
+    switch(ldi->LID)
+    {
+    case NVRAM_EF_IMEI_IMEISV_LID:
+
+        if (buffer && buffer_size < NVRAM_EF_IMEI_IMEI_SIZE * rec_amount)
+        {
+            NVRAM_EXT_ASSERT(buffer_size < NVRAM_EF_IMEI_IMEI_SIZE * rec_amount,buffer_size, NVRAM_LOC_BUFFER_SIZE_NOT_ENOUGH_1, 0);
+            return NVRAM_IO_ERRNO_INVALID_SIZE;
+        }
+
+        if (buffer)
+        {
+            memset(buffer, 0, NVRAM_EF_IMEI_IMEI_SIZE * rec_amount);
+        }
+
+        for (i = 0 ; i < rec_amount ; i++)
+        {
+            memset(imei, 0, NVRAM_EF_IMEI_IMEI_SIZE << 1);
+
+            if ((rec_index  + i) == 1)
+            {
+                result = LGE_FacReadImei(1, imei);
+            }
+            else if ((rec_index  + i) == 2)
+            {
+                result = LGE_FacReadImei(0, imei);
+            }
+            else
+            {
+                result = LGE_FacReadImei(2, imei);
+            }
+
+            if (result == KAL_FALSE)
+            {
+                kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "[ws_nvram] read imei fail, result = %d, rec_index = %d", result, rec_index);
+                return NVRAM_ERRNO_FAIL;
+            }
+
+            kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "[ws_nvram] imei(wise format): %02x %02x %02x %02x %02x %02x %02x %02x",
+                                   imei[0], imei[1], imei[2], imei[3], imei[4], imei[5], imei[6], imei[7]);
+
+            if (buffer)
+            {
+                kal_uint8 *tmp = buffer + NVRAM_EF_IMEI_IMEI_SIZE * i;
+
+                for (j = 0 ; j < NVRAM_EF_IMEI_IMEI_SIZE ; j++)
+                {
+                    tmp[j] = (imei[j << 1] & 0x0F) | ((imei[(j << 1) + 1] & 0x0F) << 4);
+                }
+                kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "[ws_nvram] imei(mtk format): %02x %02x %02x %02x %02x %02x %02x %02x",
+                                       tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7]);
+            }
+        }
+
+        break;
+    default:
+        NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)(ldi->LID), NVRAM_LOC_INVALID_LID_1, 0);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_raw_disk
+ * DESCRIPTION
+ * PARAMETERS
+ *  ldi             [?]
+ *  index           [IN]
+ *  data            [?]
+ *  buffer_size     [IN]
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+nvram_errno_enum nvram_write_custom_disk(
+                    nvram_ltable_entry_struct *ldi,
+                    kal_uint16 rec_index,
+                    kal_uint8 *data,
+                    kal_uint32 buffer_size,
+                    kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 imei[NVRAM_EF_IMEI_IMEI_SIZE << 1];
+    kal_int32 i;
+    kal_bool result = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    switch(ldi->LID)
+    {
+    case NVRAM_EF_IMEI_IMEISV_LID:
+
+        kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "[ws_nvram] imei(mtk format): %02x %02x %02x %02x %02x %02x %02x %02x",
+                               data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
+
+        for (i = 0 ;i < NVRAM_EF_IMEI_IMEI_SIZE ;i++)
+        {
+            imei[i << 1] = data[i] & 0x0F;
+            imei[(i << 1) + 1] = (data[i] & 0xF0) >> 4;
+        }
+
+        kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "[ws_nvram] imei(wise format): %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
+                               imei[0], imei[1], imei[2], imei[3], imei[4], imei[5], imei[6], imei[7],
+                               imei[8], imei[9], imei[10], imei[11], imei[12], imei[13], imei[14], imei[15]);
+
+        if (is_init)
+        {
+            return NVRAM_IO_ERRNO_OK;
+        }
+        else
+        {
+            if (rec_index == 1)
+            {
+                result = LGE_FacWriteImei(1, imei, KAL_TRUE);
+            }
+            else if (ldi->total_records > 1 && rec_index == 2)
+            {
+                result = LGE_FacWriteImei(0, imei, KAL_TRUE);
+            }
+            else if (ldi->total_records > 1 && rec_index == 3)
+            {
+                result = LGE_FacWriteImei(2, imei, KAL_TRUE);
+            }
+            else
+            {
+                NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)rec_index, NVRAM_LOC_INVALID_RECORD_1, 0);
+                return NVRAM_IO_ERRNO_INVALID_RECORD;
+            }
+        }
+
+        if (result == KAL_FALSE)
+        {
+            //use kal_trace
+            MD_TRC_EX_IO_RECOVER_IMAGE_BY_LID(ldi->LID, rec_index, __LINE__);
+            return NVRAM_ERRNO_FAIL;
+        }
+
+        break;
+    default:
+        NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)ldi->LID, NVRAM_LOC_INVALID_LID_2, 0);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+
+    }
+    return NVRAM_IO_ERRNO_OK;
+}
+#endif /* defined(__TC01__) && defined (__MTK_TARGET__) && defined(LGE_FW_COMMON) */
+
+#ifdef __NVRAM_BACKUP_DISK_FAT__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_backup_disk_init
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ * RETURN VALUES
+ *****************************************************************************/
+nvram_errno_enum nvram_init_backup_disk(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* check nvram root folder, if not exist, create it! */
+    NVRAM_FS_MAKE_BACKUP_ROOT_PATH(filename);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if (hFile >= FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+    }
+    else if (hFile == FS_FILE_NOT_FOUND || hFile == FS_PATH_NOT_FOUND)
+    {
+        NVRAM_FS_START_EX(FS_OP_CREATEDIR,filename);
+        result = FS_CreateDir((const kal_wchar*)filename);
+        NVRAM_FS_END(FS_OP_CREATEDIR,result);
+        return NVRAM_ERRNO_IMAGE_EMPTY;
+    }
+    else
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)hFile, NVRAM_LOC_OPEN_BACKUP_DISK_FAIL, 0);
+        return NVRAM_ERRNO_IMAGE_BROKEN;
+    }
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_image_by_lid
+ * DESCRIPTION
+ *  to recover the image from backup partition
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  return NVRAM_ERRNO_SUCCESS if no error
+ *****************************************************************************/
+nvram_errno_enum nvram_recover_image_by_lid(nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 error = 0;
+    FS_FileOpenHint Hint = {0};
+    NVRAM_FILE_NAME nvramname;
+    kal_int32 file_size = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (!NVRAM_IS_LID_VALID(ldi->LID))
+    {
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+    file_size = nvram_drv_fat_get_record_size(nvramname, &Hint, NVRAM_NVD_BAK);
+
+    if (file_size < FS_NO_ERROR)
+    {
+        MD_TRC_EX_IO_RECOVER_IMAGE_BY_LID(ldi->LID, file_size, __LINE__);
+        return NVRAM_ERRNO_IMAGE_DATA_NOT_EXIST;
+    }
+    else if (file_size != (kal_int32)(ldi->size + NVRAM_CHKSUM_SIZE) * ldi->total_records )
+    {
+        MD_TRC_EX_IO_RECOVER_IMAGE_BY_LID(ldi->LID, file_size, __LINE__);
+        return NVRAM_ERRNO_IMAGE_BROKEN;
+    }
+
+    error = nvram_drv_fat_backup(ldi, KAL_FALSE);
+
+    MD_TRC_EX_IO_RECOVER_IMAGE_BY_LID(ldi->LID, error, __LINE__);
+
+    if (error == FS_NO_ERROR)
+    {
+        return NVRAM_ERRNO_SUCCESS;
+    }
+    else
+    {
+        return NVRAM_ERRNO_IMAGE_BROKEN;
+    }
+}
+
+
+#elif defined(__NVRAM_BACKUP_DISK_RAW__)
+
+#if !defined(__NVRAM_SIMULATE_BACKUP_DISK__)    // Target
+#include "flash_disk.h"
+#else                                           // MoDIS simulate
+#define BACKUP_DISK_STATUS_INIT 0
+#define BACKUP_DISK_STATUS_EMPTY 1
+#define BACKUP_DISK_STATUS_LOCK 2
+
+#define RAW_DISK_ERR_NONE 0
+#define RAW_DISK_ERR_WRONG_ADDRESS 1
+#define RAW_DISK_ERR_NO_SPACE  2
+#define RAW_DISK_ERR_LOCKED 3  //only for backup partition
+#define RAW_DISK_ERR_NO_INIT 4  //only for backup partition
+#define RAW_DISK_ERR_PROG_FAIL 5
+#define RAW_DISK_ERR_ERASE_FAIL 6
+#define RAW_DISK_ERR_UNKNOWN 7
+
+#define DATA_MAX_NUMBER 64
+static kal_uint16 ID_ARRAY[DATA_MAX_NUMBER];
+static kal_uint16 DATA_BUFFER[DATA_MAX_NUMBER][1024];
+static kal_uint16 DATA_NUMBER = 0;
+static kal_int32 DATA_STATUS = BACKUP_DISK_STATUS_EMPTY;
+
+void initBackupPartition(void)
+{
+    DATA_NUMBER = 0;
+    DATA_STATUS = BACKUP_DISK_STATUS_INIT;
+    memset(DATA_BUFFER, 0, sizeof(DATA_BUFFER));
+}
+
+kal_int32 readBackupPartition(kal_uint16 ID, kal_uint8* data_ptr, kal_uint32 len)
+{
+    kal_int32 i;
+
+    if (DATA_STATUS != BACKUP_DISK_STATUS_LOCK)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE,DATA_STATUS, NVRAM_LOC_ACCESS_BACKUP_FILE_FAIL_1, 0);
+        return RAW_DISK_ERR_UNKNOWN;
+    }
+
+    for (i = 0 ; i < DATA_MAX_NUMBER ;i++)
+    {
+        if (ID_ARRAY[i] == ID)
+        {
+            memcpy(data_ptr, DATA_BUFFER[i], len);
+            return len;
+        }
+    }
+    return RAW_DISK_ERR_UNKNOWN;
+}
+
+kal_int32 writeBackupPartition(kal_uint16 ID, kal_uint8* data_ptr, kal_uint32 len)
+{
+
+    if (DATA_STATUS != BACKUP_DISK_STATUS_INIT)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE,DATA_STATUS, NVRAM_LOC_ACCESS_BACKUP_FILE_FAIL_2, 0);
+        return RAW_DISK_ERR_UNKNOWN;
+    }
+
+    if (DATA_NUMBER >= DATA_MAX_NUMBER)
+    {
+        return RAW_DISK_ERR_NO_SPACE;
+    }
+
+    ID_ARRAY[DATA_NUMBER] = ID;
+    memcpy(DATA_BUFFER[DATA_NUMBER], data_ptr, len);
+    DATA_NUMBER++;
+    return RAW_DISK_ERR_NONE;
+}
+
+void lockBackupPartition(void)
+{
+    DATA_STATUS = BACKUP_DISK_STATUS_LOCK;
+}
+
+kal_int32 getBackupPartitionStatus(void)
+{
+    return DATA_STATUS;
+}
+
+#endif  /* #if defined(__NVRAM_UNIT_TEST__) && !defined(__MTK_TARGET__) */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_backup_disk_init
+ * DESCRIPTION
+ *  to init the backup disk and check the error
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  return NVRAM_ERRNO_SUCCESS if no error
+ *****************************************************************************/
+nvram_errno_enum nvram_init_backup_disk(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 status = getBackupPartitionStatus();
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* under normal mode, we would check the back disk status,
+       if the status is BACKUP_DISK_STATUS_INIT, that means power lost during backup procedure */
+
+    kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "nvram_init_backup_disk %d", status);
+
+    if (status == BACKUP_DISK_STATUS_EMPTY)
+    {
+        return NVRAM_ERRNO_IMAGE_EMPTY;
+    }
+    else if (status == BACKUP_DISK_STATUS_LOCK)
+    {
+        return NVRAM_ERRNO_SUCCESS;
+    }
+    else
+    {
+        if (NORMAL_BOOT == stack_query_boot_mode())
+        {
+//            ASSERT(0); // design change: backup to backup partition can be execute in normal mode
+        }
+        return NVRAM_ERRNO_IMAGE_BROKEN;
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_image
+ * DESCRIPTION
+ *  to create the image into backup partition
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  return NVRAM_ERRNO_SUCCESS if no error
+ *****************************************************************************/
+nvram_errno_enum nvram_create_image(nvram_image_type_enum image_type)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 *buffer;
+    kal_int32 error = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    initBackupPartition();
+
+    /* just clear the data in backup partition */
+    if (image_type == NVRAM_IMAGE_TYPE_EMPTY)
+    {
+        lockBackupPartition();
+        return NVRAM_ERRNO_SUCCESS;
+    }
+
+    buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+        kal_bool match = KAL_FALSE;
+
+
+        if ((image_type & NVRAM_IMAGE_TYPE_CALIBRAT) && NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            match = KAL_TRUE;
+        }
+
+        if ((image_type & NVRAM_IMAGE_TYPE_IMEI) && ldi->LID == NVRAM_EF_IMEI_IMEISV_LID)
+        {
+            match = KAL_TRUE;
+        }
+
+        if (match)
+        {
+            kal_uint8 chksum[8];
+
+            if (ldi->size > MAX_NVRAM_RECORD_SIZE - NVRAM_CHKSUM_SIZE - NVRAM_FILE_LEN)
+            {
+                free_ctrl_buffer(buffer);
+                NVRAM_EXT_ASSERT(KAL_FALSE,ldi->size, NVRAM_LOC_INVALID_LID_SIZE_1, 0, free_ctrl_buffer(buffer));
+                continue;
+            }
+
+            nvram_read_data_item(ldi, 1, ldi->total_records, buffer, MAX_NVRAM_RECORD_SIZE);
+
+            nvram_util_caculate_checksum(buffer, ldi->total_records * ldi->size, chksum);
+	    kal_mem_cpy((void*)(buffer+ldi->total_records * ldi->size), chksum, NVRAM_CHKSUM_SIZE);
+
+            sprintf((char*)(buffer + (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE)), "%s%s", ldi->fileprefix, ldi->fileverno);
+
+            error = writeBackupPartition(ldi->LID, buffer, ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN);
+
+            kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "nvram_create_image %d %d", image_type, error);
+
+            if (error != RAW_DISK_ERR_NONE)
+            {
+                free_ctrl_buffer(buffer);
+                NVRAM_EXT_ASSERT(KAL_FALSE,error, NVRAM_LOC_ACCESS_BACKUP_FILE_FAIL_3, 0, free_ctrl_buffer(buffer));
+                return NVRAM_ERRNO_IMAGE_BROKEN;
+            }
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    free_ctrl_buffer(buffer);
+
+    lockBackupPartition();
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_image
+ * DESCRIPTION
+ *  to recover the image from backup partition
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  return NVRAM_ERRNO_SUCCESS if no error
+ *****************************************************************************/
+nvram_errno_enum nvram_recover_image(nvram_image_type_enum image_type)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 i;
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 *buffer;
+    kal_int32 error = 0;
+    kal_int32 status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* just clear the data in backup partition */
+    if (image_type == NVRAM_IMAGE_TYPE_EMPTY)
+    {
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    status = getBackupPartitionStatus();
+
+    if (status != BACKUP_DISK_STATUS_LOCK)
+    {
+        if (status == BACKUP_DISK_STATUS_EMPTY)
+        {
+            return NVRAM_ERRNO_IMAGE_EMPTY;
+        }
+        else if (status == BACKUP_DISK_STATUS_INIT)
+        {
+            return NVRAM_ERRNO_IMAGE_BROKEN;
+        }
+
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+        kal_bool match = KAL_FALSE;
+
+
+        if ((image_type & NVRAM_IMAGE_TYPE_CALIBRAT) && NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            match = KAL_TRUE;
+        }
+
+        if ((image_type & NVRAM_IMAGE_TYPE_IMEI) && ldi->LID == NVRAM_EF_IMEI_IMEISV_LID)
+        {
+            match = KAL_TRUE;
+        }
+
+        if (match)
+        {
+            kal_uint8 chksum1[8], *chksum2;
+            kal_char filename[NVRAM_FILE_LEN];
+
+            if (ldi->size > MAX_NVRAM_RECORD_SIZE - NVRAM_CHKSUM_SIZE - NVRAM_FILE_LEN)
+            {
+                NVRAM_EXT_ASSERT(KAL_FALSE,ldi->size, NVRAM_LOC_INVALID_LID_SIZE_2, 0, free_ctrl_buffer(buffer));
+                continue;
+            }
+
+            error = readBackupPartition(ldi->LID, buffer, ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN);
+
+            kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "nvram_recover_image %d %d %d", ldi->LID, image_type, error);
+
+            if (error != (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN))
+            {
+                /* cannot found the data in back partition, just skip it */
+                continue;
+            }
+
+             nvram_util_caculate_checksum(buffer, ldi->total_records * ldi->size, chksum1);
+	      chksum2  = (kal_uint8*) (buffer + ldi->total_records * ldi->size);
+
+            if (kal_mem_cmp(chksum1, chksum2, NVRAM_CHKSUM_SIZE)!=0)
+            {
+                free_ctrl_buffer(buffer);
+                NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)(*chksum2), NVRAM_LOC_INVALID_CHECKSUM_1, (kal_uint32)(*chksum1), free_ctrl_buffer(buffer));
+                /* the data in back partition is corruptted, just skip it */
+                continue;
+            }
+
+            sprintf(filename, "%s%s", ldi->fileprefix, ldi->fileverno);
+
+            if (strcmp(filename, (char*)(buffer + (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE)))!= 0)
+            {
+                /* the verno number is changed */
+                continue;
+            }
+
+            for (i = 0; i < ldi->total_records; i++)
+            {
+                nvram_write_data_item(ldi, (kal_uint16)(i + 1), buffer + i * (ldi->size), KAL_FALSE);
+            }
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    free_ctrl_buffer(buffer);
+
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_verify_image
+ * DESCRIPTION
+ *  to verfiy the image from backup partition
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  return NVRAM_ERRNO_SUCCESS if no error
+ *****************************************************************************/
+nvram_errno_enum nvram_verify_image(nvram_image_type_enum image_type, kal_bool fast_verify)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 *buffer1, *buffer2;
+    kal_int32 error = NVRAM_ERRNO_SUCCESS;
+    kal_int32 status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    status = getBackupPartitionStatus();
+
+    if (status != BACKUP_DISK_STATUS_LOCK)
+    {
+        if (status == BACKUP_DISK_STATUS_EMPTY)
+        {
+            return NVRAM_ERRNO_IMAGE_EMPTY;
+        }
+        else if (status == BACKUP_DISK_STATUS_INIT)
+        {
+            return NVRAM_ERRNO_IMAGE_BROKEN;
+        }
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    if (fast_verify)
+    {
+        return NVRAM_ERRNO_SUCCESS;
+    }
+
+    buffer1 = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+    buffer2 = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+        kal_bool match = KAL_FALSE;
+
+
+        if ((image_type & NVRAM_IMAGE_TYPE_CALIBRAT) && NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            match = KAL_TRUE;
+        }
+
+        if ((image_type & NVRAM_IMAGE_TYPE_IMEI) && ldi->LID == NVRAM_EF_IMEI_IMEISV_LID)
+        {
+            match = KAL_TRUE;
+        }
+
+        if (match)
+        {
+            kal_uint8 chksum1[8], *chksum2;
+            kal_char filename[NVRAM_FILE_LEN];
+
+            if (ldi->size > MAX_NVRAM_RECORD_SIZE - NVRAM_CHKSUM_SIZE - NVRAM_FILE_LEN)
+            {
+                free_ctrl_buffer(buffer1);
+                free_ctrl_buffer(buffer2);
+                NVRAM_EXT_ASSERT(KAL_FALSE,ldi->size, NVRAM_LOC_INVALID_LID_SIZE_3, 0, free_ctrl_buffer(buffer1);free_ctrl_buffer(buffer2));
+                continue;
+            }
+
+            error = readBackupPartition(ldi->LID, buffer1, ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN);
+
+            kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "nvram_verify_image %d %d %d %d", ldi->LID, image_type, fast_verify, error);
+
+            if (error != (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN))
+            {
+                error = NVRAM_ERRNO_IMAGE_DATA_NOT_EXIST;
+                break;
+            }
+
+             nvram_util_caculate_checksum(buffer1, ldi->total_records * ldi->size, chksum1);
+
+	      chksum2  = (kal_uint8*) (buffer1 + ldi->total_records * ldi->size);
+
+            if (kal_mem_cmp(chksum1, chksum2, NVRAM_CHKSUM_SIZE)!=0)
+            {
+                error = NVRAM_ERRNO_IMAGE_BROKEN;
+                break;
+            }
+
+            sprintf(filename, "%s%s", ldi->fileprefix, ldi->fileverno);
+
+            if (strcmp(filename, (char*)(buffer1 + (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE)))!= 0)
+            {
+                /* the verno number is changed */
+                error = NVRAM_ERRNO_IMAGE_DATA_NOT_SYNC;
+                break;
+            }
+
+            nvram_read_data_item(ldi, 1, ldi->total_records, buffer2, MAX_NVRAM_RECORD_SIZE);
+
+            if (memcmp(buffer1, buffer2, ldi->total_records * ldi->size) != 0)
+            {
+                error = NVRAM_ERRNO_IMAGE_DATA_NOT_SYNC;
+                break;
+            }
+
+            error = NVRAM_ERRNO_SUCCESS;
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    free_ctrl_buffer(buffer1);
+    free_ctrl_buffer(buffer2);
+
+    return error;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_image
+ * DESCRIPTION
+ *  to recover the image from backup partition
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  return NVRAM_ERRNO_SUCCESS if no error
+ *****************************************************************************/
+nvram_errno_enum nvram_recover_image_by_lid(nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 i;
+    kal_uint8 *buffer;
+    kal_int32 error = 0;
+    kal_int32 status;
+    kal_uint8 chksum1[8], *chksum2;
+    kal_char filename[NVRAM_FILE_LEN];
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (!NVRAM_IS_LID_VALID(ldi->LID))
+    {
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    status = getBackupPartitionStatus();
+
+    if (status != BACKUP_DISK_STATUS_LOCK)
+    {
+        MD_TRC_EX_IO_RECOVER_IMAGE_BY_LID(ldi->LID, status, __LINE__);
+
+        if (status == BACKUP_DISK_STATUS_EMPTY)
+        {
+            return NVRAM_ERRNO_IMAGE_EMPTY;
+        }
+        else if (status == BACKUP_DISK_STATUS_INIT)
+        {
+            return NVRAM_ERRNO_IMAGE_BROKEN;
+        }
+
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+    error = readBackupPartition(ldi->LID, buffer, ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN);
+
+    MD_TRC_EX_IO_RECOVER_IMAGE_BY_LID(ldi->LID, error, __LINE__);
+
+    if (error != (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE + NVRAM_FILE_LEN))
+    {
+        free_ctrl_buffer(buffer);
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    nvram_util_caculate_checksum(buffer, ldi->total_records * ldi->size, chksum1);
+    chksum2  = (kal_uint8*) (buffer + ldi->total_records * ldi->size);
+
+     if (kal_mem_cmp(chksum1, chksum2, NVRAM_CHKSUM_SIZE)!=0)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)(*chksum2), NVRAM_LOC_INVALID_CHECKSUM_2, (kal_uint32)(*chksum1), free_ctrl_buffer(buffer));
+    }
+
+    sprintf(filename, "%s%s", ldi->fileprefix, ldi->fileverno);
+
+    if (strcmp(filename, (char*)(buffer + (ldi->total_records * ldi->size + NVRAM_CHKSUM_SIZE)))!= 0)
+    {
+        free_ctrl_buffer(buffer);
+        /* the verno number is changed */
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    for (i = 0; i < ldi->total_records; i++)
+    {
+        nvram_write_data_item(ldi, (kal_uint16)(i + 1), buffer + i * (ldi->size), KAL_FALSE);
+    }
+
+    free_ctrl_buffer(buffer);
+
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+#endif /* __SYSDRV_BACKUP_DISK_FAT__ */
+
+
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+#include "sds_type.h"
+#include "SST_secure.h"
+#include "nvram_lid_statistics.h"
+
+extern kal_int32 SDS_PackNvramFilesToRecord(kal_uint32 index, const kal_uint16 **pFolderList, const kal_uint16 **pFileList, kal_int32 fileCount);
+extern kal_int32 SDS_RestoreNvramFilesFromRecord(kal_uint32 index);
+extern kal_int32 SDS_ReadNvramFileInRecord(kal_uint32 index, const kal_uint16 *pFilename, kal_uint8* pBuf, kal_uint32 bufLen);
+
+static kal_int32 nvram_sds_last_err;
+static kal_uint32 nvram_sds_last_line;
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drv_sds_throw_exception
+ * DESCRIPTION
+ *  record the error code and prompt message
+ * PARAMETERS
+ *  checksum        [?]
+ *  buf             [?]
+ *  size            [IN]
+ * RETURNS
+ *  checksum(?)
+ *****************************************************************************/
+void nvram_sds_throw_exception(kal_int32 err, kal_uint32 line)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_sds_last_err = err;
+    nvram_sds_last_line = line;
+
+    MD_TRC_FUNC_NVRAM_SDS_THROW_EXCEPTION(err, line);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_get_last_err
+ * DESCRIPTION
+ *  record the error code and prompt message
+ * PARAMETERS
+ *  checksum        [?]
+ *  buf             [?]
+ *  size            [IN]
+ * RETURNS
+ *  checksum(?)
+ *****************************************************************************/
+kal_int32 nvram_sds_get_last_err(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    return nvram_sds_last_err;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_lid_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_uint32 nvram_sds_fileprefix_2_int32(kal_char *fileprefix)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 result = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    result |= (kal_uint32) fileprefix[0] << 24;
+    result |= (kal_uint32) fileprefix[1] << 16;
+    result |= (kal_uint32) fileprefix[2] <<  8;
+    result |= (kal_uint32) fileprefix[3];
+
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_lid_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_sds_int32_2_fileprefix(kal_int32 index, kal_char *fileprefix)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    fileprefix[0] = (index >> 24) & 0xFF;
+    fileprefix[1] = (index >> 16) & 0xFF;
+    fileprefix[2] = (index >> 8) & 0xFF;
+    fileprefix[3] = index & 0xFF;
+    fileprefix[4] = 0;
+
+    return ;
+}
+
+
+#ifdef __NVRAM_SIMULATE_SECURE_DATA_STORAGE__
+
+#define SECURE_STORGE_PATH "Z:\\SECURE"
+
+kal_int32 SDS_AddRecord(SDS_PARTITION_TYPE partition, kal_uint32 index, const kal_uint8 *pData, kal_uint32 length, SDS_DP_TYPE dpType)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar filename[32];
+    kal_char fileprefix[5];
+    kal_int32 result = SDS_SUCCESS;
+    kal_int32 len;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+//    kal_wsprintf(filename, "%s\\%08X", SECURE_STORGE_PATH, index);
+
+    nvram_sds_int32_2_fileprefix(index, fileprefix);
+    kal_wsprintf(filename, "%s\\%s", SECURE_STORGE_PATH, fileprefix);
+
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    result = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+    if (result >= FS_NO_ERROR)
+    {
+        return SDS_RECORD_EXISTING;
+    }
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open(filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE_ALWAYS);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (FS_NO_ERROR > hFile)
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_WRITE);
+    result = FS_Write(hFile, (void *)pData, length, &len)
+    NVRAM_FS_END(FS_OP_WRITE,result);
+    if (FS_NO_ERROR > result)
+    {
+        result = SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,ret);
+
+    return result;
+
+}
+
+kal_int32 SDS_UpdateRecord(SDS_PARTITION_TYPE partition, kal_uint32 index, const kal_uint8 *pData, kal_uint32 length)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+    kal_int32 len;
+    kal_char fileprefix[5];
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+//    kal_wsprintf(filename, "%s\\%08X", SECURE_STORGE_PATH, index);
+    nvram_sds_int32_2_fileprefix(index, fileprefix);
+    kal_wsprintf(filename, "%s\\%s", SECURE_STORGE_PATH, fileprefix);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    result = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+    if (result < FS_NO_ERROR)
+    {
+        return SDS_NO_SPECIFIED_RECORD;
+    }
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open(filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE_ALWAYS);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (FS_NO_ERROR > hFile)
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_WRITE);
+    result = FS_Write(hFile, (void *)pData, length, &len);
+    NVRAM_FS_END(FS_OP_WRITE,result);
+    if (FS_NO_ERROR > result)
+    {
+        result = SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_WRITE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_WRITE,ret);
+
+    return result;
+
+}
+
+kal_int32 SDS_ReadRecord(SDS_PARTITION_TYPE partition, kal_uint32 index, kal_uint8 *pData, kal_uint32 length)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+    kal_int32 len;
+    kal_char fileprefix[5];
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    //kal_wsprintf(filename, "%s\\%08X", SECURE_STORGE_PATH, index);
+    nvram_sds_int32_2_fileprefix(index, fileprefix);
+    kal_wsprintf(filename, "%s\\%s", SECURE_STORGE_PATH, fileprefix);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    result = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+    if (result < FS_NO_ERROR)
+    {
+        return SDS_NO_SPECIFIED_RECORD;
+    }
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open(filename, FS_READ_ONLY | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (FS_NO_ERROR > hFile)
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_READ);
+    result = FS_Read(hFile, pData, length, &len);
+    NVRAM_FS_END(FS_OP_READ,result);
+    if (FS_NO_ERROR > result || len != length)
+    {
+        result = SDS_FAIL;
+    }
+    else
+    {
+        result = len;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,ret);
+
+    return result;
+}
+
+kal_int32 SDS_DelRecord(SDS_PARTITION_TYPE partition, kal_uint32 index)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+    kal_char fileprefix[5];
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    //kal_wsprintf(filename, "%s\\%08X", SECURE_STORGE_PATH, index);
+    nvram_sds_int32_2_fileprefix(index, fileprefix);
+    kal_wsprintf(filename, "%s\\%s", SECURE_STORGE_PATH, fileprefix);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    ret = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,ret);
+    if (ret < FS_NO_ERROR)
+    {
+        return SDS_NO_SPECIFIED_RECORD;
+    }
+    NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+    ret = FS_Delete(filename);
+    NVRAM_FS_END(FS_OP_DELETE,ret);
+
+    return result;
+}
+
+kal_int32 SDS_FormatPartition(SDS_PARTITION_TYPE partition)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar namepattern[32];
+    kal_int32 result = SDS_SUCCESS;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    kal_wsprintf(namepattern, "%s", SECURE_STORGE_PATH);
+    NVRAM_FS_START_EX(FS_OP_REMOVEDIR,namepattern);
+    ret = FS_RemoveDir(namepattern);
+    NVRAM_FS_END(FS_OP_REMOVEDIR,ret);
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+    return result;
+
+}
+
+kal_int32 SDS_GetRecordCount(SDS_PARTITION_TYPE partition)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar namepattern[32];
+    kal_int32 count = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    kal_wsprintf(namepattern, "%s", SECURE_STORGE_PATH);
+    NVRAM_FS_START_EX(FS_OP_COUNT,namepattern);
+    count = FS_Count((WCHAR *)namepattern, FS_DIR_TYPE |FS_FILE_TYPE|FS_RECURSIVE_TYPE,NULL,0);
+    NVRAM_FS_END(FS_OP_COUNT,count);
+
+    return count;
+
+}
+
+kal_int32 SDS_GetRecordList(SDS_PARTITION_TYPE partition, kal_uint32 *pIndexList, kal_uint32 num)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar namepattern[32];
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+    FS_DOSDirEntry fileinfo;
+    kal_uint32 count = 0;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_wsprintf(namepattern, "%s\\*", SECURE_STORGE_PATH);
+    NVRAM_FS_START_EX(FS_OP_FINDFIRST,namepattern);
+    hFile = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, filename, sizeof(filename));
+    NVRAM_FS_END(FS_OP_FINDFIRST,hFile);
+
+    if (hFile > 0)
+    {
+        do
+        {
+            if (count >=num)
+            {
+                result = SDS_FULL;
+                break;
+            }
+
+            pIndexList[count] = 0;
+            pIndexList[count] |= (kal_uint32) filename[0] << 24;
+            pIndexList[count] |= (kal_uint32) filename[1] << 16;
+            pIndexList[count] |= (kal_uint32) filename[2] <<  8;
+            pIndexList[count] |= (kal_uint32) filename[3];
+
+            //sscanf(filename, "%x", pIndexList[count]);
+            //pIndexList[count] = nvram_sds_fileprefix_2_int32(filename);
+            NVRAM_FS_START(FS_OP_FINDNEXT);
+            ret = FS_FindNext(hFile, &fileinfo, filename, sizeof(filename));
+            NVRAM_FS_END(FS_OP_FINDNEXT,ret);
+        }
+        while (ret == FS_NO_ERROR);
+        NVRAM_FS_START(FS_OP_FINDCLOSE);
+        ret = FS_FindClose(hFile);
+        NVRAM_FS_END(FS_OP_FINDCLOSE,ret);
+    }
+    else
+    {
+        result = SDS_FAIL;
+    }
+
+    return result;
+}
+
+kal_int32 SDS_GetRecordLen(SDS_PARTITION_TYPE partition, kal_uint32 index)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+    kal_int32 len;
+    kal_char fileprefix[5];
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+//    kal_wsprintf(filename, "%s\\%08X", SECURE_STORGE_PATH, index);
+    nvram_sds_int32_2_fileprefix(index, fileprefix);
+    kal_wsprintf(filename, "%s\\%s", SECURE_STORGE_PATH, fileprefix);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,namepattern);
+    ret = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,ret);
+    if (ret < FS_NO_ERROR)
+    {
+        return SDS_NO_SPECIFIED_RECORD;
+    }
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open(filename, FS_READ_ONLY | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (FS_NO_ERROR > hFile)
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_GETFILESIZE);
+    ret = FS_GetFileSize(hFile, &len);
+    NVRAM_FS_END(FS_OP_GETFILESIZE,result);
+    if (FS_NO_ERROR > ret)
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+
+    return len;
+
+}
+
+/* 1. Copy all files specified by 'pFileList' into one record  in SDS nvram partition
+   2. All files should be with full path
+   3. Target record in SDS will always be overwritten
+*/
+kal_int32 SDS_PackNvramFilesToRecord(kal_uint32 index, const kal_uint16 **pFolderList, const kal_uint16 **pFileList, kal_int32 fileCount)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar log_file[32];
+    kal_wchar src_file[32], dest_file[32];
+    kal_int32 result = SDS_SUCCESS;
+
+    kal_int32 i;
+    kal_uint32 len;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    kal_wsprintf(log_file, "%s\\path.txt", SECURE_STORGE_PATH);
+    NVRAM_FS_START_EX(FS_OP_OPEN,log_file);
+    hFile = FS_Open(log_file, FS_CREATE_ALWAYS | FS_READ_WRITE);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (hFile  < FS_NO_ERROR)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)hFile, NVRAM_LOC_CREAT_FILE_FAIL_2, 0);
+        return SDS_FAIL;
+    }
+
+    for (i = 0 ; i < fileCount ; i++)
+    {
+        kal_wsprintf(src_file, "%w\\%w", pFolderList[i], pFileList[i]);
+        kal_wsprintf(dest_file, "%s\\%w", SECURE_STORGE_PATH, pFileList[i]);
+
+//        FS_SetAttributes(dest_file, 0);
+        NVRAM_FS_START_EX(FS_OP_OPEN,dest_file);
+        ret = FS_Delete(dest_file);
+        NVRAM_FS_END(FS_OP_OPEN,ret);
+        NVRAM_FS_START_EX(FS_OP_MOVE,src_file);
+        result = FS_Move(src_file, dest_file, FS_MOVE_COPY, NULL, NULL, 0);
+        NVRAM_FS_END(FS_OP_MOVE,result);
+
+        if (result != FS_NO_ERROR)
+        {
+            result = SDS_FAIL;
+            break;
+        }
+        else
+        {
+            NVRAM_FS_START(FS_OP_WRITE);
+            ret = FS_Write(hFile, (void*) dest_file, 64, &len);
+            NVRAM_FS_END(FS_OP_WRITE,ret);
+            NVRAM_FS_START(FS_OP_WRITE);
+            ret = FS_Write(hFile, (void*) src_file, 64, &len);
+            NVRAM_FS_END(FS_OP_WRITE,ret);
+
+            result = SDS_SUCCESS;
+        }
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,ret);
+
+    return result;
+}
+
+/* 1. Restore all files packed in SDS record to their original position in the FAT
+   2. All files will be overwritten
+*/
+kal_int32 SDS_RestoreNvramFilesFromRecord(kal_uint32 index)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar src_file[32], dest_file[32];
+    kal_wchar log_file[32];
+    kal_int32 result = SDS_SUCCESS;
+
+    kal_uint32 len;
+    kal_int32 ret_src = FS_NO_ERROR;
+    kal_int32 ret_dst = FS_NO_ERROR;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    kal_wsprintf(log_file, "%s\\path.txt", SECURE_STORGE_PATH);
+    NVRAM_FS_START_EX(FS_OP_OPEN,log_file);
+    hFile = FS_Open(log_file, FS_READ_ONLY);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (hFile < FS_NO_ERROR)
+    {
+        return SDS_FAIL;
+    }
+
+    do
+    {
+        NVRAM_FS_START(FS_OP_READ);
+        ret_src = FS_Read(hFile, src_file, 64, &len);
+        NVRAM_FS_END(FS_OP_READ,ret_src);
+        NVRAM_FS_START(FS_OP_READ);
+        ret_dst = FS_Read(hFile, dest_file, 64, &len);
+        NVRAM_FS_END(FS_OP_READ,ret_dst);
+        if ( ret_src >= FS_NO_ERROR &&
+             ret_dst >= FS_NO_ERROR && len == 64)
+        {
+//            FS_SetAttributes(dest_file, 0);
+            NVRAM_FS_START_EX(FS_OP_DELETE, dest_file);
+            ret = FS_Delete(dest_file);
+            NVRAM_FS_END(FS_OP_DELETE,ret);
+            NVRAM_FS_START_EX(FS_OP_MOVE, src_file);
+            ret = FS_Move(src_file, dest_file, FS_MOVE_COPY, NULL, NULL, 0);
+            NVRAM_FS_END(FS_OP_MOVE,ret);
+        }
+        else
+        {
+            break;
+        }
+    } while (1);
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,ret);
+
+    return SDS_SUCCESS;
+}
+
+/* 1. Read a specific nvram file from packed data in SDS record
+   2. Return failure if no such file exists
+   3. The filename is with full path and should be exactly the same as that was provided in invoking SDS_PackNvramFilesToRecord (case sensitive)
+*/
+kal_int32 SDS_ReadNvramFileInRecord(kal_uint32 index, const kal_uint16 *pFilename, kal_uint8* pBuf, kal_uint32 bufLen)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+
+    kal_wchar *tmp;
+    kal_uint32 len;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    tmp = kal_wstrrchr(pFilename, '\\');
+
+    kal_wsprintf(filename, "%s\\%w", SECURE_STORGE_PATH, tmp);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open(filename, FS_READ_ONLY);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (hFile  >= FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_READ);
+        ret = FS_Read(hFile, pBuf, bufLen, &len);
+        NVRAM_FS_END(FS_OP_READ,ret);
+        if (ret < FS_NO_ERROR || len != bufLen )
+        {
+            result = SDS_FAIL;
+        }
+        else
+        {
+            result = SDS_SUCCESS;
+        }
+    }
+    else
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,ret);
+
+    if (result == SDS_SUCCESS)
+    {
+        return len;
+    }
+    else
+    {
+        return result;
+    }
+}
+
+kal_int32 SDS_GetNvramFileLengthInRecord(kal_uint32 index, const kal_uint16 *pFilename)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFile;
+    kal_wchar filename[32];
+    kal_int32 result = SDS_SUCCESS;
+
+    kal_wchar *tmp;
+    kal_uint32 size;
+    kal_int32 ret = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    tmp = kal_wstrrchr(pFilename, '\\');
+
+    kal_wsprintf(filename, "%s\\%w", SECURE_STORGE_PATH, tmp);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open(filename, FS_READ_ONLY);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (hFile  >= FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_GETFILESIZE);
+        ret = FS_GetFileSize(hFile, &size);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,ret);
+        if (ret < FS_NO_ERROR)
+        {
+            result = SDS_FAIL;
+        }
+        else
+        {
+            result = SDS_SUCCESS;
+        }
+    }
+    else
+    {
+        return SDS_FAIL;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    ret = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,ret);
+
+    if (result == SDS_SUCCESS)
+    {
+        return size;
+    }
+    else
+    {
+        return result;
+    }
+}
+
+
+#endif
+
+/* -----------------------------------------------------------------------------------
+ * |  prefix  | verno  | Flag    | Data Len | Record number | Data 1 + chksum |  Data2 + chksum
+ * -----------------------------------------------------------------------------------
+ *   4 Bytes   3 Bytes   3 Bytes    4 Bytes     2 bytes
+ */
+
+#define SDS_DATA_HEADER_LEN 16
+
+/*****************************************************************************
+ * FUNCTION
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+nvram_errno_enum nvram_sds_status(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (nvram_check_first_bootup_log("SDS") || SDS_GetRecordCount(SDS_PT_NVRAM_PARTITION) <= 0)
+    {
+        return NVRAM_ERRNO_SDS_EMPTY;
+    }
+
+    return NVRAM_ERRNO_SDS_READY;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_init_start
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+nvram_errno_enum nvram_sds_init_start(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+#ifdef __NVRAM_SIMULATE_SECURE_DATA_STORAGE__
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 ret = FS_NO_ERROR;
+#endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_create_first_bootup_log("SDS");
+    SDS_FormatPartition(SDS_PT_NVRAM_PARTITION);
+
+#ifdef __NVRAM_SIMULATE_SECURE_DATA_STORAGE__
+    kal_wsprintf(filename, "%s\\", SECURE_STORGE_PATH);
+    NVRAM_FS_START_EX(FS_OP_CREATEDIR,filename);
+    ret = FS_CreateDir(filename);
+    NVRAM_FS_END(FS_OP_CREATEDIR,ret);
+#endif
+
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_init_end
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+nvram_errno_enum nvram_sds_init_end(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_delete_first_bootup_log("SDS");
+
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+        #endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_read_data_item
+ * DESCRIPTION
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [IN]
+ *  buffer_size     [IN]
+ * RETURNS
+ *  NVRAM_IO_ERRNO_OK    if read successfully.
+ *  NVRAM_IO_ERRNO_CHK   if checksum error, and cannot be reset to default value.
+ *  NVRAM_IO_ERRNO_INIT  if checksum error, but successfully reset to default value.
+ *****************************************************************************/
+nvram_errno_enum nvram_sds_read_data_item
+    (nvram_ltable_entry_struct *ldi, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+//    FS_HANDLE hFile = 0;
+    kal_wchar *filename = (kal_wchar *)get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 chksum1[8], *chksum2;
+//    kal_uint16 chksum3 = 0;
+    kal_uint32 remainLen = 0;
+//    kal_uint32 len = 0;
+    kal_int32 section_size;
+    kal_int32 working_buffer_size = 0;
+    kal_uint8 *working_buffer = NULL;
+    kal_int32 result = NVRAM_IO_ERRNO_OK;
+    kal_int32 i;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if ((ldi->attr & NVRAM_ATTR_MSP)||(ldi->attr &NVRAM_ATTR_CONFIDENTIAL))
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + NVRAM_CHKSUM_SIZE);
+    }
+#else
+    if (ldi->attr &NVRAM_ATTR_CONFIDENTIAL)
+    {
+        /* 16 byte alignment */
+        remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + NVRAM_CHKSUM_SIZE);
+    }
+#endif
+
+    section_size = ldi->size + NVRAM_CHKSUM_SIZE + remainLen;
+    //working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    working_buffer_size = section_size * ldi->total_records;
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+
+    working_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    
+    //read the whole file
+    if (SDS_SUCCESS > (result = SDS_ReadNvramFileInRecord(0, filename, working_buffer, working_buffer_size)))
+    {
+        nvram_sds_throw_exception(result, __LINE__);
+        result = NVRAM_IO_ERRNO_SDS_FAIL;
+        goto final;
+    }
+    else if (result != working_buffer_size)
+    {
+        result = NVRAM_IO_ERRNO_SDS_FAIL;
+    }
+    else
+    {
+        result = NVRAM_IO_ERRNO_OK;
+    }
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    if (ldi->attr & NVRAM_ATTR_MSP)
+    {
+        for (i = 0; i < ldi->total_records; i++)
+        {
+            SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32) (working_buffer + section_size * i), section_size, nvram_ptr->secret_key, working_buffer + section_size * i);
+        }
+    }
+#endif
+
+    /* Handle multi-record reading */
+    for (i = 0; i < rec_amount; i++)
+    {
+
+        chksum2  = (kal_uint8*) (working_buffer + section_size * (i + rec_index - 1) + ldi->size);
+
+        /* checksum from content */
+       nvram_util_caculate_checksum(working_buffer + (section_size * (i + rec_index - 1)), ldi->size, chksum1);
+
+    	 if (kal_mem_cmp(chksum1, chksum2, NVRAM_CHKSUM_SIZE)!=0)
+        {
+            result = NVRAM_IO_ERRNO_CONTENT_BROKEN;
+            break;
+        }
+        kal_mem_cpy(buffer + ldi->size * i, working_buffer + section_size * (i + rec_index - 1), ldi->size);
+    }
+
+final:
+
+    MD_TRC_FUNC_NVRAM_SDS_READ_DATA_ITEM(ldi->LID, result);
+
+    if (working_buffer)
+    {
+        free_ctrl_buffer(working_buffer);
+    }
+
+    if (filename)
+    {
+        free_ctrl_buffer(filename);
+    }
+
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_err_handle
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_bool nvram_sds_err_handle(void)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 folder_index = 0;
+    kal_int32 file_size = 0;
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    kal_bool result = KAL_TRUE;
+    FS_FileOpenHint Hint;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint32 section_size = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* Must clear up Hint beforehand */
+    memset(&Hint, 0, sizeof(Hint));
+
+    do
+    {
+        if (!NVRAM_IS_CATEGORY_BACKUP_SDS(ldi->category))
+        {
+            continue;
+        }
+
+        folder_index = nvram_query_folder_index(ldi->category);
+
+        //NVRAM_ATTR_MULTIPLE would be turned-off if NVRAM_CATEGORY_BACKUP_SDS
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+        file_size = nvram_drv_fat_get_record_size(nvramname, &Hint, folder_index);
+
+        if ((ldi->attr & NVRAM_ATTR_MSP) ||(ldi->attr & NVRAM_ATTR_CONFIDENTIAL))
+        {
+            section_size = NVRAM_MSP_ALIGNMENT_CEILING(ldi->size + NVRAM_CHKSUM_SIZE);
+        }
+        else
+        {
+            section_size = ldi->size + NVRAM_CHKSUM_SIZE;
+        }
+
+        if ((file_size <= 0) || (file_size != (kal_int32)(section_size * ldi->total_records)))
+        {
+            result = nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records);
+        }
+
+        if (result != KAL_TRUE)
+        {
+            return result;
+        }
+    }while(nvram_util_next_data_item(&ldi));    
+    
+    return result;
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_backup
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+nvram_errno_enum nvram_sds_backup(void)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar *file_list_working_buffer;
+    kal_wchar *folder_list_working_buffer;
+    kal_int32 result = NVRAM_IO_ERRNO_OK;
+    kal_wchar **file_list, **folder_list;
+    nvram_ltable_entry_struct *ldi;
+    kal_int32 file_idx = 0, i;
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint32 retry_cnt = 0;
+    kal_bool result2 = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+TRY_AGAIN:
+
+    file_list = (kal_wchar **) get_ctrl_buffer(sizeof(kal_wchar *) * NVRAM_SDS_TOTAL);
+    folder_list = (kal_wchar **) get_ctrl_buffer(sizeof(kal_wchar *) * NVRAM_SDS_TOTAL);
+    file_list_working_buffer = (kal_wchar *) get_ctrl_buffer(sizeof(NVRAM_FILE_NAME) * NVRAM_SDS_TOTAL * 2);
+    folder_list_working_buffer = (kal_wchar *) get_ctrl_buffer(NVRAM_MAX_PATH_LEN * NVRAM_FOLDER_TOTAL * 2);
+
+    for (i = 0 ; i < NVRAM_FOLDER_TOTAL ; i++)
+    {
+        kal_wsprintf(folder_list_working_buffer + NVRAM_MAX_PATH_LEN * i , "%s", nvram_query_work_path(i));
+    }
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        if (!NVRAM_IS_CATEGORY_BACKUP_SDS(ldi->category))
+        {
+            continue;
+        }
+
+        if (file_idx >= NVRAM_SDS_TOTAL)
+        {
+            free_ctrl_buffer(file_list);
+            free_ctrl_buffer(folder_list);
+            free_ctrl_buffer(file_list_working_buffer);
+            free_ctrl_buffer(folder_list_working_buffer);
+            NVRAM_EXT_ASSERT(KAL_FALSE, file_idx, NVRAM_LOC_INVALID_INDEX_3, NVRAM_SDS_TOTAL);
+            result = NVRAM_IO_ERRNO_SDS_FAIL;
+            goto final;
+        }
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+        kal_wsprintf(file_list_working_buffer + sizeof(NVRAM_FILE_NAME) * file_idx ,
+            "%s", nvramname);
+        file_list[file_idx] = file_list_working_buffer + sizeof(NVRAM_FILE_NAME) * file_idx ;
+
+        folder_index = nvram_query_folder_index(ldi->category);
+        folder_list[file_idx] = folder_list_working_buffer + NVRAM_MAX_PATH_LEN * folder_index;
+
+        file_idx ++;
+    }while(nvram_util_next_data_item(&ldi));
+
+    if ((result = SDS_PackNvramFilesToRecord(0, (const kal_uint16**)folder_list, (const kal_uint16**)file_list, file_idx)) != SDS_SUCCESS)
+    {
+        if (!retry_cnt)
+        {
+            free_ctrl_buffer(file_list);
+            free_ctrl_buffer(folder_list);
+            free_ctrl_buffer(file_list_working_buffer);
+            free_ctrl_buffer(folder_list_working_buffer);
+            if ((result2 = nvram_sds_err_handle()) == KAL_TRUE)
+            {
+                result = NVRAM_IO_ERRNO_OK;
+                retry_cnt++;
+                file_idx = 0;
+                goto TRY_AGAIN;
+            }
+        }
+        
+        NVRAM_EXT_ASSERT(KAL_FALSE, result2, NVRAM_LOC_ACCESS_SDS_FILE_1, retry_cnt);
+        result = NVRAM_IO_ERRNO_SDS_FAIL;
+        goto final;
+    }
+    else
+    {
+        result = NVRAM_IO_ERRNO_OK;
+    }
+
+final:
+
+    MD_TRC_FUNC_NVRAM_SDS_FLUSH_IN(result);
+
+    free_ctrl_buffer(file_list);
+    free_ctrl_buffer(folder_list);
+    free_ctrl_buffer(file_list_working_buffer);
+    free_ctrl_buffer(folder_list_working_buffer);
+
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_restore
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+nvram_errno_enum nvram_sds_restore(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 result;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    MD_TRC_FUNC_NVRAM_SDS_FLUSH_OUT();
+
+    if ((result = SDS_RestoreNvramFilesFromRecord(0)) != SDS_SUCCESS)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE, result, NVRAM_LOC_ACCESS_SDS_FILE_2, 0);
+        return NVRAM_IO_ERRNO_SDS_FAIL;
+    }
+    else
+    {
+        return NVRAM_IO_ERRNO_OK;
+    }
+}
+
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_ap_bin_region_backup
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+nvram_errno_enum nvram_ap_bin_region_backup(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 result = FS_NO_ERROR;
+    #if defined(__NVRAM_BIN_REGION_SIMULATION__)
+    kal_int32 ret = FS_NO_ERROR;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_AP_BIN_REGION_BACKUP();
+
+    // Open specific device, to notify AP side
+#if defined(__NVRAM_BIN_REGION_SIMULATION__)
+    {
+        FS_HANDLE handle;
+        FS_DOSDirEntry fileinfo;
+        kal_wchar *filename = (kal_wchar *)get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar) * 3);
+        kal_wchar *src_path = (filename + NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+        kal_wchar *dst_path = (src_path + NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+        kal_uint32 bakFolder[2] = {NVRAM_NVD_CALI, NVRAM_NVD_IMPT};
+        kal_uint32 folder_idx;
+         NVRAM_FS_START_EX(FS_OP_CREATEDIR,L"Z:\\BIN_REGION");
+         ret = FS_CreateDir(L"Z:\\BIN_REGION");
+         NVRAM_FS_END(FS_OP_CREATEDIR,ret);
+        for(folder_idx = 0; folder_idx < 2; folder_idx++) {
+            kal_wsprintf(filename, "%s\\*", nvram_query_work_path(bakFolder[folder_idx]));
+            NVRAM_FS_START_EX(FS_OP_FINDFIRST,filename);
+            handle = FS_FindFirst(filename, 0, FS_ATTR_DIR, &fileinfo, filename, (NVRAM_MAX_PATH_LEN * sizeof(kal_wchar)));
+            NVRAM_FS_END(FS_OP_FINDFIRST,handle);
+            do {
+                kal_wsprintf(src_path, "%s\\%w", nvram_query_work_path(bakFolder[folder_idx]), filename);
+                kal_wsprintf(dst_path, "Z:\\BIN_REGION\\%w", filename);
+                NVRAM_FS_START_EX(FS_OP_MOVE, src_path);
+                ret = FS_Move(src_path, dst_path, FS_MOVE_COPY, NULL, NULL, 0);
+                NVRAM_FS_END(FS_OP_MOVE,ret);
+                NVRAM_FS_START(FS_OP_FINDNEXT);
+                ret = FS_FindNext(handle, &fileinfo, filename, (NVRAM_MAX_PATH_LEN * sizeof(kal_wchar)));
+                NVRAM_FS_END(FS_OP_FINDNEXT,ret);
+            }while(ret == FS_NO_ERROR);
+            NVRAM_FS_START(FS_OP_FINDCLOSE);
+            ret = FS_FindClose(handle);
+            NVRAM_FS_END(FS_OP_FINDCLOSE,ret);
+        }
+        free_ctrl_buffer(filename);
+    }while(0);
+#else
+    NVRAM_FS_START_EX(FS_OP_OPEN,L"Z:\\BACKUP");
+    result = FS_Open(L"\\BACKUP", FS_READ_WRITE);
+    NVRAM_FS_END(FS_OP_OPEN,result);
+#endif
+
+    if (result==FS_NO_ERROR)
+    {
+        return NVRAM_IO_ERRNO_OK;
+    }
+    else
+    {
+        return NVRAM_ERRNO_FAIL;
+    }
+}
diff --git a/mcu/service/nvram/src/nvram_factory_config.c b/mcu/service/nvram/src/nvram_factory_config.c
new file mode 100644
index 0000000..cd5fd77
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_factory_config.c
@@ -0,0 +1,213 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_data_items.c
+ *
+ * Project:
+ * --------
+ *   MOLY
+ *
+ * Description:
+ * ------------
+ *    This file contains `vendor' defined logical data items stored in NVRAM.
+ *    These logical data items are used in object code of Protocol Stack software.
+ *
+ *    As for customizable logical data items, they are defined in nvram_user_config.c
+ *
+ * Author:
+ * -------
+ * 
+ * 
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#ifndef NVRAM_NOT_PRESENT
+
+#define NVRAM_FACTORY_CONFIG
+
+#ifdef NVRAM_AUTO_GEN
+#include "nvram_auto_gen.h"
+#endif
+
+#include "kal_general_types.h"
+
+#include "nvram_defs.h"
+#include "nvram_enums.h"
+#include "nvram_data_items.h"
+#include "nvram_group_def.h" //add for break group files from header file
+#include "nvram_editor_data_item.h"
+#include "nvram_group_editor.h" //add for break group files from header file
+#include "custom_nvram_config.h"
+#include "custom_nvram_sec.h"
+#include "custom_nvram_restore.h"
+#include "custom_nvram_config.h"
+#if defined(__NVRAM_COMPRESS_SUPPORT__) && !defined(NVRAM_AUTO_GEN)
+#include "nvram_default_value.h"
+#endif
+
+/**
+ * Steps of defining logical data item:
+ * 1> Define LID of new logical data item into `nvram_lid_core_enum' in
+ *    nvram_data_items.h
+ * 2> Define two constants: SIZE and TOTAL, in nvram_data_items.h
+ * 3> Define default value of that new logical data item.
+ * 4> Define attributes of that new logical data item into
+ *    `logical_data_item_table_core'
+ * 5> Change NVRAM_TOTAL_LID_VENDOR in nvram_user_defs.h
+ * 6> Add structure defination in nvram_editor_data_item.h
+ * 7> Add bit-level description in nvram_editor_data_item.h
+ * 8> Change version number CODED_DATA_VERSION in nvram_user_config.c
+ *
+ * Note that multiple copied attribute DOES NOT support for
+ * near fixed logical data items.
+ */
+
+/**
+ * Step 3:
+ * Define necessary default values for each logical data item.
+ */
+
+/**
+ * Step 4:
+ * The logical data item table.
+ * Note:
+ * Each logical data item must be:
+ * 1> Size must be EVEN
+ * 2> Size of default value must be equal to the logical data item's size.
+ *
+ * The last LID in the MT reign now is MT1k
+ */
+ltable_entry_struct logical_data_item_table_factory[] =
+{
+    NVRAM_LTABLE_END
+};
+
+#endif /* NVRAM_NOT_PRESENT */
diff --git a/mcu/service/nvram/src/nvram_handler_monitor.c b/mcu/service/nvram/src/nvram_handler_monitor.c
new file mode 100644
index 0000000..e3fd46a
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_handler_monitor.c
@@ -0,0 +1,362 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ * nvram_handler_notify.h
+ *
+ * Project:
+ * --------
+ *   MT6293
+ *
+ * Description:
+ * ------------
+ *   This is nvram_mon_xxx_handler() of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+#include "nvram_handler_monitor.h"
+#include "nvram_interface.h"
+#include "nvram_io.h"
+#include "nvram_msgid.h"
+#include "nvram_defs.h"
+#include "nvram_main.h"
+
+#include "us_timer.h"
+#include "ex_public.h"
+#include "stdio.h"
+#include "stdarg.h"
+
+#if defined(__NVRAM_MONITOR_ENABLED__)
+#define MIN(a, b)    (((a)>(b))?(b):(a))
+#define MAX(a, b)   (((a)>(b))?(a):(b))
+
+typedef struct {
+    kal_bool registered;
+    module_type reg_module; // only monitor write from other modules
+    kal_uint16 lid;
+    kal_uint16 rec_index;
+    kal_uint16 rec_amount;
+    kal_uint16 hit_count;   // for debug
+} nvram_mon_reg_info;
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+extern module_type stack_get_active_module_id( void );
+
+#define NVRAM_MAX_NOTIFY_NUM 20
+static nvram_mon_reg_info nvram_reg_list[NVRAM_MAX_NOTIFY_NUM];
+static kal_mutexid nvram_reg_list_mutex = NULL;
+
+static nvram_mon_reg_info * nvram_mon_find_free_record()
+{
+    kal_int32 idx;
+    nvram_mon_reg_info *reg_info;
+
+    for (idx = 0; idx < NVRAM_MAX_NOTIFY_NUM; idx++) {
+        reg_info = &nvram_reg_list[idx];
+        if (KAL_FALSE == reg_info->registered) {
+            return reg_info;
+        }
+    }
+
+    return NULL;
+}
+
+
+static nvram_mon_reg_info * nvram_mon_find_reg_record(module_type reg_mod, 
+        nvram_lid_enum lid, kal_uint16 rec_idx, kal_int16 rec_amount)
+{
+    kal_int32 idx;
+    nvram_mon_reg_info *reg_info;
+
+    for (idx = 0; idx < NVRAM_MAX_NOTIFY_NUM; idx++) {
+        reg_info = &nvram_reg_list[idx];
+        
+        if (KAL_FALSE == reg_info->registered) {
+            continue;
+        }
+
+        if (lid == reg_info->lid 
+            && rec_idx == reg_info->rec_index
+            && rec_amount == reg_info->rec_amount
+            && reg_mod == reg_info->reg_module) {
+            return reg_info;
+        }
+    } 
+
+    return NULL;
+}
+
+
+static void nvram_mon_reg_notify(module_type reg_mod, nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
+{
+    nvram_mon_reg_info *reg_info = NULL;
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_ERRNO_SUCCESS;
+    peer_buff_struct *peer_buf_ptr = NULL;
+    kal_uint8 *pdu_ptr = NULL;
+    kal_uint16 pdu_len = 0;
+    nvram_read_cnf_struct *nvram_read_cnf = NULL;
+
+    if (!nvram_util_get_data_item(&ldi, lid)) {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,lid);
+        result = NVRAM_IO_ERRNO_INVALID_LID;
+    } else if (rec_idx < 1 || rec_idx > ldi->total_records) {
+         NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD\r\n",__FUNCTION__,lid);
+         NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_idx,ldi->total_records);
+         result = NVRAM_IO_ERRNO_INVALID_RECORD;
+    } else if (rec_idx + rec_amt -1 > ldi->total_records) {
+        rec_amt = ldi->total_records - rec_idx + 1;
+    }
+
+    if (result == NVRAM_ERRNO_SUCCESS) {
+        // check if already registered
+        nvram_util_take_mutex(nvram_reg_list_mutex);
+        reg_info = nvram_mon_find_reg_record(reg_mod, lid, rec_idx, rec_amt);
+        if (reg_info == NULL) {
+            // try reg
+            reg_info = nvram_mon_find_free_record();
+            if (reg_info == NULL) {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s no free record,LID 0x%04X\r\n",__FUNCTION__,lid);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)reg_info, NVRAM_LOC_INVALID_INDEX_4, 0);
+                return;
+            }
+            // reg OK
+            reg_info->registered = KAL_TRUE;
+            reg_info->reg_module = reg_mod;
+            reg_info->lid = lid;
+            reg_info->rec_index = rec_idx;
+            reg_info->rec_amount= rec_amt;
+            reg_info->hit_count = 0;
+        }
+        nvram_util_give_mutex(nvram_reg_list_mutex);
+
+        // read lid back
+        pdu_len = ldi->size*rec_amt;
+        peer_buf_ptr = construct_peer_buff(pdu_len, 0, 0, TD_CTRL);
+        pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_len);
+        result= nvram_read_data_item(ldi, rec_idx, rec_amt, pdu_ptr, pdu_len);
+    }
+
+    // send read confirmation
+    nvram_read_cnf = (nvram_read_cnf_struct*) construct_local_para(sizeof(nvram_read_cnf_struct), TD_CTRL);
+    nvram_read_cnf->result = result;
+    nvram_read_cnf->file_idx = lid;
+    nvram_read_cnf->para = rec_idx;
+    nvram_read_cnf->length = pdu_len;
+    nvram_read_cnf->access_id = 0;
+    
+    nvram_send_ilm(reg_mod, MSG_ID_NVRAM_READ_CNF, nvram_read_cnf, peer_buf_ptr);
+}
+
+static void nvram_mon_dereg_notify(module_type reg_mod, nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
+{
+    nvram_mon_reg_info *reg_info = NULL;
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    if (!nvram_util_get_data_item(&ldi, lid)) {
+        return;
+    }
+
+    if (rec_idx < 1 || rec_idx > ldi->total_records) {
+        return;
+    }
+
+    if (rec_idx + rec_amt -1 > ldi->total_records) {
+        rec_amt = ldi->total_records - rec_idx + 1;
+    }
+    
+    // find reg info
+    nvram_util_take_mutex(nvram_reg_list_mutex);
+    reg_info = nvram_mon_find_reg_record(reg_mod, lid, rec_idx, rec_amt);
+    if (reg_info != NULL) {
+        // mark reg status as invalid
+        reg_info->registered = KAL_FALSE;
+    }
+    nvram_util_give_mutex(nvram_reg_list_mutex);
+}
+
+static void nvram_mon_notify_change(module_type reg_mod, 
+    nvram_lid_enum lid, kal_uint16 idx, kal_uint8 *write_buff, kal_uint16 buff_len)
+{
+    nvram_read_cnf_struct *nvram_read_cnf;
+    peer_buff_struct *peer_buf_ptr;
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_len;
+
+    // construct peer buff
+    pdu_len = buff_len;
+    peer_buf_ptr = construct_peer_buff(pdu_len, 0, 0, TD_CTRL);
+    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_len);
+    kal_mem_cpy(pdu_ptr, write_buff, pdu_len);
+
+    // send read confirmation
+    nvram_read_cnf = (nvram_read_cnf_struct*) construct_local_para(sizeof(nvram_read_cnf_struct), TD_CTRL);
+    nvram_read_cnf->result = NVRAM_ERRNO_SUCCESS;
+    nvram_read_cnf->file_idx = lid;
+    nvram_read_cnf->para = idx;
+    nvram_read_cnf->length = pdu_len;
+    nvram_read_cnf->access_id = 0;
+
+    nvram_send_ilm(reg_mod, MSG_ID_NVRAM_READ_CNF, nvram_read_cnf, peer_buf_ptr);
+}
+
+
+/********************************************************
+ *
+ *    APIs Referenced by other NVRAM Component
+ *
+ ********************************************************/
+void nvram_mon_init()
+{
+    nvram_reg_list_mutex = kal_create_mutex("nvram_mon_mutex");
+}
+
+void nvram_mon_check_and_notify(module_type write_mod, 
+    nvram_write_req_struct *write_req, kal_uint8 *write_buff, kal_uint16 buff_len)
+{
+    int idx;
+    nvram_mon_reg_info *reg_info;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint16 write_start = write_req->para;
+    kal_uint16 write_end = write_start;
+    kal_uint32 mixed_start, mixed_end, mixed_buf_len;
+    kal_uint8* mixed_buf;
+
+    for (idx = 0; idx < NVRAM_MAX_NOTIFY_NUM; idx++) {
+        reg_info = &nvram_reg_list[idx];
+        
+        if (KAL_FALSE == reg_info->registered) {
+            continue;
+        }
+
+        if (write_mod != reg_info->reg_module && write_req->file_idx == reg_info->lid) {
+            nvram_util_get_data_item(&ldi, write_req->file_idx);
+            write_end = write_start + buff_len/ldi->size - 1;
+            if (write_start > reg_info->rec_index + reg_info->rec_amount - 1 || write_end < reg_info->rec_index) {
+                continue;   // not in wirte monitor range
+            }
+
+            mixed_start = MAX(write_start, reg_info->rec_index);
+            mixed_end = MIN(write_end, reg_info->rec_index + reg_info->rec_amount - 1);
+            
+            mixed_buf = write_buff+(mixed_start-write_start)*ldi->size;
+            mixed_buf_len = (mixed_end - mixed_start + 1)*ldi->size;
+            
+            reg_info->hit_count ++;
+            nvram_mon_notify_change(reg_info->reg_module, write_req->file_idx, mixed_start, mixed_buf, mixed_buf_len);
+        }
+    }
+}
+
+
+/********************************************************
+ *
+ *    NVRAM MSG HANDLERs
+ *
+ ********************************************************/
+void nvram_mon_dereg_handler(ilm_struct *ilm_ptr)
+{ 
+    nvram_read_req_struct *req = (nvram_read_req_struct *)ilm_ptr->local_para_ptr;
+
+    NVRAM_EXT_ASSERT(req != NULL,(kal_uint32)req, NVRAM_LOC_DEREG_NOTIFY_REQ_IS_NULL_1, 0);
+    nvram_mon_dereg_notify(ilm_ptr->src_mod_id, req->file_idx, req->para, req->rec_amount);    
+}
+
+void nvram_mon_reg_handler(ilm_struct *ilm_ptr)
+{
+    nvram_read_req_struct *req = (nvram_read_req_struct *)ilm_ptr->local_para_ptr;
+
+    NVRAM_EXT_ASSERT(req != NULL,(kal_uint32)req, NVRAM_LOC_REG_NOTIFY_REQ_IS_NULL_1, 0);
+    nvram_mon_reg_notify(ilm_ptr->src_mod_id, req->file_idx, req->para, req->rec_amount);    
+}
+
+
+/********************************************************
+ *
+ *    NVRAM EXTERNAL APIs (Reserved.)
+ *
+ ********************************************************/
+void nvram_external_reg_monitor(module_type reg_mod, nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
+{
+    nvram_mon_dereg_notify(reg_mod, lid, rec_idx, rec_amt); 
+}
+
+
+void nvram_external_dereg_monitor(module_type reg_mod, nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
+{
+     nvram_mon_dereg_notify(reg_mod, lid, rec_idx, rec_amt); 
+}
+
+#else
+
+void nvram_mon_init() {};
+void nvram_mon_reg_handler(ilm_struct *ilm_ptr){};
+void nvram_mon_dereg_handler(ilm_struct *ilm_ptr){};
+void nvram_mon_check_and_notify(module_type src_mod, nvram_write_req_struct *write_req, kal_uint8 *write_buff, kal_uint16 buff_len){};
+
+#endif
+
diff --git a/mcu/service/nvram/src/nvram_handler_read.c b/mcu/service/nvram/src/nvram_handler_read.c
new file mode 100644
index 0000000..d4a5fa0
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_handler_read.c
@@ -0,0 +1,761 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_handler_read.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is read handler function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/***************************************************************************** 
+* Include
+*****************************************************************************/
+
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+#include "nvram_msgid.h"
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+#include "nvram_main.h"
+
+#include "SST_secure.h"
+#include "us_timer.h"
+#include "stdlib.h"
+#include "ex_public.h"
+#include "stdio.h"
+#include "string.h"
+#include "stdarg.h"
+
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+//MSBB remove #include "fctycomp_config.h"  /* MOD_FT */
+#endif
+
+extern nvram_access_trace_information nvram_access_trace;
+extern kal_mutexid g_nvram_trace_mutex;
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+extern module_type stack_get_active_module_id( void );
+
+/*****************************************************************************
+* Global Function
+*****************************************************************************/
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_confirm
+ * DESCRIPTION
+ *  This is nvram_read_confirm() function of NVRAM module.
+ * PARAMETERS
+ *  dest_id             [IN]
+ *  result              [IN]
+ *  nvram_read_req      [?]
+ *  size                [IN]
+ *  peer_buf_ptr        [?]
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+/** Could not be static because the nvram should send a read_confirm
+ *  Message to L1 at nvram init, that will call this function
+ */
+void nvram_read_confirm(module_type dest_id, nvram_errno_enum result, nvram_read_req_struct *nvram_read_req, kal_uint16 size, peer_buff_struct *peer_buf_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_read_cnf_struct *nvram_read_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_READ_CNF(result, nvram_read_req->file_idx, nvram_read_req->para,nvram_read_req->rec_amount,size);
+
+    nvram_read_cnf = (nvram_read_cnf_struct*) construct_local_para(sizeof(nvram_read_cnf_struct), TD_CTRL);
+
+    nvram_read_cnf->result = result;
+    nvram_read_cnf->file_idx = nvram_read_req->file_idx;
+    nvram_read_cnf->para = nvram_read_req->para;
+    nvram_read_cnf->length = size;
+    nvram_read_cnf->access_id = nvram_read_req->access_id;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_READ_CNF, nvram_read_cnf, peer_buf_ptr);
+
+    return;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_handler
+ * DESCRIPTION
+ *  This is nvram_read_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_read_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_read_req_struct *nvram_read_req = (nvram_read_req_struct*) ilm_ptr->local_para_ptr;
+    nvram_ltable_entry_struct *ldi;
+    peer_buff_struct *peer_buf_ptr;
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_length;
+    kal_uint32 nvram_trace_index;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_EXT_ASSERT(nvram_read_req != NULL,(kal_uint32)nvram_read_req, NVRAM_LOC_READ_REQ_PTR_IS_NULL_1, 0);
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_MSG;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = nvram_read_req->file_idx;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+
+    MD_TRC_FUNC_NVRAM_READ();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+
+        nvram_read_confirm(
+            ilm_ptr->src_mod_id,
+            NVRAM_ERRNO_NOT_READY,
+            nvram_read_req,
+            (kal_uint16) NVRAM_INVALID_VALUE,
+            NULL);
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,nvram_read_req->file_idx);
+        return;
+    }
+
+    /**
+    * Invalid input paramters.
+    * file_idx / LID : 1 ~ (total_LID - 1)
+    * para / section: 1 ~ total_records
+    */
+    if (!NVRAM_IS_LID_VALID(nvram_read_req->file_idx))
+    {
+        nvram_read_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_LID, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,nvram_read_req->file_idx);
+        return;
+    }
+
+    nvram_util_get_data_item(&ldi, nvram_read_req->file_idx);
+
+    if(SST_NVRAM_Data_Access_Check(nvram_read_req->file_idx, 0, KAL_FALSE, NULL))
+    {
+        nvram_read_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED \r\n",__FUNCTION__,nvram_read_req->file_idx);
+        return;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+    #endif
+        {
+            nvram_read_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,nvram_read_req->file_idx);
+            return;
+        }
+    }
+#endif
+
+    if ((nvram_read_req->para < 1) ||
+        (nvram_read_req->para > ldi->total_records))
+    {
+        nvram_read_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_RECORD, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;
+        return;
+    }
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if (!(ldi->attr & NVRAM_ATTR_MULTIREC_READ)) {
+        nvram_read_req->rec_amount = 1;
+    }
+	else
+    {
+
+        if (nvram_read_req->para + nvram_read_req->rec_amount -1 > ldi->total_records)
+        {
+            nvram_read_req->rec_amount = ldi->total_records - nvram_read_req->para + 1;
+        }
+
+        if (nvram_read_req->rec_amount * (ldi->size + nvram_chksum_size) > MAX_NVRAM_RECORD_SIZE)
+        {
+            nvram_read_req->rec_amount = MAX_NVRAM_RECORD_SIZE / (ldi->size + nvram_chksum_size + 1);
+        }
+    }
+
+    pdu_length = ldi->size * nvram_read_req->rec_amount;
+
+    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+
+    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+
+    nvram_read_confirm(
+        ilm_ptr->src_mod_id,
+        nvram_read_data_item(ldi, nvram_read_req->para, nvram_read_req->rec_amount, pdu_ptr, pdu_length),
+        nvram_read_req,
+        (kal_uint16) (ldi->size * nvram_read_req->rec_amount),
+        peer_buf_ptr);
+    
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_OK;
+
+}
+
+void nvram_read_default_confirm(module_type dest_id, nvram_errno_enum result, nvram_read_default_req_struct *nvram_read_default_req, kal_uint16 size, peer_buff_struct *peer_buf_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_read_default_cnf_struct *nvram_read_default_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_READ_CNF(result, nvram_read_default_req->file_idx, nvram_read_default_req->para,nvram_read_default_req->rec_amount,size);
+
+    nvram_read_default_cnf = (nvram_read_default_cnf_struct*) construct_local_para(sizeof(nvram_read_cnf_struct), TD_CTRL);
+
+    nvram_read_default_cnf->result = result;
+    nvram_read_default_cnf->file_idx = nvram_read_default_req->file_idx;
+    nvram_read_default_cnf->para = nvram_read_default_req->para;
+    nvram_read_default_cnf->length = size;
+    nvram_read_default_cnf->access_id = nvram_read_default_req->access_id;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_READ_DEFAULT_CNF, nvram_read_default_cnf, peer_buf_ptr);
+
+    return;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_default_handler
+ * DESCRIPTION
+ *  This is nvram_read_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_read_default_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_read_default_req_struct *nvram_read_req = (nvram_read_default_req_struct*) ilm_ptr->local_para_ptr;
+    nvram_ltable_entry_struct *ldi;
+    peer_buff_struct *peer_buf_ptr;
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_length;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    ASSERT(nvram_read_req != NULL);
+
+    MD_TRC_FUNC_NVRAM_READ();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,nvram_read_req->file_idx);
+        nvram_read_default_confirm(
+            ilm_ptr->src_mod_id,
+            NVRAM_ERRNO_NOT_READY,
+            nvram_read_req,
+            (kal_uint16) NVRAM_INVALID_VALUE,
+            NULL);
+        return;
+    }
+
+    /**
+    * Invalid input paramters.
+    * file_idx / LID : 1 ~ (total_LID - 1)
+    * para / section: 1 ~ total_records
+    */
+    if (!NVRAM_IS_LID_VALID(nvram_read_req->file_idx))
+    {
+        nvram_read_default_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_LID, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+        return;
+    }
+
+    nvram_util_get_data_item(&ldi, nvram_read_req->file_idx);
+
+    if(SST_NVRAM_Data_Access_Check(nvram_read_req->file_idx, 0, KAL_FALSE, NULL))
+    {
+        nvram_read_default_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+        return;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+    #endif
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,nvram_read_req->file_idx);
+            nvram_read_default_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+            return;
+        }
+    }
+#endif
+
+    if ((nvram_read_req->para < 1) ||
+        (nvram_read_req->para > ldi->total_records))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,nvram_read_req->file_idx,nvram_read_req->para,ldi->total_records);
+        nvram_read_default_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_RECORD, nvram_read_req, (kal_uint16) NVRAM_INVALID_VALUE, NULL);     /* nvram_read_confirm */
+        return;
+    }
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if (!(ldi->attr & NVRAM_ATTR_MULTIREC_READ)) {
+        nvram_read_req->rec_amount = 1;
+    }
+	else
+    {
+
+        if (nvram_read_req->para + nvram_read_req->rec_amount -1 > ldi->total_records)
+        {
+            nvram_read_req->rec_amount = ldi->total_records - nvram_read_req->para + 1;
+        }
+
+        if (nvram_read_req->rec_amount * (ldi->size + nvram_chksum_size) > MAX_NVRAM_RECORD_SIZE)
+        {
+            nvram_read_req->rec_amount = MAX_NVRAM_RECORD_SIZE / (ldi->size + nvram_chksum_size + 1);
+        }
+    }
+
+    //pdu_length = ldi->size * nvram_read_req->rec_amount;
+    pdu_length = ldi->size;
+
+    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+
+    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+
+    nvram_read_default_confirm(
+        ilm_ptr->src_mod_id,
+        //nvram_read_data_item(ldi, nvram_read_req->para, nvram_read_req->rec_amount, pdu_ptr, pdu_length),
+        (nvram_get_default_value_to_write(ldi, nvram_read_req->para, pdu_ptr, pdu_length)==NULL?NVRAM_ERRNO_FAIL: NVRAM_IO_ERRNO_OK),
+        nvram_read_req,
+        //(kal_uint16) (ldi->size * nvram_read_req->rec_amount),
+        (kal_uint16)(ldi->size),
+        peer_buf_ptr);
+}
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#ifdef __MULTI_BOOT__
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+
diff --git a/mcu/service/nvram/src/nvram_handler_reset.c b/mcu/service/nvram/src/nvram_handler_reset.c
new file mode 100644
index 0000000..f596e9d
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_handler_reset.c
@@ -0,0 +1,625 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_handler_reset.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is reset handler function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "kal_trace.h"
+#include "nvram_msgid.h"
+#include "mcf_if.h"
+
+#ifdef __NVRAM_OTP__
+#include "fs_gprot.h"
+#include "fs_iprot.h"
+#endif
+
+//MSBB remove #include "fctycomp_config.h" /* MOD_FT */
+
+#include "nvram_main.h"
+#include "ex_public.h"
+#include "stdio.h"
+#include "stdarg.h"
+#include "us_timer.h"
+
+
+extern kal_mutexid g_nvram_impt_mutex;
+extern nvram_access_trace_information nvram_access_trace;
+extern kal_mutexid g_nvram_trace_mutex;
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+
+static void nvram_reset_confirm(module_type dest_id, nvram_errno_enum result, nvram_reset_req_struct *nvram_reset_req);
+
+static void nvram_set_lock_confirm(
+                module_type dest_id,
+                nvram_errno_enum result,
+                nvram_set_lock_req_struct *nvram_set_lock_req);
+
+extern module_type stack_get_active_module_id( void );
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_handler
+ * DESCRIPTION
+ *  This is nvram_reset_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_reset_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    nvram_ltable_entry_struct tmp_ldi = {0};
+    nvram_reset_req_struct *nvram_reset_req = (nvram_reset_req_struct*) ilm_ptr->local_para_ptr;
+    kal_uint32 nvram_trace_index  = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.reset_trace_index;
+    nvram_access_trace.reset_trace_index = (nvram_access_trace.reset_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+    
+    MD_TRC_FUNC_NVRAM_RESET();
+    NVRAM_EXT_ASSERT(nvram_reset_req != NULL,(kal_uint32)nvram_reset_req, NVRAM_LOC_RESET_REQ_PTR_IS_NULL_1, 0);
+    kal_mem_set((void *)&(nvram_access_trace.reset_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.reset_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_MSG;
+    nvram_access_trace.reset_trace[nvram_trace_index].LID = nvram_reset_req->LID;
+    nvram_access_trace.reset_trace[nvram_trace_index].start_time = ust_get_current_time();
+    if (nvram_ptr->dev_broken)
+    {
+        nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_DRV_BROKEN;
+        nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_reset_req);
+    }
+    else
+    {
+
+        if (nvram_ptr->state == NVRAM_STATE_READY)
+        {
+            if (!(nvram_reset_req->reset_category & NVRAM_RESET_CERTAIN))
+            {
+                nvram_reset_req->LID = 0;
+            }
+
+            nvram_util_get_data_item(&ldi, nvram_reset_req->LID);
+
+            if (nvram_reset_req->reset_category == NVRAM_RESET_CERTAIN)
+            {
+                if (!NVRAM_IS_LID_VALID(nvram_reset_req->LID))
+                {
+                    nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+                    nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,nvram_reset_req->LID);
+                    nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_LID, nvram_reset_req);
+                    return;
+                }
+                
+                /* In Meta mode, we cannot access the data belongs to custom sensitve area
+                   we also cannot reset the important data to prevent security problem */
+                 
+               
+                if (NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)
+                    || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)
+                    #if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+                    || NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category)
+                    || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category)
+                    #endif
+                   )
+                {
+                    if (FACTORY_BOOT == kal_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+                    {
+                        nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+                        nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED \r\n",__FUNCTION__,nvram_reset_req->LID);
+                        nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_reset_req);
+                        return;
+                    }
+                }
+            }
+
+            if (nvram_reset_data_items(nvram_reset_req->reset_category, nvram_reset_req->app_id, ldi, nvram_reset_req->rec_index, nvram_reset_req->rec_amount) == KAL_TRUE)
+            {
+                if(nvram_ptr->state == NVRAM_STATE_READY)
+                {
+                    memcpy(&tmp_ldi,ldi,sizeof(nvram_ltable_entry_struct));
+                    mcf_do_ota_by_lid(nvram_reset_req->LID,nvram_reset_req->rec_index, nvram_reset_req->rec_amount,&tmp_ldi);
+                }
+                nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+                nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_SUCCESS;
+                nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_reset_req);
+            }
+            else
+            {
+                nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+                nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_FAIL;
+                nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_reset_req);
+            }
+        }
+        /* State error */
+        else
+        {
+            MD_TRC_ERROR_NVRAM_STATE();
+            nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__,nvram_reset_req->LID);
+            nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_reset_req);
+        }
+    }
+}   /* end of nvram_reset_handler */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_confirm
+ * DESCRIPTION
+ *  This is nvram_reset_confirm() function of NVRAM module.
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  result              [IN]        
+ *  nvram_reset_req     [?]         
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void nvram_reset_confirm(module_type dest_id, nvram_errno_enum result, nvram_reset_req_struct *nvram_reset_req)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_reset_cnf_struct *nvram_reset_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_RESET_CNF(result);
+    nvram_reset_cnf = (nvram_reset_cnf_struct*) construct_local_para(sizeof(nvram_reset_cnf_struct), TD_CTRL);
+
+
+    nvram_reset_cnf->result = result;
+    nvram_reset_cnf->access_id = nvram_reset_req->access_id;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_RESET_CNF, nvram_reset_cnf, NULL);
+
+    return;
+}   /* end of nvram_reset_confirm */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_set_lock_handler
+ * DESCRIPTION
+ *  This is nvram_set_lock_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_set_lock_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool lock_state = nvram_ptr->lock;
+    nvram_set_lock_req_struct *nvram_set_lock_req = (nvram_set_lock_req_struct*) ilm_ptr->local_para_ptr;
+    #ifdef __NVRAM_OTP__
+    kal_int32 result = 0;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (nvram_ptr->dev_broken)
+    {
+        nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, nvram_set_lock_req);
+    }
+    else
+    {
+        if ((nvram_set_lock_req->lock_en == NVRAM_LOCK_ENABLE && lock_state == KAL_TRUE) ||
+            (nvram_set_lock_req->lock_en == NVRAM_LOCK_DISABLE && lock_state == KAL_FALSE))
+        {
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req);
+            return;
+        }
+        else if (nvram_set_lock_req->lock_en == NVRAM_LOCK_TEMP_DISABLE)
+        {
+            #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_set_lock_req);
+            #else
+            nvram_ptr->lock = KAL_FALSE;
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock;
+            }
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req);
+            return;
+            #endif
+        }
+    #ifdef __NVRAM_OTP__
+        else if (nvram_set_lock_req->lock_en == NVRAM_LOCK_OTP)
+        {
+            NVRAM_FS_START(FS_OP_OTPLOCK);
+            result = FS_OTPLock(FS_DEVICE_TYPE_NOR);
+            NVRAM_FS_END(FS_OP_OTPLOCK,result);
+            if(result == FS_NO_ERROR)
+            {
+                nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req);
+            }
+            else
+            {
+                nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_set_lock_req);
+            }    
+            return;
+        }
+    #endif /* __NVRAM_OTP__ */
+
+        if (nvram_set_lock_req->lock_en == NVRAM_LOCK_ENABLE)
+        {
+            nvram_write_system_record(NVRAM_LOCK_ENABLE);
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req);
+        }
+        else if (nvram_set_lock_req->lock_en == NVRAM_LOCK_DISABLE)
+        {
+            #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_set_lock_req);
+            #else
+            nvram_write_system_record(NVRAM_LOCK_DISABLE);
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req);
+            #endif
+        }
+        else
+        {
+            /* Invalid parameter */
+            nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, nvram_set_lock_req);
+            return;
+        }
+
+    }
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_set_lock_confirm
+ * DESCRIPTION
+ *  This is nvram_set_lock_confirm() function of NVRAM module.
+ * PARAMETERS
+ *  dest_id                 [IN]        
+ *  result                  [IN]        
+ *  nvram_set_lock_req      [?]         
+ *  ilm_ptr(?)              [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void nvram_set_lock_confirm(module_type dest_id,
+                                   nvram_errno_enum result,
+                                   nvram_set_lock_req_struct *nvram_set_lock_req)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_set_lock_cnf_struct *nvram_set_lock_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_set_lock_cnf = (nvram_set_lock_cnf_struct*) construct_local_para(sizeof(nvram_set_lock_cnf_struct), TD_CTRL);
+
+    nvram_set_lock_cnf->result = result;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_SET_LOCK_CNF, nvram_set_lock_cnf, NULL);
+
+    return;
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_suspend_handler
+ * DESCRIPTION
+ *  This is the handler to handle MSG_ID_NVRAM_SUSPEND_REQ
+ *  After nvram receive this request, it will be suspend forever now.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        the message content
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_suspend_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_suspend_req_struct *nvram_suspend_req = (nvram_suspend_req_struct*) ilm_ptr->local_para_ptr;
+    nvram_suspend_cnf_struct *nvram_suspend_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_suspend_cnf = (nvram_suspend_cnf_struct*) construct_local_para(sizeof(nvram_suspend_cnf_struct), TD_CTRL);
+
+    nvram_suspend_cnf->result = NVRAM_ERRNO_SUCCESS;
+
+    nvram_send_ilm(ilm_ptr->src_mod_id, MSG_ID_NVRAM_SUSPEND_CNF, nvram_suspend_cnf, NULL);
+
+    if (nvram_suspend_req == NULL || nvram_suspend_req->suspend_time == 0)
+    {
+        while(1)
+        {
+            kal_sleep_task(kal_milli_secs_to_ticks(500));
+        }
+    }
+    else
+    {
+        kal_sleep_task(kal_milli_secs_to_ticks(5*nvram_suspend_req->suspend_time));
+    }
+
+    return;
+}
diff --git a/mcu/service/nvram/src/nvram_handler_startup.c b/mcu/service/nvram/src/nvram_handler_startup.c
new file mode 100644
index 0000000..80b728b
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_handler_startup.c
@@ -0,0 +1,309 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_handler_startup.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is startup handler function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "nvram_msgid.h"
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+#include "nvram_main.h"
+#include "nvram_data_items.h"
+#include "us_timer.h"
+#include "ex_public.h"
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+extern module_type stack_get_active_module_id( void );
+
+
+extern kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi);
+
+
+static void nvram_startup_confirm(
+                module_type dest_id,
+                nvram_errno_enum result,
+                nvram_startup_req_struct *nvram_startup_req);
+
+#if defined(__NVRAM_CRITICAL_DATA_SIGN_SUPPORT__)
+kal_bool nvram_check_critcal_data_at_bootup()
+{
+    kal_bool chk_ret = KAL_FALSE;
+        
+    /* Read OEM critical data, and check signiture */
+    chk_ret = custom_nvram_read_and_check_signed_critical_data();
+    if (chk_ret == KAL_FALSE) {
+        // try to restore LID from bin region, then re-check again
+        nvram_ltable_entry_struct * ldi = NULL;
+        
+        nvram_util_get_data_item(&ldi, custom_nvram_get_signed_critical_data_lid());
+        ASSERT(ldi != NULL);
+        
+        if (NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category)) {
+            if (nvram_recover_data_item(ldi) == NVRAM_IO_ERRNO_OK) {
+                chk_ret = custom_nvram_read_and_check_signed_critical_data();
+            }
+        }
+    }
+    
+    return chk_ret;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_startup_handler
+ * DESCRIPTION
+ *  This is nvram_startup_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_startup_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_startup_req_struct *nvram_startup_req;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_STARTUP();
+    nvram_startup_req = (nvram_startup_req_struct*) ilm_ptr->local_para_ptr;
+
+    NVRAM_EXT_ASSERT(nvram_startup_req != NULL,(kal_uint32)nvram_startup_req, NVRAM_LOC_STARTUP_REQ_PTR_IS_NULL_1, 0);
+    /* Everything fine. */
+    if (nvram_ptr->state == NVRAM_STATE_READY || nvram_ptr->state == NVRAM_STATE_NOT_READY)
+    {
+        MD_TRC_STATE_NVRAM_READY();
+
+        nvram_ptr->state = NVRAM_STATE_READY;
+
+        /* Check power-on mode */
+        if (nvram_startup_req->poweron_mode == NVRAM_POWERON_NORMAL)
+        {
+            /* nvram_send_ilm(MOD_LAYER1); */
+        }
+
+#if defined(__NVRAM_CRITICAL_DATA_SIGN_SUPPORT__)
+        if (ilm_ptr->src_mod_id == MOD_L4C) {
+            if (nvram_check_critcal_data_at_bootup() != KAL_TRUE) {
+                nvram_startup_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SIG_CHK_FAIL, nvram_startup_req);
+                return;
+            }
+        }
+#endif
+        
+        /* Finally, startup success.. */
+        nvram_startup_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_startup_req);
+    }
+    /* Fatal error. */
+    /* State error */
+    else
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+
+        nvram_startup_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_startup_req);
+    }
+}   /* end of nvram_startup_handler */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_startup_confirm
+ * DESCRIPTION
+ *  This is nvram_startup_confirm() function of NVRAM module.
+ * PARAMETERS
+ *  dest_id                 [IN]        
+ *  result                  [IN]        
+ *  nvram_startup_req       [?]         
+ *  ilm_ptr(?)              [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void nvram_startup_confirm(
+                module_type dest_id,
+                nvram_errno_enum result,
+                nvram_startup_req_struct *nvram_startup_req)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_startup_cnf_struct *nvram_startup_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_STARTUP_CNF(result);
+    nvram_startup_cnf = (nvram_startup_cnf_struct*) construct_local_para(sizeof(nvram_startup_cnf_struct), TD_CTRL);
+
+    /* Cylen, __FLIGHT_MODE_SUPPORT__ */
+    if (result == NVRAM_ERRNO_SUCCESS)
+    {
+        /* read flight mode status */
+        nvram_ltable_entry_struct *ldi;
+
+        nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_CACHE_OCTET_LID);
+        result = nvram_read_data_item(ldi, NVRAM_SYS_FLIGHTMODE_STATE, 1, nvram_startup_cnf->data, NVRAM_EF_SYS_CACHE_OCTET_SIZE);
+    }
+
+    nvram_startup_cnf->result = result;
+    nvram_startup_cnf->access_id = nvram_startup_req->access_id;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_STARTUP_CNF, nvram_startup_cnf, NULL);
+
+    return;
+} 
+
diff --git a/mcu/service/nvram/src/nvram_handler_tst.c b/mcu/service/nvram/src/nvram_handler_tst.c
new file mode 100644
index 0000000..90a2074
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_handler_tst.c
@@ -0,0 +1,649 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_handler_tst.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is tst handler function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#include "string.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_internal_api.h"   /* kal_internal_hisrid */
+#include "kal_trace.h"
+#include "nvram_msgid.h"
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+#include "nvram_interface.h"
+#include "nvram_data_items.h"
+#include "nvram_main.h"
+
+#include "tst_sap.h"
+
+/* Exception */
+#include "ex_item.h"
+
+/* Statistics */
+#include "ctrl_buff_pool.h"
+#include "sysconf_statistics.h"
+
+#include "task_config.h"
+
+extern task_info_struct *task_info_g;
+extern kal_internal_hisrid kal_hisr_ptrs_g[KAL_MAX_NUM_HISRS];
+extern kal_uint32 KALTotalTasks;
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_tst_handler
+ * DESCRIPTION
+ *  This is nvram_tst_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_tst_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    tst_module_string_inject_struct *tst_inject = (tst_module_string_inject_struct*) ilm_ptr->local_para_ptr;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_TST();
+
+    NVRAM_EXT_ASSERT(tst_inject != NULL,(kal_uint32)tst_inject, NVRAM_LOC_TST_INJECT_REQ_PTR_IS_NULL_1, 0);
+    if (!nvram_ptr->dev_broken && nvram_ptr->state == NVRAM_STATE_READY)
+    {
+
+    #ifdef __NVRAM_OTP__
+        if (strcmp((kal_char*) tst_inject->string, "otp_start")==0)
+        {
+            extern kal_uint32 nvram_otp_size;
+            extern void nvram_otp_construct(void);
+            nvram_otp_size = tst_inject->index * 10;
+            nvram_otp_construct();
+        }
+        else
+    #endif /* __NVRAM_OTP__ */
+        if (strcmp((kal_char*) tst_inject->string, "ex_reset") == 0)
+        {
+            nvram_ltable_entry_struct *ldi;
+
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_EXCEPTION_LID);
+
+            if (nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE)
+            {
+                MD_TRC_TEST_RESET_OK();
+            }
+            else
+            {
+                MD_TRC_TEST_RESET_FAIL();
+            }
+        }
+        else if (strcmp((kal_char*) tst_inject->string, "ex_fetch") == 0)
+        {
+            kal_uint8 i;
+            nvram_ltable_entry_struct *ldi;
+            peer_buff_struct *peer_buf_ptr;
+            kal_uint8 *pdu_ptr;
+            kal_uint16 pdu_length;
+            nvram_read_req_struct *local_data;
+            nvram_errno_enum ret;
+
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_EXCEPTION_LID);
+
+            if ((kal_uint8*) tst_inject->index == 0)
+            {
+                /* Get ALL Exception Records */
+                for (i = 1; i <= NVRAM_EF_SYS_EXCEPTION_TOTAL; i++)
+                {
+                    local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+                    local_data->access_id = 0;
+                    local_data->file_idx = (NVRAM_EF_SYS_EXCEPTION_LID);
+                    local_data->para = i;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+
+                    ret = nvram_read_data_item(ldi, i, 1, pdu_ptr, pdu_length); /* multi-rec read support */
+
+                    if (((EX_LOG_T*) pdu_ptr)->header.ex_nvram == 0xFF)
+                    {
+                        MD_TRC_TEST_VALID_EXCEPTIONS((i - 1));
+                        free_peer_buff(peer_buf_ptr);
+                        free_local_para((struct local_para_struct*)local_data);
+
+                        break;
+                    }
+
+                    nvram_read_confirm(MOD_NVRAM, ret, local_data, ldi->size, peer_buf_ptr);
+
+                }
+
+            }
+            else if ((kal_uint8) tst_inject->index <= NVRAM_EF_SYS_EXCEPTION_TOTAL)
+            {
+                /* Get Certain Exception Records */
+                local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+                local_data->access_id = 0;
+                local_data->file_idx = (NVRAM_EF_SYS_EXCEPTION_LID);
+                local_data->para = (kal_uint8) tst_inject->index;
+
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+
+                ret = nvram_read_data_item(ldi, (kal_uint8) tst_inject->index, 1, pdu_ptr, pdu_length); /* multi-rec read support */
+                if (((EX_LOG_T*) pdu_ptr)->header.ex_nvram == 0xFF)
+                {
+                    MD_TRC_TEST_INVALID_EXCEPTIONS(tst_inject->index);
+                    free_peer_buff(peer_buf_ptr);
+                    free_local_para((struct local_para_struct*)local_data);
+                }
+                else
+                {
+
+                    nvram_read_confirm(MOD_NVRAM, ret, local_data, ldi->size, peer_buf_ptr);
+                }
+
+            }
+            else
+            {
+                MD_TRC_TEST_REC_NUM_OUT_RANGE();
+            }
+        }
+        else if (strcmp((kal_char*) tst_inject->string, "stat_checked") == 0)
+        {
+            nvram_ltable_entry_struct *ldi;
+            stack_statistics_struct *stat_ptr;
+            nvram_errno_enum ret;
+
+            /* Dynamically allocates buffer, otherwise stack could overflow. */
+            stat_ptr = (stack_statistics_struct*) get_ctrl_buffer(NVRAM_EF_SYS_STATISTICS_SIZE);
+
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_STATISTICS_LID);
+
+            /* Read statistaics data item */
+            ret = nvram_read_data_item(ldi, 1, 1, (kal_uint8*) stat_ptr, NVRAM_EF_SYS_STATISTICS_SIZE);        /* multi-rec read support */
+            if ((ret == NVRAM_IO_ERRNO_OK) || (ret == NVRAM_IO_ERRNO_INIT))
+            {
+                stat_ptr->stack_stats_status = STACK_STATS_NONE;
+                nvram_write_data_item(ldi, 1, (kal_uint8*) stat_ptr, KAL_FALSE);
+            }
+
+            free_ctrl_buffer(stat_ptr);
+        }
+        else if (strcmp((kal_char*) tst_inject->string, "stat_reset") == 0)
+        {
+            nvram_ltable_entry_struct *ldi;
+
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_EXCEPTION_LID);
+
+            if (nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE)
+            {
+                MD_TRC_TEST_RESET_STAT_OK();
+            }
+            else
+            {
+                MD_TRC_TEST_RESET_STAT_FAIL();
+            }
+        }
+        else if (strcmp((kal_char*) tst_inject->string, "stat_fetch") == 0)
+        {
+            nvram_errno_enum ret;
+            nvram_ltable_entry_struct *ldi;
+            peer_buff_struct *peer_buf_ptr;
+            kal_uint8 *pdu_ptr;
+            kal_uint16 pdu_length;
+            nvram_read_req_struct *local_data;
+            stack_statistics_struct *stat_ptr;
+            kal_uint8 i;
+
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_STATISTICS_LID);
+
+            local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+            local_data->access_id = 0;
+            local_data->file_idx = (NVRAM_EF_SYS_STATISTICS_LID);
+            local_data->para = 1;
+
+            pdu_length = ldi->size;
+            peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+            pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+
+            /* read statistics information from nvram */
+            ret = nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length); /* multi-rec read support */
+            /* Send read confirm primitive to nvram itself for catcher display raw data */
+            nvram_read_confirm(MOD_NVRAM, ret, local_data, ldi->size, peer_buf_ptr);
+
+            /* Show detail to catcher sys trace window */
+            if (ret == NVRAM_IO_ERRNO_OK || ret == NVRAM_IO_ERRNO_INIT)
+            {
+                stat_ptr = get_ctrl_buffer(ldi->size);
+
+                if (!stat_ptr)
+                {
+                    MD_TRC_TEST_RESET_ALLOC_FAIL();
+                    return;
+                }
+                /* stat_ptr = (stack_statistics_struct *)pdu_ptr; */
+                kal_mem_cpy(stat_ptr, pdu_ptr, ldi->size);
+
+                MD_TRC_TEST_SYSINFO_STATUS(stat_ptr->stack_stats_status);
+                MD_TRC_TEST_SYSINFO_MAX_SYSMEM(stat_ptr->max_sys_mem_used);
+                MD_TRC_TEST_SYSINFO_MAX_SYSDBGMEM(stat_ptr->max_sysdebug_mem_used);
+
+                MD_TRC_TEST_SYSINFO_MAX_TASK_STACK_USED();
+                for (i = 0; i < KALTotalTasks; i += 5)
+                {
+                    MD_TRC_TEST_SYSINFO_DETAIL2(
+                        i,
+                        ((i > KALTotalTasks ? NULL : task_info_g[i].task_id) == NULL ? "--" : task_info_g[i].task_name_ptr),
+                        stat_ptr->max_task_stack_used[i],
+                        ((i + 1 > KALTotalTasks ? NULL : task_info_g[i + 1].task_id) == NULL ? "--" : task_info_g[i + 1].task_name_ptr),
+                        (i + 1 >= KALTotalTasks) ? 0 : stat_ptr->max_task_stack_used[(i + 1)],
+                        ((i + 2 > KALTotalTasks ? NULL : task_info_g[i + 2].task_id) == NULL ? "--" : task_info_g[i + 2].task_name_ptr),
+                        (i + 2 >= KALTotalTasks) ? 0 : stat_ptr->max_task_stack_used[(i + 2)],
+                        ((i + 3 > KALTotalTasks ? NULL : task_info_g[i + 3].task_id) == NULL ? "--" : task_info_g[i + 3].task_name_ptr),
+                        (i + 3 >= KALTotalTasks) ? 0 : stat_ptr->max_task_stack_used[(i + 3)],
+                        ((i + 4 > KALTotalTasks ? NULL : task_info_g[i + 4].task_id) == NULL ? "--" : task_info_g[i + 4].task_name_ptr),
+                        (i + 4 >= KALTotalTasks) ? 0 : stat_ptr->max_task_stack_used[(i + 4)]);
+                    
+                }
+            #ifdef DEBUG_KAL
+                MD_TRC_TEST_SYSINFO_MAX_HISR_STACK_USED();
+                for (i = 0; i < KAL_MAX_NUM_HISRS; i += 5)
+                {
+                    MD_TRC_TEST_SYSINFO_DETAIL2(
+                        i,
+                        kal_hisr_ptrs_g[i] == NULL ? "--" : kal_hisr_ptrs_g[i]->hisr_name,
+                        stat_ptr->max_hisr_stack_used[i],
+                        kal_hisr_ptrs_g[i + 1] == NULL ? "--" : kal_hisr_ptrs_g[i + 1]->hisr_name,
+                        (i + 1) >= KAL_MAX_NUM_HISRS ? 0 : stat_ptr->max_hisr_stack_used[(i + 1)],
+                        kal_hisr_ptrs_g[i + 2] == NULL ? "--" : kal_hisr_ptrs_g[i + 2]->hisr_name,
+                        (i + 2) >= KAL_MAX_NUM_HISRS ? 0 : stat_ptr->max_hisr_stack_used[(i + 2)],
+                        kal_hisr_ptrs_g[i + 3] == NULL ? "--" : kal_hisr_ptrs_g[i + 3]->hisr_name,
+                        (i + 3) >= KAL_MAX_NUM_HISRS ? 0 : stat_ptr->max_hisr_stack_used[(i + 3)],
+                        kal_hisr_ptrs_g[i + 4] == NULL ? "--" : kal_hisr_ptrs_g[i + 4]->hisr_name,
+                        (i + 4) >= KAL_MAX_NUM_HISRS ? 0 : stat_ptr->max_hisr_stack_used[(i + 4)]);
+                }
+            #endif /* DEBUG_KAL */ 
+
+            #ifdef DEBUG_ITC
+                MD_TRC_TEST_SYSINFO_MAX_TASK_EXTQ_ENQED();
+                for (i = 0; i < KALTotalTasks; i += 5)
+                {
+                    MD_TRC_TEST_SYSINFO_DETAIL2(
+                        i,
+                        ((i > KALTotalTasks ? NULL : task_info_g[i].task_ext_qid) == NULL ? "--" : task_info_g[i].task_qname_ptr),
+                        stat_ptr->max_task_extq_enqued[i],
+                        ((i + 1 > KALTotalTasks ? NULL : task_info_g[i + 1].task_ext_qid) == NULL ? "--" : task_info_g[i + 1].task_qname_ptr),
+                        (i + 1 >= KALTotalTasks) ? 0 : stat_ptr->max_task_extq_enqued[(i + 1)],
+                        ((i + 2 > KALTotalTasks ? NULL : task_info_g[i + 2].task_ext_qid) == NULL ? "--" : task_info_g[i + 2].task_qname_ptr),
+                        (i + 2 >= KALTotalTasks) ? 0 : stat_ptr->max_task_extq_enqued[(i + 2)],
+                        ((i + 3 > KALTotalTasks ? NULL : task_info_g[i + 3].task_ext_qid) == NULL ? "--" : task_info_g[i + 3].task_qname_ptr),
+                        (i + 3 >= KALTotalTasks) ? 0 : stat_ptr->max_task_extq_enqued[(i + 3)],
+                        ((i + 4 > KALTotalTasks ? NULL : task_info_g[i + 4].task_ext_qid) == NULL ? "--" : task_info_g[i + 4].task_qname_ptr),
+                        (i + 4 >= KALTotalTasks) ? 0 : stat_ptr->max_task_extq_enqued[(i + 4)]);
+                }
+            #endif /* DEBUG_ITC */ 
+
+            #if (defined(DEBUG_BUF1) || defined(DEBUG_BUF2))
+                MD_TRC_TEST_SYSINFO_CTRLBUFF_ALLOC();
+                MD_TRC_TEST_SYSINFO_CTRLBUFF_LIST();
+                
+                for (i = 0; i < RPS_CREATED_CTRL_BUFF_POOLS; i += 5)
+                {
+                    MD_TRC_TEST_SYSINFO_DETAIL1(
+                        i,
+                        stat_ptr->max_ctrl_buff_num_allocated[i],
+                        (i + 1) >= RPS_CREATED_CTRL_BUFF_POOLS ? 0 : stat_ptr->max_ctrl_buff_num_allocated[(i + 1)],
+                        (i + 2) >= RPS_CREATED_CTRL_BUFF_POOLS ? 0 : stat_ptr->max_ctrl_buff_num_allocated[(i + 2)],
+                        (i + 3) >= RPS_CREATED_CTRL_BUFF_POOLS ? 0 : stat_ptr->max_ctrl_buff_num_allocated[(i + 3)],
+                        (i + 4) >= RPS_CREATED_CTRL_BUFF_POOLS ? 0 : stat_ptr->max_ctrl_buff_num_allocated[(i + 4)]);
+                }
+            #endif /* DEBUG_BUF2 */ 
+
+                free_ctrl_buffer(stat_ptr);
+
+            }
+            else
+            {
+                MD_TRC_TEST_GET_STAT_FAIL();
+            }
+
+        }
+        else if (strcmp((kal_char*) tst_inject->string, "reset_all") == 0)
+        {
+            if (nvram_reset_data_items(NVRAM_RESET_ALL, NVRAM_APP_RESERVED, NULL, 0, 0) != KAL_TRUE)
+            {
+                MD_TRC_TEST_RESET_ALL_OK();
+            }
+            else
+            {
+                MD_TRC_TEST_RESET_ALL_FAIL();
+            }
+        }
+        else if (strcmp((kal_char*) tst_inject->string, "reset_certain") == 0)
+        {
+            nvram_ltable_entry_struct *ldi;
+
+            if (!NVRAM_IS_LID_VALID(tst_inject->index))
+            {
+                MD_TRC_TEST_RESET_INVALID_LID();
+                return;
+            }
+
+            nvram_util_get_data_item(&ldi, tst_inject->index);
+
+            if (nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) != KAL_TRUE)
+            {
+                MD_TRC_TEST_RESET_CERTAIN_FAIL();
+            }
+            else
+            {
+                MD_TRC_TEST_RESET_CERTAIN_OK();
+            }
+
+        }
+
+        /* Belows are for internal debug testing only. >=) */
+        else
+        {
+            /* Create a exception record manually by issuing a command from Catcher. */
+            if (strcmp((kal_char*) tst_inject->string, "ex_create") == 0)
+            {
+                long *ex_data;
+
+                /* Dynamically allocates buffer, otherwise stack could overflow. */
+                ex_data = (long*)get_ctrl_buffer(NVRAM_EF_SYS_EXCEPTION_SIZE);
+
+                kal_mem_set((kal_uint8*) ex_data, 0x5, NVRAM_EF_SYS_EXCEPTION_SIZE);
+                nvram_write_exception(NVRAM_EF_SYS_EXCEPTION_SIZE, ex_data);
+
+                free_ctrl_buffer(ex_data);
+            }
+
+            /* Update statistics manually by issuing a command from Catcher. */
+            else if (strcmp((kal_char*) tst_inject->string, "stat_create") == 0)
+            {
+                nvram_ltable_entry_struct *ldi;
+                stack_statistics_struct *stat_ptr;
+
+                /* Dynamically allocates buffer, otherwise stack could overflow. */
+                stat_ptr = (stack_statistics_struct*) get_ctrl_buffer(NVRAM_EF_SYS_STATISTICS_SIZE);
+                kal_mem_set((kal_uint8*) stat_ptr, 0, NVRAM_EF_SYS_STATISTICS_SIZE);
+                stat_ptr->stack_stats_status = STACK_STATS_UPDATE;
+
+                nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_STATISTICS_LID);
+
+                nvram_write_data_item(ldi, 1, (kal_uint8*) stat_ptr, KAL_FALSE);
+
+                free_ctrl_buffer(stat_ptr);
+            }
+
+            /* Test On Demand >>==)) */
+            else if (strcmp((kal_char*) tst_inject->string, "nvram_read") == 0)
+            {
+                nvram_read_req_struct *local_data;
+
+                local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+                local_data->access_id = 0;
+                local_data->file_idx = (kal_uint8) tst_inject->index;
+                local_data->para = 1;
+                nvram_send_ilm(MOD_NVRAM, MSG_ID_NVRAM_READ_REQ, local_data, NULL);
+
+            }
+            else if (strcmp((kal_char*) tst_inject->string, "sw_lock") == 0)
+            {
+                nvram_set_lock_req_struct *local_data;
+
+                local_data =
+                    (nvram_set_lock_req_struct*) construct_local_para(sizeof(nvram_set_lock_req_struct), TD_CTRL);
+
+                if ((kal_uint8) tst_inject->index == 1)
+                {
+                    /* Lock */
+                    local_data->lock_en = NVRAM_LOCK_ENABLE;
+                    nvram_send_ilm(MOD_NVRAM, MSG_ID_NVRAM_SET_LOCK_REQ, local_data, NULL);
+                }
+                else if ((kal_uint8) tst_inject->index == 0)
+                {
+                    /* UnLock */
+                    local_data->lock_en = NVRAM_LOCK_DISABLE;
+                    nvram_send_ilm(MOD_NVRAM, MSG_ID_NVRAM_SET_LOCK_REQ, local_data, NULL);
+                }
+            }
+        #ifdef __NVRAM_UNIT_TEST__
+            else if (strcmp((kal_char*) tst_inject->string, "unit_test") == 0)
+            {
+                nvram_unit_test();
+            }
+        #endif
+
+        #ifdef __NVRAM_SECURE_DATA_STORAGE__
+            /* Error commands */
+            else if (strcmp((kal_char*) tst_inject->string, "switch_mode") == 0)
+            {
+                if (tst_inject->index == 1)
+                {
+                    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+                }
+                else
+                {
+                    nvram_access_sds(NVRAM_SDS_ACCESS_RESTORE);
+                }
+            }
+        #endif
+            else
+            {
+                MD_TRC_ERROR_NVRAM_TST_INVALID_COMM();
+            }
+        }
+    }
+    /* State error */
+    else
+    {
+        MD_TRC_STATE_NVRAM_NOT_READY();
+    }
+
+}   /* end of nvram_tst_handler */
+
diff --git a/mcu/service/nvram/src/nvram_handler_write.c b/mcu/service/nvram/src/nvram_handler_write.c
new file mode 100644
index 0000000..df0dfb5
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_handler_write.c
@@ -0,0 +1,610 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_handler_write.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is write handler function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#include "string.h"
+#include "kal_public_defs.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "nvram_msgid.h"
+
+#include "nvram_data_items.h"
+#include "nvram_main.h"
+
+#include "SST_secure.h"
+#include "us_timer.h"
+
+#include "ex_public.h"
+#include "stdio.h"
+#include "stdarg.h"
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+//MSBB remove #include "fctycomp_config.h"  /* MOD_FT */
+#endif
+
+extern kal_mutexid g_nvram_impt_mutex;
+extern nvram_access_trace_information nvram_access_trace;
+extern kal_mutexid g_nvram_trace_mutex;
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+extern module_type stack_get_active_module_id( void );
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_confirm
+ * DESCRIPTION
+ *  This is nvram_write_confirm() function of NVRAM module.
+ * PARAMETERS
+ *  dest_id             [IN]
+ *  result              [IN]
+ *  nvram_write_req     [?]
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void nvram_write_confirm(module_type dest_id, nvram_errno_enum result, nvram_write_req_struct *nvram_write_req)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_write_cnf_struct *nvram_write_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_WRITE_CNF(result);
+    nvram_write_cnf = (nvram_write_cnf_struct*) construct_local_para(sizeof(nvram_write_cnf_struct), TD_CTRL);
+
+    nvram_write_cnf->result = result;
+    nvram_write_cnf->file_idx = nvram_write_req->file_idx;
+    nvram_write_cnf->para = nvram_write_req->para;
+    nvram_write_cnf->access_id = nvram_write_req->access_id;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_WRITE_CNF, nvram_write_cnf, NULL);
+
+    return;
+}   /* end of nvram_write_confirm */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_handler
+ * DESCRIPTION
+ *  This is nvram_write_handler() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_write_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_write_req_struct *nvram_write_req = (nvram_write_req_struct*) ilm_ptr->local_para_ptr;
+
+    nvram_ltable_entry_struct *ldi;
+
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_length;
+    kal_uint32 nvram_trace_index;
+
+    nvram_errno_enum result = NVRAM_ERRNO_SUCCESS;
+#if defined(__CCCIFS_SUPPORT__)
+    //kal_uint8 modify_cnt[8];
+    //kal_uint16 modify_cnt = 0;
+#endif
+    kal_uint32 take_IMEI_nutex = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    NVRAM_EXT_ASSERT(nvram_write_req != NULL,(kal_uint32)nvram_write_req, NVRAM_LOC_WRITE_REQ_PTR_IS_NULL_1, 0);
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.write_trace_index;
+    nvram_access_trace.write_trace_index = (nvram_access_trace.write_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.write_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.write_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_MSG;
+    nvram_access_trace.write_trace[nvram_trace_index].LID = nvram_write_req->file_idx;
+    nvram_access_trace.write_trace[nvram_trace_index].start_time = ust_get_current_time();
+
+    MD_TRC_FUNC_NVRAM_WRITE();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,nvram_write_req->file_idx);
+        nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_NOT_READY, nvram_write_req);
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;
+        return;
+    }
+
+    /**
+    * Invalid input paramters.
+    * file_idx / LID : 1 ~ (total_LID - 1)
+    * para / section: 1 ~ total_records
+    */
+    if (!NVRAM_IS_LID_VALID(nvram_write_req->file_idx))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,nvram_write_req->file_idx);
+        nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_LID, nvram_write_req);
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;
+        return;
+    }
+
+    nvram_util_get_data_item(&ldi, nvram_write_req->file_idx);
+
+    if(SST_NVRAM_Data_Access_Check(nvram_write_req->file_idx, 1, KAL_FALSE, NULL))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED \r\n",__FUNCTION__,nvram_write_req->file_idx);
+        nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_write_req);
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+        return;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT)
+    #endif
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,nvram_write_req->file_idx);
+            nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_write_req);
+            nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+            return;
+        }
+    }
+#endif
+
+    if ((nvram_write_req->para < 1) ||
+        (nvram_write_req->para > ldi->total_records))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,nvram_write_req->file_idx,nvram_write_req->para,ldi->total_records);
+        nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_RECORD, nvram_write_req);
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;
+        return;
+    }
+
+    NVRAM_EXT_ASSERT(ilm_ptr->peer_buff_ptr != NULL,(kal_uint32)(ilm_ptr->peer_buff_ptr), NVRAM_LOC_ILM_PEER_BUFF_PTR_IS_NULL_1, 0);
+    pdu_ptr = get_peer_buff_pdu(ilm_ptr->peer_buff_ptr, &pdu_length);
+
+    if (pdu_length != ldi->size)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE:buffer_size(%d) size(%d)\r\n",__FUNCTION__,nvram_write_req->file_idx,pdu_length,ldi->size);
+        nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_SIZE, nvram_write_req);
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;
+        return;
+    }
+
+    if (ldi->attr & NVRAM_ATTR_RING)
+    {
+        kal_uint8 *index = (kal_uint8 *)get_ctrl_buffer(ldi->size);
+        memset(index, 0, ldi->size);
+        if (nvram_read_data_item(ldi, 1, 1, index, ldi->size) == NVRAM_IO_ERRNO_OK)
+        {
+            nvram_write_req->para = (kal_uint16)index[0];
+
+            nvram_write_req->para++;
+
+            if (nvram_write_req->para > ldi->total_records || nvram_write_req->para < 2)
+                nvram_write_req->para = 2;
+
+            index[0] = (kal_uint8)nvram_write_req->para;
+
+            if (nvram_write_data_item(ldi, 1, index, KAL_FALSE) != NVRAM_IO_ERRNO_OK)
+            {
+                free_ctrl_buffer(index);
+                nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_WRONG_RINGLID, nvram_write_req);
+                nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+                nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_WRONG_RINGLID;
+                return;
+            }
+
+            if (nvram_write_data_item(ldi, nvram_write_req->para, pdu_ptr, KAL_FALSE) == NVRAM_IO_ERRNO_OK)
+            {
+                free_ctrl_buffer(index);
+                nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_OK, nvram_write_req);
+                nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+                nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_OK;
+                return;
+            }
+        }
+        free_ctrl_buffer(index);
+        nvram_write_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_WRONG_RINGLID, nvram_write_req);
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_WRONG_RINGLID;
+
+    }
+    else
+    {
+        if (ldi->LID == NVRAM_EF_IMEI_IMEISV_LID)
+        {
+            nvram_util_take_mutex(g_nvram_impt_mutex);
+            take_IMEI_nutex = 1;
+        }
+
+        result = nvram_write_data_item(ldi, nvram_write_req->para, pdu_ptr, KAL_FALSE);
+
+        nvram_write_confirm(ilm_ptr->src_mod_id, result, nvram_write_req);
+        //if (ldi->LID == NVRAM_EF_IMEI_IMEISV_LID)
+        if (take_IMEI_nutex > 0)
+        {
+            nvram_util_give_mutex(g_nvram_impt_mutex);
+            take_IMEI_nutex = 0;
+        }
+#if defined(__NVRAM_MONITOR_ENABLED__)
+        // Notify to C2K
+        if (result == NVRAM_ERRNO_SUCCESS) 
+        {
+            nvram_mon_check_and_notify(ilm_ptr->src_mod_id, nvram_write_req, pdu_ptr, pdu_length);
+        }
+#endif
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = result;
+
+    }
+}
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
diff --git a/mcu/service/nvram/src/nvram_ilm.c b/mcu/service/nvram/src/nvram_ilm.c
new file mode 100644
index 0000000..229a40e
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ilm.c
@@ -0,0 +1,183 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ilm.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is startup handler of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "svc_sap.h"
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_send_ilm
+ * DESCRIPTION
+ *  This is nvram_send_ilm function of NVRAM module.
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  msg_id              [IN]        
+ *  local_param_ptr     [?]         
+ *  peer_buf_ptr        [?]         
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_send_ilm(module_type dest_id, msg_type msg_id, void *local_param_ptr, void *peer_buf_ptr)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (dest_id == MOD_RTC_HISR || dest_id == MOD_SIM)
+    {
+        /* (1) MOD_RTC_HISR will save RTC data into NVRAM, however, MOD_RTC_HISR is not a task,
+           so RTC HISR could not handle message from NVRAM. We would not NVRAM send out message.
+           (2) MOD_SIM, do not know why??? Please contact MOD_SIM owner.
+        */
+        if (local_param_ptr)
+            free_ctrl_buffer(local_param_ptr);
+        if (peer_buf_ptr)
+            free_peer_buff(peer_buf_ptr);
+            
+        return;
+    }
+    
+    msg_send6(MOD_NVRAM, dest_id, PS_NVRAM_SAP, msg_id, (local_para_struct*)local_param_ptr, (peer_buff_struct*)peer_buf_ptr);
+}   /* End of nvram_send_ilm */
+
+
diff --git a/mcu/service/nvram/src/nvram_interface.c b/mcu/service/nvram/src/nvram_interface.c
new file mode 100644
index 0000000..73a667f
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_interface.c
@@ -0,0 +1,3753 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ * Filename:
+ * ---------
+ * nvram_interface.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   These are interface functions of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*
+ * Include
+ */
+#include "string.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "kal_trace.h"
+
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+#include "ex_item.h"
+#include "ex_public.h"
+#include "sysconf_statistics.h"
+
+#include "fs_type.h"
+#include "fs_errcode.h"
+#include "fs_func.h"
+//MSBB remove #include "fctycomp_config.h"
+
+#include "nvram_data_items.h"
+#include "nvram_group_def.h" //add for break group files from header file
+#include "nvram_main.h"
+#include "nvram_interface.h"
+
+#include "ul1_nvram_def.h"
+#include "audio_nvram_def.h"
+#include "ex_nvram_def.h"
+#include "nvram_msgid.h"
+
+#include "SST_secure.h"
+#include "svc_sap.h"
+#include "us_timer.h"
+#include "mcf_if.h"
+#include "cc_ex_item.h"
+#include "ex_public.h"
+
+/*
+ * Macro
+ */
+#define NVRAM_SPACE_MARGIN 10
+
+/*
+* used to check nvram ee memory info 
+*/
+kal_bool g_nvram_emm_query_info_result = KAL_TRUE;
+kal_uint32 g_nvram_emm_size = 0;
+kal_uint32 g_nvram_emm_addr = 0;
+
+/*
+ * Local Variable
+ */
+#if defined(__MTK_TARGET__) || defined(__OFFLINE_EX_LOG_PARSER__) 
+static EX_FULLLOG_T exception_full_log; 
+#endif
+
+static kal_uint8 nvram_exception_buffer[NVRAM_EF_SYS_EXCEPTION_SIZE];
+extern kal_uint32 BytesPerCluster;  /* will be set to exact value in nvram_get_disk_file_info */
+extern kal_bool stack_update_sys_statistics(stack_statistics_struct *prev_stats);
+
+extern nvram_shutdown_cb_struct nvram_shutdown_cb_table[];
+extern nvram_access_trace_information nvram_access_trace;
+extern kal_mutexid g_nvram_trace_mutex;
+extern module_type stack_get_active_module_id( void );
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_info
+ * DESCRIPTION
+ *  This is nvram_get_info() function of NVRAM module.
+ * PARAMETERS
+ *  LID         [IN]
+ *  total       [?]
+ *  size        [?]
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).
+ *****************************************************************************/
+nvram_errno_enum nvram_get_info(nvram_lid_enum LID, kal_uint16 *total, kal_uint16 *size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if ((nvram_ptr->state != NVRAM_STATE_READY) && !nvram_util_is_usbboot())
+    {
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    nvram_pre_init();
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    *total = ldi->total_records;
+    *size = ldi->size;
+
+    return NVRAM_ERRNO_SUCCESS;
+}   /* end of nvram_get_info function */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_log_ota_info
+ * DESCRIPTION
+ *  show OTA version info in ELT log
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_log_ota_info(void)
+{
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE handle;
+    kal_char info[256];
+    kal_uint32 len = 0;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_FILE_TXT);
+    
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    handle = FS_Open(filename, FS_READ_ONLY);
+    NVRAM_FS_END(FS_OP_OPEN,result);
+    if (handle < FS_NO_ERROR) {
+        return;
+    }
+    NVRAM_FS_START(FS_OP_READ);
+    result = FS_Read(handle, info, sizeof(info)-1, &len);
+    NVRAM_FS_END(FS_OP_READ,result);
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(handle);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+    if (len > 0) {
+        info[len] = '\0';
+        dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_NIL, "[NVRAM] %s", info);  /* MOD_NIL will log to System trace */
+    }
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_exception
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  length:      [IN]   buffer length
+ *  ex_data:     [IN]   ex_data
+ *  ex_log:      [IN]   ex_log
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_write_exception(kal_uint16 length, long *ex_data, long *ex_log)
+{
+    #if defined(__MTK_TARGET__) || defined(__OFFLINE_EX_LOG_PARSER__)
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint16 i;
+    kal_uint16 prev_num = 0;
+
+    nvram_drv_status_enum result;
+    nvram_ltable_entry_struct *ldi;
+
+    EX_LOG_T *exception_ptr = (EX_LOG_T*) nvram_exception_buffer;    
+    EX_FULLLOG_T* exception_fulllog_ptr = (EX_FULLLOG_T*)ex_data;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s ====>\r\n",__FUNCTION__);
+    nvram_log_ota_info();
+    
+    if (ex_data == NULL)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s \r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION1();
+        return;
+    }
+    if (ex_log == NULL)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION1();
+        return;
+    }
+
+    /* Length must be equal to NVRAM_EF_SYS_EXCEPTION_SIZE */
+    if (length != NVRAM_EF_SYS_EXCEPTION_SIZE)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(length, NVRAM_EF_SYS_EXCEPTION_SIZE);
+        return;
+    }
+
+    /* Exception could happen even when no task is initialized */
+    if (nvram_ptr->state == NVRAM_STATE_NULL)
+    {
+        //nvram_init(INDX_NIL);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(NVRAM_STATE_NULL, 1);
+        return;
+    }
+
+   /**
+    * Now linear searching for a free record such that ex_data could be
+    * written.
+    *
+    * Note that if value of ex_nvram field of a exception record
+    * is NOT 0xFF, then it is a valid record; otherwise it is a free
+    * record.
+    * Furthermore, update of exception records cannot exceeds
+    * the capacity, ie, number of exception records defined in NVRAM.
+    * Once the storage is full, no more exception record can be dumped.
+    * Hence, as long as a free record is found, then that record and
+    * other records after it could be all assumed to be free.
+    */
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_EXCEPTION_LID);
+
+    for (i = 1; i <= NVRAM_EF_SYS_EXCEPTION_TOTAL; ++i)
+    {
+        memset(&exception_full_log,0,sizeof(exception_full_log));
+        result = nvram_read_exception_data_item(ldi, i, (kal_uint8*) & exception_full_log, sizeof(exception_full_log));
+        /* Ok, now determine whether it is a free record */
+
+        MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(i, result);
+        if ((result == NVRAM_DRV_OK))
+        {
+            if ((exception_full_log.mcu.ex_log.header.ex_nvram != KAL_TRUE) && (exception_full_log.mcu.ex_log.header.ex_serial_num < prev_num))  /* Found! */
+            {
+                break;
+            }
+            else
+            {
+                prev_num = exception_full_log.mcu.ex_log.header.ex_serial_num;
+            }
+        }
+        else if(result == NVRAM_DRV_EMPTY_RECORD)
+        {
+            if ((exception_full_log.mcu.ex_log.header.ex_nvram != KAL_TRUE))  /* Found! */
+            {
+                break;
+            }
+        }
+        else    /* Error, read fail!? How come?.....Dunno what to do.. */
+        {
+            MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(i, result);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+            return;
+        }
+    }
+
+    MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(0, 255);
+    if (i >= NVRAM_EF_SYS_EXCEPTION_TOTAL + 1)
+    {
+        i = 1;
+    }
+
+    prev_num += 1;
+    if (prev_num == 0xFFFF)
+    {
+        prev_num = 1;   /* wrap around to 1 if it reaches 65535 */
+    }
+
+   /**
+    *
+    * Hence the first record is the free record. Increment the serial number
+    * of the last record and take it as the new serial number for free record.
+    */
+    exception_ptr = (EX_LOG_T*) ex_log;
+    exception_ptr->header.ex_nvram = KAL_TRUE;
+    exception_ptr->header.ex_serial_num = prev_num;
+    
+    exception_fulllog_ptr->mcu.ex_log.header.ex_nvram = KAL_TRUE;
+    exception_fulllog_ptr->mcu.ex_log.header.ex_serial_num = prev_num;
+
+    MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(1, prev_num);
+    
+     MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(ldi->LID, i);
+    
+     nvram_write_exception_data_item(ldi, i, (kal_uint8*) ex_data);
+    
+     MD_TRC_FUNC_NVRAM_WRITE_EXCEPTION2(1, __LINE__);
+     NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s <====\r\n",__FUNCTION__);
+     #else
+     NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+     NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s <====\r\n",__FUNCTION__);
+     return;
+     #endif
+}   /* end of nvram_write_exception function */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_lid_num
+ * DESCRIPTION
+ *  To get the maxium LID
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_ptr->ltable.total_LID
+  *****************************************************************************/
+nvram_lid_enum nvram_get_lid_num(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    return nvram_ptr->ltable.total_LID;
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_check_backup
+ * DESCRIPTION
+ *  To tell given LID needs to backup or not
+ * PARAMETERS
+ *  LID         [IN]    LID of the file
+ *  prefix      [IN]    file prefix
+ * RETURNS
+ *  NVRAM_IO_ERRNO_OK: need to backup
+ *  NVRAM_IO_ERRNO_INVALID_LID: LID out of range or don't need to backup
+  *****************************************************************************/
+kal_uint8 nvram_check_backup(nvram_lid_enum LID, kal_char **prefix, kal_char **verno)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (!NVRAM_IS_LID_VALID(LID) || prefix == NULL)
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    if ((NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) ||
+         NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)||
+         NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) &&
+        !NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+    #ifdef __NVRAM_PSEUDO_MERGE__
+        if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+        {
+            *prefix = "PACK";
+            *verno  = "LID";
+        }
+        else
+    #endif
+        {
+            *prefix = ldi->fileprefix;
+            *verno = ldi->fileverno;
+        }
+        return NVRAM_IO_ERRNO_OK;
+    }
+    else
+    {
+        *prefix = NULL;
+        *verno = NULL;
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_validate_file
+ * DESCRIPTION
+ *  To validate integrity of  the given file
+ * PARAMETERS
+ *  LID         [IN]    LID of the file
+ *  path        [IN]    path to validate
+ * RETURNS
+ *  NVRAM_IO_ERRNO_OK: valid
+ *  NVRAM_IO_ERRNO_INVALID_LID: LID out of range
+ *  others: invalid
+  *****************************************************************************/
+nvram_errno_enum nvram_validate_file(nvram_lid_enum LID, kal_wchar *path)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *buffer = NULL;
+    kal_int32 result;
+    FS_HANDLE hFile = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    kal_uint32 file_offset;
+#endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        file_offset = (kal_uint32) (ldi->description);
+    }
+    else
+    {
+        file_offset = (kal_uint32) 0;
+    }
+#endif
+
+    /* open NV_RCD.(RCD#) file */
+    NVRAM_FS_START_EX(FS_OP_OPEN,path);
+    hFile = FS_Open((const kal_wchar*)path, FS_READ_ONLY | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+    if (FS_NO_ERROR > hFile)
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    NVRAM_FS_START(FS_OP_SEEK);
+    result = FS_Seek(hFile, file_offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,result);
+    if (file_offset && FS_NO_ERROR > result)
+    {
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(hFile);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+#endif
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    read_chksum_type = lid_chksum_info.read_chksum_type;
+
+
+    buffer = (kal_uint8 *)get_ctrl_buffer(nvram_chksum_size * ldi->total_records);
+
+    result = nvram_drv_fat_read_section(hFile, 1, ldi->total_records, ldi->size, buffer, read_chksum_type, ldi);
+
+    free_ctrl_buffer(buffer);
+
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+
+    if (result != NVRAM_DRV_OK)
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_multi_record
+ * DESCRIPTION
+ *  This function is used to get data items for external modules.
+ * PARAMETERS
+ *  LID             [IN]
+ *  rec_index       [IN]
+ *  rec_amount    [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ *  .(?)
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).
+ *****************************************************************************/
+kal_bool nvram_external_read_multi_record(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_WRONG_API_USE;
+        kal_prompt_trace(MOD_NVRAM,"%s->Raw LID 0x%x NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Raw LID 0x%04X NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+    
+    if(SST_NVRAM_Data_Access_Check(LID, 0, KAL_FALSE, NULL))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+#ifdef __NVRAM_READ_RESERVED_FILE__
+    if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+        nvram_ltable_entry_struct *ldi_r = (nvram_ltable_entry_struct*)ldi->default_value;
+        if(SST_NVRAM_Data_Access_Check(ldi_r->LID, 0, KAL_FALSE, NULL))
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Reserve LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,ldi_r->LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Reserve LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,ldi_r->LID);
+            return KAL_FALSE;
+        }    
+    }
+#endif
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;                
+        kal_prompt_trace(MOD_NVRAM,"[Error]%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return KAL_FALSE;
+    }
+
+    if (rec_index+rec_amount-1 > ldi->total_records)
+    {
+        rec_amount = ldi->total_records-rec_index+1;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item(ldi, rec_index, rec_amount, buffer, buffer_size);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+
+    if (result != NVRAM_IO_ERRNO_OK)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID(0x%x) nvram_read_data_item return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_data
+ * DESCRIPTION
+ *  This function is used to get data items for external modules.
+ * PARAMETERS
+ *  LID             [IN]
+ *  rec_index       [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ *  .(?)
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).
+ *****************************************************************************/
+kal_bool nvram_external_read_data(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    return nvram_external_read_multi_record(LID, rec_index, 1, buffer, buffer_size);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_raw_data
+ * DESCRIPTION
+ *  This function is used to get data items for external modules.
+ * PARAMETERS
+ *  LID             [IN]
+ *  offset          [IN]
+ *  buffer          [OUT]
+ *  buffer_size     [IN]
+ *  .(?)
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).
+ *****************************************************************************/
+kal_bool nvram_external_read_raw_data(nvram_lid_enum LID, kal_uint32 offset, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index  = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY) {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;
+        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    /**
+    * Invalid input paramters.
+    */
+    if(!nvram_util_get_data_item(&ldi, LID)) {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+    if(!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_WRONG_API_USE;        
+        kal_prompt_trace(MOD_NVRAM,"%s->Raw LID 0x%x NVRAM_ERRNO_WRONG_API_USE\r\n\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Raw LID 0x%04X NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    if(SST_NVRAM_Data_Access_Check(LID, 0, KAL_FALSE, NULL))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item(ldi, offset, 1, buffer, buffer_size);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    if (result != NVRAM_IO_ERRNO_OK)
+    {        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item return %d\r\n",__FUNCTION__,LID,result);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+
+}
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_secure_read_data
+ * DESCRIPTION
+ *  This function is used to get data items for external modules with secure check.
+ * PARAMETERS
+ *  LID             [IN]
+ *  rec_index       [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ *  .(?)
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).
+ *****************************************************************************/
+nvram_errno_enum nvram_external_secure_read_data(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size, void* reserved_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_SECURE_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_NOT_READY;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_WRONG_API_USE;        
+        kal_prompt_trace(MOD_NVRAM,"%s->Raw LID 0x%x NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Raw LID 0x%04X NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    if(SST_NVRAM_Data_Access_Check(LID, 0, KAL_TRUE, reserved_ptr))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }
+#ifdef __NVRAM_READ_RESERVED_FILE__
+    if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+        nvram_ltable_entry_struct *ldi_r = (nvram_ltable_entry_struct*)ldi->default_value;
+        if(SST_NVRAM_Data_Access_Check(ldi_r->LID, 0, KAL_FALSE, NULL))
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;                        
+            kal_prompt_trace(MOD_NVRAM,"%s->Reserve LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Reserve LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }    
+    }
+#endif
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;                        
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta mode\r\n",__FUNCTION__,ldi->LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta mode\r\n",__FUNCTION__,ldi->LID);
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return NVRAM_IO_ERRNO_INVALID_RECORD;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item(ldi, rec_index, 1, buffer, buffer_size);
+    if (result != NVRAM_IO_ERRNO_OK)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item return %d\r\n",__FUNCTION__,LID,result);
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item return %d\r\n",__FUNCTION__,LID,result);
+    }
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    return result;
+}
+
+nvram_errno_enum nvram_external_get_lid_chksum_algo_info(nvram_lid_enum LID, nvram_lid_chksum_algo_info* lid_chksum_algo_info)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+	kal_bool state = KAL_TRUE;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if(NULL == lid_chksum_algo_info)
+    {
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {     
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_NOT_READY;
+    }
+
+    state = nvram_util_get_data_item(&ldi, LID);
+    if (!state)
+    {       
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    result = nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    if(result != NVRAM_IO_ERRNO_OK)
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_ERRNO_GET_CHKSUM_ALGO_INGO.\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_GET_CHKSUM_ALGO_INGO.\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_GET_CHKSUM_ALGO_INGO;
+    }
+
+    lid_chksum_algo_info->chksum_algo_length = lid_chksum_info.algo_info.chksum_algo_length;
+    lid_chksum_algo_info->chksum_algo_type = lid_chksum_info.algo_info.chksum_algo_type;
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_chksum_value
+ * DESCRIPTION
+ *  This function is used to read the checksum of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  rec_amount:     [IN]    read how many record
+ *  buffer:         [OUT]   buffer pointer
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+nvram_errno_enum nvram_external_read_chksum_value(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size, nvram_lid_read_type_enum read_chksum_type)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+	kal_bool state = KAL_TRUE;
+    kal_uint32 nvram_trace_index  = 0;
+    kal_bool chksum_only = KAL_FALSE;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_NOT_READY;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+    state = nvram_util_get_data_item(&ldi, LID);
+    if (!state)
+    {       
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_INVALID;
+    }
+
+    if(((read_chksum_type == NVRAM_READ_TYPE_CHKSUM) || (read_chksum_type == NVRAM_READ_TYPE_CHKSUM_ONLY)))
+    {
+        chksum_only = (read_chksum_type == NVRAM_READ_TYPE_CHKSUM_ONLY)? KAL_TRUE : KAL_FALSE;
+        result = nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, chksum_only, KAL_FALSE);
+    }else
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_CHKSUM_TYPE_PARM;        
+        kal_prompt_trace(MOD_NVRAM, "[Error][NVRAM_ERRNO_CHKSUM_TYPE_PARM]%s->LID 0x%x, chceksum_type(%d)\r\n",__FUNCTION__,LID, read_chksum_type);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][NVRAM_ERRNO_CHKSUM_TYPE_PARM]%s->LID 0x%04X, chceksum_type(%d)\r\n",__FUNCTION__,LID, read_chksum_type);
+        return NVRAM_ERRNO_CHKSUM_TYPE_PARM;
+    }
+
+    if (result != NVRAM_IO_ERRNO_OK)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_ERRNO_GET_CHKSUM_ALGO_INGO return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_GET_CHKSUM_ALGO_INGO return %d\r\n",__FUNCTION__,LID,result);
+        return NVRAM_ERRNO_GET_CHKSUM_ALGO_INGO;
+    }
+
+    if (buffer_size < (lid_chksum_info.algo_info.chksum_algo_length * rec_amount))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;        
+        kal_prompt_trace(MOD_NVRAM, "[Error][NVRAM_IO_ERRNO_INVALID_SIZE]%s->LID 0x%x.\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][NVRAM_IO_ERRNO_INVALID_SIZE]%s->chksum_algo_type 0x%04X.\r\n",__FUNCTION__, lid_chksum_info.algo_info.chksum_algo_type);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error][NVRAM_IO_ERRNO_INVALID_SIZE]buffer_size(%d) < (chksum_algo_length*rec_amount: %d)\r\n",buffer_size,(lid_chksum_info.algo_info.chksum_algo_length * rec_amount));
+         return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return NVRAM_IO_ERRNO_INVALID_RECORD;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item_chksum(ldi, rec_index, rec_amount, buffer, buffer_size, lid_chksum_info.read_chksum_type);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    
+    if (result != NVRAM_IO_ERRNO_OK)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item_chksum return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item_chksum return %d\r\n",__FUNCTION__,LID,result);
+        return result;
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_chksum
+ * DESCRIPTION
+ *  This function is used to read the checksum of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  rec_amount:     [IN]    read how many record
+ *  buffer:         [OUT]   buffer pointer
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_read_chksum(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index  = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM_2B;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_TRUE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    read_chksum_type = lid_chksum_info.read_chksum_type;
+
+    if (buffer_size < (nvram_chksum_size * rec_amount))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;        
+        kal_prompt_trace(MOD_NVRAM, "[Error]%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_SIZE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",buffer_size,(nvram_chksum_size * rec_amount));
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return KAL_FALSE;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item_chksum(ldi, rec_index, rec_amount, buffer, buffer_size, read_chksum_type);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    
+    if (result != NVRAM_IO_ERRNO_OK)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item_chksum return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item_chksum return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_chksum_only
+ * DESCRIPTION
+ *  This function is used to read the checksum of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  rec_amount:     [IN]    read how many record
+ *  buffer:         [OUT]   buffer pointer
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_read_chksum_only(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+
+    
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_TRUE, KAL_TRUE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    read_chksum_type = lid_chksum_info.read_chksum_type;
+    
+    if (buffer_size < (nvram_chksum_size * rec_amount))
+    {        
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_SIZE buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",__FUNCTION__,LID,buffer_size,(nvram_chksum_size * rec_amount));
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",buffer_size,(nvram_chksum_size * rec_amount));
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {        
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;        
+        kal_prompt_trace(MOD_NVRAM,"[Error]%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return KAL_FALSE;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item_chksum(ldi, rec_index, rec_amount, buffer, buffer_size, read_chksum_type);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    if (result != NVRAM_IO_ERRNO_OK)
+    {                
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item_chksum return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item_chksum return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_chksum_8b
+ * DESCRIPTION
+ *  This function is used to read the checksum of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  rec_amount:     [IN]    read how many record
+ *  buffer:         [OUT]   md5 buffer pointer
+ *  buffer_size:    [IN]    md5 buffer size: must be 8-bytes length.
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_read_chksum_8b(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    read_chksum_type = lid_chksum_info.read_chksum_type;
+
+    if (buffer_size < (nvram_chksum_size * rec_amount))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_SIZE: buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",__FUNCTION__,LID,buffer_size,(nvram_chksum_size * rec_amount));
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",buffer_size,(nvram_chksum_size * rec_amount));
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;        
+        kal_prompt_trace(MOD_NVRAM,"[Error]%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return KAL_FALSE;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item_chksum_8b(ldi, rec_index, rec_amount, (kal_uint8*)buffer, buffer_size, read_chksum_type);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    if (result != NVRAM_IO_ERRNO_OK)
+    {        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item_chksum_8b return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item_chksum_8b return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_read_chksum_only_8b
+ * DESCRIPTION
+ *  This function is used to read the checksum of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  rec_amount:     [IN]    read how many record
+ *  buffer:         [OUT]   md5 buffer pointer
+ *  buffer_size:    [IN]    md5 buffer size: must be 8-bytes length.
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_read_chksum_only_8b(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index  = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM_ONLY;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.read_trace_index;
+    nvram_access_trace.read_trace_index = (nvram_access_trace.read_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.read_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.read_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.read_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.read_trace[nvram_trace_index].start_time = ust_get_current_time();    
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    /**
+    * Invalid input paramters.
+    */
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_TRUE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    read_chksum_type = lid_chksum_info.read_chksum_type;
+
+    if (buffer_size < (nvram_chksum_size * rec_amount))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_SIZE: buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",__FUNCTION__,LID,buffer_size,(nvram_chksum_size * rec_amount));
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer_size(%d) < (nvram_chksum_size * rec_amount: %d)\r\n",buffer_size,(nvram_chksum_size * rec_amount));
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||(rec_index > ldi->total_records))
+    {
+        nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.read_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return KAL_FALSE;
+    }
+
+
+    /* handle by nvram_io layer */
+    result = nvram_read_data_item_chksum_8b(ldi, rec_index, rec_amount, (kal_uint8*)buffer, buffer_size, read_chksum_type);
+    nvram_access_trace.read_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.read_trace[nvram_trace_index].ret_value = result;
+    if (result != NVRAM_IO_ERRNO_OK)
+    {        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_read_data_item_chksum_8b return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_read_data_item_chksum_8b return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_write_data
+ * DESCRIPTION
+ *  This function is used to write data items for external modules.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  buffer:         [IN]    buffer pointer
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_write_data(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index  = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.write_trace_index;
+    nvram_access_trace.write_trace_index = (nvram_access_trace.write_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.write_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.write_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.write_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.write_trace[nvram_trace_index].start_time = ust_get_current_time();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_WRONG_API_USE;        
+        kal_prompt_trace(MOD_NVRAM,"%s->Raw LID 0x%x NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Raw LID 0x%04X NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    if(SST_NVRAM_Data_Access_Check(LID, 1, KAL_FALSE, NULL))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||
+        (rec_index > ldi->total_records))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return KAL_FALSE;
+    }
+
+    if (buffer_size < ldi->size)
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_SIZE:buffer size(%d)< record_size(%d)\r\n",__FUNCTION__,LID,buffer_size,ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer size(%d)< record_size(%d)\r\n",buffer_size,ldi->size);
+        return KAL_FALSE;
+    }
+
+    result = nvram_write_data_item(ldi, rec_index, buffer, KAL_FALSE);
+    nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.write_trace[nvram_trace_index].ret_value = result;
+
+    if (result != NVRAM_IO_ERRNO_OK)
+    {        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_write_data_item return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_write_data_item return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_write_raw_data
+ * DESCRIPTION
+ *  This function is used to write data items for external modules.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  offset:         [IN]    file offset
+ *  buffer:         [IN]    buffer pointer
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_write_raw_data(nvram_lid_enum LID, kal_uint32 offset, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index  = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.write_trace_index;
+    nvram_access_trace.write_trace_index = (nvram_access_trace.write_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.write_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.write_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.write_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.write_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;        
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    /**
+    * Invalid input paramters.
+    */
+    if(!nvram_util_get_data_item(&ldi, LID)) {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+    if(!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_WRONG_API_USE;        
+        kal_prompt_trace(MOD_NVRAM,"%s->Raw LID 0x%x NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Raw LID 0x%04X NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    if(SST_NVRAM_Data_Access_Check(LID, 1, KAL_FALSE, NULL))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;            
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return KAL_FALSE;
+        }
+    }
+#endif
+
+    ldi->size = buffer_size;
+    result = nvram_write_data_item(ldi, offset, buffer, KAL_FALSE);
+    nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.write_trace[nvram_trace_index].ret_value = result;
+    if (result != NVRAM_IO_ERRNO_OK)
+    {        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_write_data_item return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_write_data_item return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    else
+    {
+        return KAL_TRUE;
+    }
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_secure_write_data
+ * DESCRIPTION
+ *  This function is used to write data items for external modules with secure check.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  buffer:         [IN]    buffer pointer
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+nvram_errno_enum nvram_external_secure_write_data(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size, void* reserved_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_trace_index  = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.write_trace_index;
+    nvram_access_trace.write_trace_index = (nvram_access_trace.write_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.write_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.write_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_SECURE_API;
+    nvram_access_trace.write_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.write_trace[nvram_trace_index].start_time = ust_get_current_time();
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;
+        kal_prompt_trace(MOD_NVRAM, "%s->LID 0x%x NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        return NVRAM_ERRNO_NOT_READY;
+    }
+
+//    nvram_pre_init();
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_WRONG_API_USE;
+        kal_prompt_trace(MOD_NVRAM,"%s->Raw LID 0x%x NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Raw LID 0x%04X NVRAM_ERRNO_WRONG_API_USE\r\n",__FUNCTION__,LID);
+        return KAL_FALSE;
+    }
+
+    if(SST_NVRAM_Data_Access_Check(LID, 1, KAL_TRUE, reserved_ptr))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED\r\n",__FUNCTION__,LID);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }
+
+#if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area */
+    if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == stack_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+            kal_prompt_trace(MOD_NVRAM,"%s->Custom LID 0x%x NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->Custom LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }
+    }
+#endif
+
+    if ((rec_index < 1) ||
+        (rec_index > ldi->total_records))
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_RECORD;
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_RECORD:rec_index(%d) total_records(%d)\r\n",__FUNCTION__,LID,rec_index,ldi->total_records);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return NVRAM_IO_ERRNO_INVALID_RECORD;
+    }
+
+    if (buffer_size < ldi->size)
+    {
+        nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.write_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_SIZE;
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x NVRAM_IO_ERRNO_INVALID_SIZE:buffer size(%d)< record_size(%d)\r\n",__FUNCTION__,LID,buffer_size,ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer size(%d)< record_size(%d)\r\n",buffer_size,ldi->size);
+        return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+
+    result = nvram_write_data_item(ldi, rec_index, buffer, KAL_FALSE);
+    nvram_access_trace.write_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.write_trace[nvram_trace_index].ret_value = result;
+    if (result != NVRAM_IO_ERRNO_OK)
+    {        
+        kal_prompt_trace(MOD_NVRAM,"%s->LID 0x%x nvram_write_data_item return %d\r\n",__FUNCTION__,LID,result);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X nvram_write_data_item return %d\r\n",__FUNCTION__,LID,result);
+        return KAL_FALSE;
+    }
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_reset_data
+ * DESCRIPTION
+ *  This function is used to reset data items for external modules.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index
+ *  buffer:         [IN]    buffer pointer
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_FALSE:  fail
+ *  KAL_TRUE:   success
+ *****************************************************************************/
+kal_bool nvram_external_reset_data(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_ltable_entry_struct tmp_ldi = {0};
+    kal_bool result = KAL_FALSE;
+    kal_uint32 nvram_trace_index  = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s ====>\r\n",__FUNCTION__);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"LID:0x%04X rec_index=%d,rec_amount=%d\r\n",LID,rec_index,rec_amount);
+    /*record nvram msg read access information to global struct*/
+    nvram_util_take_mutex(g_nvram_trace_mutex);
+    nvram_trace_index = nvram_access_trace.reset_trace_index;
+    nvram_access_trace.reset_trace_index = (nvram_access_trace.reset_trace_index + 1) % MAX_TRACE_NUM;
+    nvram_util_give_mutex(g_nvram_trace_mutex);
+
+    kal_mem_set((void *)&(nvram_access_trace.reset_trace[nvram_trace_index]), 0, sizeof(trace_info));
+    nvram_access_trace.reset_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_NORMAL_API;
+    nvram_access_trace.reset_trace[nvram_trace_index].LID = LID;
+    nvram_access_trace.reset_trace[nvram_trace_index].start_time = ust_get_current_time();
+    
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        return KAL_FALSE;
+    }
+
+//    nvram_pre_init();
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+        nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+        return KAL_FALSE;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    /* In Meta mode, we cannot access the data belongs to custom sensitve area
+       we also cannot reset the important data to prevent security problem */
+    if (NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)
+        || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)
+        #if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__)
+        || NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category)
+        || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category)
+        #endif
+       )
+    {
+    #ifdef __TC01__
+        if (FACTORY_BOOT == kal_query_boot_mode() && stack_get_active_module_id() == MOD_FT)
+    #else
+        if (FACTORY_BOOT == kal_query_boot_mode() && kal_get_active_module_id() == MOD_FT)
+    #endif
+        {
+            nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+            nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED;
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED for Meta Mode\r\n",__FUNCTION__,LID);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s <====\r\n",__FUNCTION__);
+            return KAL_FALSE;
+        }
+    }
+
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[collection]%s -> LID:0x%04X index=%d\r\n",__FUNCTION__, ldi->LID, ldi->size);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[collection]rec_amount=%d,rec_index=%d\r\n", rec_amount, rec_index);
+
+    result = nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, rec_index, rec_amount);
+    memcpy(&tmp_ldi,ldi,sizeof(nvram_ltable_entry_struct));
+    mcf_do_ota_by_lid(LID,rec_index, rec_amount,&tmp_ldi);
+    
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s <====\r\n",__FUNCTION__);
+    nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time();
+    nvram_access_trace.reset_trace[nvram_trace_index].ret_value = result;
+    
+    return result;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_default_value
+ * DESCRIPTION
+ *  This function is used to get default value for external modules.
+ * PARAMETERS
+ *  LID             [IN]
+ *  rec_index       [IN]
+ *  p_buffer        [IN/OUT]
+ *
+ * RETURNS
+ *  NVRAM_DEFAULT_VALUE_FAIL : get default value fail
+ *  NVRAM_DEFAULT_VALUE_FF   : p_buffer is invalid, default value is FF
+ *  NVRAM_DEFAULT_VALUE_ZERO : p_buffer is invalid, default value is zero
+ *  NVRAM_DEFAULT_VALUE_POINT: p_buffer is valid, use p_buffer to get default value
+ *****************************************************************************/
+nvram_default_value_enum nvram_get_default_value(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint8 **p_buffer)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_default_value_enum result = NVRAM_DEFAULT_VALUE_SUCCESS;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    if (!NVRAM_IS_LID_VALID(LID))
+    {        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID\r\n",__FUNCTION__,LID);
+        return NVRAM_DEFAULT_VALUE_FAIL;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    if ((rec_index < 1) || (rec_index > ldi->total_records))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_RECORD:\r\n",__FUNCTION__,LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]rec_index(%d) total_records(%d)\r\n",rec_index,ldi->total_records);
+        return NVRAM_DEFAULT_VALUE_FAIL;
+    }
+
+
+    /* Multi default value */
+    if ((ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+    {
+        rec_index--;
+    }
+    else
+    {
+        rec_index = 0;
+    }
+
+    if ((ldi->LID >= NVRAM_EF_L1_START && ldi->LID <= NVRAM_EF_L1_END)
+        || (ldi->LID >= NVRAM_EF_UL1_START && ldi->LID <= NVRAM_EF_UL1_END)
+    #if defined(__WIFI_SUPPORT__)&&(__CUSTOM_WIFI_FEATURES_SWITCH__)
+        || (ldi->LID >= NVRAM_EF_WNDRV_START && ldi->LID <= NVRAM_EF_WNDRV_END)
+    #endif
+#if !defined(MED_NOT_PRESENT)
+#ifdef __AMRWB_LINK_SUPPORT__
+        || (ldi->LID == NVRAM_EF_AUDIO_WB_SPEECH_INPUT_FIR_LID) || (ldi->LID == NVRAM_EF_AUDIO_WB_SPEECH_OUTPUT_FIR_LID) || (ldi->LID == NVRAM_EF_AUDIO_WB_SPEECH_MODE_PARAM_LID)
+#endif
+#ifdef __AUDIO_COMPENSATION_SW_VERSION__
+        || (ldi->LID == NVRAM_EF_AUDIO_SWFIR_LID)
+#endif
+#ifdef __BES_LOUDNESS_SUPPORT__
+        || (ldi->LID == NVRAM_EF_AUDIO_BESLOUDNESS_LID)
+#endif
+        || (ldi->LID == NVRAM_EF_AUDIO_DC_CALIBRATION_LID)
+
+        || (ldi->LID == NVRAM_EF_AUDIO_PARAM_LID)
+#endif
+        )
+    {
+        result = NVRAM_DEFAULT_VALUE_APPLICATION;
+    }
+#ifdef __NVRAM_COMPRESS_SUPPORT__
+    else if (NVRAM_IS_ATTR_ZIP_DEFAULT(ldi->attr))
+    {
+        result = NVRAM_DEFAULT_VALUE_FF;
+    }
+#endif
+    else
+    {
+        /* No default value supplied. Fill the buffer with 0xFF. */
+        if (ldi->default_value == NULL || ldi->default_value == (kal_uint8 const*)NVRAM_EF_FF_DEFAULT)
+        {
+            result = NVRAM_DEFAULT_VALUE_FF;
+        }     /* Default value is all the same value (0x00) Fill it as well. */
+        else if (ldi->default_value == (kal_uint8 const*)NVRAM_EF_ZERO_DEFAULT)
+        {
+            result = NVRAM_DEFAULT_VALUE_ZERO;
+        }
+        else
+        {
+            *p_buffer = (void*)(ldi->default_value + ldi->size * rec_index);
+            result = NVRAM_DEFAULT_VALUE_POINT;
+        }
+    }
+//#ifdef __NVRAM_PSEUDO_MERGE__
+    MD_TRC_FUNC_NVRAM_GET_DEFAULT_VALUE(ldi->LID, result, ldi->size, ldi->fileprefix);
+//#else
+//    nvram_trace(TRACE_FUNC, FUNC_NVRAM_GET_DEFAULT_VALUE, ldi->LID, result, ldi->size);
+//#endif
+    return result;
+}
+
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_shutdown_handler
+ * DESCRIPTION
+ *  Disable all interrupts, change NVRAM state, change FS command mode, and flush
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_shutdown_handler(void)
+{
+
+#ifdef __MMI_FMI__    
+#if !defined(__L1_STANDALONE__)
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* to handle shutdown callback */
+    for (i = 0; ;i++)
+    {
+        if (nvram_shutdown_cb_table[i].LID == 0 && nvram_shutdown_cb_table[i].get_data == NULL)
+        {
+            break;
+        }
+
+        if (NVRAM_IS_LID_VALID(nvram_shutdown_cb_table[i].LID) && nvram_shutdown_cb_table[i].get_data)
+        {
+            kal_uint8 *data;
+            nvram_ltable_entry_struct *ldi;
+
+            nvram_util_get_data_item(&ldi, nvram_shutdown_cb_table[i].LID);
+            data = (kal_uint8 *)get_ctrl_buffer(ldi->size);
+            if (nvram_shutdown_cb_table[i].get_data(data, ldi->size))
+            {
+                /* doesn't support linear-fix */
+                nvram_write_data_item(ldi, 1, data, KAL_FALSE);
+            }
+            free_ctrl_buffer(data);
+        }
+    }
+#endif /* !__L1_STANDALONE__ */
+#endif /* __MMI_FMI__ */
+}
+
+#ifdef __NVRAM_DISK_SIZE_CHECK__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_space_reserve
+ * DESCRIPTION
+ *  To perform software upgrade.
+ * PARAMETERS
+ *  SpecialName         [?]
+ *  StillNeed           [?]
+ *  sysrecord(?)        [IN]        Sysrecord
+ * RETURNS
+ *  Success or Fail(?)
+ *****************************************************************************/
+void nvram_space_reserve(kal_uint32 *size_from_code)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 CodeFileSize;
+    kal_uint32 clusterSize;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_FS_START_EX(FS_OP_GETCLUSTERSIZE,'Z');
+    clusterSize = FS_GetClusterSize('Z');
+    NVRAM_FS_END(FS_OP_GETCLUSTERSIZE,clusterSize);
+
+    nvram_pre_init();
+
+    nvram_get_code_file_size(&CodeFileSize);
+
+    *size_from_code = (CodeFileSize / clusterSize) + ((CodeFileSize / clusterSize)? 1 : 0) + NVRAM_SPACE_MARGIN;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_folder_name
+ * DESCRIPTION
+ *  To get NVRAM folder name.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  NVRAM folder name.
+ *****************************************************************************/
+void nvram_get_folder_name(WCHAR *nvram_folder_name)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_wstrcpy(nvram_folder_name, NVRAM_FS_FOLDER_NAME);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_work_path
+ * DESCRIPTION
+ *  To get NVRAM working directory.
+ * PARAMETERS
+ *  folder_idx  : Which folder
+ * RETURNS
+ *  NVRAM working directory.
+ *****************************************************************************/
+kal_char *nvram_get_work_path(kal_uint8 folder_idx)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    return nvram_query_work_path((nvram_folder_enum)folder_idx);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_folder_idx
+ * DESCRIPTION
+ *  To get the index of nvram folder.
+ * PARAMETERS
+ *  LID  :
+ * RETURNS
+ *  index of folder.
+ *****************************************************************************/
+kal_uint8 nvram_get_folder_idx(nvram_lid_enum LID)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    return nvram_query_folder_index(ldi->category);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_file_fullname
+ * DESCRIPTION
+ *  To get the full name of nvram file.
+ * PARAMETERS
+ *  folder_idx : [In]
+ *  nvramname  : [In]
+ *  filename   : [Out]
+ * RETURNS
+ *  index of folder.
+ *****************************************************************************/
+kal_wchar * nvram_get_file_fullname(kal_uint8 folder_idx, kal_char *nvramname, kal_wchar *filename)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    return nvram_query_file_name((nvram_folder_enum)folder_idx, nvramname, filename);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_folder_total_amount
+ * DESCRIPTION
+ *  To get the full name of nvram file.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  number of folders
+ *****************************************************************************/
+kal_uint8 nvram_get_folder_total_amount(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    return NVRAM_FOLDER_TOTAL;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_check_hidden_files
+ * DESCRIPTION
+ *  Check if the files or folder is hidden or not in Meta FAT Editor.
+ *  1. Any LID with NVRAM_CATEGORY_IMPORTANT will not appear in meta FAT Editor. ex: IMEI and SML
+ *  2. Important Folder will not appear in meta FAT Editor.
+ *  3. Customer sensitive data.
+ *  Exception 1: During backup/restore, we can see IMEI and SML
+ *  Exception 2: When NVRAM is locked. All the files and folder are hidden.
+ *
+ * PARAMETERS
+ *  filename    [IN]    the filename
+ *  backup      [IN]    During backup/restore the hidden file is different from normal
+ *                      Please set this as true during backup/restore
+ * RETURNS
+ *  a boolean value
+ * RETURN VALUES
+ *  KAL_TRUE:   hidden
+ *  KAL_FALSE:  not hidden
+ *****************************************************************************/
+kal_bool nvram_check_hidden_file(const kal_wchar* filename, kal_bool backup)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar buf[NVRAM_MAX_PATH_LEN];
+    nvram_ltable_entry_struct *ldi;
+#ifdef __NVRAM_MULTI_FOLDERS__
+    nvram_folder_enum i;
+#endif
+    kal_wchar *starter;
+    kal_char *temp_strrchr = NULL;
+
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    starter = kal_wstrchr(filename, '\\');
+
+    if (starter == NULL)
+    {
+        return KAL_FALSE;
+    }
+
+    if (kal_wstrncmp(starter + 1, NVRAM_FS_FOLDER_NAME, kal_wstrlen(NVRAM_FS_FOLDER_NAME)) !=0 )
+    {
+        /* Not belongs to NVRAM folder */
+        return KAL_FALSE;
+    }
+
+    if (nvram_test_lock() && backup == KAL_FALSE)
+    {
+        return KAL_TRUE;
+    }
+    
+    starter = kal_wstrrchr(filename, '\\') + 1;
+
+#ifdef __NVRAM_MULTI_FOLDERS__
+    for (i = NVRAM_FOLDER_BEGIN; i < NVRAM_FOLDER_TOTAL ; i++)
+    {
+        temp_strrchr = strrchr(nvram_query_work_path(i), '\\');
+        if(temp_strrchr == NULL)
+        {
+            continue;
+        }
+        kal_wsprintf(buf, "%s", temp_strrchr+1);
+        if (kal_wstrcmp(buf, starter) == 0)
+        {
+            if ((i == NVRAM_NVD_IMPT && backup == KAL_FALSE)
+                #ifdef __NVRAM_CUSTOM_SENSITIVE__
+                || i == NVRAM_NVD_CUST
+                #endif
+                )
+            {
+                return KAL_TRUE;
+            }
+            else
+            {
+                return KAL_FALSE;
+            }
+        }
+    }
+#endif
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        if (( NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) && backup == KAL_FALSE)
+            || (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) && backup == KAL_FALSE)
+        #ifdef __NVRAM_CUSTOM_SENSITIVE__
+            || NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category)
+        #endif
+        #ifdef __NVRAM_CUSTOM_DISK__
+            || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category)
+        #endif
+            )
+        {
+
+            kal_wsprintf(buf, "%s", ldi->fileprefix);
+
+            if (kal_wstrncmp(buf, starter, FILE_PREFIX_LEN)== 0)
+            {
+                return KAL_TRUE;
+            }
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    return KAL_FALSE;
+}
+
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_compare_to_default_value
+ * DESCRIPTION
+ *  This function is used to compare the value in nvram file to default value
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index, start from 1, but if the value is 0,
+ *                          this function will compare all record to default value
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  NVRAM_ERRNO_SUCCESS:            no error
+ *  NVRAM_ERRNO_FAIL:   at least one record is different to default value
+ *****************************************************************************/
+kal_int32 nvram_compare_to_default_value(nvram_lid_enum LID, kal_uint16 rec_index)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    int i;
+    kal_uint8 *default_value = NULL;
+    kal_uint8 *buffer = NULL;
+    kal_int32 compare_result = 1;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    if (rec_index > ldi->total_records)
+    {
+        return NVRAM_IO_ERRNO_INVALID_RECORD;
+    }
+
+    if (ldi->size <= MAX_NVRAM_RECORD_SIZE)
+    {
+        /* this function doesn't support the size over 2K now */
+        buffer = (kal_uint8*) get_ctrl_buffer(ldi->size);
+
+
+        for (i = (rec_index == 0?0:rec_index-1); i < ldi->total_records ; i++)
+        {
+            nvram_read_data_item(ldi, i + 1, 1, buffer, ldi->size);
+
+            default_value = (kal_uint8 *)nvram_get_default_value_to_write(ldi, i + 1, NULL, 0);
+
+            if (default_value == NULL || default_value == NVRAM_EF_FF_DEFAULT || default_value == NVRAM_EF_ZERO_DEFAULT)
+            {
+                default_value = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                nvram_get_default_value_to_write(ldi, i + 1, default_value, ldi->size);
+                compare_result = memcmp(default_value, buffer, ldi->size);
+                free_ctrl_buffer(default_value);
+            }
+            else
+            {
+                compare_result = memcmp(default_value, buffer, ldi->size);
+            }
+
+            if (rec_index != 0)
+            {
+                break;
+            }
+        }
+
+        free_ctrl_buffer(buffer);
+    }
+    else
+    {
+        kal_uint8 *chksum2 = NULL;
+        kal_uint8 *chksum1 = NULL;
+        kal_uint32 nvram_chksum_size = 0;
+        nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM;
+        nvram_lid_chksum_info lid_chksum_info = {0};
+
+        nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+        nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+        read_chksum_type = lid_chksum_info.read_chksum_type;
+
+        buffer = (kal_uint8*) get_ctrl_buffer(ldi->total_records * nvram_chksum_size);
+        chksum1 = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+        /* this is temp solution, should implement full solution in drv layer in the future */
+        nvram_read_data_item_chksum(ldi, 1, ldi->total_records, buffer, ldi->total_records * nvram_chksum_size, read_chksum_type);
+
+        for (i = (rec_index == 0?0:rec_index-1); i < ldi->total_records ; i++)
+        {
+            default_value = (kal_uint8 *)nvram_get_default_value_to_write(ldi, i + 1, NULL, 0);
+
+            /* not support special default_value now */
+            if(default_value == NULL)
+            {
+                if(buffer)
+                {
+                    free_ctrl_buffer(buffer);
+                    buffer = NULL;
+                }
+                if (chksum1)
+                {
+                    free_ctrl_buffer(chksum1);
+                    chksum1 = NULL;
+                }
+                NVRAM_EXT_ASSERT(KAL_FALSE,0, NVRAM_LOC_GET_DEFAULT_VALUE_IS_NULL_1, 0, __LINE__);
+            }
+
+            kal_mem_set(chksum1, 0, nvram_chksum_size);
+            nvram_util_caculate_checksum(ldi, default_value, ldi->size, chksum1);
+            chksum2 = buffer + (nvram_chksum_size * i);
+
+            compare_result = memcmp(chksum1, chksum2, nvram_chksum_size);
+            if(compare_result != 0)
+            {
+                compare_result = 1;
+            }
+
+            if (rec_index != 0)
+            {
+                break;
+            }
+        }
+
+        if(buffer)
+        {
+            free_ctrl_buffer(buffer);
+            buffer = NULL;
+        }
+        if (chksum1)
+        {
+            free_ctrl_buffer(chksum1);
+            chksum1 = NULL;
+        }
+    }
+
+    if (compare_result == 0)
+    {
+        return NVRAM_ERRNO_SUCCESS;
+    }
+    else
+    {
+        return NVRAM_ERRNO_FAIL;
+    }
+}
+
+kal_uint8 *nvram_get_custpack_version(void)
+{
+    return nvram_ptr->custpack_version;
+}
+void nvram_dummy(void)
+{
+}
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_set_restore_factory_flag
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_bool nvram_set_restore_factory_flag(nvram_restore_flag_enum restore_flag)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 sys_cache[NVRAM_EF_SYS_CACHE_OCTET_SIZE];
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_CACHE_OCTET_LID);
+
+    /*
+     * if current record just record NVRAM_SYS_FACTORY_FLAG
+     *  1. please use memory set
+     *  2. else read out first.
+     */
+    memset(sys_cache, 0, NVRAM_EF_SYS_CACHE_OCTET_SIZE);
+
+    sys_cache[0] = (kal_uint8) restore_flag;
+
+    nvram_write_data_item(ldi, NVRAM_SYS_FACTORY_FLAG, sys_cache, KAL_FALSE);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_check_restore_factory_flag
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_bool nvram_check_restore_factory_flag(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 sys_cache[NVRAM_EF_SYS_CACHE_OCTET_SIZE];
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_CACHE_OCTET_LID);
+
+    nvram_read_data_item(ldi, NVRAM_SYS_FACTORY_FLAG, 1, sys_cache, NVRAM_EF_SYS_CACHE_OCTET_SIZE);
+
+    if (NVRAM_RESTORE_TRUE == sys_cache[0])
+    {
+        return KAL_TRUE;
+    }
+    else
+    {
+        return KAL_FALSE;
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_msg_read_req
+ * DESCRIPTION
+ *  This function issues MSG_ID_NVRAM_READ_REQ  to nvram.
+ * PARAMETERS
+ *  file_idx            [IN]        
+ *  record_index        [IN]        
+ *  access_id           [IN]        
+ *  rec_amount          [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_external_msg_read_req(
+                kal_uint16 file_idx,
+                kal_uint16 record_index,
+                kal_uint8 access_id,
+                kal_uint16 rec_amount)
+{
+
+    nvram_read_req_struct *nvram_read_req;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    nvram_read_req = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+    nvram_read_req->file_idx = (nvram_lid_enum) file_idx;
+    nvram_read_req->para = record_index;
+    nvram_read_req->access_id = (kal_uint16) access_id;
+    nvram_read_req->rec_amount = rec_amount;
+	
+    msg_send6(stack_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_READ_REQ, (local_para_struct *)nvram_read_req,NULL);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+}   /* end of nvram_msg_read_req */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_msg_write_req
+ * DESCRIPTION
+ *  This function issues NVRAM_WRITE_REQ to nvram.
+ * PARAMETERS
+ *  file_idx            [IN]        
+ *  record_index        [IN]        
+ *  access_id           [IN]        
+ *  peer_buf_ptr        [?]         
+ *  ilm_ptr(?)          [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_external_msg_write_req(
+                kal_uint16 file_idx,
+                kal_uint16 record_index,
+                kal_uint8 access_id,
+                peer_buff_struct *peer_buf_ptr)
+{
+
+    nvram_write_req_struct *nvram_write_req;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    
+    nvram_write_req = (nvram_write_req_struct*) construct_local_para(sizeof(nvram_write_req_struct), TD_CTRL);
+    nvram_write_req->file_idx = (nvram_lid_enum) file_idx;
+    nvram_write_req->para = record_index;
+    nvram_write_req->access_id = (kal_uint16) access_id;
+
+    msg_send6(stack_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_WRITE_REQ, (local_para_struct *)nvram_write_req, peer_buf_ptr);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+}   /* end of nvram_msg_write_req */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_msg_reset_req
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  src_id              [IN]        
+ *  reset_category      [IN]        
+ *  lid                 [IN]        
+ *  rec_index           [IN]        
+ *  rec_amount          [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_external_msg_reset_req(
+	     kal_uint16 file_idx,
+            kal_uint16 record_index,
+            kal_uint16 rec_amount,
+            kal_uint8 access_id)
+{
+    nvram_reset_req_struct *nvram_reset_req;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    
+    nvram_reset_req = (nvram_reset_req_struct*) construct_local_para((kal_uint16) sizeof(nvram_reset_req_struct), TD_RESET);
+
+    nvram_reset_req->reset_category = NVRAM_RESET_CERTAIN;
+    nvram_reset_req->LID = file_idx;
+    nvram_reset_req->access_id = access_id;
+    nvram_reset_req->rec_index = record_index;
+    nvram_reset_req->rec_amount = rec_amount;
+
+    msg_send6(stack_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_RESET_REQ, (local_para_struct *)nvram_reset_req, NULL);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+}
+
+
+extern void nvram_set_ltable(nvram_ltable_entry_struct *table);
+extern nvram_ltable_entry_struct *nvram_get_ltable(void);
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_ltable_register
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_ltable_register(nvram_ltable_entry_struct *table)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    
+    nvram_set_ltable(table);
+}
+
+// The return value not used now, always return KAL_TRUE
+kal_bool nvram_register_read_req(nvram_read_callback_struct *entry)
+{
+    nvram_callback_req_struct *local_data;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    
+    entry->processed = KAL_FALSE;
+    /*send a message to NVRAM to wakeup NVRAM task*/
+    local_data = (nvram_callback_req_struct*) construct_local_para(sizeof(nvram_callback_req_struct), TD_CTRL);
+    local_data->ref_count = 1;
+    local_data->access_id = 0;
+    local_data->cfun_addr = (void*)(entry->callback);
+    nvram_send_ilm(MOD_NVRAM, MSG_ID_NVRAM_CALLBACK_REQ, local_data, NULL);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_msg_reg_req
+ * DESCRIPTION
+ *  file_idx               [IN]  
+ *  rec_index           [IN]        
+ *  rec_amount          [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_external_msg_reg_req(
+            kal_uint16 file_idx,
+            kal_uint16 record_index,
+            kal_uint16 rec_amount)
+{
+    nvram_reg_notify_req_struct *nvram_read_req;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    
+    nvram_read_req = (nvram_reg_notify_req_struct*) construct_local_para(sizeof(nvram_reg_notify_req_struct), TD_CTRL);
+    nvram_read_req->file_idx = (nvram_lid_enum) file_idx;
+    nvram_read_req->para = record_index;
+    nvram_read_req->access_id = 0;
+    nvram_read_req->rec_amount = rec_amount;
+    
+    msg_send6(stack_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_REG_NOTIFY_REQ, (local_para_struct *)nvram_read_req,NULL);
+}
+
+void nvram_external_msg_dereg_req(
+            kal_uint16 file_idx,
+            kal_uint16 record_index,
+            kal_uint16 rec_amount)
+{
+    nvram_dereg_notify_req_struct *nvram_read_req;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    
+    nvram_read_req = (nvram_dereg_notify_req_struct*) construct_local_para(sizeof(nvram_dereg_notify_req_struct), TD_CTRL);
+    nvram_read_req->file_idx = (nvram_lid_enum) file_idx;
+    nvram_read_req->para = record_index;
+    nvram_read_req->access_id = 0;
+    nvram_read_req->rec_amount = rec_amount;
+    
+    msg_send6(stack_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_DEREG_NOTIFY_REQ, (local_para_struct *)nvram_read_req,NULL);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+}
+
+#ifdef __NVRAM_READ_RESERVED_FILE__
+kal_bool nvram_external_search_reserved_lid(nvram_lid_enum LID, kal_char *verno, kal_uint16 total_records, kal_uint16 size)
+{
+    nvram_ltable_entry_struct *ldi, *ldi_r;
+    kal_char filename[NVRAM_MAX_PATH_LEN];
+    NVRAM_FULL_PATH r_filename;
+    nvram_ldi_ota_header ota_hdr;
+    kal_int32 result = 0;
+
+    nvram_util_get_data_item(&ldi, LID);
+    if (!ldi) {
+        return KAL_FALSE;
+    }
+
+    //search file
+    sprintf(filename, "%s?%s_", ldi->fileprefix, verno);
+    if(total_records) {
+        sprintf((filename + NVRAM_FILE_LEN + 1), "%04X", total_records);
+    }
+    else {
+        strcat(filename, "????");
+    }
+
+    if(size) {
+       result = sprintf((filename + NVRAM_FILE_LEN + 5), "%04X", size);
+       if(result < 0)
+       {
+            return KAL_FALSE;
+       }
+    }
+    else {
+        strcat(filename, "????");
+    }
+    
+    if(!nvram_ota_search_backup_file(filename, (NVRAM_FULL_PATH *)r_filename)) {
+        return KAL_FALSE;
+    }
+
+    //check file header
+    if(!nvram_read_data_header(r_filename, LDI_HEADER_OTA_SECTION, (void*)&ota_hdr, NVRAM_LDI_OTA_HEADER_SIZE)) {
+        return KAL_FALSE;
+    }
+
+    //Prepare NVRAM_EF_READ_RESERVED_LID_VERNO
+    nvram_util_get_data_item(&ldi_r, NVRAM_EF_READ_RESERVED_LID);
+    if (!ldi_r) {
+        return KAL_FALSE;
+    }
+    ldi_r->attr = ota_hdr.ldi_attr;
+    ldi_r->total_records = ota_hdr.total_records;
+    ldi_r->size = ota_hdr.record_size;
+    ldi_r->default_value = (kal_uint8*)ldi;
+    strncpy(ldi_r->fileprefix, ldi->fileprefix, FILE_PREFIX_LEN);
+    ldi_r->fileprefix[FILE_PREFIX_LEN] = '\0';
+    strncpy(ldi_r->fileverno, verno, FILE_VERNO_LEN);
+    ldi_r->fileverno[FILE_VERNO_LEN] = '\0';
+    
+    return KAL_TRUE;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_external_get_lid_info
+ * DESCRIPTION
+ *  This function is used to get the LID info
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  ldi:            [OUT]   LID info buffer pointer,store the LID info 
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  NVRAM_ERRNO_SUCCESS:            no error
+ *  NVRAM_IO_ERRNO_INVALID_LID:     invalid LID
+ *  NVRAM_ERRNO_INVALID:            lid pointer is NULL
+ *****************************************************************************/
+
+
+nvram_errno_enum nvram_external_get_lid_info(nvram_lid_enum LID,nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *tmp_ldi = NULL;
+    kal_bool ret = KAL_TRUE;
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    
+    if(ldi == NULL)
+    {
+        return NVRAM_ERRNO_INVALID;
+    }
+    ret = nvram_util_get_data_item(&tmp_ldi, LID);
+    
+    if (!ret)
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+    memcpy(ldi,tmp_ldi,sizeof(nvram_ltable_entry_struct));
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+kal_bool nvram_debug_info_init(kal_uint32 **share_mem,kal_uint32 *length_ptr)
+{
+    #if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+    if(nvram_ee_info == NULL)
+    {
+        g_nvram_emm_query_info_result = EMM_DirInfo_Query(EMM_DIRECT_WRITE_NVRAM, &g_nvram_emm_addr, &g_nvram_emm_size);
+        if((g_nvram_emm_size < sizeof(nvram_ee_info_type)) || !g_nvram_emm_query_info_result)
+        {
+            share_mem = NULL;
+            nvram_ee_info = NULL;
+            *length_ptr = 0;
+            return KAL_FALSE;
+        }        
+        nvram_ee_info = (nvram_ee_info_type *)g_nvram_emm_addr;
+        kal_mem_set(nvram_ee_info,0,sizeof(nvram_ee_info_type));
+        *share_mem =(kal_uint32 *)(&(nvram_ee_info->md_ccci_debug_info[0]));
+        *length_ptr = MD_CCCI_INFO_SIZE * sizeof(nvram_ee_info->md_ccci_debug_info[0]);
+    }
+    return KAL_TRUE;
+    #else
+    return KAL_FALSE;
+    #endif
+}
+
diff --git a/mcu/service/nvram/src/nvram_io.c b/mcu/service/nvram/src/nvram_io.c
new file mode 100644
index 0000000..8d3a738
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_io.c
@@ -0,0 +1,4580 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_io.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is main() function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ ×
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include "string.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+
+/* For FAT */
+#include "fs_type.h"
+#include "fs_gprot.h"
+#include "fs_iprot.h"
+
+#include "nvram_data_items.h"
+#include "nvram_group_def.h" //add for break group files from header file
+#include "nvram_main.h"
+#include "custom_nvram_restore.h"
+#include "custom_nvram_sec.h"
+
+#if defined(__MMI_FMI__)
+#include "nvram_common_defs.h"
+
+#endif
+#include "mcf_enum.h"
+#include "mcf_if.h"
+
+#ifdef __NVRAM_LID_CACHE__
+#include "nvram_cache_interface.h"
+#endif
+#include "us_timer.h"
+#include "ex_public.h"
+#if defined(__HIF_CCCI_SUPPORT__)
+#include "ccci_if.h"
+#endif
+
+/*
+ * External Function
+ */
+extern void WDT_Restart2(void);
+extern void MMICheckDiskDisplay(void);
+extern void DRV_ABN_RESET(void);
+extern kal_bool nvram_set_restore_factory_flag(nvram_restore_flag_enum restore_flag);
+
+extern const nvram_clean_folder_entry nvram_clean_folder_list[];
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+extern module_type stack_get_active_module_id( void );
+
+#if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+extern kal_bool bResetNvramData;
+#endif
+
+#ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+extern kal_bool isneedwriteprotect2;
+#endif
+
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+extern kal_taskid pre_write_check_mutex_owner;
+#endif
+/*
+ * Local Function
+ */
+static nvram_errno_enum nvram_read_data_item_multiple(
+                            nvram_ltable_entry_struct *ldi,
+                            kal_uint32 rec_index,
+                            kal_uint16 rec_amount,
+                            kal_uint8 *buffer,
+                            kal_uint32 buffer_size);
+static nvram_errno_enum nvram_write_fs_data_item(
+                            nvram_ltable_entry_struct *ldi,
+                            kal_uint32 index,
+                            kal_uint8 *buffer,
+                            kal_uint32 buffer_size,
+                            kal_bool is_init);
+ 
+static nvram_errno_enum nvram_reset_one_data_item(nvram_ltable_entry_struct *ldi,
+                                        kal_uint16 rec_index,
+                                        kal_uint16 rec_amount);
+static kal_bool nvram_factory_restore_sys_cache(
+                    nvram_reset_category_enum category,
+                    nvram_app_id_enum app_id);
+
+static kal_bool nvram_factory_rmdir_user(nvram_reset_category_enum category);
+
+kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi);
+
+#if defined(__NVRAM_DEBUG_READ_DUMP__) || defined(__NVRAM_DEBUG_WRITE_DUMP__)
+kal_char str_buffer[1024];
+kal_uint32 dump_offset = 0;
+void nvram_debug_rw_dump(nvram_ltable_entry_struct *ldi, kal_uint16 idx, kal_uint32 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size, nvram_errno_enum status)
+{
+    kal_uint16 size, rec_size;
+    kal_uint32 rec,i,j;
+    kal_uint8 *ptr;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    extern kal_mutexid g_nvram_fs_mutex;
+    kal_int32 result = FS_NO_ERROR;
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    kal_wsprintf(filename, "%s\\%s", NVRAM_FS_ROOT_PATH, "RW_LOG");
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_CREATE | FS_READ_WRITE | FS_OPEN_NO_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if(idx & 0x8000) { //write
+        sprintf(str_buffer, "W_LID:%s, rec_index:%d, rec_amount:%d, idx:0x%02X, status:0x%X\n", ldi->fileprefix, rec_index, rec_amount, idx, status);
+    }
+    else {
+        sprintf(str_buffer, "R_LID:%s, rec_index:%d, rec_amount:%d, idx:0x%02X, status:0x%X\n", ldi->fileprefix, rec_index, rec_amount, idx, status);
+    }
+    size = strlen(str_buffer);
+    NVRAM_FS_START(FS_OP_SEEK);
+    result = FS_Seek(hFile, dump_offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,result);
+    NVRAM_FS_START(FS_OP_WRITE);
+    result = FS_Write(hFile, str_buffer, size, &len);
+    NVRAM_FS_END(FS_OP_WRITE,result);
+    dump_offset += size;
+    rec_size = (idx & 0x80)?sizeof(kal_uint16):ldi->size;
+    
+    if((status == NVRAM_ERRNO_SUCCESS) && buffer && buffer_size) {
+        for(rec = 0; rec < rec_amount; rec++) {
+            size = 0;
+            ptr = &buffer[rec * rec_size];
+            j = (rec_size > 0x100)?0x100:rec_size;
+            for(i = 0; i < j; i++) {
+                sprintf((char*)&str_buffer[size], "%02X ", *ptr);
+                ptr++;
+                size += 3;
+                if((i & 0xF) == 0xF) {
+                    str_buffer[size++] = '\n';
+                }
+            }
+            str_buffer[size++] = '\n';
+            str_buffer[size++] = '\n';
+            NVRAM_FS_START(FS_OP_WRITE);
+            result = FS_Write(hFile, str_buffer, size, &len);
+            NVRAM_FS_END(FS_OP_WRITE,result);
+            dump_offset += size;
+        }
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+    
+}
+
+void nvram_debug_log_dump(kal_bool valid, kal_char *log_str, kal_uint32 p1, kal_uint32 p2, kal_uint32 p3, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    kal_uint16 size;
+    kal_uint32 i,j;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    extern kal_mutexid g_nvram_fs_mutex;
+    kal_int32 result = FS_NO_ERROR;
+    if(!valid) return;
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    kal_wsprintf(filename, "%s\\%s", NVRAM_FS_ROOT_PATH, "READ_LOG");
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_CREATE | FS_READ_WRITE | FS_OPEN_NO_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    sprintf(str_buffer, "%s (0x%08X, 0x%08X, 0x%08X)\n", log_str, p1, p2, p3);
+    size = strlen(str_buffer);
+    NVRAM_FS_START(FS_OP_SEEK);
+    result = FS_Seek(hFile, dump_offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,result);
+    NVRAM_FS_START(FS_OP_WRITE);
+    result = FS_Write(hFile, str_buffer, size, &len);
+    NVRAM_FS_END(FS_OP_WRITE,result);
+    dump_offset += size;
+
+    if(buffer && buffer_size) {
+        size = 0;
+        j = (buffer_size > 0x100)?0x100:buffer_size;
+        for(i = 0; i < j; i++) {
+            sprintf((char*)&str_buffer[size], "%02X ", *buffer);
+            buffer++;
+            size += 3;
+            if((i & 0xF) == 0xF) {
+                str_buffer[size++] = '\n';
+            }
+        }
+        str_buffer[size++] = '\n';
+        str_buffer[size++] = '\n';
+        NVRAM_FS_START(FS_OP_WRITE);
+        result = FS_Write(hFile, str_buffer, size, &len);
+        NVRAM_FS_END(FS_OP_WRITE,result);
+        dump_offset += size;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+    
+}
+#else
+#define nvram_debug_log_dump(...)
+#endif
+
+#ifdef __NVRAM_DEBUG_READ_DUMP__
+#define nvram_debug_read_dump(ldi, idx, rec_index, rec_amount, buffer, buffer_size, status) \
+    nvram_debug_rw_dump(ldi, ((idx) & 0x7FFF), rec_index, rec_amount, buffer, buffer_size, status)
+#else
+#define nvram_debug_read_dump(...)
+#endif /* __NVRAM_DEBUG_READ_DUMP__ */
+
+#ifdef __NVRAM_DEBUG_WRITE_DUMP__
+#define nvram_debug_write_dump(ldi, idx, rec_index, rec_amount, buffer, buffer_size, status) \
+    nvram_debug_rw_dump(ldi, ((idx) | 0x8000), rec_index, rec_amount, buffer, buffer_size, status)
+#else
+#define nvram_debug_write_dump(...)
+#endif /* __NVRAM_DEBUG_WRITE_DUMP__ */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_item_chk
+ * DESCRIPTION
+ *  This is nvram_read_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi             [IN]        MUST be 1 ~ (total_LID - 1)
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [IN]        MUST be even-bytes aligned.
+ *  rec_size        [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2
+ *  index(?)        [IN]        MUST be 1 ~ total_records
+ * RETURNS
+ *  NVRAM_IO_ERRNO_OK    if read successfully.
+ *  NVRAM_IO_ERRNO_CHK   if checksum error, and cannot be reset to default value.
+ *  NVRAM_IO_ERRNO_INIT  if checksum error, but successfully reset to default value.
+ *****************************************************************************/
+nvram_errno_enum nvram_read_data_item_chksum
+    (nvram_ltable_entry_struct *ldi, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *chksum, kal_uint32 chksum_size, nvram_drv_read_type_enum read_type)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 status;
+    kal_uint8 *default_value = NULL, *default_value_buffer = NULL;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 *checksum_buf = NULL;
+    kal_uint16 *temp_chksum = (kal_uint16 *)chksum;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};  
+    #ifdef __NV_CHKSUM_ENHANCE__
+    kal_uint32 chksum_algo_type = NVRAM_MD5;
+    #endif
+
+    kal_uint32 file_offset = 0;
+    nvram_folder_enum folder_index;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s-> LID 0x%04X rec_index=%d,\r\n",__FUNCTION__,ldi->LID,rec_index);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"rec_amount=%d,read_type=%d \r\n",rec_amount, read_type);
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    #ifdef __NV_CHKSUM_ENHANCE__
+    chksum_algo_type = lid_chksum_info.algo_info.chksum_algo_type;
+    #endif
+
+    checksum_buf = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+/******************************************************
+ *  Device Broken
+ ******************************************************/
+
+    /* Read Default Value */
+    if (nvram_ptr->dev_broken)
+    {
+        kal_uint32 i;
+        
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+        for (i = 0; i < rec_amount; i++)
+        {
+            /* when ldi size too big, we cannot operator it on buffer,
+               use original default value pointer directly */
+
+            default_value = (kal_uint8*) nvram_get_default_value_to_write(ldi, (kal_uint16)(i + 1), NULL, 0);
+
+            /* the default_value is not assigned in table , ex: L1 LID */
+            if (default_value == NULL)
+            {
+                nvram_get_default_value_to_write(ldi, (kal_uint16)(i + 1), default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+                default_value = default_value_buffer;
+            }
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+            }
+            else
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+                kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            }
+            #else
+            temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+            #endif
+            
+        }
+
+
+        free_ctrl_buffer(default_value_buffer);
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+        
+        status = NVRAM_IO_ERRNO_OK;
+        return (nvram_errno_enum)status;
+    }
+
+/******************************************************
+ *  OTP
+ ******************************************************/
+#ifdef __NVRAM_OTP__
+    /* Handle request to OTP */
+    if (NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+        if (nvram_ptr->state != NVRAM_STATE_READY)
+        {
+            status = NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }
+        else
+        {
+            kal_uint32 i;
+           
+            default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+            status = nvram_read_otp_data_item(ldi, rec_index, rec_amount, default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+
+            for (i = 0; i < rec_amount; i++)
+            {
+                #ifdef __NV_CHKSUM_ENHANCE__
+                if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+                {
+                    kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                    temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                }
+                else
+                {
+                    kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                    kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+                }
+                #else
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                #endif
+            }
+            free_ctrl_buffer(default_value_buffer);
+        }
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+        return (nvram_errno_enum)status;
+    }
+#endif
+
+/******************************************************
+ *  Custom Disk
+ ******************************************************/
+
+#ifdef __NVRAM_CUSTOM_DISK__
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+        kal_uint32 i;
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+        status = nvram_read_custom_disk(ldi, rec_index, rec_amount, default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+
+        for (i = 0; i < rec_amount; i++)
+        {
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+            }
+            else
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            }
+            #else
+            temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+            #endif
+        }
+
+        free_ctrl_buffer(default_value_buffer);
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+        return (nvram_errno_enum)status;
+    }
+#endif
+
+/******************************************************
+ *  FAT
+ ******************************************************/
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+        if (!nvram_util_has_file_created( ldi)) {
+            kal_uint32 i;
+        
+            default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+            for (i = 0; i < rec_amount; i++)
+            {
+                /* when ldi size too big, we cannot operator it on buffer,
+                   use original default value pointer directly */
+                default_value = (kal_uint8*) nvram_get_default_value_to_write(ldi, (kal_uint16)(i + rec_index), NULL, 0);
+
+                /* the default_value is not assigned in table , ex: L1 LID */
+                if (default_value == NULL)
+                {
+                    nvram_get_default_value_to_write(ldi, (kal_uint16)(i + rec_index), default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+                    default_value = default_value_buffer;
+                }
+
+                #ifdef __NV_CHKSUM_ENHANCE__
+                if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+                {
+                    kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                    temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+                }
+                else
+                {
+                    kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+                    kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+                }
+                #else
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+                #endif
+            }
+
+
+            free_ctrl_buffer(default_value_buffer);
+            if (checksum_buf)
+            {
+                free_ctrl_buffer(checksum_buf);
+                checksum_buf = NULL;
+            }
+            return NVRAM_IO_ERRNO_OK;
+        }
+ #endif
+
+    folder_index = nvram_query_folder_index(ldi->category);
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        file_offset = (kal_uint32) (ldi->description);
+    }
+    else
+#endif
+    {
+        file_offset = NVRAM_LDI_HEADER_SIZE;
+    }
+
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+#ifdef __NVRAM_READ_RESERVED_FILE__
+    if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+        sprintf((nvramname + NVRAM_FILE_LEN), "_%04X%04X", ldi->total_records, ldi->size);
+    }
+#endif
+
+    status = nvram_drv_fat_read(nvramname, folder_index, file_offset, rec_index, rec_amount, ldi->size, (kal_uint8*) chksum, read_type, ldi);
+
+    if (status != NVRAM_DRV_OK && (ldi->attr & NVRAM_ATTR_MULTIPLE)
+#ifdef __NVRAM_READ_RESERVED_FILE__
+        && (ldi->LID != NVRAM_EF_READ_RESERVED_LID)
+#endif
+       )
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+        status = nvram_drv_fat_read(nvramname, folder_index, file_offset, rec_index, rec_amount, ldi->size, (kal_uint8*) chksum, read_type, ldi);
+
+        if (status == NVRAM_DRV_OK)
+        {
+            nvram_drv_fat_backup(ldi, KAL_FALSE);
+        }
+    }
+
+    free_ctrl_buffer(checksum_buf);
+
+    return (nvram_errno_enum)status;
+}   /* end of nvram_read_data_item */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_item_chksum_8b
+ * DESCRIPTION
+ *  This is nvram_read_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi             [IN]        MUST be 1 ~ (total_LID - 1)
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [IN]        MUST be even-bytes aligned.
+ *  rec_size        [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2
+ *  index(?)        [IN]        MUST be 1 ~ total_records
+ * RETURNS
+ *  NVRAM_IO_ERRNO_OK    if read successfully.
+ *  NVRAM_IO_ERRNO_CHK   if checksum error, and cannot be reset to default value.
+ *  NVRAM_IO_ERRNO_INIT  if checksum error, but successfully reset to default value.
+ *****************************************************************************/
+nvram_errno_enum nvram_read_data_item_chksum_8b
+    (nvram_ltable_entry_struct *ldi, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *chksum, kal_uint32 chksum_size, nvram_drv_read_type_enum read_type)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 status;
+    kal_uint8 *default_value = NULL, *default_value_buffer = NULL;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8* checksum_buf = NULL;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+    #ifdef __NV_CHKSUM_ENHANCE__
+	kal_uint16 *temp_chksum = (kal_uint16 *)chksum;
+    kal_uint32 chksum_algo_type = NVRAM_MD5;
+    #endif
+    kal_uint32 file_offset = 0;
+    nvram_folder_enum folder_index;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s -> LID 0x%04X rec_index=%d\r\n",__FUNCTION__,ldi->LID,rec_index);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"rec_amount=%d,read_type=%d \r\n",rec_amount, read_type);
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    #ifdef __NV_CHKSUM_ENHANCE__
+    chksum_algo_type = lid_chksum_info.algo_info.chksum_algo_type;
+    #endif
+
+    checksum_buf = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size);
+
+    /******************************************************
+     *  Device Broken
+     ******************************************************/
+
+    /* Read Default Value */
+    if (nvram_ptr->dev_broken)
+    {
+        kal_uint32 i;
+        
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+        for (i = 0; i < rec_amount; i++)
+        {
+            /* when ldi size too big, we cannot operator it on buffer,
+               use original default value pointer directly */
+
+            default_value = (kal_uint8*) nvram_get_default_value_to_write(ldi, (kal_uint16)(i + 1), NULL, 0);
+
+            /* the default_value is not assigned in table , ex: L1 LID */
+            if (default_value == NULL)
+            {
+                nvram_get_default_value_to_write(ldi, (kal_uint16)(i + 1), default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+                default_value = default_value_buffer;
+            }
+
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+            }
+            else
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+                kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            }
+            #else
+            nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+            kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            #endif
+        }
+
+
+        free_ctrl_buffer(default_value_buffer);
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+        status = NVRAM_IO_ERRNO_OK;
+
+        return (nvram_errno_enum)status;
+    }
+
+/******************************************************
+ *  OTP
+ ******************************************************/
+#ifdef __NVRAM_OTP__
+    /* Handle request to OTP */
+    if (NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+        if (nvram_ptr->state != NVRAM_STATE_READY)
+        {
+            status = NVRAM_IO_ERRNO_ACCESS_DENIED;
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[Error] OTP LID:0x%04X NVRAM_ERRNO_NOT_READY\r\n",ldi->LID);
+        }
+        else
+        {
+            kal_uint32 i;
+           
+            default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+            status = nvram_read_otp_data_item(ldi, rec_index, rec_amount, default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+
+            for (i = 0; i < rec_amount; i++)
+            {
+                #ifdef __NV_CHKSUM_ENHANCE__
+                if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+                {
+                    kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                    temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                }
+                else
+                {
+                    kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                    nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                    kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+                }
+                #else
+                nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+                #endif
+            }
+            free_ctrl_buffer(default_value_buffer);
+        }
+
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+
+        return (nvram_errno_enum)status;
+    }
+#endif
+
+/******************************************************
+ *  Custom Disk
+ ******************************************************/
+
+#ifdef __NVRAM_CUSTOM_DISK__
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+        kal_uint32 i;
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+        status = nvram_read_custom_disk(ldi, rec_index, rec_amount, default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+
+        for (i = 0; i < rec_amount; i++)
+        {
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+            }
+            else
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+                kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            }
+            #else
+            nvram_util_caculate_checksum(ldi, default_value_buffer + i * ldi->size, ldi->size, checksum_buf);
+            kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            #endif
+        }
+
+        free_ctrl_buffer(default_value_buffer);
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+        nvram_debug_read_dump(ldi, 0x80, rec_index, rec_amount, chksum, chksum_size, NVRAM_IO_ERRNO_OK);
+        return (nvram_errno_enum)status;
+    }
+#endif
+
+/******************************************************
+ *  FAT
+ ******************************************************/
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    if (!nvram_util_has_file_created( ldi)) {
+        kal_uint32 i;
+    
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+        for (i = 0; i < rec_amount; i++)
+        {
+            /* when ldi size too big, we cannot operator it on buffer,
+               use original default value pointer directly */
+            default_value = (kal_uint8*) nvram_get_default_value_to_write(ldi, (kal_uint16)(i + rec_index), NULL, 0);
+
+            /* the default_value is not assigned in table , ex: L1 LID */
+            if (default_value == NULL)
+            {
+                nvram_get_default_value_to_write(ldi, (kal_uint16)(i + rec_index), default_value_buffer, MAX_NVRAM_RECORD_SIZE);
+                default_value = default_value_buffer;
+            }
+
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if((chksum_algo_type == NVRAM_MD5) && ((read_type == NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B )|| (read_type == NVRAM_DRV_READ_TYPE_CHKSUM_2B)))
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                temp_chksum[i] = nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+            }
+            else
+            {
+                kal_mem_set(checksum_buf, 0, nvram_chksum_size);
+                nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+                kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            }
+            #else
+            nvram_util_caculate_checksum(ldi, default_value, ldi->size, checksum_buf);
+            kal_mem_cpy((chksum+ (i * nvram_chksum_size)), checksum_buf, nvram_chksum_size);
+            #endif
+        }
+
+
+        free_ctrl_buffer(default_value_buffer);
+        if (checksum_buf)
+        {
+            free_ctrl_buffer(checksum_buf);
+            checksum_buf = NULL;
+        }
+        return NVRAM_IO_ERRNO_OK;
+    }
+ #endif
+
+    folder_index = nvram_query_folder_index(ldi->category);
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        file_offset = (kal_uint32) (ldi->description);
+    }
+    else
+#endif
+    {
+        file_offset = NVRAM_LDI_HEADER_SIZE;
+    }
+
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+    status = nvram_drv_fat_read(nvramname, folder_index, file_offset, rec_index, rec_amount, ldi->size, (kal_uint8*) chksum, read_type, ldi);
+    nvram_debug_read_dump(ldi, 0x82, rec_index, rec_amount, chksum, chksum_size, status);
+    
+    if (status != NVRAM_DRV_OK && (ldi->attr & NVRAM_ATTR_MULTIPLE))
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+        status = nvram_drv_fat_read(nvramname, folder_index, file_offset, rec_index, rec_amount, ldi->size, (kal_uint8*) chksum, read_type, ldi);
+
+        if (status == NVRAM_DRV_OK)
+        {
+            nvram_drv_fat_backup(ldi, KAL_FALSE);
+        }
+    }
+
+    free_ctrl_buffer(checksum_buf);
+
+    return (nvram_errno_enum)status;
+}   /* end of nvram_read_data_item */
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_item
+ * DESCRIPTION
+ *  This is nvram_read_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi             [IN]        MUST be 1 ~ (total_LID - 1)
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [IN]        MUST be even-bytes aligned.
+ *  rec_size        [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2
+ *  index(?)        [IN]        MUST be 1 ~ total_records
+ * RETURNS
+ *  NVRAM_IO_ERRNO_OK    if read successfully.
+ *  NVRAM_IO_ERRNO_CHK   if checksum error, and cannot be reset to default value.
+ *  NVRAM_IO_ERRNO_INIT  if checksum error, but successfully reset to default value.
+ *****************************************************************************/
+nvram_errno_enum nvram_read_data_item
+    (nvram_ltable_entry_struct *ldi, kal_uint32 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    kal_uint8 *filename;
+    FS_HANDLE hFile;
+    nvram_ltable_entry_struct tmp_ldi ={0};
+    mcf_ota_result_e mcf_ota_ret = MCF_OTA_R_SUCCESS;
+    #if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+    kal_int32 ret;
+    #endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    MD_TRC_IO_READ_DATA_ITEM_START(ldi->LID, rec_index, rec_amount, buffer_size);
+    MD_TRC_INFO_NVRAM_DATA_ITEM(ldi->LID, ldi->size);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[collection]%s->LID 0x%04X,rec_index:%d,\r\n",__FUNCTION__,ldi->LID, rec_index);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[collection]rec_amount:%d,rec_size:%d \r\n",rec_amount,ldi->size);
+    if (!NVRAM_IS_ATTR_RAW_DATA(ldi->attr) &&
+        (buffer_size < ldi->size * rec_amount))
+    {
+        MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_INVALID_SIZE, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X NVRAM_IO_ERRNO_INVALID_SIZE\r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]buffer_size(%d) < total_size(%d)\r\n",buffer_size,ldi->size * rec_amount);
+        return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+
+/******************************************************
+ *  Device Broken
+ ******************************************************/
+    if (nvram_ptr->dev_broken)
+    {
+        kal_uint32 i;
+
+        MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_DRV_BROKEN, __LINE__);
+
+        if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+            nvram_get_default_value_to_write(ldi, rec_index, buffer, buffer_size);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"return RAW LID 0x%04X default value as NVRAM_IO_ERRNO_DRV_BROKEN\r\n",ldi->LID);
+            return NVRAM_IO_ERRNO_OK;
+        }
+
+        for (i = 0; i < rec_amount; i++)
+        {
+            nvram_get_default_value_to_write(ldi, (i + 1), buffer + (i * ldi->size), ldi->size);
+        }
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"return LID 0x%04X default value as NVRAM_IO_ERRNO_DRV_BROKEN\r\n",ldi->LID);
+        return NVRAM_IO_ERRNO_OK;
+    }
+
+/******************************************************
+ *  OTP
+ ******************************************************/
+#ifdef __NVRAM_OTP__
+    /* Handle request to OTP */
+    if ((nvram_ptr->state != NVRAM_STATE_READY) && NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+        MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_OK, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[Error] OTP LID 0x%04X NVRAM_ERRNO_NOT_READY\r\n",ldi->LID);
+        return NVRAM_IO_ERRNO_OK;
+    }
+    else  if ((nvram_ptr->state == NVRAM_STATE_READY) && NVRAM_IS_CATEGORY_OTP(ldi->category))
+    {
+        if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]OTP Don't support Raw LID 0x%04X \r\n",ldi->LID);
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }
+        status = nvram_read_otp_data_item(ldi, rec_index, rec_amount, buffer, buffer_size);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X read OTP data result=%d\r\n",ldi->LID,status);
+    }
+    else
+#endif
+
+
+/******************************************************
+ *  Custom Disk
+ ******************************************************/
+#ifdef __NVRAM_CUSTOM_DISK__
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+        if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }    
+        status = nvram_read_custom_disk(ldi, rec_index, rec_amount, buffer, buffer_size);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s LID 0x%04X read Custom Disk data result=%d\r\n",__FUNCTION__,ldi->LID,status);
+    }
+    else
+#endif
+
+/******************************************************
+ *  FAT
+ ******************************************************/
+    { //be care about this "{}" it is use for "else" code of different store device
+        #ifdef __NVRAM_CRYPT_TEST__
+        if (ldi->LID == NVRAM_EF_NVRAM_MSP_TEST_LID)
+        {
+            extern kal_uint32 bReadMsp;
+            bReadMsp = 1;
+        }
+        #endif
+
+        #if defined(__NVRAM_INIT_LID_BUFFER__)
+        if(nvram_init_lid_buffer_read(ldi->LID, rec_index, rec_amount, buffer, buffer_size) == NVRAM_ERRNO_SUCCESS) {
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X read from buffer\r\n",ldi->LID);
+            return NVRAM_IO_ERRNO_OK;
+        }
+        #endif
+        if(ldi->attr & NVRAM_ATTR_GEN_DEFAULT)
+        {
+            status = nvram_read_data_item_multiple(ldi, rec_index, rec_amount, buffer, buffer_size);            
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X with GEN_DEFAULT read result=%d\r\n",ldi->LID,status);
+            
+        }
+        #if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+        else if (!nvram_util_has_file_created(ldi)) {
+            kal_uint32 i;
+
+            MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_INIT, __LINE__);
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"LID 0x%04X file uncreated\r\n",ldi->LID);
+            if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+                nvram_get_default_value_to_write(ldi, rec_index, buffer, buffer_size);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"Raw Data LID 0x%04X read default value\r\n",ldi->LID);
+                return NVRAM_IO_ERRNO_OK;
+            }
+
+            for (i = 0; i < rec_amount; i++)
+            {
+                nvram_get_default_value_to_write(ldi, (kal_uint16)(i + rec_index), buffer + (i * ldi->size), ldi->size);
+            }
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X read return default value\r\n",ldi->LID);
+            return NVRAM_IO_ERRNO_OK;
+        }
+        #endif
+        else
+        {
+            status = nvram_read_data_item_multiple(ldi, rec_index, rec_amount, buffer, buffer_size);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID 0x%04X read file result=%d\r\n",ldi->LID,status);
+        }
+    }
+    /*
+    If read fail and the LID is located in NVRAM folder's subfolder,
+    first check the root folder is OK or not.
+    */
+    if(status != NVRAM_IO_ERRNO_OK)
+    {
+        if(NVRAM_IS_CATEGORY_INTERNAL(ldi->category) || NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) ||
+           NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) || (NVRAM_NVD_DATA == nvram_query_folder_index(ldi->category)))
+        {
+            filename = (kal_uint8 *) get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+            #ifdef __NVRAM_LID_CACHE__
+            nvram_util_take_mutex(g_nvram_fs_mutex);
+            #endif
+            NVRAM_FS_MAKE_ROOT_PATH((kal_wchar*)filename);
+            NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+            hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_DIR);
+            NVRAM_FS_END(FS_OP_OPEN,hFile);
+            free_ctrl_buffer(filename);     
+            if(hFile >= FS_NO_ERROR)   /* Open NVRAM root folder Success */
+            {
+                NVRAM_FS_START(FS_OP_CLOSE);
+                kal_int32 fs_result = FS_Close(hFile);
+                NVRAM_FS_END(FS_OP_CLOSE,fs_result);
+            }
+            else if (hFile == FS_FILE_NOT_FOUND || hFile == FS_PATH_NOT_FOUND)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s NVRAM main folder lost,result:%d\r\n",__FUNCTION__,(kal_uint32)hFile);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)hFile, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_1, 0);
+            }
+            else
+            {
+                kal_prompt_trace(MOD_NVRAM, "Open NVRAM root folder result:%d\n\r", (kal_uint32)hFile);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s Open NVRAM root folder result:%d \r\n",__FUNCTION__,(kal_uint32)hFile);
+            }
+            #ifdef __NVRAM_LID_CACHE__
+            nvram_util_give_mutex(g_nvram_fs_mutex);
+            #endif
+        }
+    }
+
+
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr) && (status == NVRAM_IO_ERRNO_ACCESS_DENIED)) {
+        kal_prompt_trace(MOD_NVRAM, "NVRAM READ RAW DATA OUT OF BOUNDARY:%d\n\r", DISPLAY_ERROR(status));
+        kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);        
+        
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"NVRAM READ RAW DATA OUT OF BOUNDARY:%d\r\n",DISPLAY_ERROR(status));
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"LID:0x%04X, total_records:%d, record_size:%d\r\n",ldi->LID, ldi->total_records, ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"category:0x%08X, attr:0x%08X\r\n",ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"fileprefix:%s, fileverno:%s\r\n",ldi->fileprefix, ldi->fileverno);
+        return status;
+    }
+     memcpy((void *)(&tmp_ldi),ldi,sizeof(nvram_ltable_entry_struct));
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+    if ((status != NVRAM_IO_ERRNO_OK) && NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+    {
+        MD_TRC_IO_READ_DATA_ITEM_MULTIPLE(ldi->LID, status, status,nvram_drv_fat_get_last_err(), __LINE__);
+
+        //if AP restore fail, nvram_recover_data_item() will assert
+        ret = nvram_recover_data_item(ldi);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s LID 0x%04X recover result:%d\r\n",__FUNCTION__,ldi->LID,ret);
+
+        if((nvram_ptr->state == NVRAM_STATE_READY) && (ret == NVRAM_IO_ERRNO_OK))
+        {
+            mcf_ota_ret = mcf_do_ota_by_lid(ldi->LID,1,ldi->total_records,&tmp_ldi);
+            kal_prompt_trace(MOD_NVRAM, "%s @%d mcf_ota_ret=%d\n\r",__FUNCTION__,__LINE__ , mcf_ota_ret);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP," %s mcf_do_ota_by_lid return %d\r\n",__FUNCTION__,mcf_ota_ret);
+        }
+        status = nvram_read_data_item_multiple(ldi, rec_index, rec_amount, buffer, buffer_size);
+
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s read data after recover result:%d\r\n",__FUNCTION__,status);
+        if(status != NVRAM_IO_ERRNO_OK)
+        {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_RESTORE_SUCCESS_READ_FAIL:%d\n\r", DISPLAY_ERROR(status));
+            kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);            
+
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_RESTORE_SUCCESS_READ_FAIL:%d\r\n", DISPLAY_ERROR(status));
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_LOC_RESTORE_SUCCESS_READ_FAIL, ldi->LID);
+            }
+        }
+    }
+#endif
+
+
+#ifdef __NVRAM_UNIT_TEST__
+    status = nvram_unit_test_get_io_status(status);
+#endif
+
+    /*
+     *  Error Handling
+     *  1. try to restore data from backup partition
+     *  2. reset data if data is not in important category
+     *
+     */
+
+#ifdef __NVRAM_BACKUP_DISK_RAW__
+    if (status != NVRAM_IO_ERRNO_OK && NVRAM_IS_ATTR_BACKUP_RAW(ldi->attr))
+    {
+        MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, status, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s LID 0x%04X read for backup disk raw result:%d\r\n",__FUNCTION__,ldi->LID,status);
+        if (nvram_recover_image_by_lid(ldi) == NVRAM_ERRNO_SUCCESS)
+        {
+            #ifdef __NVRAM_LID_CACHE__
+            if((!(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))) && NVRAM_RD_WITH_CACHE(ldi->LID))
+            {
+                unmask_valid_bit_by_ltable_entry(ldi, 0, (ldi->total_records + 1));
+            }
+            #endif
+            status = nvram_read_data_item_multiple(ldi, rec_index, rec_amount, buffer, buffer_size, KAL_FALSE);
+        }
+    }
+#endif
+
+    /* it is impossible to read data from sds fail
+       if it fails, we have no error handling here , so assert */
+
+
+    /* If we read internal item fail, we do not reset it , just return fail
+       We will reset it after error handling */
+
+    //internal data locates in the SDS also, need to consider this
+    if (status != NVRAM_IO_ERRNO_OK && !NVRAM_IS_CATEGORY_INTERNAL(ldi->category)
+        #if defined (__NVRAM_UT_TEST__)
+        && (ldi->LID != NVRAM_EF_SYS_LID)
+        #endif
+    )
+    {
+
+        MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, status, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM ASSERT ERROR After Recover:%d\r\n", DISPLAY_ERROR(status));
+        if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_READ_IMPORTANT_DATA_FAIL:%d\r\n", DISPLAY_ERROR(status));            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_READ_IMPORTANT_DATA_FAIL:%d\n\r", DISPLAY_ERROR(status));
+            kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+            NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_LOC_READ_IMPORTANT_DATA_FAIL, ldi->LID);
+        }
+
+        if((status = nvram_reset_one_data_item(ldi, 1, ldi->total_records)) == NVRAM_IO_ERRNO_OK)    
+        {
+            kal_uint32 i;
+
+            MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, status, __LINE__);
+            if(nvram_ptr->state == NVRAM_STATE_READY)
+            {
+                mcf_ota_ret = mcf_do_ota_by_lid(ldi->LID,1,ldi->total_records,&tmp_ldi);
+                kal_prompt_trace(MOD_NVRAM, "%s @%d mcf_ota_ret=%d\n\r",__FUNCTION__,__LINE__ , mcf_ota_ret);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s mcf_do_ota_by_lid return %d\r\n",__FUNCTION__,mcf_ota_ret);
+                if(nvram_util_has_file_created(ldi))
+                {
+                    status = nvram_read_data_item_multiple(ldi, rec_index, rec_amount, buffer, buffer_size);
+                }
+                else
+                {
+                    for (i = 0; i < rec_amount; i++)
+                    {
+                        nvram_get_default_value_to_write(ldi, (kal_uint16)(rec_index + i), buffer + (i * ldi->size), ldi->size);
+                    }
+                }
+            }
+            else
+            {
+                for (i = 0; i < rec_amount; i++)
+                {
+                    nvram_get_default_value_to_write(ldi, (kal_uint16)(rec_index + i), buffer + (i * ldi->size), ldi->size);
+                }
+            }
+
+        }
+        else
+        {
+            MD_TRC_IO_READ_DATA_ITEM_RESULT(ldi->LID, status, __LINE__);
+            kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_READ_AND_RESET_FAIL:%d\n\r", DISPLAY_ERROR(status));
+            kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_READ_AND_RESET_FAIL:%d\r\n", DISPLAY_ERROR(status));
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_LOC_READ_AND_RESET_FAIL, ldi->LID);
+        }        
+    }
+    return status;
+}   /* end of nvram_read_data_item */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_item_multiple
+ * DESCRIPTION
+ *  This is nvram_read_data_item_multiple() function of NVRAM module.
+ *  Note that multiple copied attribute DOES NOT support for
+ *  linear fixed logical data items.
+ * PARAMETERS
+ *  ldi             [IN]
+ *  rec_index       [IN]
+ *  rec_amount      [IN]
+ *  buffer          [IN/OUT]
+ *  rec_size        [IN]
+ * RETURNS
+ *  NVRAM_IO_ERRNO_INIT if all copies are corrupted and any of them is reset successfully.
+ *  NVRAM_IO_ERRNO_CHK if all copies are corrupted and reset failed.
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is read.
+ *****************************************************************************/
+static nvram_errno_enum nvram_read_data_item_multiple
+    (nvram_ltable_entry_struct *ldi, kal_uint32 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_drv_status_enum drv_status[2] = {NVRAM_DRV_OK, NVRAM_DRV_OK};
+
+    NVRAM_FILE_NAME nvramname;
+    kal_uint32 file_offset = 0;
+    nvram_folder_enum folder_index;
+    kal_bool multiple = KAL_FALSE;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_drv_read_type_enum read_chksum_type = NVRAM_DRV_READ_TYPE_CHKSUM;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        multiple = KAL_TRUE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+
+    file_offset = NVRAM_LDI_HEADER_SIZE;
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        file_offset = (kal_uint32) (ldi->description);
+        if (!multiple)
+        {
+            nvram_make_package_filename(nvramname, 'A');
+        }
+    }
+#endif
+#ifdef __NVRAM_READ_RESERVED_FILE__
+    if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+        sprintf((nvramname + NVRAM_FILE_LEN), "_%04X%04X", ldi->total_records, ldi->size);
+    }
+#endif
+    /*************************************************************************
+     *  Step 1:  try to find one valid copy
+     *  Step 2:  If found,  try to recover another one if need
+     *  Step 3:  If not found or recover fail, reset the data
+     *
+     *  If fail in step 2 and step 3, return error
+     ***************************************************************************/
+
+    /* First, try to find one valid / healthy copy */
+    
+    do
+    {
+        if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))
+            drv_status[0] = nvram_drv_fat_read(
+                                    nvramname,
+                                    folder_index,
+                                    (file_offset + rec_index),
+                                    1,
+                                    1,
+                                    buffer_size,
+                                    buffer,
+                                    NVRAM_DRV_READ_TYPE_DATA,
+                                    ldi);
+        else
+            drv_status[0] = nvram_drv_fat_read(
+                                    nvramname,
+                                    folder_index,
+                                    file_offset,
+                                    rec_index,
+                                    rec_amount,
+                                    ldi->size,
+                                    buffer,
+                                    NVRAM_DRV_READ_TYPE_DATA,
+                                    ldi);
+
+    #ifdef __NVRAM_UNIT_TEST__
+        drv_status[0] = nvram_unit_test_get_drv_status(drv_status[0]);
+    #endif   
+  
+    #ifdef __NVRAM_READ_RESERVED_FILE__
+        if (ldi->LID == NVRAM_EF_READ_RESERVED_LID) break;
+    #endif
+        if (!multiple) break;
+
+    //Read 2nd copy
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            folder_index = NVRAM_NVD_BAK;
+        }
+    #endif
+
+    
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+        {
+            folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+        }
+    #endif
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+        if (drv_status[0] == NVRAM_DRV_OK)
+        {
+            #if defined(__NVRAM_WRITE_PROTECT_ENABLE__)	&& defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+            if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+            {
+                //read NVRAM_NVD_IMPNT success, return directly
+                drv_status[1] = NVRAM_DRV_OK;
+            }
+            else
+            #endif
+            {
+                //Read checksum only
+                kal_uint8* extra_buffer;
+
+                #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+                folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+                #endif
+
+            	nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+            	nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+            	read_chksum_type = lid_chksum_info.read_chksum_type;
+
+            	extra_buffer = (kal_uint8*) get_ctrl_buffer(nvram_chksum_size * rec_amount);
+
+            	drv_status[1] = nvram_drv_fat_read(
+                                    nvramname,
+                                    folder_index,
+                                    file_offset,
+                                    rec_index,
+                                    rec_amount,
+                                    ldi->size,
+                                    extra_buffer,
+                                    read_chksum_type,
+                                    ldi);
+            	free_ctrl_buffer(extra_buffer);
+			}
+        }
+        else
+        {
+            //read data
+            drv_status[1] = nvram_drv_fat_read(
+                                    nvramname,
+                                    folder_index,
+                                    file_offset,
+                                    rec_index,
+                                    rec_amount,
+                                    ldi->size,
+                                    buffer,
+                                    NVRAM_DRV_READ_TYPE_DATA,
+                                    ldi);
+        }
+
+        MD_TRC_IO_READ_DATA_ITEM_MULTIPLE(ldi->LID, drv_status[0], drv_status[1], nvram_drv_fat_get_last_err(), __LINE__);
+        if ((drv_status[0] == NVRAM_DRV_OK) && (drv_status[1] == NVRAM_DRV_OK))
+        {
+            //Need to check if checksum[0] != checksum[1] in the future
+            return NVRAM_IO_ERRNO_OK;
+        }
+        else if ((drv_status[0] != NVRAM_DRV_OK) && (drv_status[1] != NVRAM_DRV_OK))
+        {
+            //if SDS, backup from SDS            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]return NVRAM_IO_ERRNO_CHK,drv_status[0]=%d drv_status[1]=%d\r\n",drv_status[0],drv_status[1]);
+            return NVRAM_IO_ERRNO_CHK;        
+        }
+        else if ((drv_status[0] != NVRAM_DRV_OK))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s try to backup,drv_status[0]=%d,last_err(%d)\r\n",__FUNCTION__,drv_status[0], nvram_drv_fat_get_last_err());
+            drv_status[0] = nvram_drv_fat_backup(ldi, KAL_FALSE);
+        }
+        else
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"%s try to backup,drv_status[1]=%d, last_err(%d)\r\n",__FUNCTION__,drv_status[1], nvram_drv_fat_get_last_err());
+            drv_status[1] = nvram_drv_fat_backup(ldi, KAL_TRUE);        
+        }
+    
+    }while(0);
+
+
+    /* read two copy fail or recover fail */
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr) && ((drv_status[0] == FS_INVALID_FILE_POS) || (drv_status[1] == FS_INVALID_FILE_POS))) {
+        MD_TRC_IO_READ_DATA_ITEM_MULTIPLE(ldi->LID, drv_status[0], drv_status[1], nvram_drv_fat_get_last_err(), __LINE__);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail after restore raw file\r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]return NVRAM_IO_ERRNO_ACCESS_DENIED drv_status[0]=%d drv_status[1]=%d\r\n",drv_status[0],drv_status[1]);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }      
+    if ((drv_status[0] != NVRAM_DRV_OK) || (drv_status[1] != NVRAM_DRV_OK))
+    {
+        MD_TRC_IO_READ_DATA_ITEM_MULTIPLE(ldi->LID, drv_status[0], drv_status[1], nvram_drv_fat_get_last_err(), __LINE__);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s fail after restore\r\n",__FUNCTION__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]return NVRAM_IO_ERRNO_CHK, drv_status[0]=%d drv_status[1]=%d\r\n",drv_status[0],drv_status[1]);
+        return NVRAM_IO_ERRNO_CHK;
+    }
+    return NVRAM_IO_ERRNO_OK;
+}   /* end of nvram_read_data_item_multiple */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_data_item
+ * DESCRIPTION
+ *  This is nvram_read_exception_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi                 [IN]        MUST be 1 ~ (total_LID - 1)
+ *  index               [IN]        MUST be 1 ~ total_records
+ *  data                [?]
+ *  is_init             [IN]
+ *  buffer_size(?)      [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2 Note that content of `data' could be changed due to encyrption!!
+ *  buffer(?)           [IN]        MUST be even-bytes aligned.
+ * RETURNS
+ *  NVRAM_IO_ERRNO_INVALID_LID
+ *  NVRAM_IO_ERRNO_INVALID_RECORD
+ *  NVRAM_IO_ERRNO_INVALID_SIZE
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to read
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+nvram_errno_enum nvram_read_exception_data_item(nvram_ltable_entry_struct *ldi, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size)
+
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status;
+    NVRAM_FILE_NAME nvramname;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    MD_TRC_IO_WRITE_DATA_ITEM_START(ldi->LID, rec_index, 0);
+    MD_TRC_INFO_NVRAM_DATA_ITEM(ldi->LID, ldi->size);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X rec_index=%d,rec_size=%d\r\n",ldi->LID, rec_index, ldi->size);
+    /* Construct a even bytes aligned buffer, and assign it to returned data pointer */
+    if (buffer == NULL)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_INVALID_SIZE, __LINE__, 0);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X buffer is NULL\r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+
+    /* Do not allow normal access use exception API */
+    if(ldi->LID != NVRAM_EF_SYS_EXCEPTION_LID_DUMMY &&
+        ldi->LID != NVRAM_EF_SYS_STATISTICS_LID)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_ACCESS_DENIED, __LINE__, 0);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Not Exception LID 0x%04X Access Denied \r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }
+
+/******************************************************
+ *  Device Broken
+ ******************************************************/
+    if (nvram_ptr->dev_broken)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_DRV_BROKEN, __LINE__, 0);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X NVRAM_IO_ERRNO_DRV_BROKEN\r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_OK;        
+    }
+
+/******************************************************
+ *  OTP
+ ******************************************************/    
+#ifdef __NVRAM_OTP__
+    //block OTP request
+    if (ldi->category & NVRAM_CATEGORY_OTP)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_ACCESS_DENIED, __LINE__, 0);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s OTP LID 0x%04X Access Denied \r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }
+    else
+#endif
+
+/******************************************************
+ *  Custom Disk
+ ******************************************************/
+#ifdef __NVRAM_CUSTOM_DISK__
+    //block CUSTOM_DISK request
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_ACCESS_DENIED, __LINE__, 0);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Custom Disk LID 0x%04X Access Denied \r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED; 
+    }
+    else
+#endif
+
+
+/******************************************************
+ *  FAT
+ ******************************************************/
+    { //be care about this "{}" it is use for "else" code of different store device
+        if(buffer_size > ldi->size)
+        {
+            buffer_size = ldi->size;
+        }
+
+        //Read exception file directly
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+        status = nvram_drv_fat_read_exception_item(
+                    buffer,
+                    nvramname,
+                    rec_index,      // record id
+                    ldi->size,  // record size
+                    buffer_size);  // buffer size
+    }
+    
+    if((status != NVRAM_DRV_OK) && (status != NVRAM_DRV_EMPTY_RECORD))
+    {
+        status = NVRAM_IO_ERRNO_CHK;
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, 0);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X failed,status=%d\r\n",__FUNCTION__,ldi->LID,status);
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return status;
+}
+
+#ifdef __NVRAM_WRITE_WITH_FILE_SIZE__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_lid_default_value_to_write
+ * DESCRIPTION
+ *  This is nvram_get_default_value_to_write() function of NVRAM module.
+ *  Get default value of certain logical data item.
+ *  The default value is copied into buffer.
+ *  The returned content of buffer may be encrypted if needed.
+ * PARAMETERS
+ *  ldi             [?]
+ *  rec_index       [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ * RETURNS
+ *  KAL_FALSE if no default value defined, KAL_TRUE otherwise.(?)
+ *****************************************************************************/
+kal_uint8 const * nvram_get_lid_default_value_to_write(
+                                nvram_ltable_entry_struct *ldi, 
+                                kal_uint16 rec_index,
+                                kal_uint8 *buffer, 
+                                kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 const *default_value = ldi->default_value;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT)
+    {
+        if (buffer && ldi->default_value)
+        {
+            nvram_query_deault_func query_func = (nvram_query_deault_func)ldi->default_value;
+            nvram_memset(buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, buffer_size);
+            if(ldi->LID != NVRAM_EF_SYS_LID)
+            {
+                query_func(ldi->LID, buffer, buffer_size);
+            }
+        }
+        return NULL;
+    }
+    else
+    {       
+        rec_index++;        
+        /* Multi default value */
+        if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+        {
+            rec_index--;
+        }
+        else
+        {
+            rec_index = 0;
+        }
+
+        if (buffer)
+        {
+            if(buffer_size < ldi->size)
+            {
+                kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM:%d\n\r", NVRAM_INTERNAL_ERR(ldi->LID));
+                kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+                kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM:%d\r\n", NVRAM_INTERNAL_ERR(ldi->LID));
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                NVRAM_EXT_ASSERT(KAL_FALSE, NVRAM_INTERNAL_ERR(ldi->LID), NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM, buffer_size);
+            }                        
+            nvram_memset(buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, buffer_size);
+            kal_mem_cpy(buffer, (void*)(default_value + (ldi->size * rec_index)), ldi->size);
+        }
+        return default_value + (ldi->size * rec_index);
+    }
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_default_value_to_write
+ * DESCRIPTION
+ *  This is nvram_get_default_value_to_write() function of NVRAM module.
+ *  Get default value of certain logical data item.
+ *  The default value is copied into buffer.
+ *  The returned content of buffer may be encrypted if needed.
+ * PARAMETERS
+ *  ldi             [?]
+ *  rec_index       [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ * RETURNS
+ *  KAL_FALSE if no default value defined, KAL_TRUE otherwise.(?)
+ *****************************************************************************/
+kal_uint8 const * nvram_get_default_value_to_write
+    (nvram_ltable_entry_struct *ldi, kal_uint32 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 const *default_value = ldi->default_value;
+    kal_uint32 default_value_buffer_size = 0;
+    kal_uint8 *default_value_buffer;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        nvram_memset(buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, buffer_size);
+        return NVRAM_EF_ZERO_DEFAULT; 
+    }
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+    if (NVRAM_IS_CATEGORY_BACKUP_SDS(ldi->category) && !(nvram_ptr->sw_status & NVRAM_SW_EMPTY_SDS))
+    {
+        if (buffer)
+        {
+            kal_uint32 status;
+            kal_uint32 rec_amount = buffer_size / ldi->size;
+            if ((status = nvram_sds_read_data_item(ldi, rec_index, rec_amount, buffer, buffer_size)) == NVRAM_ERRNO_SUCCESS)
+            {
+                //use the default value from the sds
+                if ((ldi->total_records > 1) && !(ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+                {
+                    ldi->attr |= NVRAM_ATTR_MULTI_DEFAULT;
+                }
+                return NULL;
+            }
+            else
+            {
+                //error handle for the important data
+                if (NVRAM_IS_CATEGORY_IMPORTANT(ldi->category))
+                {
+                    extern void nvram_sds_throw_exception(kal_int32 err, kal_uint32 line);
+                    nvram_sds_throw_exception(status, __LINE__);
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_GET_DEFAULT_FROM_SDS_FAIL:%d\n\r", DISPLAY_ERROR(status));
+                    kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_GET_DEFAULT_FROM_SDS_FAIL:%d\r\n", DISPLAY_ERROR(status));
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                    NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_LOC_GET_DEFAULT_FROM_SDS_FAIL ,ldi->LID);
+                }
+                //read sds fail, goto original flow
+                goto GET_DEFAULT_VALUE;
+            }    
+        }
+        return NULL;
+    }
+GET_DEFAULT_VALUE:
+#endif
+
+    if (ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT)
+    {
+        if (buffer && ldi->default_value)
+        {
+            nvram_query_deault_func query_func = (nvram_query_deault_func)ldi->default_value;
+
+            if(ldi->LID == NVRAM_EF_SYS_LID)
+            {
+                nvram_memset(buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, buffer_size);
+                if(rec_index == 2)
+                    query_func(NVRAM_EF_BRANCH_VERNO_LID, buffer, ldi->size);
+                else if(rec_index == 3)
+                    query_func(NVRAM_EF_FLAVOR_VERNO_LID, buffer, ldi->size);
+                else if(rec_index == 4)
+                    query_func(NVRAM_EF_BUILD_TIME_LID, buffer, ldi->size);
+                else
+                    query_func(NVRAM_EF_SYS_LID, buffer, ldi->size);
+              
+            }else
+            {
+                default_value_buffer_size = ldi->size * ldi->total_records;
+                if (default_value_buffer_size > MAX_NVRAM_RECORD_SIZE)
+                {
+                    default_value_buffer_size = MAX_NVRAM_RECORD_SIZE;
+                }
+                default_value_buffer = (kal_uint8 *)get_ctrl_buffer(default_value_buffer_size);
+                nvram_memset(default_value_buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, default_value_buffer_size);
+                query_func(ldi->LID, default_value_buffer, default_value_buffer_size);
+                if ((ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+                {
+                    kal_mem_cpy(buffer, (void*)(default_value_buffer + (ldi->size * (rec_index -1))), buffer_size);
+                }
+                else
+                {  
+                    kal_uint32 i,record_num;
+                    record_num = buffer_size / (ldi->size);
+                    for (i = 0; i < record_num; i++)
+                    {
+                        kal_mem_cpy(buffer+(i*ldi->size), (void*)(default_value_buffer), ldi->size);
+                    }
+                }   
+                free_ctrl_buffer(default_value_buffer);
+            }
+            return buffer;
+        }
+    }
+    else
+    {
+        if (default_value == NULL || default_value == NVRAM_EF_FF_DEFAULT)
+            /* No default value supplied. Fill the buffer with 0xFF. */
+        {
+            if (buffer)
+            {
+                kal_mem_set(buffer, (kal_uint8) NVRAM_INVALID_VALUE, buffer_size);
+            }
+            return NVRAM_EF_FF_DEFAULT;
+        }
+        else if (default_value == NVRAM_EF_ZERO_DEFAULT)
+            /* Default value is all the same value (0x00) Fill it as well. */
+        {
+            if (buffer)
+            {
+                kal_mem_set(buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, buffer_size);
+            }
+            return NVRAM_EF_ZERO_DEFAULT;
+        }
+        else
+        {
+            /* Multi default value */
+            if ((ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+            {
+                rec_index--;
+            }
+            else
+            {
+                rec_index = 0;
+            }
+
+
+            if (buffer)
+            {
+                if(buffer_size < ldi->size)
+                {
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM:%d\n\r", NVRAM_INTERNAL_ERR(ldi->LID));
+                    kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM:%d\r\n", NVRAM_INTERNAL_ERR(ldi->LID));
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                    NVRAM_EXT_ASSERT(KAL_FALSE, NVRAM_INTERNAL_ERR(ldi->LID), NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM_1, buffer_size);
+                }
+                nvram_memset(buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, buffer_size);
+                kal_mem_cpy(buffer, (void*)(default_value + (ldi->size * rec_index)), ldi->size);
+            }
+            return default_value + (ldi->size * rec_index);
+        }
+    }    
+    return NULL;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_data_item
+ * DESCRIPTION
+ *  This is nvram_write_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi                 [IN]        MUST be 1 ~ (total_LID - 1)
+ *  index               [IN]        MUST be 1 ~ total_records
+ *  data                [?]
+ *  is_init             [IN]
+ *  buffer_size(?)      [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2 Note that content of `data' could be changed due to encyrption!!
+ *  buffer(?)           [IN]        MUST be even-bytes aligned.
+ * RETURNS
+ *  NVRAM_IO_ERRNO_INVALID_LID
+ *  NVRAM_IO_ERRNO_INVALID_RECORD
+ *  NVRAM_IO_ERRNO_INVALID_SIZE
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+nvram_errno_enum nvram_write_data_item(nvram_ltable_entry_struct *ldi, kal_uint32 index, kal_uint8 *data, kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status;
+    kal_uint8 *filename;
+    FS_HANDLE hFile;
+    kal_bool lid_is_gen_default = KAL_FALSE;
+    nvram_ltable_entry_struct tmp_ldi = {0};
+    mcf_ota_result_e mcf_ota_ret = MCF_OTA_R_SUCCESS;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+
+    MD_TRC_IO_WRITE_DATA_ITEM_START(ldi->LID, index, is_init);
+    MD_TRC_INFO_NVRAM_DATA_ITEM(ldi->LID, ldi->size);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[collection]%s -> LID:0x%04X index=%d\r\n",__FUNCTION__,ldi->LID, index);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[collection]is_init=%d,rec_size=%d\r\n",is_init,ldi->size);
+    /* Construct a even bytes aligned buffer, and assign it to returned data pointer */
+    if (data == NULL)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_INVALID_SIZE, __LINE__, is_init);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X data pointer is NULL is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+        return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+
+    /* Global software lock status is locked and this logical data item's attribute is write-protected. */
+    if ((nvram_ptr->lock == KAL_TRUE) && NVRAM_IS_ATTR_WRITEPROTECT(ldi->attr))
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_LOCKED, __LINE__, is_init);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X Fail as NVRAM_IO_ERRNO_LOCKED,is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+        return NVRAM_IO_ERRNO_LOCKED;
+    }
+#ifdef __NVRAM_READ_RESERVED_FILE__
+    if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_INVALID_LID, __LINE__, is_init);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X NVRAM_IO_ERRNO_INVALID_LID,is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+#endif
+
+/******************************************************
+ *  Device Broken
+ ******************************************************/
+    if (nvram_ptr->dev_broken)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_DRV_BROKEN, __LINE__, is_init);        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X NVRAM_IO_ERRNO_DRV_BROKEN,is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+        return NVRAM_IO_ERRNO_OK;
+    }
+
+#if defined(__NVRAM_CRITICAL_DATA_SIGN_SUPPORT__)
+    if (is_init == KAL_FALSE && ldi->LID == custom_nvram_get_signed_critical_data_lid()) {
+        kal_bool chk_ret = custom_nvram_check_signed_critical_data_before_write(data, ldi->size);
+        if (chk_ret != KAL_TRUE) {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X NVRAM_ERRNO_SIG_CHK_FAIL\r\n",__FUNCTION__,ldi->LID);
+            return NVRAM_ERRNO_SIG_CHK_FAIL;
+        }
+    }
+#endif
+
+
+/******************************************************
+ *  OTP
+ ******************************************************/
+
+#ifdef __NVRAM_OTP__
+    /* Handle request to OTP */
+    if(ldi->category & NVRAM_CATEGORY_OTP)
+    {
+        if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Raw LID:0x%04X,NVRAM_IO_ERRNO_ACCESS_DENIED,is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }
+        else if (nvram_ptr->state == NVRAM_STATE_READY)
+        {
+            status = nvram_write_otp_data_item(ldi, index, data, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s OTP LID:0x%04X,status=%d,is_init=%d\r\n",__FUNCTION__,ldi->LID,status,is_init);
+            return status;
+        }
+        else if (nvram_ptr->state != NVRAM_STATE_READY)
+        {
+            MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_OK, __LINE__, is_init);
+            status = nvram_write_fs_data_item(ldi, index, data, ldi->size, is_init);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s OTP LID:0x%04X NVRAM_ERRNO_NOT_READY,is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+        }
+    }
+    else
+#endif
+
+/******************************************************
+ *  Custom Disk
+ ******************************************************/
+#ifdef __NVRAM_CUSTOM_DISK__
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+        if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP," %s LID:0x%04X,NVRAM_IO_ERRNO_ACCESS_DENIED,is_init=%d\r\n",__FUNCTION__,ldi->LID,is_init);
+            return NVRAM_IO_ERRNO_ACCESS_DENIED;
+        }    
+        status = nvram_write_custom_disk(ldi, index, data, ldi->size, is_init);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X,custom disk access status=%d,is_init=%d\r\n",ldi->LID,status,is_init);
+    }
+    else
+#endif
+
+/******************************************************
+ *  FAT
+ ******************************************************/
+    { //be care about this "{}" it is use for "else" code of different store device
+        #ifdef __NVRAM_CRYPT_TEST__
+        if (ldi->LID == NVRAM_EF_NVRAM_MSP_TEST_LID)
+        {
+            extern kal_uint32 bWriteMsp;
+            bWriteMsp = 1;
+        }
+        #endif
+
+        #if defined(__NVRAM_INIT_LID_BUFFER__)
+        if(nvram_init_lid_buffer_write(ldi->LID, index, 1, data, ldi->size) == NVRAM_ERRNO_SUCCESS) {
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X write data to buffer,return\r\n",ldi->LID);
+            return NVRAM_IO_ERRNO_OK;
+        }
+        #endif
+        #if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+        if(pre_write_check_mutex_owner != kal_get_current_task()) {
+            if (nvram_util_has_file_created(ldi)) {
+                if(!is_init) {
+                    nvram_write_data_header(ldi, LDI_HEADER_DBG_SECTION);
+                }
+            }
+            else {
+                nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION);
+            }
+        }
+        nvram_util_pre_write_lid(ldi);
+        #endif
+
+        status = nvram_write_fs_data_item(ldi, index, data, ldi->size, is_init);
+    }
+    /*
+    If write fail and the LID is located in NVRAM folder's subfolder,
+    first check the root folder is OK or not.
+    */
+    if(status != NVRAM_IO_ERRNO_OK)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"nvram_write_fs_data_item status = %d\r\n",status);
+        if(NVRAM_IS_CATEGORY_INTERNAL(ldi->category) || NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) ||
+           NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) || (NVRAM_NVD_DATA == nvram_query_folder_index(ldi->category)))
+        {
+            filename = (kal_uint8 *) get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+            NVRAM_FS_MAKE_ROOT_PATH((kal_wchar*)filename);
+            #ifdef __NVRAM_LID_CACHE__
+            nvram_util_take_mutex(g_nvram_fs_mutex);
+            #endif
+            NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+            hFile = FS_Open((const kal_wchar*)filename, FS_READ_ONLY | FS_OPEN_DIR);
+            NVRAM_FS_END(FS_OP_OPEN,hFile);
+            free_ctrl_buffer(filename);
+            if(hFile >= FS_NO_ERROR)   /* Open NVRAM root folder Success */
+            {
+                NVRAM_FS_START(FS_OP_CLOSE);
+                result = FS_Close(hFile);
+                NVRAM_FS_END(FS_OP_CLOSE,result);
+            }
+            else if (hFile == FS_FILE_NOT_FOUND || hFile == FS_PATH_NOT_FOUND)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s NVRAM main folder lost\r\n",__FUNCTION__);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)hFile, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_2, 0);
+            }
+            else
+            {
+                kal_prompt_trace(MOD_NVRAM, "Open NVRAM root folder result:%d\n\r", (kal_uint32)hFile);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"Open NVRAM root folder result:%d\r\n",(kal_uint32)hFile);
+            }
+            #ifdef __NVRAM_LID_CACHE__
+            nvram_util_give_mutex(g_nvram_fs_mutex);
+            #endif
+        }
+    }
+
+
+#ifdef __NVRAM_UNIT_TEST__
+    if (!is_init)
+    {
+        status = nvram_unit_test_get_io_status(status);
+    }
+#endif
+    memcpy((void *)(&tmp_ldi),ldi,sizeof(nvram_ltable_entry_struct));
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+        if (NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            // try restore from bin region
+            if (nvram_recover_data_item(ldi) == NVRAM_IO_ERRNO_OK)
+            {
+                 if(nvram_ptr->state == NVRAM_STATE_READY)
+                {
+                    mcf_ota_ret = mcf_do_ota_by_lid(ldi->LID,1, ldi->total_records,&tmp_ldi);
+                    kal_prompt_trace(MOD_NVRAM, "%s @%d mcf_ota_ret=%d\n\r",__FUNCTION__,__LINE__ , mcf_ota_ret);
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"mcf_do_ota_by_lid return %d\r\n",mcf_ota_ret);
+                }
+                status = nvram_write_fs_data_item(ldi, index, data, ldi->size, is_init);                 
+                if (status == NVRAM_IO_ERRNO_OK)
+                {
+                    goto end;
+                }
+            }
+            else
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->nvram_recover_data_item fail\r\n",__FUNCTION__);
+            }
+        }        
+#endif
+
+        /* IMEI and SML */
+        if (NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr))
+        {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL:%d\n\r", DISPLAY_ERROR(status));
+            kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%08X\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL:%d\r\n", DISPLAY_ERROR(status));
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_EXT_ASSERT (KAL_FALSE, DISPLAY_ERROR(status),NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL , ldi->LID);
+            return status;
+        }
+
+
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, is_init);
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"write after recover status:%d\r\n",status);
+        if (is_init == KAL_FALSE
+        #ifdef __NVRAM_CUSTOM_DISK__
+            && !NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category)
+        #endif
+        #ifdef __NVRAM_OTP__
+            && !NVRAM_IS_CATEGORY_OTP(ldi->category)
+        #endif
+            )
+        {
+            if (!nvram_util_always_gen_default(ldi))
+            {
+                ldi->attr |= NVRAM_ATTR_GEN_DEFAULT;
+                lid_is_gen_default = KAL_TRUE;
+            }
+            /* Try to reset data if it is not a initial case */
+            if ((status = nvram_reset_one_data_item(ldi, 1, ldi->total_records)) == NVRAM_IO_ERRNO_OK)
+            {
+                MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, is_init);
+                NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s->nvram_reset_one_data_item successfully is_init=%d\r\n",__FUNCTION__,is_init);
+                if(nvram_ptr->state == NVRAM_STATE_READY)
+                {
+                    mcf_ota_ret = mcf_do_ota_by_lid(ldi->LID,1, ldi->total_records,&tmp_ldi);
+                    kal_prompt_trace(MOD_NVRAM, "%s @%d mcf_ota_ret=%d\n\r",__FUNCTION__,__LINE__ , mcf_ota_ret);
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s->mcf_do_ota_by_lid return %d\r\n",__FUNCTION__,mcf_ota_ret);
+                }
+                status = nvram_write_fs_data_item(ldi, index, data, ldi->size, is_init);                                
+            }
+            if(lid_is_gen_default)
+            {
+                ldi->attr &= ~NVRAM_ATTR_GEN_DEFAULT;
+                lid_is_gen_default = KAL_FALSE;
+            }
+        }
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, is_init);
+        kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_WRITE_AND_RESET_FAIL:%d\n\r", DISPLAY_ERROR(status));
+        kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_WRITE_AND_RESET_FAIL:%d\r\n", DISPLAY_ERROR(status));
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_LOC_WRITE_AND_RESET_FAIL, ldi->LID);
+    }
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+end:
+#endif
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    if (status == NVRAM_IO_ERRNO_OK)
+    {
+        nvram_util_post_write_lid(ldi);
+    }
+#endif
+    return status;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_data_item
+ * DESCRIPTION
+ *  This is nvram_write_exception_data_item() function of NVRAM module.
+ * PARAMETERS
+ *  ldi                 [IN]        MUST be 1 ~ (total_LID - 1)
+ *  index               [IN]        MUST be 1 ~ total_records
+ *  data                [?]
+ *  is_init             [IN]
+ *  buffer_size(?)      [IN]        MUST be even-bytes aligned: ie, ((ldi->size + 1) / 2) * 2 Note that content of `data' could be changed due to encyrption!!
+ *  buffer(?)           [IN]        MUST be even-bytes aligned.
+ * RETURNS
+ *  NVRAM_IO_ERRNO_INVALID_LID
+ *  NVRAM_IO_ERRNO_INVALID_RECORD
+ *  NVRAM_IO_ERRNO_INVALID_SIZE
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+nvram_errno_enum nvram_write_exception_data_item(nvram_ltable_entry_struct *ldi, kal_uint16 index, kal_uint8 *data)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status;
+    NVRAM_FILE_NAME nvramname;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    MD_TRC_IO_WRITE_DATA_ITEM_START(ldi->LID, index, 0);
+    MD_TRC_INFO_NVRAM_DATA_ITEM(ldi->LID, ldi->size);
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X index=%d,rec_size=%d\r\n",ldi->LID, index, ldi->size);
+    /* Construct a even bytes aligned buffer, and assign it to returned data pointer */
+    if (data == NULL)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_INVALID_SIZE, __LINE__, 0);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X data pointer is NULL\r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_INVALID_SIZE;
+    }
+
+    /* Do not allow normal access use exception API */
+    if(ldi->LID != NVRAM_EF_SYS_EXCEPTION_LID_DUMMY &&
+        ldi->LID != NVRAM_EF_SYS_STATISTICS_LID)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_ACCESS_DENIED, __LINE__, 0);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Not Exception LID 0x%04X Access Denied \r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }
+
+    /* Global software lock status is locked and this logical data item's attribute is write-protected. */
+    // Skip lock check
+
+/******************************************************
+ *  Device Broken
+ ******************************************************/
+    if (nvram_ptr->dev_broken)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_DRV_BROKEN, __LINE__, 0);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X NVRAM_IO_ERRNO_DRV_BROKEN\r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_OK;
+    }
+
+/******************************************************
+ *  OTP
+ ******************************************************/    
+#ifdef __NVRAM_OTP__
+    //block OTP request
+    if (ldi->category & NVRAM_CATEGORY_OTP)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_ACCESS_DENIED, __LINE__, 0);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s OTP LID 0x%04X Access Denied \r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED;
+    }
+    else
+#endif
+
+/******************************************************
+ *  Custom Disk
+ ******************************************************/
+#ifdef __NVRAM_CUSTOM_DISK__
+    //block CUSTOM_DISK request
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_ACCESS_DENIED, __LINE__, 0);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s Custom Disk LID 0x%04X Access Denied \r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+        return NVRAM_IO_ERRNO_ACCESS_DENIED; 
+    }
+    else
+#endif
+
+/******************************************************
+ *  FAT
+ ******************************************************/
+    { //be care about this "{}" it is use for "else" code of different store device
+        //status = nvram_write_fs_data_item(ldi, index, data, ldi->size, 0);
+        //Read exception file directly
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+        status = nvram_drv_fat_write_exception_item(
+                    data,
+                    nvramname,
+                    index,      // record id
+                    ldi->size,  // record size
+                    ldi->size);  // buffer size
+    }
+    
+    if(status != NVRAM_DRV_OK)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID:0x%04X,nvram_drv_fat_write_exception_item return %d\r\n",__FUNCTION__,ldi->LID,status);
+        status = NVRAM_IO_ERRNO_CHK;
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, 0);        
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return status;
+}
+
+#if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_fs_data_item_multiple
+ * DESCRIPTION
+ *  This is nvram_write_data_item_multiple() function of NVRAM module.
+ * PARAMETERS
+ *  ldi             [?]
+ *  index           [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ *  is_init         [IN]
+ * RETURNS
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+static nvram_errno_enum nvram_write_fs_data_item_multiple
+    (nvram_ltable_entry_struct *ldi, 
+    kal_uint16 index, 
+    kal_uint16 rec_mount, 
+    const kal_uint8 *buffer,
+    kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    nvram_drv_status_enum drv_status[2] = {NVRAM_DRV_OK, NVRAM_DRV_OK};
+    kal_uint32 record_ID;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint32 file_offset;
+    nvram_folder_enum folder_index;
+    kal_bool multiple = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        multiple = KAL_TRUE;
+    }
+
+    folder_index = nvram_query_folder_index(ldi->category);
+
+    file_offset = NVRAM_LDI_HEADER_SIZE;
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+    for (record_ID = 0; record_ID < 2; record_ID++)
+    {
+
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (record_ID == 1 && NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            folder_index = NVRAM_NVD_BAK;
+        }
+    #endif
+
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+        if (record_ID == 1)
+        {
+            #ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+            extern kal_bool smu_is_write_protect2(nvram_lid_enum file_idx);
+            if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+            {       
+                // Aussme protect2 is always locked, acctually it only unlocked at first boot in factory
+                if (drv_status[0] == NVRAM_DRV_OK)
+                {
+                    if (smu_is_write_protect2(ldi->LID)) {
+                        // only trigger backup for specific LIDs when they are written legally (shoudn't be frequently)
+                        if (is_init == KAL_FALSE) {
+                            // trigger backup, this will write sync pattern in AP side
+                            MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, 0xFFFF, 0x0001,__LINE__);
+                            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP," LID 0x%04X write sync pattern \r\n",ldi->LID);
+                            ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xABC);
+                        } else {
+                            // trigger backup after init stage
+                            isneedwriteprotect2 = KAL_TRUE;
+                        }
+                    } else {
+                       // Don't trigger backup.
+                       // think about this scenario: 
+                       // some LID will update at known time (every md bootup time)
+                       // this will leave sync pattern in AP if we trigger backup, 
+                       // then hacker can deleted all files on protect1 before reboot the phone
+                       // the SML data on protect2 will lost after phone reboot ...
+                    }
+                    return NVRAM_IO_ERRNO_OK;
+                } 
+                else
+                {
+                    // don't trigger backup due to protect1 write failed
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]LID 0x%04X nvram_drv_fat_write_multRec fail,result=%d\r\n",ldi->LID,drv_status[0]);
+                    return NVRAM_IO_ERRNO_CHK;
+                } 
+			}
+            #endif
+            folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+        }
+    #endif
+       
+        drv_status[record_ID] = nvram_drv_fat_write_multRec(
+                            ldi,
+                            nvramname,
+                            folder_index,
+                            file_offset,
+                            index,
+                            rec_mount,
+                            ldi->size,
+                            buffer,
+                            is_init);
+        nvram_debug_write_dump(ldi, 0x800, index, rec_mount, buffer, ldi->size, drv_status[record_ID]);
+        
+        /* Try to reset data if it is not a initial case */
+        if (drv_status[record_ID] != NVRAM_DRV_OK)
+        {
+            MD_TRC_IO_WRITE_DATA_ITEM_MULTIPLE(ldi->LID, drv_status, nvram_drv_fat_get_last_err(), __LINE__);
+            status = NVRAM_IO_ERRNO_CHK;
+        }
+
+        if (!multiple)
+        {
+            break;
+        }        
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK && multiple == KAL_TRUE) 
+    {
+        kal_int32 recovery_status;
+        if (drv_status[0] != NVRAM_DRV_OK &&  drv_status[1] == NVRAM_DRV_OK)
+        {
+            recovery_status = nvram_drv_fat_backup(ldi, KAL_FALSE);   /* A <-- B */
+        } 
+        else if (drv_status[0] == NVRAM_DRV_OK &&  drv_status[1] != NVRAM_DRV_OK) 
+        {
+            recovery_status = nvram_drv_fat_backup(ldi, KAL_TRUE);   /* A --> B */
+        }
+        else
+        {
+            // Both A&B write fail
+            recovery_status = drv_status[0];
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"recover status:%d\r\n",recovery_status);
+        }        
+        if (recovery_status == NVRAM_DRV_OK)
+        {            
+            return NVRAM_IO_ERRNO_OK;
+        }
+    }
+    return status;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_fs_data_item
+ * DESCRIPTION
+ *  This is nvram_write_data_item_multiple() function of NVRAM module.
+ * PARAMETERS
+ *  ldi             [?]
+ *  index           [IN]
+ *  buffer          [?]
+ *  buffer_size     [IN]
+ *  is_init         [IN]
+ * RETURNS
+ *  NVRAM_IO_ERRNO_CHK if all copies are failed to write
+ *  NVRAM_IO_ERRNO_OK at least one valid copy is written.
+ *****************************************************************************/
+static nvram_errno_enum nvram_write_fs_data_item
+    (nvram_ltable_entry_struct *ldi, kal_uint32 index, kal_uint8 *buffer, kal_uint32 buffer_size, kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+    nvram_drv_status_enum drv_status[2] = {NVRAM_DRV_OK, NVRAM_DRV_OK};
+
+    kal_uint32 record_ID;
+    NVRAM_FILE_NAME nvramname;
+
+    kal_uint32 file_offset;
+    nvram_folder_enum folder_index;
+    kal_bool multiple = KAL_FALSE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/    
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        multiple = KAL_TRUE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+
+    file_offset = NVRAM_LDI_HEADER_SIZE;
+    if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) {
+        file_offset += index;
+        index = 1;
+    }
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        file_offset = (kal_uint32) (ldi->description);
+        if (!multiple)
+        {
+            nvram_make_package_filename(nvramname, 'A');
+        }
+    }
+#endif
+
+    for (record_ID = 0; record_ID < 2; record_ID++)
+    {
+
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        if (record_ID == 1 && NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+        {
+            folder_index = NVRAM_NVD_BAK;
+        }
+    #endif
+
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+        if (record_ID == 1)
+        {
+            #ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+            extern kal_bool smu_is_write_protect2(nvram_lid_enum file_idx);
+            if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+            {       
+                // Aussme protect2 is always locked, acctually it only unlocked at first boot in factory
+                if (drv_status[0] == NVRAM_DRV_OK)
+                {
+                    if (smu_is_write_protect2(ldi->LID)) {
+                        // only trigger backup for specific LIDs when they are written legally (shoudn't be frequently)
+                        if (is_init == KAL_FALSE) {
+                            // trigger backup, this will write sync pattern in AP side
+                            MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, 0xFFFF, 0x0001,__LINE__);
+                            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"LID:0x%04X write sync pattern to AP\r\n",ldi->LID);
+                            ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xABC);
+                        } else {
+                            // trigger backup after init stage
+                            isneedwriteprotect2 = KAL_TRUE;
+                        }
+                    } else {
+                       // Don't trigger backup.
+                       // think about this scenario: 
+                       // some LID will update at known time (every md bootup time)
+                       // this will leave sync pattern in AP if we trigger backup, 
+                       // then hacker can deleted all files on protect1 before reboot the phone
+                       // the SML data on protect2 will lost after phone reboot ...
+                    }                    
+                    return NVRAM_IO_ERRNO_OK;
+                } 
+                else
+                {
+                    // don't trigger backup due to protect1 write failed
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s return NVRAM_IO_ERRNO_CHK,drv_status[0]=%d \r\n",__FUNCTION__,drv_status[0]);
+                    return NVRAM_IO_ERRNO_CHK;
+                } 
+            }
+            #endif
+            folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+        }
+    #endif
+
+        // if LID == SYS_LID, file can be empty & index is the index of record needs to write (amount is 1)
+        // if is_init == TRUE, file can be empty & index is the # of record needs to write (index always 1)
+        // if is_init == FALSE, file should not be empty & index is the index of record needs to write (amount always 1)
+
+        if(is_init && NVRAM_EF_SYS_LID != ldi->LID)
+        {
+
+            drv_status[record_ID] = nvram_drv_fat_write(
+                            nvramname,
+                            folder_index,
+                            file_offset,
+                            1,
+                            index,
+                            buffer_size,
+                            buffer,
+                            ldi,
+                            is_init);
+
+        }
+        else
+        {
+            drv_status[record_ID] = nvram_drv_fat_write(
+                            nvramname,
+                            folder_index,
+                            file_offset,
+                            index,
+                            1,
+                            buffer_size,
+                            buffer,
+                            ldi,
+                            is_init);
+        }
+
+
+        /* Try to reset data if it is not a initial case */
+        if (drv_status[record_ID] != NVRAM_DRV_OK)
+        {
+            MD_TRC_IO_WRITE_DATA_ITEM_MULTIPLE(ldi->LID, drv_status, nvram_drv_fat_get_last_err(), __LINE__);            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s return NVRAM_IO_ERRNO_CHK,drv_status[%d]!=%d \r\n",__FUNCTION__,record_ID,drv_status[record_ID]);
+            status = NVRAM_IO_ERRNO_CHK;
+        }
+
+        if (!multiple)
+        {
+            break;
+        }        
+
+        #ifdef __NVRAM_LID_CACHE__
+        if(NVRAM_WR_WITH_CACHE(ldi->LID) && (!(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))) && ((drv_status[0] == NVRAM_DRV_OK) || (drv_status[1] == NVRAM_DRV_OK)))
+        {
+            status = NVRAM_IO_ERRNO_OK;
+            break;
+        }
+        #endif
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK && multiple == KAL_TRUE)
+    {
+        kal_int32 recovery_status = NVRAM_DRV_OK;
+        if (drv_status[0] != NVRAM_DRV_OK &&  drv_status[1] == NVRAM_DRV_OK)
+        {
+            recovery_status = nvram_drv_fat_backup(ldi, KAL_FALSE);   /* A <-- B */
+        } 
+        else if (drv_status[0] == NVRAM_DRV_OK &&  drv_status[1] != NVRAM_DRV_OK)
+        {
+            recovery_status = nvram_drv_fat_backup(ldi, KAL_TRUE);   /* A --> B */
+        } 
+        else
+        {
+            // Both A&B write fail
+            recovery_status = drv_status[0];
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s recovery_status = %d\r\n",__FUNCTION__,recovery_status);
+        }
+
+        if (recovery_status == NVRAM_DRV_OK) 
+        {            
+            return NVRAM_IO_ERRNO_OK;
+        }
+    }
+    return status;
+}
+
+#if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_mutilpe_data_item
+ * DESCRIPTION
+ *  write data with lid size but not a record.Support write 1..amount records
+ *  one time if (lid->size+checksum) * amount < MAX_NVRAM_RECORD_SIZE
+ * PARAMETERS
+ *  ldi         [IN]    the data item to be write
+ *  rec_idnex   [IN]    the start record index will be write
+ *  rec_amount  [IN]    the amount of the records will be write 
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static nvram_errno_enum nvram_write_default_data_item_mutilpe(nvram_ltable_entry_struct *ldi,
+                                        kal_uint16 rec_index,
+                                        kal_uint16 rec_amount)
+{
+    
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_errno_enum status = NVRAM_IO_ERRNO_OK;
+        
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    MD_TRC_IO_WRITE_DATA_ITEM_START(ldi->LID, rec_index, rec_amount);
+    MD_TRC_INFO_NVRAM_DATA_ITEM(ldi->LID, ldi->size);
+    /******************************************************
+     *  Device Broken
+     ******************************************************/
+    if (nvram_ptr->dev_broken)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, NVRAM_IO_ERRNO_DRV_BROKEN, __LINE__, ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s NVRAM_IO_ERRNO_DRV_BROKEN\r\n",__FUNCTION__);
+        return status;
+    }
+
+//#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+    
+    /* prepare data */
+    if( ldi->default_value == NVRAM_EF_FF_DEFAULT || 
+        ldi->default_value == NVRAM_EF_ZERO_DEFAULT)
+    {
+        kal_uint8 const *default_value = ldi->default_value;
+        status = nvram_write_fs_data_item_multiple(ldi,rec_index,rec_amount,default_value,KAL_TRUE);
+    }
+    else if(ldi->default_value == NULL)
+    {
+        kal_uint8 const *default_value = NVRAM_EF_FF_DEFAULT;
+        status = nvram_write_fs_data_item_multiple(ldi,rec_index,rec_amount,default_value,KAL_TRUE);
+    }
+    else
+    {
+        kal_uint8 *default_value_buffer;
+        kal_uint32 i;
+        kal_uint8 *default_value_p;
+        kal_uint8 *def_buff;
+
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(ldi->size * rec_amount + NVRAM_BUFFER_TAIL_SIZE);
+        kal_mem_cpy((default_value_buffer + (ldi->size * rec_amount)), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE);
+            
+        if((ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT) && (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT))
+        {
+            nvram_get_lid_default_value_to_write(ldi, 0, default_value_buffer, (ldi->size * rec_amount));
+        }
+        else
+        {
+            def_buff = (kal_uint8*) get_ctrl_buffer(ldi->size + NVRAM_BUFFER_TAIL_SIZE);
+            kal_mem_cpy((def_buff + ldi->size), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE);
+            for (i = 0; i < rec_amount; i++)
+            {
+                default_value_p = (kal_uint8*) nvram_get_lid_default_value_to_write(ldi, i, NULL, 0);        
+                if (default_value_p == NULL)
+                {
+                    nvram_get_lid_default_value_to_write(ldi, i, def_buff, ldi->size);
+                    default_value_p = def_buff;
+                }           
+                kal_mem_cpy(default_value_buffer + i*(ldi->size), default_value_p, ldi->size);
+                default_value_p = NULL;
+            }
+
+            if(kal_mem_cmp((def_buff + ldi->size), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE) != 0)
+            {
+                // Return default value is out of buffer. 
+                MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(ldi->LID, (ldi->size * rec_amount), __LINE__, 0,0);
+                free_ctrl_buffer(def_buff);
+                free_ctrl_buffer(default_value_buffer);
+                NVRAM_EXT_ASSERT(KAL_FALSE, (ldi->size * ldi->total_records), NVRAM_LOC_SPACE_NOT_ENOUGH, ldi->LID, free_ctrl_buffer(def_buff);free_ctrl_buffer(default_value_buffer));
+            }           
+            free_ctrl_buffer(def_buff);     
+        }
+
+        if(kal_mem_cmp((default_value_buffer + (ldi->size * rec_amount)), NVRAM_BUFFER_TAIL_MARK, NVRAM_BUFFER_TAIL_SIZE) != 0)
+        {
+            // Return default value is out of buffer. 
+            MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(ldi->LID, (ldi->size * rec_amount), __LINE__, 0,0);
+            free_ctrl_buffer(default_value_buffer);
+            NVRAM_EXT_ASSERT(KAL_FALSE, (ldi->size * ldi->total_records), NVRAM_LOC_SPACE_NOT_ENOUGH_1, ldi->LID, free_ctrl_buffer(default_value_buffer));
+        }
+        
+        status = nvram_write_fs_data_item_multiple(ldi,rec_index,rec_amount,default_value_buffer,KAL_TRUE);
+        free_ctrl_buffer(default_value_buffer);
+    }
+    
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+        /* IMEI and SML */  
+        if ((NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)
+    #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+                || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+        #else
+            )
+        #endif
+    #else
+            )
+    #endif  
+            )
+        {
+            kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_1:%d\n\r", DISPLAY_ERROR(status));
+            kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+            kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+            kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_1:%d\r\n", DISPLAY_ERROR(status));
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_EXT_ASSERT (KAL_FALSE, DISPLAY_ERROR(status),NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_1 , ldi->LID);
+            return status;
+        }
+
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, KAL_TRUE);
+    }
+
+    if (status != NVRAM_IO_ERRNO_OK)
+    {
+        MD_TRC_IO_WRITE_DATA_ITEM_RESULT(ldi->LID, status, __LINE__, KAL_TRUE);
+        kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_WRITE_AND_RESET_FAIL_1:%d\n\r", DISPLAY_ERROR(status));
+        kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM_LOC_WRITE_AND_RESET_FAIL_1:%d\r\n", DISPLAY_ERROR(status));
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+        NVRAM_EXT_ASSERT(KAL_FALSE, DISPLAY_ERROR(status), NVRAM_LOC_WRITE_AND_RESET_FAIL_1, ldi->LID);
+    }
+    return status;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_one_data_item
+ * DESCRIPTION
+ *  Reset only one data item
+ * PARAMETERS
+ *  ldi         [IN]    the data item to reset
+ *  buffer      [IN]    buffer which has enough space
+ *  buffer_size [IN]    the max buffer size
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static nvram_errno_enum nvram_reset_one_data_item(nvram_ltable_entry_struct *ldi,
+                                        kal_uint16 rec_index,
+                                        kal_uint16 rec_amount)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 *default_value;
+    kal_uint32 i , start, end;
+    kal_uint8 *default_value_buffer;
+    kal_uint32 working_buffer_size = 0;
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (rec_index < 1 ||
+        rec_index > ldi->total_records ||
+        rec_amount < 1 ||
+        rec_amount > ldi->total_records - rec_index + 1)
+    {
+        /* arguments invalid */
+        start = 1;
+        end = ldi->total_records;
+    }
+    else
+    {
+        start = rec_index,
+        end = rec_index + rec_amount - 1;
+    }
+
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    if (start == 1 && end == ldi->total_records)
+    {
+		#ifdef __NVRAM_LID_CACHE__
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+		#endif
+        nvram_util_mark_file_uncreated(ldi);
+		#ifdef __NVRAM_LID_CACHE__
+        nvram_util_give_mutex(g_nvram_fs_mutex);
+		#endif
+    }
+    if (!nvram_util_always_gen_default(ldi))
+    {
+        if (start == 1 && end == ldi->total_records)
+        {
+            nvram_debug_write_dump(ldi, 0x700, rec_index, rec_amount, NULL, ldi->size, NVRAM_IO_ERRNO_CHK);
+            return NVRAM_IO_ERRNO_OK;
+        }
+    } 
+    else 
+    {
+        /* reset always gen default LID for the first time */
+        nvram_util_pre_reset_gen_default_lid(ldi);
+    }
+    
+#endif
+
+    // LID total size can not over MAX_NVRAM_RECORD_SIZE
+    if((ldi->default_value != NVRAM_EF_ZERO_DEFAULT) && 
+        ((ldi->size * ldi->total_records + NVRAM_BUFFER_TAIL_SIZE) > MAX_NVRAM_RECORD_SIZE) )
+    {
+        MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(ldi->LID, (ldi->size * ldi->total_records), __LINE__, 0,0);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s -> LID 0x%04X\r\n",__FUNCTION__,ldi->LID);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]total size(%d) over %d\r\n",(ldi->size * ldi->total_records + NVRAM_BUFFER_TAIL_SIZE),MAX_NVRAM_RECORD_SIZE);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (ldi->size * ldi->total_records), NVRAM_LOC_GET_DEFAULT_WITH_WRONG_PARAM_2, ldi->LID);      
+    }
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+#if defined(__MTK_TARGET__) && defined(__NVRAM_WRITE_WITH_FILE_SIZE__)  && !defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+    do
+    {   
+        if (KAL_FALSE == bResetNvramData 
+            || KAL_FALSE == kal_query_systemInit()   //initiation
+            || (ldi->size + nvram_chksum_size) > MAX_NVRAM_RECORD_SIZE   //large record
+            || ldi->LID == NVRAM_EF_SYS_LID
+        #ifdef __NVRAM_OTP__        
+            || NVRAM_IS_CATEGORY_OTP(ldi->category)
+        #endif
+        #ifdef __NVRAM_CUSTOM_DISK__
+            || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category)
+        #endif      
+        #ifdef __NVRAM_PSEUDO_MERGE__
+            || NVRAM_IS_ATTR_PACKAGE(ldi->attr)
+        #endif
+        #ifdef __NVRAM_CRYPT_TEST__
+            || ldi->LID == NVRAM_EF_NVRAM_MSP_TEST_LID
+        #endif
+            )
+        {           
+            break;
+        }
+            
+        // only support reset 1..total_records
+        if (start == 1 && end == ldi->total_records)
+        {
+            kal_uint32 remainLen = 0;
+            default_value = NULL;
+            default_value_buffer = NULL;
+        
+            #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+            if (ldi->attr & NVRAM_ATTR_MSP)
+            {
+                /* 4 byte alignment */
+                remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size);
+            }
+            #endif
+            
+            working_buffer_size = (ldi->size + nvram_chksum_size + remainLen) * ldi->total_records;
+                        
+            if (working_buffer_size <= MAX_NVRAM_RECORD_SIZE)
+            {
+                result = nvram_write_default_data_item_mutilpe(ldi,1,ldi->total_records);                
+            #if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+                if (nvram_util_always_gen_default(ldi)) {
+                    nvram_util_post_reset_gen_default_lid(ldi);
+                }
+            #endif
+                return result;
+            }           
+        }
+        break;
+        
+    }while(0);
+#endif
+
+    //default_value_buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+    working_buffer_size = ldi->size * rec_amount;
+    if ((start == 1) && (end == ldi->total_records))
+    {
+        working_buffer_size = ldi->size * ldi->total_records;
+    }
+
+    if (working_buffer_size > MAX_NVRAM_RECORD_SIZE)
+    {
+        working_buffer_size = MAX_NVRAM_RECORD_SIZE;
+    }
+  
+    default_value_buffer = (kal_uint8*) get_ctrl_buffer(working_buffer_size);
+    nvram_debug_write_dump(ldi, 0x701, rec_index, rec_amount, NULL, ldi->size, NVRAM_IO_ERRNO_CHK);
+  
+    for (i = start; i <= end; i++)
+    {
+        /* when ldi size too big, we cannot operator it on buffer,
+           use original default value pointer directly */
+
+        default_value = (kal_uint8*) nvram_get_default_value_to_write(ldi, i, NULL, 0);
+
+        /* the default_value is not assigned in table , ex: L1 LID */
+        if (default_value == NULL)
+        {
+            if((i == 1 && end == ldi->total_records) && (NVRAM_EF_SYS_LID != ldi->LID))
+            {
+                nvram_get_default_value_to_write(ldi, i, default_value_buffer, working_buffer_size);
+            }
+            else
+            {
+                nvram_memset(default_value_buffer, (kal_uint8) NVRAM_EF_ZERO_DEFAULT_VALUE, working_buffer_size);
+                nvram_get_default_value_to_write(ldi, i, default_value_buffer, ldi->size);
+            }
+            
+            default_value = default_value_buffer;
+        }
+
+        /* initial case, we reset it directly to enhance performance*/
+        if (start == 1 && end == ldi->total_records)
+        {
+            if(NVRAM_EF_SYS_LID == ldi->LID)
+            {
+                result = nvram_write_data_item(ldi, i, default_value, KAL_TRUE);
+                if (result != NVRAM_IO_ERRNO_OK)
+                {
+                    break;
+                }                
+            }
+            else
+            {
+                result = nvram_write_data_item(ldi, ldi->total_records, default_value, KAL_TRUE);
+                break;
+            }
+        }
+        else
+        {
+            result = nvram_write_data_item(ldi, i, default_value, KAL_FALSE);
+
+            if (result != NVRAM_IO_ERRNO_OK)
+            {
+                NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"nvram_write_data_item return %d\r\n",result);
+                break;
+            }
+        }
+    }
+
+    free_ctrl_buffer(default_value_buffer);
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    if (nvram_util_always_gen_default(ldi)) {
+        nvram_util_post_reset_gen_default_lid(ldi);
+    }
+#endif
+    return result;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_one_data_item
+ * DESCRIPTION
+ *  Reset only one data item
+ * PARAMETERS
+ *  ldi         [IN]    the data item to reset
+ *  buffer      [IN]    buffer which has enough space
+ *  buffer_size [IN]    the max buffer size
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static nvram_errno_enum nvram_reset_category(nvram_category_enum included, nvram_category_enum excluded)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    do
+    {
+        if (ldi->category & excluded)
+        {
+            continue;
+        }
+
+        /*
+         *  special handle for reset all
+         */
+        if (included == NVRAM_CATEGORY_ALL)
+        {
+        #ifdef __NVRAM_BACKUP_DISK__
+            /* recover the data from backup partition */
+            if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_ATTR_BACKUP_RAW(ldi->attr))
+            {
+                if (nvram_recover_image_by_lid(ldi) == NVRAM_ERRNO_SUCCESS)
+                {
+                    continue;
+                }
+            }
+        #endif
+        #ifdef __NVRAM_CUSTOM_DISK__
+            if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+            {
+                if (nvram_read_custom_disk(ldi, 1, ldi->total_records, NULL, 0) == NVRAM_IO_ERRNO_OK)
+                {
+                    /* do not reset the data in custom disk */
+                    continue;
+                }
+            }
+        #endif
+        }
+
+        #if defined(__NVRAM_WRITE_PROTECT_ENABLE__)	&& defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+            if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) 
+            {
+                if (nvram_drv_fat_backup(ldi, KAL_FALSE) == NVRAM_ERRNO_SUCCESS)
+                {
+                    /* unconditionally restore from protect_s to protect_f if file exist */
+                    #if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+                    nvram_util_post_reset_gen_default_lid(ldi);
+                    #endif
+                    continue;
+                }
+            }
+        #endif
+
+        if (included == NVRAM_CATEGORY_ALL || ldi->category & included)
+        {
+            result = nvram_reset_one_data_item(ldi, 1, ldi->total_records);
+        }        
+        if (result != NVRAM_IO_ERRNO_OK)
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s LID 0x%04X result=%d \r\n",__FUNCTION__,ldi->LID,result);
+            break;
+        }
+    }while(nvram_util_next_data_item(&ldi));
+    
+    return result;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_one_data_item
+ * DESCRIPTION
+ *  Reset only one data item
+ * PARAMETERS
+ *  ldi         [IN]    the data item to reset
+ *  buffer      [IN]    buffer which has enough space
+ *  buffer_size [IN]    the max buffer size
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#ifdef __NVRAM_PSEUDO_MERGE__ 
+static nvram_errno_enum nvram_reset_attr(nvram_attr_enum included, nvram_attr_enum excluded)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    nvram_errno_enum result = NVRAM_IO_ERRNO_OK;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    do
+    {
+
+        if (ldi->attr & excluded)
+        {
+            continue;
+        }
+
+        if (included == NVRAM_ATTR_ALL || ldi->attr & included)
+        {
+            result = nvram_reset_one_data_item(ldi, 1, ldi->total_records);
+        }
+
+        if (result != NVRAM_IO_ERRNO_OK)
+        {
+            break;
+        }
+    }while(nvram_util_next_data_item(&ldi));
+    return result;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset_data_items
+ * DESCRIPTION
+ *  This is nvram_reset_data_item() function of NVRAM module.
+ *
+ *  When invoking nvram_write_data_item(), `is_init' flag is ALWAYS TRUE;
+ *  such that for each data item to be written:
+ *
+ *  1. Driver Layer could delete records of the data item, if it
+ *  already exists.
+ *  (In current flash driver, namely fd, this function is fd_rcd_delete())
+ *
+ *  2. Then Driver Layer write default value to each record of the data item.
+ *  (In current flash driver, namely fd, this function is fd_rcd_initialize())
+ *
+ *  This function may be invoked due to incompatible version.
+ *  For data items located in the `reset_category',
+ *  they may be (1) newly added, (2)newly removed, or (3)just default value modified.
+ *  Consider invoking nvram_write_data_item() with `is_init' flag set to true for
+ *  each case:
+ *  (1) Newly added:
+ *  Invoke fd_rcd_delete() to delete records of the data item is no effect.
+ *  fd_rcd_initialize() will allocate spaces for that data item.
+ *
+ *  (2) Newly deleted:
+ *  This results in a effect of "shift" due to some data item LID's are deleted.
+ *  It should be ok since fd_rcd_delete()/fd_rcd_initialize() will be called
+ *  for each valid LID. Of course, some out-of-dated LID's are possibly
+ *  left and occupies FLASH space.
+ *
+ *  (3) Default value modified:
+ *  This is ok.
+ * PARAMETERS
+ *  reset_category      [IN]        Coubld be NVRAM_RESET_ALL NVRAM_RESET_SYSTEM NVRAM_RESET_USER
+ *  ldi                 [?]
+ * RETURNS
+ *
+ *****************************************************************************/
+kal_bool nvram_reset_data_items(
+            nvram_reset_category_enum reset_category,
+            nvram_app_id_enum   app_id,
+            nvram_ltable_entry_struct *ldi,
+            kal_uint16 rec_index,
+            kal_uint16 rec_amount)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool status = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (ldi)
+    {
+        MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(reset_category, nvram_ptr->state, app_id, ldi->LID, rec_index);
+        kal_prompt_trace(MOD_NVRAM,"reset_category=%d,LID 0x%x, ldi->attr 0x%x.\r\n",reset_category,ldi->LID, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM,"rec_index=%d,rec_amount=%d\r\n",rec_index,rec_amount);
+        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"reset_category=%d,LID 0x%04X, ldi->attr 0x%x.\r\n",reset_category,ldi->LID, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"rec_index=%d,rec_amount=%d\r\n",rec_index,rec_amount);
+    }
+    else
+    {
+        MD_TRC_FUNC_NVRAM_RESET_DATA_ITEMS(reset_category, nvram_ptr->state, app_id, 0, rec_index);
+    }
+
+    /* Since reset is highest priority, the software lock must be unlocked temporarily. */
+    nvram_ptr->lock = KAL_FALSE;
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock;
+    }
+    /* Since entire logical data item is to be reset, nvram_write_data_item() is invoked. */
+    switch (reset_category)
+    {
+        case NVRAM_RESET_CERTAIN:
+        {
+            #ifdef __NVRAM_OTP__
+                if(ldi && (ldi->category & NVRAM_CATEGORY_OTP))
+                {
+                    /*
+                     * if from nvram init, return true.
+                     */
+                    if (nvram_ptr->state != NVRAM_STATE_READY)
+                    {
+                        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__);
+                        return KAL_TRUE;
+                    }
+                    else
+                    {
+                        return KAL_FALSE;
+                    }
+                }
+            #endif /* __NVRAM_OTP__ */
+
+                nvram_reset_one_data_item(ldi, rec_index, rec_amount);
+            break;
+        }
+
+        case NVRAM_RESET_ALL:
+        {
+            {
+
+            #ifdef __NVRAM_PSEUDO_MERGE__
+                nvram_calculate_write_data_offset(NULL, KAL_TRUE);
+            #endif
+
+                if (nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT)
+                {
+                    nvram_reset_category(NVRAM_CATEGORY_ALL, 0);
+                    if(nvram_ee_info != NULL){
+                        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_RESET_ALL_FILE_DONE;
+                        nvram_ee_info->nvram_init_time[3] = kal_get_systicks();
+                    }
+                }
+                else
+                {
+                #if defined(__CCCIFS_SUPPORT__)
+                    nvram_reset_category(NVRAM_CATEGORY_ALL, NVRAM_CATEGORY_IMPORTANT | NVRAM_CATEGORY_CALIBRAT 
+                                        | NVRAM_CATEGORY_IMPORTANT_L4 | NVRAM_CATEGORY_IMPORTANT_L1);
+                #else
+                    nvram_reset_category(NVRAM_CATEGORY_ALL, NVRAM_CATEGORY_IMPORTANT);
+                #endif
+                    if(nvram_ee_info != NULL){
+                        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTOR_BOOT_RESET_NON_CRITICAL_FILE_DONE;
+                        nvram_ee_info->nvram_init_time[6] = kal_get_systicks();
+                    }
+                }
+            }
+
+            nvram_factory_rmdir_user(NVRAM_RESET_ALL);
+
+            break;
+        }
+    #ifdef __NVRAM_PSEUDO_MERGE__
+        case NVRAM_RESET_PACKAGE:
+        {
+            /* write information of package LID into info_file */
+            nvram_calculate_write_data_offset(NULL, KAL_TRUE);
+            nvram_reset_attr(NVRAM_ATTR_PACKAGE, 0);
+            break;
+        }
+    #endif /* __NVRAM_PSEUDO_MERGE__ */
+        case NVRAM_RESET_FACTORY:
+        {
+            if (nvram_ptr->state != NVRAM_STATE_READY)/* init stage */
+            {
+                //nvram_reset_attr(NVRAM_ATTR_FACTORY_RESET, 0);
+                nvram_reset_category(NVRAM_CATEGORY_ALL, NVRAM_CATEGORY_IMPORTANT_L4 | NVRAM_CATEGORY_IMPORTANT_L1);
+                
+                //nvram_factory_restore_mmi_cache(NVRAM_RESET_FACTORY, app_id);
+                nvram_factory_restore_sys_cache(NVRAM_RESET_FACTORY, app_id);
+                nvram_factory_rmdir_user(NVRAM_RESET_FACTORY);
+                nvram_set_restore_factory_flag(NVRAM_RESTORE_FALSE);
+            }
+            else
+            {
+                nvram_set_restore_factory_flag(NVRAM_RESTORE_TRUE);
+            }
+            break;
+        }
+        case NVRAM_RESET_BRANCH:
+        {
+            nvram_reset_category(NVRAM_CATEGORY_ALL, NVRAM_CATEGORY_IMPORTANT | NVRAM_CATEGORY_CALIBRAT 
+                                | NVRAM_CATEGORY_IMPORTANT_L4 | NVRAM_CATEGORY_IMPORTANT_L1);
+            nvram_factory_rmdir_user(NVRAM_RESET_BRANCH);
+            break;
+        }
+    #ifdef __NVRAM_SUPPORT_CUSTPACK__
+        case NVRAM_RESET_CUSTPACK:
+        {
+            nvram_reset_category(NVRAM_CATEGORY_CUSTPACK, 0);
+
+            nvram_util_get_data_item(&ldi, NVRAM_EF_CUSTPACK_VERNO_LID);
+            nvram_reset_one_data_item(ldi, 1, ldi->total_records);
+
+            break;
+        }
+    #endif
+       
+        default:
+        {            
+            status = KAL_FALSE;
+            break;
+        }
+    }
+
+    /* Restore lock state */
+    nvram_ptr->lock = nvram_ptr->saved_lock;
+    return status;
+}   /* end of nvram_reset_data_item */
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_factory_restore_sys_cache
+ * DESCRIPTION
+ *  Reset system cache
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or not
+ *****************************************************************************/
+static kal_bool nvram_factory_restore_sys_cache(nvram_reset_category_enum category, nvram_app_id_enum app_id)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 record_idx;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 *buffer;
+    kal_uint8 *tmp_buffer;
+    nvram_drv_status_enum status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_CACHE_OCTET_LID);
+    buffer = (kal_uint8*)get_ctrl_buffer(ldi->total_records * ldi->size);
+
+    if (NVRAM_IO_ERRNO_OK == (status = nvram_read_data_item(ldi, 1, ldi->total_records, buffer, ldi->total_records * ldi->size)))
+    {
+//        nvram_restore_system_cache(category, app_id, buffer);
+        nvram_restore_system_cache(category, 0, buffer);
+
+        for (record_idx = 1; record_idx < ldi->total_records; record_idx++)
+        {
+            tmp_buffer = buffer + ldi->size * (record_idx - 1);
+            nvram_write_data_item(ldi, (kal_uint16)record_idx, tmp_buffer, KAL_FALSE);
+        }
+
+    }
+    else
+    {
+        //This function will not be used
+        free_ctrl_buffer(buffer);
+        kal_prompt_trace(MOD_NVRAM, "Last status:%d,Errno:0x%x,status:%d",DISPLAY_ERROR(status),NVRAM_LOC_READ_SYS_CACHE_FAIL,status);
+        return KAL_FALSE;
+    }
+
+    free_ctrl_buffer(buffer);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_factory_rmdir_user
+ * DESCRIPTION
+ *  Remove customizable folder list
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or not
+ *****************************************************************************/
+static kal_bool nvram_factory_rmdir_user(nvram_reset_category_enum category)
+{
+
+#ifdef __MMI_FMI__
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 dir_idx;
+    nvram_clean_folder_enum clean_folder_category;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    switch (category)
+    {
+        case NVRAM_RESET_ALL:
+            clean_folder_category = NVRAM_CLEAN_FOLDER_ALL;
+            break;
+        case NVRAM_RESET_BRANCH:
+            clean_folder_category = NVRAM_CLEAN_FOLDER_BRANCH;
+            break;
+        case NVRAM_RESET_FACTORY:
+            clean_folder_category = NVRAM_CLEAN_FOLDER_FACTORY;
+            break;
+        default:
+            clean_folder_category = NVRAM_CLEAN_FOLDER_NONE;
+        break;
+    }
+
+    if (clean_folder_category != NVRAM_CLEAN_FOLDER_NONE)
+    {
+        for (dir_idx = nvram_custom_max_clean_folder_size() - 1; dir_idx >= 0 ; dir_idx--)
+        {
+            if ((clean_folder_category & nvram_clean_folder_list[dir_idx].category) &&
+                nvram_clean_folder_list[dir_idx].folder_path != NULL)
+            {
+                NVRAM_FS_START_EX(FS_OP_XDELETE,nvram_clean_folder_list[dir_idx].folder_path);
+                result = FS_XDelete(nvram_clean_folder_list[dir_idx].folder_path, (FS_FILE_TYPE | FS_RECURSIVE_TYPE), NULL, 0);
+                NVRAM_FS_END(FS_OP_XDELETE,result);
+                NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"delete file %s result=%d\r\n",nvram_clean_folder_list[dir_idx].folder_path,result);
+            }
+        }
+    }
+#else
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+#endif /* __MMI_FMI__ */
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return KAL_TRUE;
+}
+
+
+#if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_data_item
+ * DESCRIPTION
+ *  Data item auto-receovery for smart phone
+ * PARAMETERS
+ *  ldi             [?]
+  * RETURNS
+ *  kal_int32   error code from AP FS
+ *****************************************************************************/
+kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                                                  */
+    /*----------------------------------------------------------------*/
+    kal_int32 drv_status[2] = {0, 0};
+    NVRAM_FILE_NAME nvramname;
+    nvram_folder_enum folder_index;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                                                        */
+    /*----------------------------------------------------------------*/
+
+    folder_index = nvram_query_folder_index(ldi->category);    
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    drv_status[0] = nvram_drv_fat_auto_recover(nvramname, folder_index);
+
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"recover LID:0x%04X filename:%s drv_status[0]=%d\r\n",ldi->LID,nvramname,drv_status[0]);
+    MD_TRC_IO_READ_DATA_ITEM_MULTIPLE(ldi->LID, drv_status[0],drv_status[0],nvram_drv_fat_get_last_err(), __LINE__);
+
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+        drv_status[1] = nvram_drv_fat_auto_recover(nvramname, folder_index);
+
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"recover LID:0x%04X filename:%s drv_status[1]=%d\r\n",ldi->LID,nvramname,drv_status[1]);
+        MD_TRC_IO_READ_DATA_ITEM_MULTIPLE(ldi->LID, drv_status[0],drv_status[1], nvram_drv_fat_get_last_err(), __LINE__);
+    }
+    
+    if ((drv_status[0] != 0) || (drv_status[1] != 0))
+    {
+        kal_prompt_trace(MOD_NVRAM, "NVRAM ASSERT ERROR NVRAM_LOC_BIN_REGION_RESTORE_FAIL:%d\n\r", drv_status[0]?drv_status[0]:drv_status[1]);
+        kal_prompt_trace(MOD_NVRAM, "LID:0x%x, total_records:%d, record_size:%d\n\r", ldi->LID, ldi->total_records, ldi->size);
+        kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+        kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM_LOC_BIN_REGION_RESTORE_FAIL:%d \r\n", drv_status[0]?drv_status[0]:drv_status[1]);        
+        if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr) && (nvram_ptr->state == NVRAM_STATE_READY)) {            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"LID:0x%04X, total_records:%d, record_size:%d \r\n", ldi->LID, ldi->total_records, ldi->size);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+            NVRAM_EXT_ASSERT(KAL_FALSE, drv_status[0]?drv_status[0]:drv_status[1], NVRAM_LOC_BIN_REGION_RESTORE_FAIL, ldi->LID);
+        } else {
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s return NVRAM_IO_ERRNO_CHK\r\n",__FUNCTION__);
+            return NVRAM_IO_ERRNO_CHK;
+        }
+    }
+
+  #if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    nvram_util_post_reset_gen_default_lid(ldi);
+  #endif
+    return NVRAM_IO_ERRNO_OK;
+}
+
+#endif
+
diff --git a/mcu/service/nvram/src/nvram_l1def.c b/mcu/service/nvram/src/nvram_l1def.c
new file mode 100644
index 0000000..cc98f46
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_l1def.c
@@ -0,0 +1,1577 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_l1def.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *    This file provides a fuction for NVRAM Task to get L1 default value
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+#include "nvram_main.h"         /* nvram_ltable_entry_struct & nvram_ptr, should be removed in the future */
+#include "nvram_l1def.h"
+
+#ifdef __MTK_TARGET__
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+// #include "stack_ltlcom.h" //MSBB change #include "app_ltlcom.h" /* Task message communiction */
+
+/* L1 calibration data defination */
+#include "l1cal.h"
+#include "l1d_public.h"
+#include "l1d_data_pcore.h"
+#include "nvram_data_items.h"
+#include "nvram_interface.h"
+#include "l1d_custom_drdi.h"
+#if IS_GEN95_L1D_CUSTOM_DYNAMIC_SUPPORT
+#else
+#include "l1d_custom_rf.h"
+#endif
+#include "mml1_rf_global.h"
+#endif /* __MTK_TARGET__ */ 
+kal_bool l1d_DRDI_had_done = KAL_FALSE;
+kal_bool Is_2GDRDI_Enable = KAL_FALSE;
+void L1D_CustomDynamicGetParam(kal_uint16 setIdx)
+{
+   #if defined(__MTK_TARGET__) && !defined(L1_NOT_PRESENT)
+    kal_uint32 band;
+   kal_uint32 i;
+   #if defined(__MD93__)
+   kal_uint32 j;
+   #endif
+   for(band= 0; band < FrequencyBandCount; band++)
+   {
+      #if defined(__MD97__)||defined(__MD97P__)
+      //none
+      #elif defined(__2G_MIPI_SUPPORT__)
+      if(l1d_mipi_ctrl_data[setIdx].GGE_MIPI_CTRL_TABLE[band] != 0)
+      {
+         /*l1d_custom_mipi.c 2G mipi ctrl data point init*/
+         kal_mem_cpy(GGE_MIPI_CTRL_TABLE[band],l1d_mipi_ctrl_data[setIdx].GGE_MIPI_CTRL_TABLE[band],(sizeof(l1cal_mipi_ctrl_table_band_T)));
+      }	
+      #endif			
+      /*m12193.c  Tx_Power_Offset point init*/
+      #if defined (__TX_POWER_OFFSET_SUPPORT__)
+      if(l1d_feature_data[setIdx].L1D_TX_Power_Offset_Data.Tx_Power_Offset_GMSK[band]!=0)
+      {
+         kal_mem_cpy(Tx_Power_Offset_GMSK[band],l1d_feature_data[setIdx].L1D_TX_Power_Offset_Data.Tx_Power_Offset_GMSK[band],(sizeof(tx_power_offset_t)));
+      }
+         #if defined(__EPSK_TX__)
+      if(l1d_feature_data[setIdx].L1D_TX_Power_Offset_Data.Tx_Power_Offset_EPSK[band]!=0)
+      {
+         kal_mem_cpy(Tx_Power_Offset_EPSK[band],l1d_feature_data[setIdx].L1D_TX_Power_Offset_Data.Tx_Power_Offset_EPSK[band],(sizeof(tx_power_offset_t)));
+      }
+         #endif /* defined(__EPSK_TX__) */ 
+      #endif /*__TX_POWER_OFFSET_SUPPORT__ || defined (__SAR_TX_POWER_BACKOFF_SUPPORT__)*/
+
+      #if defined (__RX_POWER_OFFSET_SUPPORT__)
+      if(l1d_feature_data[setIdx].L1D_RX_Power_Offset_Data.RX_Power_Offset_Table.agcPathLoss[band]!=0)
+      {
+         kal_mem_cpy(AGCLNA_PATHLOSS_OFFSET[band],l1d_feature_data[setIdx].L1D_RX_Power_Offset_Data.RX_Power_Offset_Table.agcPathLoss[band],(sizeof(sAGCLNAGAINOFFSET) * PLTABLE_SIZE));
+
+      }
+         #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+      if(l1d_feature_data[setIdx].L1D_RX_Power_Offset_Data.RX_Power_Offset_Table.agcPathLoss_RXD[band]!=0)
+      {
+         kal_mem_cpy(AGCLNA_PATHLOSS_RXD_OFFSET[band],l1d_feature_data[setIdx].L1D_RX_Power_Offset_Data.RX_Power_Offset_Table.agcPathLoss_RXD[band],(sizeof(sAGCLNAGAINOFFSET) * PLTABLE_SIZE));
+      }
+         #endif//#if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+      #endif /*__RX_POWER_OFFSET_SUPPORT__*/
+
+      #if defined (__NSFT_ADJUST_TX_POWER_OFFSET_SUPPORT__)
+      if (l1d_feature_data[setIdx].adjust_tpo_data.Adjust_TPO_GMSK[band] != 0)
+      {
+         kal_mem_cpy(Adjust_TPO_GMSK[band],l1d_feature_data[setIdx].adjust_tpo_data.Adjust_TPO_GMSK[band],(sizeof(nsft_adjust_tpo_t)));
+      }
+         #if defined(__EPSK_TX__)
+            #if defined(__EPSK_ADJUST_TPO_SUPPORT__)
+      if(l1d_feature_data[setIdx].adjust_tpo_data.Adjust_TPO_EPSK[band]!=0)
+      {
+         kal_mem_cpy(Adjust_TPO_EPSK[band],l1d_feature_data[setIdx].adjust_tpo_data.Adjust_TPO_EPSK[band],(sizeof(nsft_adjust_tpo_t)));
+      }
+            #endif//__EPSK_ADJUST_TPO_SUPPORT__
+         #endif /* defined(__EPSK_TX__) */ 
+      #endif /*__NSFT_ADJUST_TX_POWER_OFFSET_SUPPORT__*/
+
+      #if IS_2G_CALIBRATION_DATA_DRDI_ENABLE
+         if(L1D_Cal_Data[setIdx].AGC_PATHLOSS_TABLE[band] != 0)
+         { 
+            kal_mem_cpy(AGC_PATHLOSS_TABLE[band],L1D_Cal_Data[setIdx].AGC_PATHLOSS_TABLE[band],(sizeof(sAGCGAINOFFSET) * PLTABLE_SIZE)); 
+         }
+         #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         if(L1D_Cal_Data[setIdx].AGC_PATHLOSS_RXD_TABLE[band] != 0)
+         { 
+            kal_mem_cpy(AGC_PATHLOSS_RXD_TABLE[band],L1D_Cal_Data[setIdx].AGC_PATHLOSS_RXD_TABLE[band],(sizeof(sAGCGAINOFFSET) * PLTABLE_SIZE)); 
+         }
+         #endif //#if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         if(L1D_Cal_Data[setIdx].RampData[band]!=0)
+         {
+            kal_mem_cpy(RampData[band], L1D_Cal_Data[setIdx].RampData[band], sizeof(sRAMPDATA));	
+         }
+         #if defined(__EPSK_TX__)
+         if(L1D_Cal_Data[setIdx].RampData_EPSK[band]!=0)
+         {
+            kal_mem_cpy(RampData_EPSK[band], L1D_Cal_Data[setIdx].RampData_EPSK[band], sizeof(sRAMPDATA));
+         }
+         #endif /* defined(__EPSK_TX__) */ 
+         if(L1D_Cal_Data[setIdx].InterRampData[band]!=0)
+         {
+            kal_mem_cpy(InterRampData[band], L1D_Cal_Data[setIdx].InterRampData[band], sizeof(sMIDRAMPDATA));
+         }
+         #if defined(__EPSK_TX__)
+         for(i = 0; i < 4; i++)
+         {
+            if(L1D_Cal_Data[setIdx].InterRampData[band]!=0)
+            {
+               kal_mem_cpy((*(EPSK_InterRampData[band])[i]),(*(L1D_Cal_Data[setIdx].EPSK_InterRampData[band])[i]),sizeof(sMIDRAMPDATA));
+            }
+         }
+         #endif /* defined(__EPSK_TX__) */ 
+         #if defined(__PS_SERVICE__) 
+         if(L1D_Cal_Data[setIdx].tx_power_rollback_gmsk[band] != 0)
+         {
+            kal_mem_cpy(tx_power_rollback_gmsk[band], L1D_Cal_Data[setIdx].tx_power_rollback_gmsk[band], sizeof(sTX_POWER_ROLLBACK));
+         }
+            #if defined(__EGPRS_MODE__) 
+         if(L1D_Cal_Data[setIdx].tx_power_rollback_epsk[band] != 0)
+         {
+            kal_mem_cpy(tx_power_rollback_epsk[band], L1D_Cal_Data[setIdx].tx_power_rollback_epsk[band], sizeof(sTX_POWER_ROLLBACK));
+         }
+            #endif /*defined(__EGPRS_MODE__)*/        	  
+         #endif /*defined(__PS_SERVICE__)*/
+         #if defined(__2G_TX_POWER_CONTROL_SUPPORT__)   
+            #if IS_TXPC_CL_AUXADC_SUPPORT || IS_TXPC_CL_BSI_SUPPORT
+
+         if(L1D_Cal_Data[setIdx].TXADC_Data[band]!=0)
+         {
+            kal_mem_cpy(TXADC_Data[band], L1D_Cal_Data[setIdx].TXADC_Data[band], sizeof(sTXPC_ADCDATA));
+         }
+         if(L1D_Cal_Data[setIdx].TXTEMP_Data[band]!=0)
+         {
+            kal_mem_cpy(TXTEMP_Data[band], L1D_Cal_Data[setIdx].TXTEMP_Data[band], sizeof(sTXPC_TEMPDATA));
+         }
+               #if defined(__EPSK_TX__)
+         if(L1D_Cal_Data[setIdx].TXADC_Data_EPSK[band]!=0)
+         {
+            kal_mem_cpy(TXADC_Data_EPSK[band], L1D_Cal_Data[setIdx].TXADC_Data_EPSK[band], sizeof(sTXPC_ADCDATA));
+         }
+          if(L1D_Cal_Data[setIdx].TXTEMP_Data_EPSK[band]!=0)
+         {
+            kal_mem_cpy(TXTEMP_Data_EPSK[band], L1D_Cal_Data[setIdx].TXTEMP_Data_EPSK[band], sizeof(sTXPC_TEMPDATA));
+         }
+               #endif
+            #endif
+         #endif
+         #if defined(__MULTI_LNA_MODE_CALIBRATION_SUPPORT__)
+         if(L1D_Cal_Data[setIdx].LNA_PATHLOSS_TABLE[band] != 0)
+         { 
+            kal_mem_cpy(LNA_PATHLOSS_TABLE[band],L1D_Cal_Data[setIdx].LNA_PATHLOSS_TABLE[band],(sizeof(sLNAGAINOFFSET) * PLTABLE_SIZE)); 
+         }
+            #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+            if(L1D_Cal_Data[setIdx].LNA_PATHLOSS_RXD_TABLE[band] != 0)
+            { 
+               kal_mem_cpy(LNA_PATHLOSS_RXD_TABLE[band],L1D_Cal_Data[setIdx].LNA_PATHLOSS_RXD_TABLE[band],(sizeof(sLNAGAINOFFSET) * PLTABLE_SIZE)); 
+            }
+            #endif //#if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         #endif
+      #else
+         if(L1D_Cal_Data[0].AGC_PATHLOSS_TABLE[band] != 0)
+         { 
+            kal_mem_cpy(AGC_PATHLOSS_TABLE[band],L1D_Cal_Data[0].AGC_PATHLOSS_TABLE[band],(sizeof(sAGCGAINOFFSET) * PLTABLE_SIZE)); 
+         }
+         #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         if(L1D_Cal_Data[0].AGC_PATHLOSS_RXD_TABLE[band] != 0)
+         { 
+            kal_mem_cpy(AGC_PATHLOSS_RXD_TABLE[band],L1D_Cal_Data[0].AGC_PATHLOSS_RXD_TABLE[band],(sizeof(sAGCGAINOFFSET) * PLTABLE_SIZE)); 
+         }
+         #endif //#if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         if(L1D_Cal_Data[0].RampData[band]!=0)
+         {
+            kal_mem_cpy(RampData[band], L1D_Cal_Data[0].RampData[band], sizeof(sRAMPDATA));	
+         }
+         #if defined(__EPSK_TX__)
+         if(L1D_Cal_Data[0].RampData_EPSK[band]!=0)
+         {
+            kal_mem_cpy(RampData_EPSK[band], L1D_Cal_Data[0].RampData_EPSK[band], sizeof(sRAMPDATA));
+         }
+         #endif /* defined(__EPSK_TX__) */ 
+         if(L1D_Cal_Data[0].InterRampData[band]!=0)
+         {
+            kal_mem_cpy(InterRampData[band], L1D_Cal_Data[0].InterRampData[band], sizeof(sMIDRAMPDATA));
+         }
+         #if defined(__EPSK_TX__)
+         for(i = 0; i < 4; i++)
+         {
+            if(L1D_Cal_Data[0].InterRampData[band]!=0)
+            {
+               kal_mem_cpy((*(EPSK_InterRampData[band])[i]),(*(L1D_Cal_Data[0].EPSK_InterRampData[band])[i]),sizeof(sMIDRAMPDATA));
+            }
+         }
+         #endif /* defined(__EPSK_TX__) */ 
+         #if defined(__PS_SERVICE__) 
+         if(L1D_Cal_Data[0].tx_power_rollback_gmsk[band] != 0)
+         {
+            kal_mem_cpy(tx_power_rollback_gmsk[band], L1D_Cal_Data[0].tx_power_rollback_gmsk[band], sizeof(sTX_POWER_ROLLBACK));
+         }
+            #if defined(__EGPRS_MODE__) 
+         if(L1D_Cal_Data[0].tx_power_rollback_epsk[band] != 0)
+         {
+            kal_mem_cpy(tx_power_rollback_epsk[band], L1D_Cal_Data[0].tx_power_rollback_epsk[band], sizeof(sTX_POWER_ROLLBACK));
+         }
+            #endif /*defined(__EGPRS_MODE__)*/        	  
+         #endif /*defined(__PS_SERVICE__)*/
+         #if defined(__2G_TX_POWER_CONTROL_SUPPORT__)   
+            #if IS_TXPC_CL_AUXADC_SUPPORT || IS_TXPC_CL_BSI_SUPPORT
+
+         if(L1D_Cal_Data[0].TXADC_Data[band]!=0)
+         {
+            kal_mem_cpy(TXADC_Data[band], L1D_Cal_Data[0].TXADC_Data[band], sizeof(sTXPC_ADCDATA));
+         }
+         if(L1D_Cal_Data[0].TXTEMP_Data[band]!=0)
+         {
+            kal_mem_cpy(TXTEMP_Data[band], L1D_Cal_Data[0].TXTEMP_Data[band], sizeof(sTXPC_TEMPDATA));
+         }
+               #if defined(__EPSK_TX__)
+         if(L1D_Cal_Data[0].TXADC_Data_EPSK[band]!=0)
+         {
+            kal_mem_cpy(TXADC_Data_EPSK[band], L1D_Cal_Data[0].TXADC_Data_EPSK[band], sizeof(sTXPC_ADCDATA));
+         }
+          if(L1D_Cal_Data[0].TXTEMP_Data_EPSK[band]!=0)
+         {
+            kal_mem_cpy(TXTEMP_Data_EPSK[band], L1D_Cal_Data[0].TXTEMP_Data_EPSK[band], sizeof(sTXPC_TEMPDATA));
+         }
+               #endif
+            #endif
+         #endif
+         #if defined(__MULTI_LNA_MODE_CALIBRATION_SUPPORT__)
+         if(L1D_Cal_Data[0].LNA_PATHLOSS_TABLE[band] != 0)
+         { 
+            kal_mem_cpy(LNA_PATHLOSS_TABLE[band],L1D_Cal_Data[0].LNA_PATHLOSS_TABLE[band],(sizeof(sLNAGAINOFFSET) * PLTABLE_SIZE)); 
+         }
+            #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+            if(L1D_Cal_Data[0].LNA_PATHLOSS_RXD_TABLE[band] != 0)
+            { 
+               kal_mem_cpy(LNA_PATHLOSS_RXD_TABLE[band],L1D_Cal_Data[0].LNA_PATHLOSS_RXD_TABLE[band],(sizeof(sLNAGAINOFFSET) * PLTABLE_SIZE)); 
+            }
+            #endif  //#if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         #endif
+      #endif
+      
+   }
+    /*l1d_custom_frontend.c 2G front end data point init*/
+    #if defined(__2G_RF_CUSTOM_TOOL_SUPPORT__)    
+      kal_mem_cpy(&l1d_rf_custom_input_data, l1d_front_end_data[setIdx].l1d_rf_custom_input_data, sizeof(l1d_rf_custom_input_data_T));
+    #endif
+    /*  TAS init */
+    #if defined(__TAS_SUPPORT__)
+      {
+      #if defined(__MD95__)
+         {    
+            for(i = FrequencyBand1900; i > FrequencyBand400; i--)
+            {
+               kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_custom_tas_split_database[i]),&(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_custom_tas_split_database[i]),sizeof(L1D_CUSTOM_TAS_SPLIT_CONFIG_T));
+            }
+         }
+      #elif defined(__MD93__)
+         {
+            kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_custom_tas_fe_database),&(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_custom_tas_fe_database),sizeof(L1D_CUSTOM_TAS_FE_DATABASE_T));
+            kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_custom_tas_fe_cat_a),l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_custom_tas_fe_cat_a_ptr,sizeof(L1D_CUSTOM_TAS_FE_CAT_A_T));
+            kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_custom_tas_fe_cat_b),l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_custom_tas_fe_cat_b_ptr,sizeof(L1D_CUSTOM_TAS_FE_CAT_B_T));
+            kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_custom_tas_fe_cat_c),l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_custom_tas_fe_cat_c_ptr,sizeof(L1D_CUSTOM_TAS_FE_CAT_C_T));
+            #if defined(__2G_MIPI_SUPPORT__)
+            for(i=0;i<L1D_TAS_MAX_CAT_A_CONFIG_NUM;i++)
+            {
+               for(j=0;j<L1D_TAS_MAX_MIPI_EVNET_NUM;j++)
+               {
+                  kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_tas_cat_a_mipi_event[i][j]),(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_tas_cat_a_mipi_event_ptr[i]+ j),sizeof(sGGE_MIPIEVENT));
+               }
+
+               for(j=0;j<L1D_TAS_MAX_MIPI_DATA_NUM;j++)
+               {
+                  kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_tas_cat_a_mipi_data[i][j]),(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_tas_cat_a_mipi_data_ptr[i]+ j),sizeof(sGGE_MIPIDATA_SUBBAND));
+               }
+            }
+            for(i=0;i<L1D_TAS_MAX_CAT_B_CONFIG_NUM;i++)
+            {
+               for(j=0;j<L1D_TAS_MAX_MIPI_EVNET_NUM;j++)
+               {
+                  kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_tas_cat_b_mipi_event[i][j]),(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_tas_cat_b_mipi_event_ptr[i]+ j),sizeof(sGGE_MIPIEVENT));
+               }
+
+               for(j=0;j<L1D_TAS_MAX_MIPI_DATA_NUM;j++)
+               {
+                  kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_tas_cat_b_mipi_data[i][j]),(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_tas_cat_b_mipi_data_ptr[i]+ j),sizeof(sGGE_MIPIDATA_SUBBAND));
+               }
+            }   
+            for(i=0;i<L1D_TAS_MAX_CAT_C_CONFIG_NUM;i++)
+            {
+               for(j=0;j<L1D_TAS_MAX_MIPI_EVNET_NUM;j++)
+               {
+                  kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_tas_cat_c_mipi_event[i][j]),(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_tas_cat_c_mipi_event_ptr[i]+ j),sizeof(sGGE_MIPIEVENT));
+               }
+
+               for(j=0;j<L1D_TAS_MAX_MIPI_DATA_NUM;j++)
+               {
+                  kal_mem_cpy (&(L1_TAS_Custom_FE_NVRAM.l1d_tas_cat_c_mipi_data[i][j]),(l1d_front_end_data[setIdx].L1_TAS_Custom_FE_NVRAM->l1d_tas_cat_c_mipi_data_ptr[i]+ j),sizeof(sGGE_MIPIDATA_SUBBAND));
+               }
+            }   
+         #endif
+         }   
+      #else
+      #endif      
+      }
+      kal_mem_cpy( &L1_TAS_Custom_NVRAM,l1d_front_end_data[setIdx].L1_TAS_Custom_NVRAM, sizeof(L1D_CUSTOM_TAS_NVRAM_T) );
+    #endif
+   #if IS_2G_TAS_INHERIT_4G_ANT
+    {
+       kal_uint32 b_idx = 0;
+       kal_uint16 counter=0;
+       L1D_CUSTOM_TAS_INHERIT_LTE_BAND_T* tas_inherit_lte_p;
+       kal_mem_cpy( &L1_TAS_Custom_InheritLteAntTable,l1d_front_end_data[setIdx].L1_TAS_Custom_InheritLteAntTable, sizeof(L1D_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T) );  
+       for(b_idx = 0; b_idx<FrequencyBandCount; b_idx++)
+       {
+          kal_uint32 temp_bitmap[L1D_TAS_INHERIT_LTE_BAND_BITMAP_NUM] = {0};
+          kal_uint32 temp_bitmap_idx = 0;
+
+          tas_inherit_lte_p = l1d_front_end_data[setIdx].L1_TAS_Custom_InheritLteAntTable->inherit_lte_band_bitmap_table[b_idx].l1_inherit_lte_ant_gsmBand_ptr;
+
+          do
+          {
+             if(tas_inherit_lte_p->inherit_lte_band == L1D_TAS_INHERIT_LTE_BAND_END)
+             {
+                break;
+             }
+             else if(tas_inherit_lte_p->inherit_lte_band <= L1D_TAS_INHERIT_LTE_BAND_MAX_NUM)
+             {
+             
+                kal_uint32 word_idx  = (tas_inherit_lte_p->inherit_lte_band)/32;
+                kal_uint32 bit_shift = (tas_inherit_lte_p->inherit_lte_band)%32;
+                temp_bitmap[word_idx] |= (1<<bit_shift);
+             }
+             else
+             {
+                ASSERT(KAL_FALSE);
+             }
+             tas_inherit_lte_p=tas_inherit_lte_p+1;
+             counter=counter+1;
+          }while(counter < L1D_TAS_INHERIT_LTE_BAND_MAX_NUM );
+
+          for(temp_bitmap_idx = 0 ; temp_bitmap_idx < L1D_TAS_INHERIT_LTE_BAND_BITMAP_NUM ; temp_bitmap_idx++)
+          {
+             L1_TAS_Custom_InheritLteAntTable.inherit_lte_band_bitmap_table[b_idx].inherit_lte_band_bitmap[temp_bitmap_idx] = temp_bitmap[temp_bitmap_idx];
+          }
+       }
+    }
+   #endif
+   #if IS_2G_DYNAMIC_ANTENNA_TUNING_SUPPORT //defined(__DYNAMIC_ANTENNA_TUNING__)
+      #if defined(__MD93__)
+   kal_mem_cpy (&(L1_DAT_Custom_FE_CAT_A_NVRAM.l1d_custom_dat_fe_cat_a),l1d_front_end_data[setIdx].L1_DAT_Custom_FE_CAT_A_NVRAM->l1d_custom_dat_fe_cat_a_ptr,sizeof(L1D_CUSTOM_DAT_FE_CAT_A_T));
+   kal_mem_cpy (&(L1_DAT_Custom_FE_CAT_B_NVRAM.l1d_custom_dat_fe_cat_b),l1d_front_end_data[setIdx].L1_DAT_Custom_FE_CAT_B_NVRAM->l1d_custom_dat_fe_cat_b_ptr,sizeof(L1D_CUSTOM_DAT_FE_CAT_B_T));
+
+         #if defined(__2G_MIPI_SUPPORT__)
+   for(i=0;i<L1D_DAT_MAX_CAT_A_CONFIG_NUM;i++)
+   {
+      for(j=0;j<L1D_DAT_MAX_MIPI_EVNET_NUM;j++)
+      {
+         kal_mem_cpy (&(L1_DAT_Custom_FE_CAT_A_NVRAM.l1d_dat_cat_a_mipi_event[i][j]),(l1d_front_end_data[setIdx].L1_DAT_Custom_FE_CAT_A_NVRAM->l1d_dat_cat_a_mipi_event_ptr[i]+ j),sizeof(sGGE_MIPIEVENT));
+      }
+
+      for(j=0;j<L1D_DAT_MAX_MIPI_DATA_NUM;j++)
+      {
+         kal_mem_cpy (&(L1_DAT_Custom_FE_CAT_A_NVRAM.l1d_dat_cat_a_mipi_data[i][j]),(l1d_front_end_data[setIdx].L1_DAT_Custom_FE_CAT_A_NVRAM->l1d_dat_cat_a_mipi_data_ptr[i]+ j),sizeof(sGGE_MIPIDATA_SUBBAND));
+      }
+   }
+   for(i=0;i<L1D_DAT_MAX_CAT_B_CONFIG_NUM;i++)
+   {
+      for(j=0;j<L1D_DAT_MAX_MIPI_EVNET_NUM;j++)
+      {
+         kal_mem_cpy (&(L1_DAT_Custom_FE_CAT_B_NVRAM.l1d_dat_cat_b_mipi_event[i][j]),(l1d_front_end_data[setIdx].L1_DAT_Custom_FE_CAT_B_NVRAM->l1d_dat_cat_b_mipi_event_ptr[i]+ j),sizeof(sGGE_MIPIEVENT));
+      }
+
+      for(j=0;j<L1D_DAT_MAX_MIPI_DATA_NUM;j++)
+      {
+         kal_mem_cpy (&(L1_DAT_Custom_FE_CAT_B_NVRAM.l1d_dat_cat_b_mipi_data[i][j]),(l1d_front_end_data[setIdx].L1_DAT_Custom_FE_CAT_B_NVRAM->l1d_dat_cat_b_mipi_data_ptr[i]+ j),sizeof(sGGE_MIPIDATA_SUBBAND));
+      }
+   }   
+         #endif
+      #endif
+   kal_mem_cpy( &L1_DAT_Custom_FE_ROUTE_NVRAM,l1d_front_end_data[setIdx].L1_DAT_Custom_FE_ROUTE_NVRAM, sizeof(L1D_CUSTOM_DAT_FE_ROUTE_NVRAM_T) );
+
+   #endif
+   
+   #if defined(__RX_POWER_OFFSET_SUPPORT__)
+   kal_mem_cpy(&AGCLNA_PL_OFFSET_SETTING, l1d_feature_data[setIdx].L1D_RX_Power_Offset_Data.RX_Power_Offset_Setting, sizeof(l1_2g_rf_rx_parameter_ext_t));
+   #endif
+
+   #if defined(__ANT_RXPWR_OFFSET_SUPPORT__)
+   kal_mem_cpy( &L1D_ANT_RxPWR_Offset_NVRAM, l1d_feature_data[setIdx].L1D_ANT_RxPWR_Offset_NVRAM, sizeof(sL1D_ANT_RxPWR_Offset_T) );
+   #endif
+
+   #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+   kal_mem_cpy( &L1_RAS_Custom_NVRAM,l1d_front_end_data[setIdx].L1_RAS_Custom_NVRAM, sizeof(L1D_CUSTOM_RAS_NVRAM_T) );
+   #endif
+   
+   #if IS_2G_CALIBRATION_DATA_DRDI_ENABLE
+   kal_mem_cpy(&(afc_crystal_data.AFC_XO_CapID), &(L1D_Cal_Data[setIdx].afc_crystal_data->AFC_XO_CapID), sizeof(l1cal_crystalCapData_T));
+      #if IS_32K_CRYSTAL_REMOVAL_SUPPORT
+   kal_mem_cpy(&(CLoad_FreqOffset_data.CLoad_FreqOffset), &(L1D_Cal_Data[setIdx].Cload_FreqOffset_Data->CLoad_FreqOffset), sizeof(sCloadParameter));
+      #endif
+   kal_mem_cpy(&tx_apc_voltage_compensation, L1D_Cal_Data[setIdx].tx_apc_voltage_compensation, sizeof(sTX_POWER_VOLTAGE_COMPENSATION));
+   #else
+   kal_mem_cpy(&(afc_crystal_data.AFC_XO_CapID), &(L1D_Cal_Data[0].afc_crystal_data->AFC_XO_CapID), sizeof(l1cal_crystalCapData_T));
+      #if IS_32K_CRYSTAL_REMOVAL_SUPPORT
+   kal_mem_cpy(&(CLoad_FreqOffset_data.CLoad_FreqOffset), &(L1D_Cal_Data[0].Cload_FreqOffset_Data->CLoad_FreqOffset), sizeof(sCloadParameter));
+      #endif
+   kal_mem_cpy(&tx_apc_voltage_compensation, L1D_Cal_Data[0].tx_apc_voltage_compensation, sizeof(sTX_POWER_VOLTAGE_COMPENSATION));
+   #endif
+   kal_mem_cpy(&l1d_custom_band_support, L1D_Custom_Band_Support_Data_Array[setIdx], sizeof(l1cal_l1CustomBandSupport_T));
+
+   #if IS_2G_CALIBRATION_DATA_DRDI_ENABLE
+   kal_mem_cpy(&afc_crystal_data_dac_slop, L1D_Cal_Data[setIdx].afc_crystal_data_dac_slop, sizeof(l1cal_afcData_T));
+   kal_mem_cpy(w_coef_data, L1D_Cal_Data[setIdx].w_coef_data, (sizeof(w_coef) * WCTABLE_SIZE));
+      #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+   kal_mem_cpy(w_coef_rxd_data, L1D_Cal_Data[setIdx].w_coef_rxd_data, (sizeof(w_coef) * WCTABLE_SIZE));
+      #endif
+   kal_mem_cpy(&pa_data, L1D_Cal_Data[setIdx].pa_data, sizeof(orionRFtx_pa_vbias));
+   #else
+   kal_mem_cpy(&afc_crystal_data_dac_slop, L1D_Cal_Data[0].afc_crystal_data_dac_slop, sizeof(l1cal_afcData_T));
+   kal_mem_cpy(w_coef_data, L1D_Cal_Data[0].w_coef_data, (sizeof(w_coef) * WCTABLE_SIZE));
+      #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+      kal_mem_cpy(w_coef_rxd_data, L1D_Cal_Data[0].w_coef_rxd_data, (sizeof(w_coef) * WCTABLE_SIZE));
+      #endif
+   kal_mem_cpy(&pa_data, L1D_Cal_Data[0].pa_data, sizeof(orionRFtx_pa_vbias));
+   #endif
+
+   #if defined(__SAR_TX_POWER_BACKOFF_SUPPORT__)
+   kal_mem_cpy( &L1_Custom_SAR_TX_BACKOFF_DB_NVRAM,l1d_feature_data[setIdx].L1_Custom_SAR_TX_BACKOFF_DB_NVRAM, sizeof(L1D_CUSTOM_SAR_TX_BACKOFF_DB_NVRAM_T) );
+   #endif
+
+  // L1D_CustomDynamicGetBandSupportParam(setIdx);
+  #endif
+}
+void L1D_CustomDynamicInit()
+{
+#if defined(__MTK_TARGET__) && !defined(L1_NOT_PRESENT)
+   unsigned short l1d_Drdi_SetIndex;
+   Is_2GDRDI_Enable = L1D_CUSTOM_DYNAMIC_SUPPORT;
+   #if IS_2G_DRDI_SUPPORT
+   if(Is_2GDRDI_Enable)
+  {
+   if(!l1d_DRDI_had_done)
+      {
+         l1d_Drdi_SetIndex=0;
+      #if IS_L1_RF_DRDI_CUSTOM_SETTING_FROM_MML1
+         /* Get DRDI result parameters from MML1 */
+         l1d_Drdi_SetIndex = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_2G);
+         /* set the pointer to RF custom data by set index */
+         L1D_CustomDynamicGetParam(l1d_Drdi_SetIndex);
+         l1d_DRDI_had_done = KAL_TRUE;
+      #else
+         /*always support MML1 DRDI*/
+      #endif
+      }
+   }
+   else 
+   L1D_CustomDynamicGetParam(0);
+  #else
+   (void)l1d_Drdi_SetIndex;
+   L1D_CustomDynamicGetParam(0);
+  #endif 
+#endif
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_L1_default_value_to_write
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  lid         [IN]        
+ *  buffer      [?]         
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_get_L1_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#if defined(__MTK_TARGET__) && !defined(L1_NOT_PRESENT)
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i;
+    l1cal_agcPathLoss_T *agc;
+    l1cal_rampTable_T *ramp;
+
+    /* l1cal_txiq_T  txiq; */
+    FrequencyBand band = FrequencyBand850;
+
+    l1cal_interRampData_T *interRamp;
+
+#if defined(__EPSK_TX__)
+    l1cal_EPSK_interRampData_T *EPSK_interRamp;
+#endif 
+   // l1cal_crystalAfcData_T *crystalAfc;
+    l1cal_crystalCapData_T *crystalCap;
+#if defined(__F32_XOSC_REMOVAL_SUPPORT__)    
+    l1cal_CloadParameter_T *cloadfreqoffset;
+#endif
+    nvram_ltable_entry_struct *ldi;
+
+#if defined(__PS_SERVICE__) 
+    l1cal_tx_power_rollback_T *tx_power_rollback;
+#endif
+#if defined(__RX_POWER_OFFSET_SUPPORT__)
+    l1cal_agclnaPathLoss_T *agc_offset;
+#endif/*__RX_POWER_OFFSET_SUPPORT__*/
+    L1D_CustomDynamicInit();
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_util_get_data_item(&ldi, lid);
+
+    kal_mem_set(buffer, 0x00, ldi->size);
+    
+    switch (lid)
+    {
+        case NVRAM_EF_L1_AGCPATHLOSS_LID:
+            /* L1 Data - AGC */
+            agc = (l1cal_agcPathLoss_T*) buffer;
+            for (i = 0; i < FrequencyBandCount; i++)
+            {
+//              L1D_RF_GetPathLossTable( i, agc->agcPathLoss[i] );
+                if (AGC_PATHLOSS_TABLE[i] != 0)
+                {
+                    kal_mem_cpy(
+                        &agc->agcPathLoss[i][0],
+                        AGC_PATHLOSS_TABLE[i],
+                        (sizeof(sAGCGAINOFFSET) * PLTABLE_SIZE));
+                }
+            }
+            break;
+        #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+        case NVRAM_EF_L1_AGCPATHLOSS_RXD_LID:
+            /* L1 Data - AGC */
+            agc = (l1cal_agcPathLoss_T*) buffer;
+
+            for ( i = 0; i < FrequencyBandCount; i++ )
+            {
+               L1D_RF_GetPathLossTable_RXD( i, agc->agcPathLoss[i] );
+            }
+            break;
+        #endif  /* defined(__2G_RX_DIVERSITY_PATH_SUPPORT__) */
+
+        #if defined(__RX_POWER_OFFSET_SUPPORT__)
+        case NVRAM_EF_L1_2G_RF_RX_PARAMETER_EXT_LID:
+            kal_mem_cpy(buffer, &AGCLNA_PL_OFFSET_SETTING, sizeof(l1_2g_rf_rx_parameter_ext_t));
+            break;
+
+        case NVRAM_EF_L1_AGCPATHLOSS_OFFSET_LID:
+            /* L1 Data - AGC OFFSET */
+            agc_offset = (l1cal_agclnaPathLoss_T*) buffer;
+            for (i = 0; i < FrequencyBandCount; i++)
+            {
+//              L1D_RF_GetPathLoss_Offset_Table( i, agc_offset->agcPathLoss[i] );
+                if (AGCLNA_PATHLOSS_OFFSET[i] != 0)
+                {
+                   kal_mem_cpy(
+                        &agc_offset->agcPathLoss[i][0],
+                        AGCLNA_PATHLOSS_OFFSET[i],
+                        (sizeof(sAGCLNAGAINOFFSET) * PLTABLE_SIZE));
+                }
+            }
+            break;
+
+            #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+        case NVRAM_EF_L1_AGCPATHLOSS_OFFSET_RXD_LID:
+            /* L1 Data - AGC OFFSET */
+            agc_offset = (l1cal_agclnaPathLoss_T*) buffer;
+
+            for ( i = 0; i < FrequencyBandCount; i++ )
+            {
+               L1D_RF_GetPathLoss_Offset_Table_RXD( i, agc_offset->agcPathLoss[i] );
+            }
+            break;
+            #endif  /* defined(__2G_RX_DIVERSITY_PATH_SUPPORT__) */
+        #endif /* defined(__RX_POWER_OFFSET_SUPPORT__) */ 
+        case NVRAM_EF_L1_RAMPTABLE_GSM850_LID:
+        case NVRAM_EF_L1_RAMPTABLE_GSM900_LID:
+        case NVRAM_EF_L1_RAMPTABLE_DCS1800_LID:
+        case NVRAM_EF_L1_RAMPTABLE_PCS1900_LID:
+            /* L1 Data - Ramp */
+            ramp = (l1cal_rampTable_T*) buffer;
+            switch (lid)
+            {
+                case NVRAM_EF_L1_RAMPTABLE_GSM850_LID:
+                    band = FrequencyBand850;
+                    break;
+                case NVRAM_EF_L1_RAMPTABLE_GSM900_LID:
+                    band = FrequencyBand900;
+                    break;
+                case NVRAM_EF_L1_RAMPTABLE_DCS1800_LID:
+                    band = FrequencyBand1800;
+                    break;
+                case NVRAM_EF_L1_RAMPTABLE_PCS1900_LID:
+                    band = FrequencyBand1900;
+                    break;
+            }
+            if (RampData[band] != 0)
+            {
+                extern void L1D_RF_InitEmptyRampData( int rf_band, int is_epsk );
+                L1D_RF_InitEmptyRampData( (int)band, (int)0/*gmsk*/ );
+                kal_mem_cpy(&ramp->rampData, RampData[band], sizeof(sRAMPDATA));
+            }
+            break;
+        #if defined(__EPSK_TX__)
+        case NVRAM_EF_L1_EPSK_RAMPTABLE_GSM850_LID:
+        case NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID:
+        case NVRAM_EF_L1_EPSK_RAMPTABLE_DCS1800_LID:
+        case NVRAM_EF_L1_EPSK_RAMPTABLE_PCS1900_LID:
+            /* L1 Data - Ramp */
+            ramp = (l1cal_rampTable_T*) buffer;
+            switch (lid)
+            {
+                case NVRAM_EF_L1_EPSK_RAMPTABLE_GSM850_LID:
+                    band = FrequencyBand850;
+                    break;
+                case NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID:
+                    band = FrequencyBand900;
+                    break;
+                case NVRAM_EF_L1_EPSK_RAMPTABLE_DCS1800_LID:
+                    band = FrequencyBand1800;
+                    break;
+                case NVRAM_EF_L1_EPSK_RAMPTABLE_PCS1900_LID:
+                    band = FrequencyBand1900;
+                    break;
+            }
+            if (RampData_EPSK[band] != 0)
+            {
+                extern void L1D_RF_InitEmptyRampData( int rf_band, int is_epsk );
+                L1D_RF_InitEmptyRampData( (int)band, (int)1/*epsk*/ );
+                kal_mem_cpy(&ramp->rampData, RampData_EPSK[band], sizeof(sRAMPDATA));
+            }
+            break;
+        #endif /* defined(__EPSK_TX__) */ 
+        case NVRAM_EF_L1_AFCDATA_LID:
+            /* L1 Data - Afc */
+        {
+            extern void L1D_RF_GetAFCData( void *buffer );
+            L1D_RF_GetAFCData( buffer );
+        }
+            break;
+        case NVRAM_EF_L1_TXIQ_LID:
+            /* L1 Data - TX IQ */
+            //txiq.TxTrimI   = bbtx_trim_i;
+            //txiq.TxTrimQ   = bbtx_trim_q;
+            //txiq.TxOffsetI = bbtx_offset_i;
+            //txiq.TxOffsetQ = bbtx_offset_q;
+            //kal_mem_cpy(buffer, &txiq, sizeof(l1cal_txiq_T));
+            //L1D_RF_Custom_BBTXParameter_Update();
+            #if IS_TELEMATICS_VOLT_TEMP_TX_COMPENSATION_SUPPORT
+            BBTXParameters.apc_bat_voltage_threshold[0] = tx_apc_voltage_compensation.BAT_VOLTAGE_THRESHOLD[0];
+            BBTXParameters.apc_bat_voltage_threshold[1] = tx_apc_voltage_compensation.BAT_VOLTAGE_THRESHOLD[1];
+            BBTXParameters.apc_bat_voltage_threshold[2] = tx_apc_voltage_compensation.BAT_VOLTAGE_THRESHOLD[2];
+            BBTXParameters.apc_bat_voltage_threshold[3] = tx_apc_voltage_compensation.BAT_VOLTAGE_THRESHOLD[3];
+            BBTXParameters.apc_bat_temperature_threshold[0] = tx_apc_voltage_compensation.BAT_TEMPERATURE_THRESHOLD[0];
+            BBTXParameters.apc_bat_temperature_threshold[1] = tx_apc_voltage_compensation.BAT_TEMPERATURE_THRESHOLD[1];
+            BBTXParameters.apc_bat_temperature_threshold[2] = tx_apc_voltage_compensation.BAT_TEMPERATURE_THRESHOLD[2];
+            BBTXParameters.apc_bat_temperature_threshold[3] = tx_apc_voltage_compensation.BAT_TEMPERATURE_THRESHOLD[3];
+            #else
+            BBTXParameters.apc_bat_low_voltage =tx_apc_voltage_compensation.BAT_LOW_VOLTAGE;
+            BBTXParameters.apc_bat_high_voltage =tx_apc_voltage_compensation.BAT_HIGH_VOLTAGE;
+            BBTXParameters.apc_bat_low_temperature =tx_apc_voltage_compensation.BAT_LOW_TEMPERATURE;
+            BBTXParameters.apc_bat_high_temperature =tx_apc_voltage_compensation.BAT_HIGH_TEMPERATURE;
+            #endif
+            BBTXParameters.ap_update_volinfo_period =tx_apc_voltage_compensation.AP_UPDATE_VOLTINFO_PERIOD;
+            kal_mem_cpy(buffer, &BBTXParameters, sizeof(l1cal_txiq_T));
+            break;
+        case NVRAM_EF_L1_RFSPECIALCOEF_LID:
+            /* L1 Data - RF Special coef */
+        {
+            extern void L1D_RF_Init_SpecialCoef(void);
+
+            L1D_RF_Init_SpecialCoef();
+        }
+            kal_mem_cpy(buffer, &RFSpecialCoef, sizeof(l1cal_rfspecialcoef_T));
+            break;
+        #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+        case NVRAM_EF_L1_WCOEF_RXD_LID:
+        {
+            extern void L1D_RF_Init_Wcoef_RXD(void);
+            L1D_RF_Init_Wcoef_RXD();
+            kal_mem_cpy(buffer, &RFSpecial_wcoef_rxd.Wcoef_data, sizeof(l1cal_wcoef_T));
+        }
+            break;
+         case NVRAM_EF_L1_RAS_CUSTOM_PARAMES_LID:
+        {
+            kal_mem_cpy( buffer, &L1_RAS_Custom_NVRAM, sizeof(L1D_CUSTOM_RAS_NVRAM_T) );
+        }
+            break;
+        #endif  /* defined(__2G_RX_DIVERSITY_PATH_SUPPORT__) */
+        case NVRAM_EF_L1_INTERSLOT_RAMP_GSM850_LID:
+        case NVRAM_EF_L1_INTERSLOT_RAMP_GSM900_LID:
+        case NVRAM_EF_L1_INTERSLOT_RAMP_DCS1800_LID:
+        case NVRAM_EF_L1_INTERSLOT_RAMP_PCS1900_LID:
+            interRamp = (l1cal_interRampData_T*) buffer;
+            switch (lid)
+            {
+                case NVRAM_EF_L1_INTERSLOT_RAMP_GSM850_LID:
+                    band = FrequencyBand850;
+                    break;
+                case NVRAM_EF_L1_INTERSLOT_RAMP_GSM900_LID:
+                    band = FrequencyBand900;
+                    break;
+                case NVRAM_EF_L1_INTERSLOT_RAMP_DCS1800_LID:
+                    band = FrequencyBand1800;
+                    break;
+                case NVRAM_EF_L1_INTERSLOT_RAMP_PCS1900_LID:
+                    band = FrequencyBand1900;
+                    break;
+            }
+            /* Shine modified start */
+            if (InterRampData[band] != 0)
+            {
+                extern void L1D_RF_InitEmptyInterRampData( void* p );
+                L1D_RF_InitEmptyInterRampData( InterRampData[band] );
+                kal_mem_cpy(&(interRamp->interRampData[0]), InterRampData[band], sizeof(sMIDRAMPDATA));
+            }
+            /* Shine modified end */
+            break;
+
+        #if defined(__EPSK_TX__)
+        case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM850_LID:
+        case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM900_LID:
+        case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_DCS1800_LID:
+        case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_PCS1900_LID:
+            EPSK_interRamp = (l1cal_EPSK_interRampData_T*) buffer;
+            switch (lid)
+            {
+                case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM850_LID:
+                    band = FrequencyBand850;
+                    break;
+                case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM900_LID:
+                    band = FrequencyBand900;
+                    break;
+                case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_DCS1800_LID:
+                    band = FrequencyBand1800;
+                    break;
+                case NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_PCS1900_LID:
+                    band = FrequencyBand1900;
+                    break;
+            }
+            for (i = 0; i < 4; i++)
+            {
+                if ((*(EPSK_InterRampData[band])[i]) != 0)
+                {
+                    extern void L1D_RF_InitEmptyInterRampData( void *p );
+                    L1D_RF_InitEmptyInterRampData( (*(EPSK_InterRampData[band])[i]) );
+                    kal_mem_cpy(
+                        &(EPSK_interRamp->EPSK_interRampData[i]),
+                        (*(EPSK_InterRampData[band])[i]),
+                        sizeof(sMIDRAMPDATA));
+                }
+            }
+            break;
+        #endif /* defined(__EPSK_TX__) */ 
+
+        case NVRAM_EF_L1_CRYSTAL_AFCDATA_LID:
+            /* Shine modified start */
+            //crystalAfc = (l1cal_crystalAfcData_T*) buffer;
+            //kal_mem_cpy(&(crystalAfc->XO_SlopeAreaData[0]), XO_SlopeAreaData_RO, sizeof(l1cal_crystalAfcData_T));
+            /* Shine modified end */
+            break;
+        case NVRAM_EF_L1_CRYSTAL_CAPDATA_LID:
+            /* Shine modified start */
+            //L1D_RF_CAPID_Update();
+            crystalCap = (l1cal_crystalCapData_T*) buffer;
+            kal_mem_cpy(&(crystalCap->cap_id), &(afc_crystal_data.AFC_XO_CapID), sizeof(l1cal_crystalCapData_T));
+            /* Shine modified end */
+            break;
+        #if defined(__PS_SERVICE__) 
+        case NVRAM_EF_L1_GMSK_TX_POWER_ROLLBACK_TABLE_LID:
+            //L1D_RF_Custom_TX_Power_Rollback_Table_Update_GPRS();
+            tx_power_rollback = (l1cal_tx_power_rollback_T*) buffer;
+            for (i = 0; i < FrequencyBandCount; i++)
+            {
+                if (tx_power_rollback_gmsk[i] != 0)
+                {
+                    kal_mem_cpy(&(tx_power_rollback->rollback_data[i]), tx_power_rollback_gmsk[i], sizeof(sTX_POWER_ROLLBACK));
+                }
+            }             
+            break;
+        #if defined(__EGPRS_MODE__) 
+        case NVRAM_EF_L1_EPSK_TX_POWER_ROLLBACK_TABLE_LID:
+            //L1D_RF_Custom_TX_Power_Rollback_Table_Update_EGPRS();
+            tx_power_rollback = (l1cal_tx_power_rollback_T*) buffer;
+            for (i = 0; i < FrequencyBandCount; i++)
+            {
+                if (tx_power_rollback_epsk[i] != 0)
+                {
+                    kal_mem_cpy(&(tx_power_rollback->rollback_data[i]), tx_power_rollback_epsk[i], sizeof(sTX_POWER_ROLLBACK));
+                }
+            }             
+             break;
+        #endif /*defined(__EGPRS_MODE__)*/             
+        #endif /*defined(__PS_SERVICE__)*/
+        #if defined(__2G_TX_POWER_CONTROL_SUPPORT__)
+        case NVRAM_EF_L1_GMSK_TXPC_LID:
+            L1D_RF_TXPC_GET_L1_SETTING( (sTXPC_L1CAL*)buffer, 0 /*GMSK*/ );
+            break;
+           #if defined(__EPSK_TX__)
+        case NVRAM_EF_L1_EPSK_TXPC_LID:
+            L1D_RF_TXPC_GET_L1_SETTING( (sTXPC_L1CAL*)buffer, 1 /*EPSK*/ );
+            break;
+           #endif /*defined(__EPSK_TX__)*/
+        #endif /*defined(__2G_TX_POWER_CONTROL_SUPPORT__)*/
+        #if defined(__MULTI_LNA_MODE_CALIBRATION_SUPPORT__)
+        case NVRAM_EF_L1_LNAPATHLOSS_LID:
+            /* L1 Data - LNA */
+            L1D_RF_GetLnaPathLossTable( (sLNAPATHLOSS_L1CAL*)buffer );
+            break;
+           #if defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)
+         case NVRAM_EF_L1_LNAPATHLOSS_RXD_LID:
+            /* L1 Data - LNA */
+            L1D_RF_GetLnaPathLossTable_RXD( (sLNAPATHLOSS_L1CAL*)buffer );
+            break;
+           #endif  /*defined(__2G_RX_DIVERSITY_PATH_SUPPORT__)*/
+        #endif /*defined(__MULTI_LNA_MODE_CALIBRATION_SUPPORT__)*/
+        #if defined(__2G_RF_CUSTOM_TOOL_SUPPORT__)
+        case NVRAM_EF_L1_2G_RF_PARAMETER_LID:
+            kal_mem_cpy(buffer, &l1d_rf_custom_input_data, sizeof(l1d_rf_custom_input_data_T));
+            break;
+        #endif
+        #if defined(__2G_TX_POWER_CONTROL_SUPPORT__)
+           #if !defined(__UMTS_RAT__) || !defined(__MTK_UL1_FDD__)|| defined(__MULTI_RAT_AFC_TADC_SHARE_SUPPORT__)
+        case NVRAM_EF_L1_TEMPERATURE_ADC_LID:
+            L1D_RF_TXPC_Get_Temp_ADC( (sTEMPERATURE_ADC_L1CAL*)buffer );
+            break;
+           #endif /*!defined(__UMTS_RAT__) || !defined(__MTK_UL1_FDD__)|| defined(__MULTI_RAT_AFC_TADC_SHARE_SUPPORT__)*/
+        #endif /*defined(__2G_TX_POWER_CONTROL_SUPPORT__)*/
+        #if defined(__F32_XOSC_REMOVAL_SUPPORT__)
+        case NVRAM_EF_L1_CLOAD_FREQ_OFFSET_LID:
+           // L1D_RF_GetCLoadFreqOffset( (kal_int32*)buffer );
+            cloadfreqoffset = (l1cal_CloadParameter_T*) buffer;
+            kal_mem_cpy(&(cloadfreqoffset->CLoad_FreqOffset), &(CLoad_FreqOffset_data.CLoad_FreqOffset), sizeof(l1cal_CloadParameter_T));
+            break;
+        #endif /*defined(__F32_XOSC_REMOVAL_SUPPORT__)*/
+        #if defined(__2G_TX_GAIN_RF_CALIBRATION__)
+        case NVRAM_EF_L1_GAINRF_LID:
+            L1D_RF_GetGainRF((l1cal_gainrf_T*)buffer);
+            break;
+        #endif
+        #if defined(__MD97__)
+        #else
+        case NVRAM_EF_L1_RFC_LID:
+        {
+            L1D_RF_RFCData_Init_Pcore();
+            L1D_RF_Get_RFC_Result((l1cal_mmrfc_result_T*)buffer);
+            break;
+        }
+        #endif
+        #if defined(__MD97__)||defined(__MD97P__)
+        //none
+		case NVRAM_EF_L1_MIPI_CTRL_TABLE_GSM850_LID:
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_GSM900_LID:
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_DCS1800_LID:
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_PCS1900_LID:
+            //dummy
+            break;
+        #elif defined(__2G_MIPI_SUPPORT__)
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_GSM850_LID:
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_GSM900_LID:
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_DCS1800_LID:
+        case NVRAM_EF_L1_MIPI_CTRL_TABLE_PCS1900_LID:
+            switch (lid)
+            {
+                case NVRAM_EF_L1_MIPI_CTRL_TABLE_GSM850_LID:
+                    band = FrequencyBand850;
+                    break;
+                case NVRAM_EF_L1_MIPI_CTRL_TABLE_GSM900_LID:
+                    band = FrequencyBand900;
+                    break;
+                case NVRAM_EF_L1_MIPI_CTRL_TABLE_DCS1800_LID:
+                    band = FrequencyBand1800;
+                    break;
+                case NVRAM_EF_L1_MIPI_CTRL_TABLE_PCS1900_LID:
+                    band = FrequencyBand1900;
+                    break;
+            }
+            if (GGE_MIPI_CTRL_TABLE[band] != 0)
+            {
+                kal_mem_cpy(buffer, GGE_MIPI_CTRL_TABLE[band], sizeof(l1cal_mipi_ctrl_table_band_T));
+            }
+            break;
+        #endif
+        case NVRAM_EF_L1_CUSTOM_BAND_SUPPORT_LID:
+        {
+           kal_mem_cpy(buffer, &l1d_custom_band_support, sizeof(l1cal_l1CustomBandSupport_T));
+        }
+            break;
+
+#if defined(__TX_POWER_OFFSET_SUPPORT__) 
+        case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_GSM850_LID:
+        case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_GSM900_LID:
+        case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_DCS_LID:
+        case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_PCS_LID:
+           switch (lid)
+           {
+               case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_GSM850_LID:
+                   band = FrequencyBand850;
+                   break;
+               case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_GSM900_LID:
+                   band = FrequencyBand900;
+                   break;
+               case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_DCS_LID:
+                   band = FrequencyBand1800;
+                   break;
+               case NVRAM_EF_L1_GMSK_TX_POWER_OFFSET_PCS_LID:
+                   band = FrequencyBand1900;
+                   break;
+           }
+           kal_mem_cpy(buffer, Tx_Power_Offset_GMSK[band], sizeof(tx_power_offset_t));
+           break;
+   #if defined(__EPSK_TX__)
+        case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_GSM850_LID:
+        case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_GSM900_LID:
+        case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_DCS_LID:
+        case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_PCS_LID:
+           switch (lid)
+           {
+               case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_GSM850_LID:
+                   band = FrequencyBand850;
+                   break;
+               case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_GSM900_LID:
+                   band = FrequencyBand900;
+                   break;
+               case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_DCS_LID:
+                   band = FrequencyBand1800;
+                   break;
+               case NVRAM_EF_L1_EPSK_TX_POWER_OFFSET_PCS_LID:
+                   band = FrequencyBand1900;
+                   break;
+           }
+           kal_mem_cpy(buffer, Tx_Power_Offset_EPSK[band], sizeof(tx_power_offset_t));
+           break;
+   #endif /*defined(__EPSK_TX__)*/
+#endif /*__TX_POWER_OFFSET_SUPPORT__ || defined (__SAR_TX_POWER_BACKOFF_SUPPORT__)*/
+#if defined (__NSFT_ADJUST_TX_POWER_OFFSET_SUPPORT__)
+                case NVRAM_EF_L1_GMSK_ADJUST_TPO_GSM850_LID:
+                case NVRAM_EF_L1_GMSK_ADJUST_TPO_GSM900_LID:
+                case NVRAM_EF_L1_GMSK_ADJUST_TPO_DCS_LID:
+                case NVRAM_EF_L1_GMSK_ADJUST_TPO_PCS_LID:
+                switch (lid)
+               {
+                   case NVRAM_EF_L1_GMSK_ADJUST_TPO_GSM850_LID:
+                   band = FrequencyBand850;
+                   break;
+                   case NVRAM_EF_L1_GMSK_ADJUST_TPO_GSM900_LID:
+                   band = FrequencyBand900;
+                   break;
+                   case NVRAM_EF_L1_GMSK_ADJUST_TPO_DCS_LID:
+                   band = FrequencyBand1800;
+                   break;
+                   case NVRAM_EF_L1_GMSK_ADJUST_TPO_PCS_LID:
+                   band = FrequencyBand1900;
+                   break;
+               }
+               kal_mem_cpy(buffer, Adjust_TPO_GMSK[band], sizeof(nsft_adjust_tpo_t));
+               break;
+   #if defined(__EPSK_TX__)
+       #if defined(__EPSK_ADJUST_TPO_SUPPORT__)
+               case NVRAM_EF_L1_EPSK_ADJUST_TPO_GSM850_LID:
+               case NVRAM_EF_L1_EPSK_ADJUST_TPO_GSM900_LID:
+               case NVRAM_EF_L1_EPSK_ADJUST_TPO_DCS_LID:
+               case NVRAM_EF_L1_EPSK_ADJUST_TPO_PCS_LID:
+               switch (lid)
+               {
+                   case NVRAM_EF_L1_EPSK_ADJUST_TPO_GSM850_LID:
+                   band = FrequencyBand850;
+                   break;
+                   case NVRAM_EF_L1_EPSK_ADJUST_TPO_GSM900_LID:
+                   band = FrequencyBand900;
+                   break;
+                   case NVRAM_EF_L1_EPSK_ADJUST_TPO_DCS_LID:
+                   band = FrequencyBand1800;
+                   break;
+                   case NVRAM_EF_L1_EPSK_ADJUST_TPO_PCS_LID:
+                   band = FrequencyBand1900;
+                   break;
+               }
+               kal_mem_cpy(buffer, Adjust_TPO_EPSK[band], sizeof(nsft_adjust_tpo_t));
+               break;
+       #endif//__EPSK_ADJUST_TPO_SUPPORT__
+   #endif /*defined(__EPSK_TX__)*/
+#endif /*__NSFT_ADJUST_TX_POWER_OFFSET_SUPPORT__*/
+        #if defined(__TAS_SUPPORT__)
+        case NVRAM_EF_L1_TAS_CUSTOM_PARAMES_LID:
+           kal_mem_cpy( buffer, &L1_TAS_Custom_NVRAM, sizeof(L1D_CUSTOM_TAS_NVRAM_T) );
+           break;
+           #if (defined(__MD93__) || defined(__MD95__))    /*Not supported for Gen97*/
+        case NVRAM_EF_L1_TAS_CUSTOM_FE_PARAMS_LID:
+           kal_mem_cpy( buffer, &L1_TAS_Custom_FE_NVRAM, sizeof(L1D_CUSTOM_TAS_FE_NVRAM_T) );
+           break;
+           #endif
+           #if defined(__MD93__)    /*GL1D is not involved from Gen95 onwards since GL1C is taking care of it*/
+        case NVRAM_EF_L1_TAS_CUSTOM_INHERIT_LTE_BAND_LID:
+           kal_mem_cpy( buffer, &L1_TAS_Custom_InheritLteAntTable, sizeof(L1D_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T) );
+           break;
+           #endif
+        #endif
+        #if IS_2G_DYNAMIC_ANTENNA_TUNING_SUPPORT //defined(__DYNAMIC_ANTENNA_TUNING__)
+        case NVRAM_EF_L1_DAT_CUSTOM_FE_ROUTE_PARAMES_LID:
+           kal_mem_cpy( buffer,&L1_DAT_Custom_FE_ROUTE_NVRAM, sizeof(l1_dat_custom_fe_route_params_T) );
+           break;
+           #if defined(__MD93__)
+        case NVRAM_EF_L1_DAT_CUSTOM_FE_CAT_A_PARAMES_LID:
+           kal_mem_cpy( buffer,&L1_DAT_Custom_FE_CAT_A_NVRAM, sizeof(l1_dat_custom_fe_cata_params_T) );
+           break;       
+        case NVRAM_EF_L1_DAT_CUSTOM_FE_CAT_B_PARAMES_LID:
+           kal_mem_cpy( buffer,&L1_DAT_Custom_FE_CAT_B_NVRAM, sizeof(l1_dat_custom_fe_catb_params_T) );
+           break;
+           #endif
+        #endif
+        #if defined(__ANT_RXPWR_OFFSET_SUPPORT__)
+        case NVRAM_EF_L1_ANT_RXPWR_OFFSET_LID:
+           kal_mem_cpy( buffer,&L1D_ANT_RxPWR_Offset_NVRAM, sizeof(sL1D_ANT_RxPWR_Offset_T) );
+           break;
+        #endif
+        #if defined(__SAR_TX_POWER_BACKOFF_SUPPORT__)
+        case NVRAM_EF_L1_SAR_TX_BACKOFF_DB_CUSTOM_PARAMES_LID:
+           kal_mem_cpy( buffer, &L1_Custom_SAR_TX_BACKOFF_DB_NVRAM, sizeof(L1D_CUSTOM_SAR_TX_BACKOFF_DB_NVRAM_T) );
+           break;
+        #endif
+        default:
+            ASSERT(KAL_FALSE);
+            break;
+    }
+
+#endif /* __MTK_TARGET__ */ 
+
+}
+
diff --git a/mcu/service/nvram/src/nvram_ltable.c b/mcu/service/nvram/src/nvram_ltable.c
new file mode 100644
index 0000000..aa43249
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ltable.c
@@ -0,0 +1,2010 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ * Filename:
+ * ---------
+ * nvram_ltable.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*
+ * include
+ */
+#include "stdio.h"
+#include "string.h"
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+
+#if defined(__MMI_FMI__)
+#if !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__)
+#include "custom_jump_tbl.h"
+#include "resource_custpack_jtbl.h"
+#endif /* !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) */
+#include "resource_verno.h"
+#endif
+
+#include "nvram_editor_data_item.h"
+#include "nvram_group_editor.h" //add for break group files from header file
+#include "nvram_main.h"
+
+#include "nvram_lid_statistics.h"
+
+#ifdef __NVRAM_OTP__
+#include "fs_gprot.h"
+#include "fs_iprot.h"
+#endif
+
+#if defined(__MTK_TARGET__)
+#include "SST_secure.h"
+#endif
+
+#include "us_timer.h"
+#include "custom_nvram_cat.h"
+
+/********************************************
+ * External API, cannot include header file
+ **************************************************/
+extern kal_char *release_verno(void);
+extern kal_char *release_branch(void);
+extern kal_char *release_flavor(void);
+extern kal_char *build_date_time(void);
+extern kal_bool nvram_custom_lock_status(void);
+extern module_type stack_get_active_module_id( void );
+
+
+/********************************************
+ * Global and Static Variable
+ **************************************************/
+typedef struct
+{
+    kal_uint8 const* version;
+    nvram_lid_enum lid[NVRAM_CUSTPACK_TOTAL];
+}nvram_custpack_lid_tbl_struct;
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+#ifdef __NVRAM_LID_CACHE__
+extern kal_uint8* g_nvcache_base_address;
+extern kal_uint32 g_nvcache_memory_size;
+extern kal_bool g_nvram_cache_ready;
+#endif
+
+//#if !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__)
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+static custpack_nvram_header *custpack_nvram_header_ptr;
+#endif
+//#endif
+
+#ifdef __NVRAM_OTP__
+typedef struct
+{
+    nvram_lid_enum  LID;                /* Logical Data Item ID */
+    kal_uint32  offset;                 /* start address in Shadow buffer*/
+}nvram_otp_table_sturct;
+
+static nvram_otp_table_sturct nvram_otp_ltable[NVRAM_OTP_TOTAL];
+#endif
+
+#if defined (__NVRAM_UT_TEST__)
+kal_uint8 NVRAM_EF_TEST_8_DEFAULT[NVRAM_EF_TEST_8_LID_RECORD_TOTAL][NVRAM_EF_TEST_8_LID_SIZE] = {
+    {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
+    {0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18},
+    {0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28},
+};
+#endif
+
+#ifndef __MTK_TARGET__
+#ifdef _MSC_VER
+nvram_ltable_entry_struct __pragma(data_seg("_nvram_ltable_begin")) _nvram_ltable_start ={0};
+#else
+__attribute__ ((section("_nvram_ltable_begin"))) nvram_ltable_entry_struct _nvram_ltable_start ={0};
+#endif
+#endif
+#ifdef __NVRAM_SEC_CHECK_EN__
+extern void srand(kal_uint32 seed);
+extern int  rand(void);
+extern void nvram_AES_encrypt(unsigned char *buffer, unsigned int length);
+void nvram_get_sec_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    kal_uint32 rec0_idx, rec1_idx;
+    kal_uint8 nvram_sec_buf[NVRAM_SEC_CHECK_LEN*2];
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    kal_uint8 *rec0_buf_ptr=NULL;
+    #endif
+    kal_uint8 *rec1_buf_ptr=NULL;
+    
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    rec0_buf_ptr = &nvram_sec_buf[0];
+    #endif
+    
+    rec1_buf_ptr = &nvram_sec_buf[NVRAM_SEC_CHECK_LEN];
+    srand(0);
+    for(rec0_idx =0; rec0_idx<(NVRAM_SEC_CHECK_LEN/2); rec0_idx++){
+	rec1_idx = rec0_idx+NVRAM_SEC_CHECK_LEN;
+	nvram_sec_buf[rec0_idx]=rand()%0xFF;
+	nvram_sec_buf[rec1_idx]=rand()%0xFF;
+	nvram_sec_buf[rec0_idx+NVRAM_SEC_CHECK_LEN/2]=~(nvram_sec_buf[rec0_idx]);
+	nvram_sec_buf[rec1_idx+NVRAM_SEC_CHECK_LEN/2]=~(nvram_sec_buf[rec1_idx]);
+   }
+     #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__	
+         SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)rec0_buf_ptr, NVRAM_SEC_CHECK_LEN, nvram_ptr->secret_key, rec0_buf_ptr);
+     #endif
+
+      nvram_AES_encrypt(rec1_buf_ptr, NVRAM_SEC_CHECK_LEN);
+
+	 kal_mem_cpy(buffer, nvram_sec_buf, buffer_size);
+
+}
+#endif
+
+#if defined (__NVRAM_UT_TEST__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_internal_test_fun_default_value
+ * DESCRIPTION
+ *  This function is assign
+ *      the internal test LID function default value
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_internal_test_fun_default_value(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i = 0, offset = 0;
+    
+    nvram_util_get_data_item(&ldi, file_id);
+    kal_mem_set(buffer, 0, buffer_size);
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        offset = (i-1) * ldi->size;
+        buffer[offset] = i;
+    }
+}
+
+#endif
+
+static void nvram_assign_sys_default(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size);
+
+ltable_entry_struct logical_data_item_table_internal[] =
+{
+    {
+        NVRAM_EF_SYS_LID,
+        NVRAM_EF_SYS_TOTAL,
+        NVRAM_EF_SYS_SIZE,
+        NVRAM_DEFAULT_FUNC(nvram_assign_sys_default),
+        NVRAM_CATEGORY_IMPORTANT_L1 | NVRAM_CATEGORY_FUNC_DEFAULT,
+        NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTIPLE
+        #if defined (__CCCIFS_SUPPORT__)
+        | NVRAM_ATTR_COMMITTED
+        #endif
+        ,
+        "MT00",
+        VER(NVRAM_EF_SYS_LID)
+    },
+
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+    {
+        NVRAM_EF_CUSTPACK_VERNO_LID,
+        NVRAM_EF_CUSTPACK_VERNO_TOTAL,
+        NVRAM_EF_CUSTPACK_VERNO_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_INTERNAL,
+        NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_AVERAGE,
+        "MT02",
+        VER(NVRAM_EF_CUSTPACK_VERNO_LID)
+    },
+#endif
+    {
+        NVRAM_EF_NVRAM_LOCK_LID,
+        NVRAM_EF_NVRAM_LOCK_TOTAL,
+        NVRAM_EF_NVRAM_LOCK_SIZE,
+        NVRAM_DEFAULT_FUNC(nvram_assign_sys_default),
+        NVRAM_CATEGORY_IMPORTANT | NVRAM_CATEGORY_FUNC_DEFAULT,
+        NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_FAULT_ASSERT 
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+         | NVRAM_ATTR_MSP | NVRAM_ATTR_MULTIPLE
+        #endif
+        #if defined (__CCCIFS_SUPPORT__)
+        | NVRAM_ATTR_COMMITTED
+        #endif
+        ,
+        "NV01",
+        VER(NVRAM_EF_NVRAM_LOCK_LID)
+    },
+#ifdef __NVRAM_READ_RESERVED_FILE__    
+    {
+        NVRAM_EF_READ_RESERVED_LID,
+        NVRAM_EF_READ_RESERVED_TOTAL,
+        NVRAM_EF_READ_RESERVED_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_RESERVED,
+        NVRAM_ATTR_AVERAGE,
+        "NONE",
+        VER(NVRAM_EF_READ_RESERVED_LID)
+    }, 
+#endif    
+#ifdef __NVRAM_SEC_CHECK_EN__
+    {
+        NVRAM_EF_NVRAM_SEC_CHECK_LID,
+        NVRAM_EF_NVRAM_SEC_CHECK_TOTAL,
+        NVRAM_EF_NVRAM_SEC_CHECK_SIZE,
+        NVRAM_DEFAULT_FUNC(nvram_get_sec_default_value_to_write),
+        NVRAM_CATEGORY_IMPORTANT | NVRAM_CATEGORY_FUNC_DEFAULT,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_FAULT_ASSERT | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT
+        #if defined (__CCCIFS_SUPPORT__)
+         | NVRAM_ATTR_COMMITTED
+        #endif
+        ,
+        "NV0S",
+        VER(NVRAM_EF_NVRAM_SEC_CHECK_LID)
+    },
+#endif
+#ifdef __NVRAM_UNIT_TEST__
+    {
+        NVRAM_EF_NVRAM_UNIT_TEST_LID,
+        NVRAM_EF_NVRAM_UNIT_TEST_TOTAL,
+        NVRAM_EF_NVRAM_UNIT_TEST_SIZE,
+        NVRAM_NORMAL((const kal_uint8 *)NVRAM_EF_ZERO_DEFAULT),
+#ifdef __SECURE_DATA_STORAGE__
+        NVRAM_CATEGORY_INTERNAL,
+#else
+        NVRAM_CATEGORY_USER,
+#endif
+        NVRAM_ATTR_AVERAGE,
+        "MT10",
+        VER(NVRAM_EF_NVRAM_UNIT_TEST_LID)
+    },
+#endif
+
+#if defined (__NVRAM_UT_TEST__)
+
+    {
+        NVRAM_EF_NVRAM_TEST_1_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT,
+        "MTT1",
+        VER(NVRAM_EF_NVRAM_TEST_1_LID)
+    },
+
+    {
+        NVRAM_EF_NVRAM_TEST_2_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_INTERNAL,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT, 
+        "MTT2",
+        VER(NVRAM_EF_NVRAM_TEST_2_LID)
+    },
+
+    {
+        NVRAM_EF_NVRAM_TEST_3_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_CALIBRAT,
+        NVRAM_ATTR_AVERAGE,
+        "MTT3",
+        VER(NVRAM_EF_NVRAM_TEST_3_LID)
+    },
+
+    {
+        NVRAM_EF_NVRAM_TEST_4_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_IMPORTANT,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT
+        #if defined (__CCCIFS_SUPPORT__)
+         | NVRAM_ATTR_COMMITTED
+        #endif
+        , 
+        "MTT4",
+        VER(NVRAM_EF_NVRAM_TEST_4_LID)
+    },
+
+    {
+        NVRAM_EF_NVRAM_TEST_5_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_IMPORTANT_L1,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT,
+        "MTT5",
+        VER(NVRAM_EF_NVRAM_TEST_5_LID)
+    },
+    
+    {
+        NVRAM_EF_NVRAM_TEST_6_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_IMPORTANT_L4,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_CHKSUM_INTEGRATE
+        #if defined (__CCCIFS_SUPPORT__)
+         | NVRAM_ATTR_COMMITTED
+        #endif
+        ,
+        "MTT6",
+        VER(NVRAM_EF_NVRAM_TEST_6_LID)
+    },
+
+    {
+        NVRAM_EF_NVRAM_TEST_7_LID,
+        1, //NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_CALIBRAT,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_RAW_DATA,
+        "MTT7",
+        VER(NVRAM_EF_NVRAM_TEST_7_LID)
+    },
+
+    {
+        NVRAM_EF_NVRAM_TEST_8_LID,
+        NVRAM_EF_TEST_8_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_8_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_TEST_8_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_CHKSUM_INTEGRATE,
+        "MTT8",
+        VER(NVRAM_EF_NVRAM_TEST_8_LID)
+    },
+    {
+        NVRAM_EF_NVRAM_TEST_9_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA_FOR_QUERY,
+        "MTT9",
+        VER(NVRAM_EF_NVRAM_TEST_9_LID)
+    },
+    {
+        NVRAM_EF_NVRAM_TEST_10_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA_BY_OP,
+        "MTTA",
+        VER(NVRAM_EF_NVRAM_TEST_10_LID)
+    },
+    {
+        NVRAM_EF_NVRAM_TEST_11_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA | NVRAM_ATTR_MCF_OTA_BY_OP,
+        "MTTB",
+        VER(NVRAM_EF_NVRAM_TEST_11_LID)
+    },
+    {
+        NVRAM_EF_NVRAM_TEST_12_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA,
+        "MTTC",
+        VER(NVRAM_EF_NVRAM_TEST_12_LID)
+    },
+    {
+        NVRAM_EF_INTERNAL_13_LID,
+        NVRAM_EF_TEST_13_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_13_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_IMPORTANT_L1,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT,
+        "MTTD",
+        VER(NVRAM_EF_INTERNAL_13_LID)
+    },
+    {
+        NVRAM_EF_INTERNAL_TEST_14_LID,
+        NVRAM_EF_TEST_14_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_14_LID_SIZE,
+        NVRAM_DEFAULT_FUNC(nvram_internal_test_fun_default_value),
+        NVRAM_CATEGORY_USER | NVRAM_CATEGORY_FUNC_DEFAULT,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT,
+        "MTTE",
+        VER(NVRAM_EF_INTERNAL_TEST_14_LID)
+    },
+	{
+        NVRAM_EF_INTERNAL_TEST_16_LID,
+        NVRAM_EF_INTERNAL_TEST_16_LID_RECORD_TOTAL,
+        NVRAM_EF_INTERNAL_TEST_16_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_CALIBRAT,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_CHKSUM_INTEGRATE | NVRAM_ATTR_FAULT_ASSERT,
+        "MTTG",
+        VER(NVRAM_EF_INTERNAL_TEST_16_LID)
+    },
+    {
+        NVRAM_EF_INTERNAL_TEST_17_LID,
+        NVRAM_EF_TEST_LID_RECORD_TOTAL,
+        NVRAM_EF_TEST_LID_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_USER,
+        NVRAM_ATTR_AVERAGE | NVRAM_ATTR_MULTIPLE,
+        "MTTH",
+        VER(NVRAM_EF_INTERNAL_TEST_17_LID)
+    },
+#endif
+
+#if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    {
+        NVRAM_EF_CHKSUM_RESET_REC_LID,
+        NVRAM_EF_CHKSUM_RESET_REC_LID_TOTAL,
+        NVRAM_EF_CHKSUM_RESET_REC_SIZE,
+        NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+        NVRAM_CATEGORY_INTERNAL,
+        NVRAM_ATTR_AVERAGE,
+        "MTCR", //NVRAM check sum reset
+        VER(NVRAM_EF_CHKSUM_RESET_REC_LID)
+    },
+#endif
+
+};
+
+#ifdef __NVRAM_READ_RESERVED_FILE__
+//use to reset NVRAM_EF_READ_RESERVED_LID default value
+nvram_ltable_entry_struct const reserved_logical_data_item =
+{
+    NVRAM_EF_READ_RESERVED_LID,
+    NVRAM_EF_READ_RESERVED_TOTAL,
+    NVRAM_EF_READ_RESERVED_SIZE,
+    NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+    NVRAM_CATEGORY_RESERVED,
+    NVRAM_ATTR_AVERAGE,
+    "NONE",
+    VER(NVRAM_EF_READ_RESERVED_LID)
+};
+#endif    
+
+#ifndef __MTK_TARGET__
+#ifdef _MSC_VER
+#pragma comment(linker, "/MERGE:_nvram_ltable_content=_nvram_ltable_begin")
+
+nvram_ltable_entry_struct __pragma(data_seg("_nvram_ltable_end")) the_nvram_ltable_end = {0};
+
+#pragma comment(linker, "/MERGE:_nvram_ltable_end=_nvram_ltable_begin")
+
+nvram_ltable_entry_struct __pragma(data_seg("thegarbge")) the_garbge = {0};
+#else
+  // section merge is moved to linker script for other compilers
+  __attribute__ ((section("_nvram_ltable_end"))) nvram_ltable_entry_struct the_nvram_ltable_end = {0};
+  __attribute__ ((section("thegarbge"))) nvram_ltable_entry_struct the_garbge = {0};
+#endif
+//#ifndef __L1_STANDALONE__
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+#pragma comment(linker, "/INCLUDE:_g_nvram_custpack_init")
+#endif
+//#endif
+
+#include "nvram_ltable_list.h"
+#endif
+extern void nvram_data_item_register(void);
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_ee_info_init
+ * DESCRIPTION
+ *  This function init NVRAM Debug information on share memory.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *****************************************************************************/
+void nvram_ee_info_init(void)
+{    
+    #if defined (__NVRAM_UT_TEST__)    
+    if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))
+    {} //do not create mutex again, otherwise fatal error happen
+    else
+    #endif
+    {
+        if(g_nvram_dump_trace_mutex == NULL)
+        {
+            g_nvram_dump_trace_mutex = kal_create_mutex("NV_DUMP");
+        }
+        nvram_trace_dump_buffer_offset = 0;
+        kal_mem_set(nvram_trace_dump_buffer,0,NVRAM_DUMP_TRACE_BUFFER_SIZE);
+    }    
+    if(nvram_ee_info != NULL){
+        //kal_mem_set(nvram_ee_info,0,sizeof(nvram_ee_info_type));        
+        nvram_ee_info->nvram_init_step = NVRAM_INIT_START;
+        nvram_ee_info->nvram_init_time[0] = kal_get_systicks();
+
+        nvram_ee_info->nvram_init_context.sw_status = 0;
+        nvram_ee_info->nvram_init_context.lock = KAL_FALSE;
+        nvram_ee_info->nvram_init_context.saved_lock = nvram_custom_lock_status();
+        nvram_ee_info->nvram_access_info.total_time = 0;
+        nvram_ee_info->nvram_access_info.max_time = 0;
+        nvram_ee_info->nvram_access_info.min_time = 0xFFFFFFFF;
+        nvram_ee_info->nvram_trace_fs_access_val = 0;
+        #ifdef __NVRAM_LID_CACHE__
+        nvram_ee_info->nvram_cache_setting.cache_memory_addr = (kal_uint32)g_nvcache_base_address;
+        nvram_ee_info->nvram_cache_setting.cache_memory_size = g_nvcache_memory_size;
+        nvram_ee_info->nvram_cache_setting.cache_init_status = g_nvram_cache_ready;
+        #endif
+    }
+}
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_pre_init
+ * DESCRIPTION
+ *  This function init necessary NVRAM information.
+ *  (no matter NVRAM task is on or not)
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).(?)(?)
+ *****************************************************************************/
+void nvram_pre_init(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    //NVRAM table force link
+    nvram_data_item_register();
+
+    /* For HAL rule, NVRAM cannot access the symbols directly, but in-direct reference instead.
+      User shall call NVRAM API to register their logical data item tables, to force the Linker links these symbols in the target load.*/
+    //nvram_ltable_register(logical_data_item_table_ul1);
+
+    if (nvram_ptr->ltable.table == NULL)    /* assume that ltable still not initialized if total_LID==0 */
+    {
+        nvram_init_secupack(nvram_ptr->secret_key);
+
+        custom_nvram_get_key((char*)nvram_ptr->secret_key, nvram_ptr->secret_key);
+
+        /* Construct logical data item table */
+        nvram_ltable_construct();
+    }
+
+    //reset NVRAM_EF_READ_RESERVED_LID info
+    {
+        extern nvram_ltable_entry_struct const reserved_logical_data_item;
+        nvram_ltable_entry_struct *ldi;
+        nvram_util_get_data_item(&ldi, NVRAM_EF_READ_RESERVED_LID);
+        if(ldi) {
+            kal_mem_cpy(ldi, &reserved_logical_data_item, sizeof(nvram_ltable_entry_struct));
+        }
+    }
+    if(nvram_ee_info != NULL){
+        kal_mem_cpy((kal_uint8 *)(nvram_ee_info->nvram_init_context.secret_key),(kal_uint8 *)nvram_ptr->secret_key,NVRAM_SECRET_SEED_KEY_SIZE);        
+    }
+}
+//#ifndef __L1_STANDALONE__
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+void nvram_custpack_int_init(custpack_nvram_header *custpack_ptr)
+{
+    custpack_nvram_header_ptr = custpack_ptr;
+}
+#endif
+//#endif
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_assign_custpack_default_value
+ * DESCRIPTION
+ *  This function is assign
+ *      the point of default value from 3rd jump table to logical table
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#define NVRAM_LTABLE_C_ONLY
+static void nvram_assign_sys_default(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+
+    switch(file_id)
+    {
+        case NVRAM_EF_SYS_LID:
+            memcpy(buffer, nvram_ptr->coded_version, buffer_size);
+            break;
+        case NVRAM_EF_BRANCH_VERNO_LID:
+            memcpy(buffer, nvram_ptr->branch_version, buffer_size);
+            break;
+        case NVRAM_EF_FLAVOR_VERNO_LID:
+            memcpy(buffer, nvram_ptr->flavor_version, buffer_size);
+            break;
+        case NVRAM_EF_BUILD_TIME_LID:
+            memcpy(buffer, nvram_ptr->build_time, buffer_size);
+            break;
+        case NVRAM_EF_NVRAM_LOCK_LID:
+            //default value get from nvram_custom_lock_status()
+            if(nvram_ptr->saved_lock) {
+                memcpy(buffer, NVRAM_LOCK_PATTERN_LOCKED, CODED_LOCK_PATTERN_SIZE);
+            }
+            else {
+                memcpy(buffer, NVRAM_LOCK_PATTERN_UNLOCKED, CODED_LOCK_PATTERN_SIZE);
+            }
+            //NVRAM_EF_NVRAM_LOCK_LID have NVRAM_ATTR_CONFIDENTIAL
+            //custom_nvram_encrypt(nvram_ptr->secret_key, buffer, CODED_LOCK_PATTERN_SIZE, 1);
+            break;
+    }
+}
+static void nvram_assign_custpack_default_value(void)
+{
+#if defined(__MMI_FMI__)
+#if !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__)
+
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 file_idx;
+    nvram_lid_enum custpack_idx = 0;
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    #include "nvram_custpack_table_lid.c"
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+//    custpack_header = (void **)GET_ResCUSTPACK_Addr(g_entry_preamble);
+//    custpack_nvram_header_ptr = (custpack_nvram_header*) custpack_header[g_custpack_nvram];
+
+#ifndef __MTK_TARGET__ 
+    extern void nvram_custpack_init(void);
+    nvram_custpack_init();
+
+#endif
+    do
+    {
+
+//    #ifdef __NVRAM_SUPPORT_CUSTPACK__
+        if (ldi->LID == NVRAM_EF_CUSTPACK_VERNO_LID)
+        {
+            memset(nvram_ptr->custpack_version, 0, NVRAM_EF_CUSTPACK_VERNO_SIZE + 1);
+
+            if (custpack_nvram_header_ptr->version != NULL)
+            {
+                strncpy((char*)nvram_ptr->custpack_version, (char*)custpack_nvram_header_ptr->version, NVRAM_EF_CUSTPACK_VERNO_SIZE);
+            }
+            else
+            {
+                sprintf((char*)nvram_ptr->custpack_version, "version %d", CURRENT_CUSTPACK_RES_VERSION);
+            }
+
+            ldi->default_value = nvram_ptr->custpack_version;
+        }
+//    #endif
+
+        if (!NVRAM_IS_CATEGORY_CUSTPACK(ldi->category))
+        {
+            continue;
+        }
+
+        for (file_idx = 0; file_idx < NVRAM_CUSTPACK_TOTAL; file_idx++)
+        {
+            if (custpack_nvram_lid_tbl.lid[file_idx] == ldi->LID)
+            {
+                break;
+            }
+        }
+        
+        ldi->default_value = custpack_nvram_header_ptr->custpack_default[file_idx];
+        custpack_idx++;
+
+        NVRAM_EXT_ASSERT(custpack_idx <= NVRAM_CUSTPACK_TOTAL && file_idx <= NVRAM_CUSTPACK_TOTAL, 0, NVRAM_LOC_GEN_TARGET_ASYNC_CUSTPACK, (custpack_idx > file_idx ? (custpack_idx): file_idx));
+
+    }while(nvram_util_next_data_item(&ldi));
+
+#endif  /* __NVRAM_SUPPORT_CUSTPACK__ */
+#endif /* !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) */
+#endif  /* __MMI_FMI__ */
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_update_lock_state
+ * DESCRIPTION
+ *  This function construct the default value of lock status.
+ * PARAMETERS
+ *  locked  :[in ] lock state.
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_update_lock_state(kal_bool locked)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_ptr->saved_lock = locked;
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_LOCK_LID);
+    return nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, 1);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_decrypt_lock_state
+ * DESCRIPTION
+ *  Set lock state to nvram context.
+ * PARAMETERS
+ *
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_bool nvram_decrypt_lock_state()
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 lock_pattern[NVRAM_EF_NVRAM_LOCK_SIZE];
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_LOCK_LID);
+    nvram_read_data_item(ldi, 1, 1, lock_pattern, NVRAM_EF_NVRAM_LOCK_SIZE);
+
+    //NVRAM_EF_NVRAM_LOCK_LID have NVRAM_ATTR_CONFIDENTIAL
+    //custom_nvram_decrypt(nvram_ptr->secret_key, lock_pattern, CODED_LOCK_PATTERN_SIZE, 0);
+
+    /* Compare the lock pattern to set current lock status */
+    if (kal_mem_cmp(lock_pattern, NVRAM_LOCK_PATTERN_LOCKED, CODED_LOCK_PATTERN_SIZE) == 0)
+    {
+        nvram_ptr->saved_lock = KAL_TRUE;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.saved_lock = nvram_ptr->saved_lock;
+        }
+        return KAL_TRUE;
+    }
+    else
+    {
+        nvram_ptr->saved_lock = KAL_FALSE;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.saved_lock = nvram_ptr->saved_lock;
+        }
+        return KAL_FALSE;
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_assign_system_record_default_value
+ * DESCRIPTION
+ *  This function construct the default value of system record.
+ * PARAMETERS
+ *  des_str_sys_rec     :[out] point of the string of des system record.
+ *  source_str_sys_rec  :[in ] point of the string of source system record.
+ * RETURNS
+ *  point of the string of des system record
+ *****************************************************************************/
+kal_char * nvram_assign_system_record_default_value(kal_char *des_str_sys_rec, const kal_char *source_str_sys_rec)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8* CODED_PADDING = (kal_uint8*)"\x00\xDD\xC5\xB9";
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_mem_set(des_str_sys_rec, 0, NVRAM_EF_SYS_SIZE);
+
+    /**
+    * If length of returned verno is larger than maximum capacity,
+    * truncate it to retain tail `CODED_DATA_VERSION_SIZE' bytes, and
+    * use it as coded_version.
+    * Note that maximum capacity is exactly CODED_DATA_VERSION_SIZE,
+    * instead of (CODED_DATA_VERSION_SIZE - 1); because CODED_PADDING
+    * guarantees to terminated it with zero.
+    */
+    if (strlen(source_str_sys_rec) > CODED_DATA_VERSION_SIZE)
+    {
+        kal_uint16 len = strlen(source_str_sys_rec) - CODED_DATA_VERSION_SIZE;
+
+        source_str_sys_rec += len;
+    }
+
+    /* code version */
+    strncpy(des_str_sys_rec, source_str_sys_rec, CODED_DATA_VERSION_SIZE);
+
+    /* code padding */
+    kal_mem_cpy(des_str_sys_rec + CODED_DATA_VERSION_SIZE, CODED_PADDING, CODED_PADDING_SIZE);
+
+    return des_str_sys_rec;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_pre_init
+ * DESCRIPTION
+ *  This function init necessary NVRAM information.
+ *  (no matter NVRAM task is on or not)
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).(?)(?)
+ *****************************************************************************/
+static void nvram_assign_table_entry(nvram_lid_enum position, nvram_ltable_entry_struct* ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    
+    //Tool check begin: nvram_pre_gen.pl check if it is same as nvram_assign_table_entry() and nvram_gen_assign_entry() 
+    //***************************************************************************
+    // Adjust Attr/Category I
+    //     Do not need multiple attribute if nvram saved on nor flash
+    //***************************************************************************
+
+    //***************************************************************************
+    // Adjust Attr/Category II
+    //     MULTIPLE / BACKUP_RAW / BACKUP_FAT  are mutually exclusive
+    //***************************************************************************
+    if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+    {
+    #if defined(__NVRAM_BACKUP_DISK_FAT__)
+        ldi->attr &= ~NVRAM_ATTR_MULTIPLE;
+        ldi->attr &= ~NVRAM_ATTR_BACKUP_RAW;
+        ldi->attr |= NVRAM_ATTR_BACKUP_FAT;
+    #elif defined(__NVRAM_BACKUP_DISK_RAW__)
+        ldi->attr &= ~NVRAM_ATTR_MULTIPLE;
+        ldi->attr |= NVRAM_ATTR_BACKUP_RAW;
+        ldi->attr &= ~NVRAM_ATTR_BACKUP_FAT;
+    #else
+        #if !defined(__CCCIFS_SUPPORT__) && !defined(__FS_RAMDISK__)
+        ldi->attr |= NVRAM_ATTR_MULTIPLE;
+        #endif
+        ldi->attr &= ~NVRAM_ATTR_BACKUP_RAW;
+        ldi->attr &= ~NVRAM_ATTR_BACKUP_FAT;
+    #endif
+    }
+
+
+
+    //***************************************************************************
+    // Adjust Attr/Category V
+    //      Add pseudo merge attribute
+    //***************************************************************************
+    /* Record data item will be restored (end) */
+#ifdef __NVRAM_PSEUDO_MERGE__
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if (!NVRAM_IS_CATEGORY_INTERNAL(ldi->category) &&
+        !NVRAM_IS_CATEGORY_SECUPACK(ldi->category) &&
+        !NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) &&
+        !NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) &&
+    #ifdef __NVRAM_CUSTOM_SENSITIVE__
+        !NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) &&
+    #endif
+    #ifdef __NVRAM_CUSTOM_DISK__
+        !NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category) &&
+    #endif
+          ((ldi->size + nvram_chksum_size) * ldi->total_records < NVRAM_CLUSTER_SIZE))
+    {
+        ldi->attr |= NVRAM_ATTR_PACKAGE;
+    }
+
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        ldi->description = NULL;
+        ldi->attr &= ~ (NVRAM_ATTR_MULTIPLE);
+        ldi->attr &= ~ (NVRAM_ATTR_MSP);
+    }
+#endif
+
+
+
+    //***************************************************************************
+    // Adjust Attr/Category
+    //      Simulation/Palladium/FPGA remove NVRAM_ATTR_GEN_DEFAULT
+    //***************************************************************************
+#if defined(_SIMULATION) || defined(__PALLADIUM__) || defined(__FPGA__)
+    if (!NVRAM_IS_CATEGORY_INTERNAL(ldi->category) && (ldi->LID != NVRAM_EF_SYS_LID) && (ldi->LID != NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID))
+    {
+#if defined (__NVRAM_UT_TEST__)
+    // Don't remove test lid gen default attribute
+    if(ldi->LID < NVRAM_EF_NVRAM_UNIT_TEST_LID || ldi->LID > NVRAM_EF_NVRAM_UNIT_TEST_LID_END)
+#endif
+        ldi->attr &= ~(NVRAM_ATTR_GEN_DEFAULT);
+    }
+#endif
+
+
+    //***************************************************************************
+    // Adjust Attr/Category X
+    //      1. Compress the data in MT table and it is in custpack
+    //      2. Compress the default value of the data not in MT table
+    //         and its default value is not zero default or ff default
+    // coppress function had phaseout
+    //***************************************************************************
+
+    //***************************************************************************
+    // Adjust Attr/Category XI
+    //      Put Internal, Calibration, Important data into SDS
+    //***************************************************************************
+#if defined(__NVRAM_SECURE_DATA_STORAGE__)
+    if (NVRAM_IS_CATEGORY_INTERNAL(ldi->category) ||
+        NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) ||
+        NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) ||
+        NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        ldi->category |= NVRAM_CATEGORY_BACKUP_SDS;
+
+        ldi->attr &= ~ NVRAM_ATTR_MULTIPLE;
+        ldi->attr &= ~ NVRAM_ATTR_RING;
+        ldi->attr &= ~ NVRAM_ATTR_PACKAGE;
+        ldi->attr &= ~ NVRAM_ATTR_BACKUP_FAT;
+        ldi->attr &= ~ NVRAM_ATTR_BACKUP_RAW;
+    }
+    #endif
+    //Tool check end: nvram_pre_gen.pl
+
+    //***************************************************************************
+    //  Assign entry I
+    //      Assign the secupack
+    //***************************************************************************
+    if (NVRAM_IS_CATEGORY_SECUPACK(ldi->category))
+    {
+        nvram_assign_secupack_entry(ldi);
+    }
+
+    //***************************************************************************
+    //  Assign entry II
+    //      Assign the pseudo merge, nvram will use ldi->description as file offset
+    //***************************************************************************
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    ldi->description = NULL;
+#endif
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_assign_cat_entry
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+static void nvram_assign_cat_default_value(nvram_lid_enum position, nvram_cat_replace_setting* cat_item)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_util_get_data_item(&ldi, position);
+
+    if (cat_item->size != ldi->size ||
+        cat_item->total_records != ldi->total_records)
+    {
+        return;
+    }
+
+    ldi->default_value = cat_item->default_value;
+
+    if (cat_item->is_multi_default)
+    {
+        ldi->attr &= NVRAM_ATTR_MULTI_DEFAULT;
+    }
+    else
+    {
+        ldi->attr &= ~NVRAM_ATTR_MULTI_DEFAULT;
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  ltable_construct
+ * DESCRIPTION
+ *  Constructor of ltable. Calculate  Record ID according to each logical data item's
+ *  attributes.
+ * PARAMETERS
+ *  ltable          [IN/OUT]        The user configured logical data item table.
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static nvram_ltable_entry_struct *tbl_p;
+void nvram_set_ltable(nvram_ltable_entry_struct *table)
+{
+    tbl_p = (table>logical_data_item_table_internal)?table:logical_data_item_table_internal;
+}
+
+nvram_ltable_entry_struct *nvram_get_ltable(void)
+{
+    return tbl_p;
+}
+
+static void nvram_assgn_ltable(void)
+{
+#ifdef __MTK_TARGET__
+    extern kal_uint32 _nvram_ltable$$Base, _nvram_ltable$$Length;
+
+    logical_data_item_table = (nvram_ltable_entry_struct *)&_nvram_ltable$$Base;
+    nvram_ptr->ltable.table = &logical_data_item_table;
+    nvram_ptr->ltable.area_size = (kal_uint32)&_nvram_ltable$$Length;
+    nvram_ptr->ltable.total_LID = nvram_ptr->ltable.area_size/sizeof(nvram_ltable_entry_struct);
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_context.total_LID= nvram_ptr->ltable.total_LID;
+        nvram_ee_info->nvram_init_context.area_size = nvram_ptr->ltable.area_size;
+    }    
+#else
+    kal_uint32 i, offset = 0;
+    nvram_ltable_entry_struct *ltable_entry = NULL;
+    nvram_ltable_entry_struct *the_start = &_nvram_ltable_start;
+    kal_uint32 start_addr = (kal_uint32)the_start, end_addr = (kal_uint32)&the_nvram_ltable_end;
+
+  #if defined(_MSC_VER) && !defined(L1_SIM)
+    //skip session gap
+    for (offset = 0; offset < 0x1000; offset += 32) // __declspec(align(32))
+    {
+        ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[0] + offset);
+        if(ltable_entry->fileprefix[0]) {
+            break;
+        }
+    }
+  #endif
+
+    for (i = 0;(kal_uint32)ltable_entry <= end_addr; i++)
+    {
+        ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[i] + offset);
+        
+        if (logical_data_item_table == NULL && ltable_entry->fileprefix[0])
+        {
+            logical_data_item_table = ltable_entry;
+            nvram_ptr->ltable.table = &logical_data_item_table;
+        }
+
+        if (ltable_entry->fileprefix[0])
+        {
+            //printf("%03d: ltable[%d]:%x filename = %s\n", nvram_ptr->ltable.total_LID, ltable_entry->LID, ltable_entry, ltable_entry->fileprefix);
+            nvram_ptr->ltable.total_LID++;
+        }
+        else
+        {
+            ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[i] + offset + 32);
+            if (ltable_entry->fileprefix[0])
+            {
+                //printf("%03d: ltable[%d]:%x filename = %s\n", nvram_ptr->ltable.total_LID, ltable_entry->LID, ltable_entry, ltable_entry->fileprefix);
+                nvram_ptr->ltable.total_LID++;
+            }
+        }
+    }
+
+    nvram_ptr->ltable.area_size = (kal_uint32)ltable_entry - (kal_uint32)logical_data_item_table;
+
+#endif
+}
+
+void nvram_ltable_construct(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i = 0;
+    nvram_ltable_entry_struct *ltable_entry;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+
+    nvram_assgn_ltable();
+
+    ltable_entry = &logical_data_item_table[0];
+    do 
+    {
+        if (ltable_entry)
+        {
+        #ifdef __NVRAM_PSEUDO_MERGE__
+            if (nvram_query_lid_merge(ltable_entry))
+            {
+                nvram_assign_package_entry(ltable_entry);
+            }
+        #endif /* __NVRAM_PSEUDO_MERGE__ */
+        
+            nvram_assign_table_entry(ltable_entry->LID, ltable_entry);
+        }
+        
+    }while(nvram_util_next_data_item(&ltable_entry));
+    
+    
+    /*
+     * So far,logical table has been constructed
+     */
+
+    /*
+     * Assign the custpack default value to ltable
+     */
+    nvram_assign_custpack_default_value();
+
+    /*
+     *  Assign the cat tool default value
+     */
+    i = 0;
+    while (nvram_cat_replace_tbl[i].LID != NVRAM_EF_RESERVED_LID)
+    {
+        nvram_assign_cat_default_value(nvram_cat_replace_tbl[i].LID, &nvram_cat_replace_tbl[i]);
+        i++;
+    }
+
+    /*
+     * Assign the versions to ltable
+     */
+
+    /* First, define system-level record */
+
+
+    /* Branch version */
+    memset(nvram_ptr->branch_version, 0, NVRAM_EF_BRANCH_VERNO_SIZE + 1);
+    strncpy((char*)nvram_ptr->branch_version, (char*)release_branch(), NVRAM_EF_BRANCH_VERNO_SIZE);
+
+    /* Flavor version */
+    memset(nvram_ptr->flavor_version, 0, NVRAM_EF_FLAVOR_VERNO_SIZE + 1);
+    strncpy((char*)nvram_ptr->flavor_version, (char*)release_flavor(), NVRAM_EF_FLAVOR_VERNO_SIZE);
+
+    /* Build time */
+    memset(nvram_ptr->build_time, 0, NVRAM_EF_BUILD_TIME_SIZE + 1);
+    strncpy((char*)nvram_ptr->build_time, (char*)build_date_time(), NVRAM_EF_FLAVOR_VERNO_SIZE);
+
+
+    /* Default lock status is LOCKED -- by using lock pattern of CODED_LOCK_PATTERN */
+    nvram_assign_system_record_default_value((kal_char *)nvram_ptr->coded_version, release_verno());
+    //nvram_ptr->lock should be KAL_FALSE during pre-init
+    nvram_ptr->lock = KAL_FALSE;
+    nvram_ptr->saved_lock = nvram_custom_lock_status();
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock;
+        nvram_ee_info->nvram_init_context.saved_lock = nvram_ptr->saved_lock;
+    }
+}   /* end of ltable_construct function */
+
+
+#ifdef __NVRAM_OTP__
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_otp_construct
+ * DESCRIPTION
+ *  Construct OTP table.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_otp_construct(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+//    kal_uint32 file_idx;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint32 fs_otp_size = 0;
+    nvram_lid_enum nvram_otp_idx = 0;
+    kal_uint32 nvram_otp_size = 0;  /* if version is supported, init it as version length */
+    nvram_drv_status_enum status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        if (ldi->category & NVRAM_CATEGORY_OTP)
+        {
+            NVRAM_EXT_ASSERT(nvram_otp_idx < NVRAM_OTP_TOTAL,(kal_uint32)nvram_otp_idx, NVRAM_LOC_INVALID_INDEX_1, NVRAM_OTP_TOTAL);
+
+            nvram_otp_ltable[nvram_otp_idx].offset = nvram_otp_size;
+            nvram_otp_size += ldi->size * ldi->total_records;
+
+            nvram_otp_ltable[nvram_otp_idx].LID = ldi->LID;
+            nvram_otp_idx++;
+        }
+    }while(nvram_util_next_data_item(&ldi));
+#ifdef __MTK_TARGET__
+    NVRAM_FS_START(FS_OP_OTPQUERYLENGTH);
+    status = FS_OTPQueryLength(FS_DEVICE_TYPE_UNKNOWN, &fs_otp_size);
+    NVRAM_FS_END(FS_OP_OTPQUERYLENGTH,status);
+#else
+    fs_otp_size = 256;
+#endif
+    NVRAM_EXT_ASSERT(nvram_otp_size <= fs_otp_size, status, NVRAM_LOC_OTP_INIT_FAIL, fs_otp_size);
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_otp_offset
+ * DESCRIPTION
+ *  Construct OTP table.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_uint32 nvram_get_otp_offset(nvram_lid_enum lid)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 i;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    for(i = NVRAM_OTP_TOTAL - 1; i >= 0 ; i--)
+    {
+        if (nvram_otp_ltable[i].LID == lid)
+        {
+            return nvram_otp_ltable[i].offset;
+        }
+    }
+
+    NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)lid, NVRAM_LOC_INVALID_LID_3, i);
+
+    return 0;
+}
+
+
+#endif /* __NVRAM_OTP__ */
diff --git a/mcu/service/nvram/src/nvram_ltable_register.c b/mcu/service/nvram/src/nvram_ltable_register.c
new file mode 100644
index 0000000..aef3bfb
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ltable_register.c
@@ -0,0 +1,284 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ * Filename:
+ * ---------
+ * nvram_ltable_register.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *  
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*
+ * include
+ */
+#include "stdio.h"
+#include "string.h"
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+
+#include "nvram_editor_data_item.h"
+#include "nvram_main.h"
+
+#include "nvram_lid_statistics.h"
+
+
+
+nvram_ltable_entry_struct *logical_data_item_table;
+
+extern void nvram_ltable_register(nvram_ltable_entry_struct *table);
+#if defined(__MTK_TARGET__)
+    extern ltable_entry_struct logical_data_item_table_internal[];
+    extern ltable_entry_struct logical_data_item_table_factory[];
+    extern ltable_entry_struct logical_data_item_table_core[];
+    extern ltable_entry_struct logical_data_item_table_exception[];
+    extern ltable_entry_struct logical_data_item_table_ul1[];
+    extern ltable_entry_struct logical_data_item_table_asband[];
+    extern ltable_entry_struct logical_data_item_table_bt[];
+    extern ltable_entry_struct logical_data_item_table_bwcs[];
+    extern ltable_entry_struct logical_data_item_table_csg[];
+    extern ltable_entry_struct logical_data_item_table_dhl[];
+    extern ltable_entry_struct logical_data_item_table_drm[];
+    extern ltable_entry_struct logical_data_item_table_ecompass[];
+    extern ltable_entry_struct logical_data_item_table_el1[];
+    extern ltable_entry_struct logical_data_item_table_emm[];
+    extern ltable_entry_struct logical_data_item_table_erac[];
+    extern ltable_entry_struct logical_data_item_table_errc[];
+    extern ltable_entry_struct logical_data_item_table_ft[];
+    extern ltable_entry_struct logical_data_item_table_gps[];
+    extern ltable_entry_struct logical_data_item_table_ims[];
+    extern ltable_entry_struct logical_data_item_table_l1[];
+    extern ltable_entry_struct logical_data_item_table_l4[];
+    extern ltable_entry_struct logical_data_item_table_minilog[];
+    extern ltable_entry_struct logical_data_item_table_mml1[];
+    extern ltable_entry_struct logical_data_item_table_nas[];
+    extern ltable_entry_struct logical_data_item_table_nmu[];
+    extern ltable_entry_struct logical_data_item_table_rr[];
+    extern ltable_entry_struct logical_data_item_table_rtc[];
+    extern ltable_entry_struct logical_data_item_table_sbp[];
+    extern ltable_entry_struct logical_data_item_table_scsi[];
+    extern ltable_entry_struct logical_data_item_table_sim[];
+    extern ltable_entry_struct logical_data_item_table_td[];
+    extern ltable_entry_struct logical_data_item_table_umts[];
+    extern ltable_entry_struct logical_data_item_table_vsim[];
+    extern ltable_entry_struct logical_data_item_table_wndrv[];
+    extern ltable_entry_struct logical_data_item_table_d2[];
+    extern ltable_entry_struct logical_data_item_table_cl1[];
+    extern ltable_entry_struct logical_data_item_table_cl1cal[];
+    extern ltable_entry_struct logical_data_item_customer[];
+    extern ltable_entry_struct logical_data_item_cuex[];
+    extern ltable_entry_struct logical_data_item_table_as[];
+#else
+    extern logical_data_item_table_internal[];
+    extern logical_data_item_table_factory[];
+    extern logical_data_item_table_core[];
+    extern logical_data_item_table_exception[];
+    extern logical_data_item_table_ul1[];
+    extern logical_data_item_table_asband[];
+    extern logical_data_item_table_bt[];
+    extern logical_data_item_table_bwcs[];
+    extern logical_data_item_table_csg[];
+    extern logical_data_item_table_dhl[];
+    extern logical_data_item_table_drm[];
+    extern logical_data_item_table_ecompass[];
+    extern logical_data_item_table_el1[];
+    extern logical_data_item_table_emm[];
+    extern logical_data_item_table_erac[];
+    extern logical_data_item_table_errc[];
+    extern logical_data_item_table_ft[];
+    extern logical_data_item_table_gps[];
+    extern logical_data_item_table_ims[];
+    extern logical_data_item_table_l1[];
+    extern logical_data_item_table_l4[];
+    extern logical_data_item_table_minilog[];
+    extern logical_data_item_table_mml1[];
+    extern logical_data_item_table_nas[];
+    extern logical_data_item_table_nmu[];
+    extern logical_data_item_table_rr[];
+    extern logical_data_item_table_rtc[];
+    extern logical_data_item_table_sbp[];
+    extern logical_data_item_table_scsi[];
+    extern logical_data_item_table_sim[];
+    extern logical_data_item_table_td[];
+    extern logical_data_item_table_umts[];
+    extern logical_data_item_table_vsim[];
+    extern logical_data_item_table_wndrv[];
+    extern logical_data_item_table_d2[];
+    extern logical_data_item_table_cl1[];
+    extern logical_data_item_table_cl1cal[];
+    extern logical_data_item_customer[];
+    extern logical_data_item_cuex[];
+    extern logical_data_item_table_as[];
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_data_item_register
+ * DESCRIPTION
+ *  This function to register nvram data item tables.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  
+ *****************************************************************************/
+void nvram_data_item_register(void)
+{
+
+    //NVRAM table force link
+    nvram_ltable_register(logical_data_item_table_internal);
+    nvram_ltable_register( logical_data_item_table_factory);
+    nvram_ltable_register( logical_data_item_table_core);
+    nvram_ltable_register( logical_data_item_table_exception);
+    nvram_ltable_register( logical_data_item_table_ul1);
+    nvram_ltable_register( logical_data_item_table_asband);
+    nvram_ltable_register( logical_data_item_table_bt);
+    nvram_ltable_register( logical_data_item_table_bwcs);
+    nvram_ltable_register( logical_data_item_table_csg);
+    nvram_ltable_register( logical_data_item_table_dhl);
+    nvram_ltable_register( logical_data_item_table_drm);
+    nvram_ltable_register( logical_data_item_table_ecompass);
+    nvram_ltable_register( logical_data_item_table_el1);
+    nvram_ltable_register( logical_data_item_table_emm);
+    nvram_ltable_register( logical_data_item_table_erac);
+    nvram_ltable_register( logical_data_item_table_errc);
+    nvram_ltable_register( logical_data_item_table_ft);
+    nvram_ltable_register( logical_data_item_table_gps);
+    nvram_ltable_register( logical_data_item_table_ims);
+    nvram_ltable_register( logical_data_item_table_l1);
+    nvram_ltable_register( logical_data_item_table_l4);
+    nvram_ltable_register( logical_data_item_table_minilog);
+    nvram_ltable_register( logical_data_item_table_mml1);
+    nvram_ltable_register( logical_data_item_table_nas);
+    nvram_ltable_register( logical_data_item_table_nmu);
+    nvram_ltable_register( logical_data_item_table_rr);
+    nvram_ltable_register( logical_data_item_table_rtc);
+    nvram_ltable_register( logical_data_item_table_sbp);
+    nvram_ltable_register( logical_data_item_table_scsi);
+    nvram_ltable_register( logical_data_item_table_sim);
+    nvram_ltable_register( logical_data_item_table_td);
+    nvram_ltable_register( logical_data_item_table_umts);
+    nvram_ltable_register( logical_data_item_table_vsim);
+    nvram_ltable_register( logical_data_item_table_wndrv);
+    nvram_ltable_register( logical_data_item_table_d2);
+    nvram_ltable_register((nvram_ltable_entry_struct *)logical_data_item_table_cl1);
+    nvram_ltable_register((nvram_ltable_entry_struct *)logical_data_item_table_cl1cal);
+    nvram_ltable_register( logical_data_item_customer);
+    nvram_ltable_register( logical_data_item_cuex);
+    nvram_ltable_register( logical_data_item_table_as);
+}
diff --git a/mcu/service/nvram/src/nvram_main.c b/mcu/service/nvram/src/nvram_main.c
new file mode 100644
index 0000000..ef3788c
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_main.c
@@ -0,0 +1,4043 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_main.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is main() function of NVRAM module.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+/*
+ * Include
+ */
+#include <string.h>
+#include "nvram_msgid.h"
+
+#include "kal_general_types.h"
+#include "kal_internal_api.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+#include "syscomp_config.h"
+#include "task_config.h"
+#include "sysconf_statistics.h"     /* stack_statistics_struct */
+#include "custom_em.h"
+/* Factory mode, should not send ADC calibration data to BMT  */
+#ifdef __MULTI_BOOT__
+#include "multiboot_config.h"
+#include "intrCtrl.h"               /* INT_BootMode */
+#endif /* __MULTI_BOOT__ */
+
+#ifdef __CCCIFS_SUPPORT__
+#include "ccci.h"
+#endif
+
+#if defined(__HIF_CCCI_SUPPORT__)
+#include "ccci_if.h"
+#endif
+
+#if defined(__MTK_TARGET__)
+#include "SST_secure.h"
+#endif
+
+#include "fs_type.h"                /* FS_HANDLE */
+#include "fs_func.h"                /* FS_Delete */
+#include "fs_errcode.h"             /* FS_NO_ERROR */
+#include "ex_item.h"                /* EX_LOG_T */
+
+#include "nvram_main.h"
+#include "nvram_interface.h"
+
+#include "nvram_msg_handler.h"
+
+#include "tst_msgid.h"
+#include "sbp_public_utility.h"
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+
+#include "mcf_if.h"
+#include "mcf_enum.h"
+
+#ifdef __NVRAM_LID_CACHE__
+#include "nvram_cache_interface.h"
+#endif
+#include "ex_public.h"
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+extern void MMISWChangeWarning(
+                kal_uint8 type,
+                kal_uint32 space,
+                kal_uint8 const *codeversion,
+                kal_uint8 const *diskversion);
+
+extern void MMICheckDiskDisplay(void);
+
+
+extern void *kal_tmp_mem_alloc(kal_uint32 size);
+extern void kal_tmp_mem_free(void *mem_ptr);
+extern kal_char *release_verno(void);
+extern kal_char *release_branch(void);
+extern kal_char *release_flavor(void);
+extern kal_char *build_date_time(void);
+extern kal_bool nvram_custom_lock_status(void);
+extern void custom_nvram_config(void);
+extern void custom_default_mode_config(void);
+extern kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi);
+
+#ifdef __NVRAM_DEBUG_READ_DUMP__
+extern void nvram_debug_log_dump(kal_bool valid, kal_char *log_str, kal_uint32 p1, kal_uint32 p2, kal_uint32 p3, kal_uint8 *buffer, kal_uint32 buffer_size);
+#else
+#define nvram_debug_log_dump(...)
+#endif
+#ifdef __TC01__ // ALPS0144925
+extern nvram_ef_sbp_modem_config_struct cust_sbp_config; 
+#endif
+#if defined (__NVRAM_UT_TEST__)
+extern kal_uint32 nvram_boot_trace;
+extern kal_uint8 is_clean_boot_test;
+#endif
+
+#if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+extern const checksum_reset_struct lid_structure_chksum[];
+extern const checksum_reset_struct lid_default_value_chksum[];
+#endif
+
+extern void nvram_sml_ota_converter(kal_uint8 *old_value_buffer, kal_uint32 ota_hdr_record_size, kal_uint8 *new_value_buffer, kal_uint32 new_record_size);
+/*******************************************************
+ * Define
+ *******************************************************/
+#define OVERHEAD_CLUSTER        5           /* extra space in bytes needed for conflict resolution. ex, report files */
+#define DISPLAY_WARNING_TIME    1000        /* 1000 ticks = 4.6 sec */
+#define MAX_CHANGE_ARRAY_SIZE   (nvram_ptr->ltable.total_LID + 1)
+
+#define NVRAM_SET_OTA_MARKED(LID) \
+    nvram_util_take_mutex(g_nvram_impt_mutex); \
+    nvram_util_lid_bimtap_set(LIDCheckedArray, LID); \
+    nvram_util_give_mutex(g_nvram_impt_mutex)
+
+#define NVRAM_CHK_OTA_MARKED(LID) nvram_util_lid_bitmap_check(LIDCheckedArray, LID)
+
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+#define NVRAM_SET_CREATEED_FILE_INFO(LID) \
+    nvram_util_take_mutex(nvram_bitmap_mutex); \
+    nvram_util_lid_bimtap_set(nvram_bitmap_ptr, LID); \
+    nvram_util_give_mutex(nvram_bitmap_mutex)
+    
+#define NVRAM_CHK_CREATEED_FILE_INFO(LID) nvram_util_lid_bitmap_check(nvram_bitmap_ptr, LID)
+#else
+#define NVRAM_SET_CREATEED_FILE_INFO(LID)
+#define NVRAM_CHK_CREATEED_FILE_INFO(LID) KAL_FALSE
+#endif
+
+#define CALIBRATE_FILE_MAX_CNT (1000)
+#define IMEI_FILE_MAX_CNT (64)
+#define FILE_LIST_ITEM_LENGTH (9)
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+typedef struct
+{
+    kal_bool checked;
+    WCHAR diskfile[NVRAM_FILE_LEN + 1];
+} diskTableEntry;
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+kal_mutexid g_nvram_impt_mutex = NULL;
+kal_mutexid g_nvram_fs_mutex = NULL;
+kal_mutexid g_nvram_trace_mutex = NULL; //this mutex is used to record nvram last read/write 10 times information
+                                        //nvram external API may called by many users, so need this mutex
+kal_mutexid g_nvram_dump_trace_mutex = NULL;//this mutex is used to dump nvram trace to file                                         
+kal_uint32 g_nvram_task_idx = 0xFFFFFFFF; 
+ilm_struct *g_ilm_ptr = NULL;
+nvram_access_trace_information nvram_access_trace;
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+DCL_HANDLE nvram_gpt_handle;
+#endif
+
+#ifdef __NVRAM_WRITE_WITH_FILE_SIZE__
+kal_bool bResetNvramData = KAL_FALSE;
+#endif
+
+#ifdef __NVRAM_WRITE_PROTECT_ENABLE__
+kal_bool isneedwriteprotect2 = KAL_FALSE;
+#endif
+
+nvram_context_type nvram_context;
+nvram_context_type *nvram_ptr = &nvram_context;
+#ifdef __NV_CHKSUM_ENHANCE__
+extern nvram_algo_info *chksum_algo_ptr;
+#endif
+
+mcf_ota_result_e mcf_full_ota_status = MCF_OTA_R_MAX;
+
+nvram_ee_info_type* nvram_ee_info = NULL;
+kal_wchar nvram_trace_filename[NVRAM_MAX_PATH_LEN];
+kal_char nvram_trace_dump_temp_buffer[NVRAM_DUMP_TRACE_TEMP_BUFFER_SIZE];
+kal_char nvram_trace_dump_buffer[NVRAM_DUMP_TRACE_BUFFER_SIZE];
+kal_uint32 nvram_trace_dump_buffer_offset = 0;
+FS_HANDLE nvram_trace_file_hdl = 0;
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+static kal_bool nvram_init_all_ldi(nvram_reset_category_enum reset_category);
+static kal_bool nvram_supplementary_check(void);
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+static kal_uint32 BytesPerCluster;  /* will be set to exact value in nvram_get_disk_file_info */
+static kal_uint32 *nvram_init_tmp_pool;
+//static diskTableEntry *DiskTable;
+static kal_uint16 files_in_folder[NVRAM_FOLDER_TOTAL];
+static kal_uint32 diskSize_of_folder[NVRAM_FOLDER_TOTAL];
+
+static nvram_lid_enum *LIDResetArray = NULL;        /* [count, lid1, lid2,..] ex. [3, 12, 29] */
+static nvram_lid_enum LIDResetCnt = 0;
+static kal_uint32 LIDResetMax = 0;
+
+static kal_uint8 *LIDCheckedArray = NULL;
+#ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+kal_uint8 *CALI_FileListBuf = NULL;
+kal_uint8 *IMEI_FileListBuf = NULL;
+kal_bool is_nvram_in_ota_flow = KAL_FALSE;
+kal_bool is_nvram_first_restore = KAL_TRUE;
+kal_bool Cali_filelist_found = KAL_FALSE;
+kal_bool Imei_filelist_found = KAL_FALSE;
+#endif
+kal_bool is_nvram_factory_reset = KAL_FALSE;
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create
+ * DESCRIPTION
+ *  NVRAM task create function
+ * PARAMETERS
+ *  handle      [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+kal_bool nvram_create(comptask_handler_struct **handle)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    static const comptask_handler_struct nvram_handler_info =
+    {
+        nvram_task_main,    /* task entry function */
+        nvram_init,         /* task initialization function */
+        nvram_reset        /* task reset handler */
+    };
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    *handle = (comptask_handler_struct*) & nvram_handler_info;
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_task_main
+ * DESCRIPTION
+ *  NVRAM task
+ * PARAMETERS
+ *  task_entry_ptr      [?]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+
+#ifndef __MTK_TARGET__
+  #ifdef _MSC_VER
+    nvram_read_callback_struct __pragma(data_seg("_nvram_callback_tbl_begin")) _nvram_callback_tbl_begin_p = {0};
+    
+    #pragma comment(linker, "/MERGE:_nvram_callback_tbl_content=_nvram_callback_tbl_begin")
+    
+    nvram_read_callback_struct __pragma(data_seg("_nvram_callback_tbl_end")) _nvram_callback_tbl_end_p = {0};
+    
+    #pragma comment(linker, "/MERGE:_nvram_callback_tbl_end=_nvram_callback_tbl_begin")
+  #else
+    // section merge is moved to linker script for other compilers
+    __attribute__ ((section("_nvram_callback_tbl_begin"))) nvram_read_callback_struct _nvram_callback_tbl_begin_p = {0};
+    __attribute__ ((section("_nvram_callback_tbl_end"))) nvram_read_callback_struct _nvram_callback_tbl_end_p = {0};
+  #endif
+#endif
+
+void nvram_task_main(task_entry_struct *task_entry_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    ilm_struct current_ilm;
+    kal_int32  cb_idx;
+    nvram_read_callback_struct *cb_first_entry;
+    
+#ifdef __MTK_TARGET__
+    extern kal_uint32 _nvram_callback_tbl$$Base, _nvram_callback_tbl$$Length;
+    cb_idx = (kal_uint32)&_nvram_callback_tbl$$Length/sizeof(nvram_read_callback_struct);
+    cb_first_entry = (nvram_read_callback_struct *)&_nvram_callback_tbl$$Base;
+
+
+#else
+
+    cb_idx = (kal_uint32)(&_nvram_callback_tbl_end_p - &_nvram_callback_tbl_begin_p);
+    cb_first_entry = (nvram_read_callback_struct *)&_nvram_callback_tbl_begin_p;
+
+#endif
+
+#if defined(__NVRAM_INIT_LID_BUFFER__)
+    NVRAM_INIT_TIME_UT_STAMP(8);
+    nvram_init_lid_buffer_writeback();
+    NVRAM_INIT_TIME_UT_STAMP(9);
+#endif
+    // Write result to NVRAM_SYS_NVRAM_INIT_TIME_UT
+    NVRAM_INIT_TIME_UT_SAVE();  
+	
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    while (1)
+    {
+        kal_int32 i = 0;
+        /* nvram special service */
+        for (;i < cb_idx; i++)
+        {
+            nvram_read_callback_struct *entry = (nvram_read_callback_struct *)(cb_first_entry + i);
+            if (!entry->processed)
+            {
+                kal_bool result = KAL_TRUE;
+                if (entry->callback)
+                {
+                    result = entry->callback(entry->user_data);
+                    entry->processed = KAL_TRUE;
+                }
+
+                if (result && entry->module != MOD_NIL && NVRAM_IS_LID_VALID(entry->file_id))
+                {
+                    {
+                        nvram_ltable_entry_struct *ldi;
+                        peer_buff_struct *peer_buf_ptr;
+                        kal_uint8 *pdu_ptr;
+                        kal_uint16 pdu_length;
+                        nvram_read_req_struct *local_data;
+                        nvram_util_get_data_item(&ldi, entry->file_id);
+                    
+                        local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+                    
+                        local_data->access_id = 0;
+                        local_data->file_idx = entry->file_id;
+                        local_data->para = 1;
+                    
+                        pdu_length = ldi->size;
+                        peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    
+                        pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    
+                        nvram_read_confirm(
+                            entry->module,
+                            nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length),  /* multi-rec read support */
+                            local_data,
+                            ldi->size,
+                            peer_buf_ptr);
+                    
+                        free_local_para((local_para_struct*) local_data);
+                    }
+                    
+                    entry->processed = KAL_TRUE;
+                }
+                
+            }
+        }
+
+        #if defined(__NVRAM_WRITE_PROTECT_ENABLE__)	&& defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)	
+		if (KAL_TRUE == isneedwriteprotect2)
+		{
+			ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xCBA);
+			isneedwriteprotect2 = KAL_FALSE;
+		}
+	    #endif
+
+        msg_receive_extq(&current_ilm);
+        kal_set_active_module_id(current_ilm.dest_mod_id);
+
+        nvram_main(&current_ilm);
+
+        destroy_ilm(&current_ilm);
+    }
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_main
+ * DESCRIPTION
+ *  This is main() function of NVRAM module.
+ * PARAMETERS
+ *  ilm_ptr     [IN]        The primitives
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_main(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    EXT_ASSERT(ilm_ptr != NULL,(kal_uint32)ilm_ptr, NVRAM_LOC_ILM_PTR_IS_NULL_1, 0);
+
+    if (ilm_ptr != NULL)
+    {
+        if ((ilm_ptr->msg_id >= MSG_ID_NVRAM_CODE_BEGIN) && (ilm_ptr->msg_id <= MSG_ID_NVRAM_CODE_END))
+        {
+            g_ilm_ptr = ilm_ptr;
+            g_nvram_task_idx = kal_get_current_task_index();
+            if (ilm_ptr->msg_id == MSG_ID_NVRAM_STARTUP_REQ)
+            {
+                nvram_startup_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_RESET_REQ)
+            {
+                nvram_reset_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_REQ)
+            {
+                nvram_read_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_DEFAULT_REQ)
+            {
+                nvram_read_default_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_WRITE_REQ)
+            {
+                nvram_write_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_WRITE_IMEI_REQ)
+            {
+                nvram_write_imei_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_SET_LOCK_REQ)
+            {
+                nvram_set_lock_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_CALLBACK_REQ)
+            {
+                /*when user call nvram_register_read_req() will send this message to NVRAM
+                  this is used to wakeup NVRAM task if NVRAM task is waiting for extq msg*/
+                return; 
+            }
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_SUSPEND_REQ)
+            {
+                nvram_suspend_handler(ilm_ptr);
+            }
+        #ifdef __NVRAM_BACKUP_DISK_RAW__
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_CREATE_IMAGE_REQ)
+            {
+                nvram_create_image_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_RECOVER_IMAGE_REQ)
+            {
+                nvram_recover_image_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_VERIFY_IMAGE_REQ)
+            {
+                nvram_verify_image_handler(ilm_ptr);
+            }
+        #endif /* __SYSDRV_BACKUP_DISK_RAW__ */
+        #ifdef __NVRAM_SECURE_DATA_STORAGE__
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_SDS_REQ)
+            {
+                nvram_sds_handler(ilm_ptr);
+            }
+        #endif
+        #if defined(__CCCIFS_SUPPORT__) && defined(__MODEM_CARD__)  // Hosted Dongle Data Card
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_BIN_REGION_REQ)
+            {
+                nvram_ap_bin_region_handler(ilm_ptr);
+            }
+        #endif
+        #if defined(__NVRAM_MONITOR_ENABLED__)
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_REG_NOTIFY_REQ)
+            {
+                nvram_mon_reg_handler(ilm_ptr);
+            }
+            else if (ilm_ptr->msg_id == MSG_ID_NVRAM_DEREG_NOTIFY_REQ)
+            {
+                nvram_mon_dereg_handler(ilm_ptr);
+            }
+        #endif
+        }
+    #ifdef TST_HANDLER
+        else
+        {
+            /* not nvram defined message */
+            if (ilm_ptr->msg_id == MSG_ID_TST_INJECT_STRING)
+            {
+                nvram_tst_handler(ilm_ptr);
+            }
+        }
+    #endif /* TST_HANDLER */
+
+    }
+}   /* end of module main function */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_report_reset_data_item
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  LID     [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void nvram_report_reset_data_item(nvram_lid_enum LID)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    LIDResetCnt++;
+    EXT_ASSERT(LIDResetCnt < LIDResetMax,(kal_uint32)LIDResetCnt, NVRAM_LOC_INVALID_INDEX_2, LIDResetMax);
+
+    LIDResetArray[0] = LIDResetCnt;   /* Count */
+    LIDResetArray[LIDResetCnt] = LID;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_report_file
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *
+ *****************************************************************************/
+static kal_bool nvram_create_report_file()
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE handle;
+    kal_int32 result = FS_NO_ERROR;
+#if !defined(__CCCIFS_SUPPORT__)    
+    kal_uint32 filelen = (1 + LIDResetCnt) * sizeof(nvram_lid_enum);
+    kal_uint32 written;
+#endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#if !defined(__CCCIFS_SUPPORT__)	
+    kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_FILE);
+    NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+    result = FS_Delete(filename);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    handle = FS_Open(filename, FS_CREATE_ALWAYS | FS_READ_WRITE);
+    NVRAM_FS_END(FS_OP_OPEN,handle);
+    if (handle > FS_NO_ERROR)
+    {
+        NVRAM_FS_START(FS_OP_WRITE);
+        result = FS_Write(handle, LIDResetArray, filelen, &written);
+        NVRAM_FS_END(FS_OP_WRITE,result);
+        if (result != FS_NO_ERROR)
+        {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            result = FS_Close(handle);
+            NVRAM_FS_END(FS_OP_CLOSE,result);
+            return KAL_FALSE;
+        }
+    }
+    else
+    {
+        return KAL_FALSE;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(handle);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+#endif
+
+    kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_FILE_TXT);
+    NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+    result = FS_Delete(filename);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    handle = FS_Open(filename, FS_CREATE_ALWAYS | FS_READ_WRITE);
+    NVRAM_FS_END(FS_OP_OPEN,handle);
+    if (handle > FS_NO_ERROR)
+    {
+#if 1
+        // Write previous version and current version into SWCHANGE.TXT
+        // Version string saved in coded_verion len is 18 bytes
+        kal_char buf[128] = {0};     
+        kal_uint32 len = 0;
+
+        len = kal_snprintf(buf, 128, "OTA from %s to %s(%s), ", nvram_ptr->old_coded_version, nvram_ptr->coded_version, nvram_ptr->build_time);
+        NVRAM_FS_START(FS_OP_WRITE);
+        result = FS_Write(handle, buf, len, &len);
+        NVRAM_FS_END(FS_OP_WRITE,result);
+        NVRAM_FS_START(FS_OP_WRITE);
+        len = kal_snprintf(buf, 64, "%s(%s)\n", release_branch(), release_flavor());
+        result = FS_Write(handle, buf, len, &len);
+        NVRAM_FS_END(FS_OP_WRITE,result);
+#else
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+    }
+    else
+    {
+        return KAL_FALSE;
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(handle);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_swchange_warning
+ * DESCRIPTION
+ *  To warn the user there is no enough space to perform software change.
+ * PARAMETERS
+ *  SpaceNedded     [IN]
+ *  diskversion     [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#if (!defined(__L1_STANDALONE__) && !defined(EMPTY_MMI)) && !defined(EXTERNAL_MMI)
+/* under construction !*/
+#endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_disk_file_info
+ * DESCRIPTION
+ *  To get infomation of NVRAM FS usage.
+ * PARAMETERS
+ *  diskfilesize        [OUT]       Total existence file size
+ *  freespace           [OUT]       Free space of FS (in byte)
+ *  overhead            [OUT]       Overhead space (in byte)
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_get_disk_file_info(kal_uint32 *diskfilesize, kal_uint32 *freespace, kal_uint32 *overhead)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    WCHAR DriveName[8];
+    FS_DiskInfo DI;
+    kal_uint32 loop_idx;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_wsprintf(DriveName, "%s\0", "Z:\\");
+    NVRAM_FS_START_EX(FS_OP_GETDISKINFO,DriveName);
+    result = FS_GetDiskInfo((const WCHAR*)DriveName, &DI, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
+    NVRAM_FS_END(FS_OP_GETDISKINFO,result);
+    if (result < FS_NO_ERROR)
+    {
+        return KAL_FALSE;
+    }
+
+    /* Set BytesPerCluster to the accurate value */
+    BytesPerCluster = DI.BytesPerSector * DI.SectorsPerCluster;
+
+    *freespace = BytesPerCluster * DI.FreeClusters;
+
+    for (*diskfilesize = 0, loop_idx = NVRAM_FOLDER_TOTAL; loop_idx > NVRAM_FOLDER_BEGIN; loop_idx--)
+    {
+        *diskfilesize += diskSize_of_folder[loop_idx - 1];
+    }
+
+    *overhead = BytesPerCluster * OVERHEAD_CLUSTER;
+
+    return KAL_TRUE;
+}
+
+#ifdef __NVRAM_DISK_SIZE_CHECK__
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_code_file_size
+ * DESCRIPTION
+ *  To get infomation of NVRAM RO usage.
+ * PARAMETERS
+ *  CodeFileSizeTotal       [OUT]       Total RO size
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_get_code_file_size(kal_uint32 *CodeFileSizeTotal)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    kal_uint32 onefilesize;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    kal_uint32 package_size = 0;
+    kal_uint32 infolid_size = sizeof(head_info_struct);
+#endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    *CodeFileSizeTotal = 2 * BytesPerCluster * (1 + (NVRAM_EF_SYS_SIZE - 1) / BytesPerCluster);
+
+    do
+    {
+
+        nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+        nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+        /* each record followed by a 2-byte checksum */
+        onefilesize = (ldi->size + nvram_chksum_size) * ldi->total_records;
+
+    #ifdef __NVRAM_PSEUDO_MERGE__
+        if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+        {
+            package_size += onefilesize;
+            infolid_size += sizeof(LID_info_struct);
+        }
+        else
+    #endif
+        if (NVRAM_IS_CATEGORY_OTP(ldi->category))
+        {
+            continue;
+        }
+        else if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+        {
+            *CodeFileSizeTotal += 2 * BytesPerCluster * (1 + (onefilesize - 1) / BytesPerCluster);
+        }
+        else
+        {
+            *CodeFileSizeTotal += BytesPerCluster * (1 + (onefilesize - 1) / BytesPerCluster);
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (package_size)
+    {
+        *CodeFileSizeTotal += BytesPerCluster * (1 + (package_size - 1) / BytesPerCluster);
+        *CodeFileSizeTotal += BytesPerCluster * (1 + (infolid_size - 1) / BytesPerCluster);
+    }
+#endif
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_conflict_resolve_prelim
+ * DESCRIPTION
+ *  To calc the disk size that software upgrade needs.
+ * PARAMETERS
+ *  sysrecord       [IN]        Sysrecord
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_conflict_resolve_prelim(kal_uint8 *sysrecord)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 diskfilesize, codefilesize, freespace, overhead;
+    kal_int32 spaceDelta;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (!nvram_get_disk_file_info(&diskfilesize, &freespace, &overhead))
+    {
+        return KAL_FALSE;
+    }
+
+    nvram_get_code_file_size(&codefilesize);
+
+    spaceDelta = codefilesize + overhead - diskfilesize;
+
+    if ((spaceDelta > 0) && (spaceDelta > (kal_int32)freespace))
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE, 0, NVRAM_LOC_SPACE_NOT_ENOUGH_2, spaceDelta - freespace);
+    }
+
+    return KAL_TRUE;
+}
+#endif /* __NVRAM_DISK_SIZE_CHECK__ */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_destruct_certain_disk_table
+ * DESCRIPTION
+ *  Free memory pool
+ * PARAMETERS
+ *  ret     [IN]
+ * RETURNS
+ *
+ *****************************************************************************/
+static kal_bool nvram_destruct_disk_table(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (nvram_init_tmp_pool)
+    {
+        //kal_tmp_mem_free(nvram_init_tmp_pool);
+        //nvram_init_tmp_pool = NULL;
+        free_ctrl_buffer_set_null(nvram_init_tmp_pool);
+        #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+        free_ctrl_buffer_set_null(CALI_FileListBuf);
+        free_ctrl_buffer_set_null(IMEI_FileListBuf);
+        #endif
+    }
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_malloc_disk_table
+ * DESCRIPTION
+ *  Malloc and construct disk table
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_malloc_disk_table(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 folder_idx;
+    kal_uint32 size;
+
+#ifdef NVRAM_DISK_SIZE_CHECK
+    kal_uint16 total_file = 0;
+    kal_wchar namepattern[32];
+    kal_wchar nvramname[NVRAM_FILE_LEN + 1];
+    FS_DOSDirEntry fileinfo;
+    FS_HANDLE handle;
+    kal_int32 result = FS_NO_ERROR;
+#endif
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* Step 1: Use FS_FindFist to parse the nvram folder to get the file number and file size */
+
+    for (folder_idx = NVRAM_FOLDER_BEGIN; folder_idx < NVRAM_FOLDER_TOTAL; folder_idx++)
+    {
+        files_in_folder[folder_idx] = 0;
+        diskSize_of_folder[folder_idx] = 0;
+
+        //skip scan OTA backup folder
+        if((nvram_folder_enum)folder_idx == NVRAM_NVD_BACKUP) {
+            continue;
+        }
+
+#ifdef __NVRAM_DISK_SIZE_CHECK__
+        nvram_query_file_name((nvram_folder_enum)folder_idx, "*", namepattern);
+
+        /*
+         * 1: Collect disk file count
+         * 2: Compute allocate DiskTable
+         */
+        NVRAM_FS_START_EX(FS_OP_FINDFIRST,namepattern);  
+        handle = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, nvramname, sizeof(nvramname));
+        NVRAM_FS_END(FS_OP_FINDFIRST,handle);
+        if (handle > 0)
+        {
+            do
+            {
+                files_in_folder[folder_idx]++;
+                diskSize_of_folder[folder_idx] += BytesPerCluster * (1 + (fileinfo.FileSize - 1) / BytesPerCluster);
+                NVRAM_FS_START(FS_OP_FINDNEXT);  
+                result = FS_FindNext(handle, &fileinfo, nvramname, sizeof(nvramname));
+                NVRAM_FS_END(FS_OP_FINDNEXT,result);
+            }
+            while (result == FS_NO_ERROR);
+            NVRAM_FS_START(FS_OP_FINDCLOSE); 
+            result = FS_FindClose(handle);
+            NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+        }
+        else
+        {
+            files_in_folder[folder_idx] = 0;
+        }
+
+        total_file += files_in_folder[folder_idx];
+#endif
+    }
+
+    /* Step 2: allocate enough memory */
+    /* Should revise this place some day. NVRAM should not use kal_tmp_mem_alloc
+       And there is a hidden limitation of kal_tmp_mem_alloc.
+       kal_tmp_mem_free must be used in pair with kal_tmp_mem_alloc without
+       kal_tmp_mem_alloc/kal_sys_mem_alloc in between.
+       Therefore, We need to invoke FS_GetDiskInfo in nvram_init one time to avoid this prolem.
+       FS_GetDiskInfo -> RTFSYSALLocMutex() -> kal_create_sem -> kal_sys_mem_alloc */
+
+    //nvram_init_tmp_pool = (kal_uint32 *)kal_tmp_mem_alloc(sizeof(kal_uint32) * MAX_CHANGE_ARRAY_SIZE * 2 +
+    //                                                       (kal_uint32)(total_file * sizeof(diskTableEntry)));
+
+    LIDResetMax = MAX_CHANGE_ARRAY_SIZE;
+    //nvram_init_tmp_pool = (kal_uint32 *)kal_tmp_mem_alloc((sizeof(nvram_lid_enum) * LIDResetMax) + nvram_ota_buffer_size());
+    size = ((sizeof(nvram_lid_enum) * LIDResetMax) + nvram_ota_buffer_size());
+    nvram_init_tmp_pool = (kal_uint32 *)get_ctrl_buffer(size);
+    kal_mem_set(nvram_init_tmp_pool, 0, size);
+
+    LIDResetArray = (nvram_lid_enum *)nvram_init_tmp_pool;
+    LIDCheckedArray = ((kal_uint8*)LIDResetArray + (sizeof(nvram_lid_enum) * LIDResetMax));
+    #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+    CALI_FileListBuf = (kal_uint8 *)get_ctrl_buffer(CALIBRATE_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH);
+    kal_mem_set(CALI_FileListBuf, 0, CALIBRATE_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH);
+    
+    IMEI_FileListBuf = (kal_uint8 *)get_ctrl_buffer(IMEI_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH);
+    kal_mem_set(IMEI_FileListBuf, 0, IMEI_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH);
+    #endif
+    LIDResetArray[0] = 0;  /* Count */
+    LIDResetCnt = 0;
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_filelost_precheck
+ * DESCRIPTION
+ *  check if assert when found the NVRAM_EF_SML_LID/NVRAM_EF_SIM_LOCK_LID lost
+ * PARAMETERS
+ *  LIDtoCheck      [IN]        Should be the assign record to check
+ *  default_value   [IN]           
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__)) 
+static kal_bool nvram_filelost_precheck(nvram_lid_enum LIDtoCheck,kal_uint8 *default_item_value)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    kal_bool result = KAL_FALSE;
+    
+    kal_uint16 rec_id = 1;//NVRAM_EF_SYS_LID
+    kal_uint8 *buffer;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    switch(LIDtoCheck)
+    {
+        case NVRAM_EF_SYS_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 1;
+            break;
+        case NVRAM_EF_BRANCH_VERNO_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 2;
+            break;
+        case NVRAM_EF_FLAVOR_VERNO_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 3;
+            break;
+        case NVRAM_EF_BUILD_TIME_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 4;
+            break;
+        default:
+            nvram_util_get_data_item(&ldi, LIDtoCheck);
+            break;
+    }
+    buffer = (kal_uint8*) get_ctrl_buffer(ldi->size);
+    kal_mem_set(buffer, 0, ldi->size);
+    if(nvram_read_data_item(ldi, rec_id, 1, buffer, ldi->size) == NVRAM_IO_ERRNO_OK)
+    {
+        if(NULL != strstr((const char *)buffer,(const char *)default_item_value))
+        {
+            result = KAL_FALSE;
+        }
+        else
+        {
+            result = KAL_TRUE;
+        }
+    }
+    else
+    {
+        result = KAL_FALSE;
+    }
+    free_ctrl_buffer(buffer);
+    return result;
+}
+
+#endif
+
+#if defined(__CCCIFS_SUPPORT__)
+static kal_bool nvram_update_SML_info(nvram_ltable_entry_struct *ldi,kal_uint32  ota_hdr_record_size,kal_uint32 ota_hdr_ldi_attr)
+{
+    kal_uint8 *old_value_buffer = NULL;
+    kal_uint8 *new_value_buffer = NULL;
+    kal_uint32 old_value_buffer_size = 0;
+    kal_uint32 new_value_buffer_size = 0;
+    kal_uint32 new_record_size = ldi->size; //backup the record size
+    kal_uint32 new_ldi_attr = ldi->attr ; //backup the LID attribute
+    nvram_errno_enum status;
+    kal_uint8 *data = NULL;
+    kal_uint32 i = 0;
+
+    //Alloc the memory to save the old SML data
+    old_value_buffer_size  = ldi->total_records *ota_hdr_record_size;
+    old_value_buffer = (kal_uint8 *)get_ctrl_buffer(old_value_buffer_size);
+    if((ota_hdr_ldi_attr & NVRAM_ATTR_MSP) != (ldi->attr & NVRAM_ATTR_MSP)) 
+    {
+         NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_ERROR_LOC_LID_ATTR_CHANGE_1,ota_hdr_ldi_attr);
+    }
+    if(old_value_buffer == NULL)
+    {
+        NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)old_value_buffer,NVRAM_LOC_BUFFER_PTR_IS_NULL_8,old_value_buffer_size);
+    } 
+    kal_mem_set(old_value_buffer,0, old_value_buffer_size);
+    
+    //Alloc the memory to save the new SML data
+    new_value_buffer_size  = ldi->total_records *new_record_size;
+    new_value_buffer = (kal_uint8 *)get_ctrl_buffer(new_value_buffer_size); 
+    if(new_value_buffer == NULL)
+    {
+        free_ctrl_buffer_set_null(old_value_buffer);
+        NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)new_value_buffer,NVRAM_LOC_BUFFER_PTR_IS_NULL_9,new_value_buffer_size);
+    }
+    kal_mem_set(new_value_buffer,0, new_value_buffer_size);
+    
+    //Update the old record size to LID table
+    ldi->size = ota_hdr_record_size;
+    //Update the old LID attribute to LID table
+    ldi->attr = ota_hdr_ldi_attr;
+    
+    //Read the old SML data from the storage
+    status = nvram_read_data_item(ldi,1,ldi->total_records , old_value_buffer,  old_value_buffer_size);
+    if(status != NVRAM_IO_ERRNO_OK)
+    {
+        free_ctrl_buffer_set_null(old_value_buffer);
+        free_ctrl_buffer_set_null(new_value_buffer);
+        NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_READ_IMPORTANT_DATA_FAIL_2,0);
+        return KAL_FALSE;
+    }
+    if(ldi->LID == NVRAM_EF_SML_LID)
+    {
+        //convert the old data to new data
+        /*
+        parameter description:
+         - kal_uint8 *old_value_buffer: the source point of data buffer
+         - kal_uint32 ota_hdr_record_size: old structure size
+         - kal_uint8 *new_value_buffer: destination point of data buffer
+         - kal_uint32 new_record_size: new structure size
+        */
+        nvram_sml_ota_converter(old_value_buffer,ota_hdr_record_size,new_value_buffer,new_record_size);
+    }
+    else
+    {
+        kal_mem_cpy(new_value_buffer,old_value_buffer,ota_hdr_record_size);
+    }
+    nvram_util_mark_file_uncreated(ldi);
+    //free the non-used buffer to avoid alloc new buffer fail
+    free_ctrl_buffer_set_null(old_value_buffer);
+
+    //Recover the record size and attribute
+    ldi->size = new_record_size;
+    ldi->attr = new_ldi_attr;
+
+    //Reset SML LID
+    if (!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        free_ctrl_buffer_set_null(new_value_buffer);
+        NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_3,0);
+        return KAL_FALSE;
+    }
+
+    //Update the New data to storage
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        data = new_value_buffer + (i-1)*ldi->size;
+         //write one record data per time
+        status = nvram_write_data_item(ldi, i, data, KAL_FALSE);
+        if(status != NVRAM_IO_ERRNO_OK)
+        {
+            free_ctrl_buffer_set_null(new_value_buffer);
+            NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_4,0);
+            return KAL_FALSE;
+        }
+    }
+
+    free_ctrl_buffer_set_null(new_value_buffer);
+    
+    return KAL_TRUE;
+}
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_file_lost_judgement
+ * DESCRIPTION
+ *  deal with nvram file lost condition
+ * PARAMETERS
+ *  LID     [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static kal_bool nvram_file_lost_judgement(nvram_ltable_entry_struct *ldi, kal_bool trigger_assert)
+{
+    #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__))
+    kal_char default_brach_verno[] = "LR12A.R1.MP";
+    switch(ldi->LID) {
+        case NVRAM_EF_SML_LID:
+        case NVRAM_EF_SIM_LOCK_LID:        
+        case NVRAM_EF_SML_GBLOB_LID:
+        case NVRAM_EF_SML_GBLOB_KEY_LID:
+        case NVRAM_EF_SML_S_LID:
+        case NVRAM_EF_SUBSIDY_LOCK_LID:
+        case NVRAM_EF_SUBSIDY_LOCK_ODM_DATA_LID:
+            /* Do not allow file lost */
+            if(trigger_assert && nvram_filelost_precheck(NVRAM_EF_BRANCH_VERNO_LID,(kal_uint8*)default_brach_verno)) {
+                NVRAM_EXT_ASSERT(KAL_FALSE, ldi->LID, NVRAM_LOC_READ_IMPORTANT_DATA_FAIL_1, -9); //FS_FILE_NOT_FOUND
+            }
+            return KAL_TRUE;
+        default:
+            break;
+    };
+    #endif
+    return KAL_FALSE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_construct_certain_disk_table
+ * DESCRIPTION
+ *  Construct the files in certain folder to disk table
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_construct_certain_disk_table(nvram_folder_enum folder_idx, kal_uint8 *rst_record_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE handle;
+    FS_DOSDirEntry fileinfo;
+    WCHAR namepattern[NVRAM_MAX_PATH_LEN];
+    WCHAR filename[NVRAM_FILE_LEN + 1];
+    char cfilename[NVRAM_FILE_LEN + 1];
+    char trace_filename[NVRAM_FILE_LEN + 1];
+    nvram_ldi_header nv_header;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_bool hdr_ret = KAL_TRUE;
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    chksum_rst_rec_struct *rst_rec_ptr = (chksum_rst_rec_struct *)rst_record_ptr;
+    kal_int32 chksum_index;
+    const char invalid_chksum[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
+    #endif
+    kal_int32 result = FS_NO_ERROR;    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_mem_set(&nv_header, 0x0, sizeof(nv_header));
+    nvram_query_file_name(folder_idx, "*", namepattern);
+    NVRAM_FS_START_EX(FS_OP_FINDFIRST,namepattern);
+    handle = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, filename, sizeof(filename));
+    NVRAM_FS_END(FS_OP_FINDFIRST,handle);
+    if (handle > 0)
+    {
+        do
+        {
+            // Get file header
+            nvram_query_file_name(folder_idx, "", namepattern);
+            kal_wstrcat(namepattern, filename);
+            kal_mem_set(&nv_header, 0x0, sizeof(nv_header));
+            hdr_ret = nvram_read_data_header(namepattern, LDI_HEADER_ALL_SECTION, (void*)&nv_header, NVRAM_LDI_HEADER_SIZE);
+            if(!hdr_ret) {
+                //read header fail, skip OTA this file
+                NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]nvram_construct_certain_disk_table() ->nvram_read_data_header %s fail\r\n",cfilename);
+                goto find_next_file;
+            }
+
+            // check in ltable
+            kal_dchar2char(filename, cfilename);
+            if(!nvram_util_get_data_item_by_fileprefix(&ldi, cfilename)) {
+                if(NVRAM_IS_ATTR_RESERVE_BACKWARD(nv_header.nv_ota_header.ldi_attr)) {
+                    hdr_ret = nvram_ota_backup_file(namepattern, &(nv_header.nv_ota_header));
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]backup file %s at %d\r\n",cfilename,__LINE__);
+                }
+                NVRAM_FS_START_EX(FS_OP_DELETE, namepattern);
+                result = FS_Delete(namepattern);
+                NVRAM_FS_END(FS_OP_DELETE,result);
+                goto find_next_file;
+            }
+
+            // check file verno
+            // check file category
+            kal_dchar2char(&filename[NVRAM_FILE_LEN - FILE_VERNO_LEN], cfilename);
+            kal_dchar2char(&filename[NVRAM_FILE_LEN - NVRAM_FILE_LEN], trace_filename);
+            if((strcmp(ldi->fileverno, cfilename) == 0) && strcmp(nv_header.nv_ota_header.header,"LDI")){
+                nvram_prepare_data_header(ldi,(kal_uint8 *)(&nv_header));
+                nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION);
+            }
+            if(strcmp(ldi->fileverno, cfilename) ||
+                (ldi->category != nv_header.nv_ota_header.ldi_category) ) 
+            {
+                if(NVRAM_IS_ATTR_RESERVE_BACKWARD(nv_header.nv_ota_header.ldi_attr)) {
+                    hdr_ret = nvram_ota_backup_file(namepattern, &(nv_header.nv_ota_header));
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]backup file %s at %d\r\n",cfilename,__LINE__);
+                }
+                NVRAM_FS_START_EX(FS_OP_DELETE,namepattern);
+                result = FS_Delete(namepattern);
+                NVRAM_FS_END(FS_OP_DELETE,result);
+                if(strcmp(ldi->fileverno, cfilename)) {
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]new VERNO %s mismatch ->VERNO:%s \r\n", ldi->fileverno, cfilename);
+                }
+                if(ldi->category != nv_header.nv_ota_header.ldi_category) {
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]new Category 0x%08X mismatch ->Category:0x%08X\r\n", (kal_uint32)ldi->category, (kal_uint32)nv_header.nv_ota_header.ldi_category);
+                }                
+                goto find_next_file;
+            }
+
+            // check NVRAM_ATTR_OTA_RESET
+            if(NVRAM_IS_ATTR_OTA_RESET(ldi->attr)) {
+                nvram_report_reset_data_item(ldi->LID);
+                NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan
+                NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Mark LID 0x%04X with OTA_RESET,attr 0x%08X,filename:%s\r\n",ldi->LID, (kal_uint32)ldi->attr,trace_filename);
+                goto find_next_file;
+            }
+
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]name%s->LID 0x%04x NVRAM_LOC_ATTRIBUITE_2:(0x%x), nv_hd_attr(0x%x)\r\n", cfilename, ldi->LID, ldi->attr, nv_header.nv_ota_header.ldi_attr);
+            // check NVRAM checksum algorithm whether change
+            #ifdef __NV_CHKSUM_ENHANCE__
+            if(NVRAM_IO_ERRNO_OK == nvram_ota_for_lid_chksum_algo(&nv_header, ldi))
+            {
+                NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan
+                NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                goto find_next_file;
+            }
+            #endif
+                
+            //for R1->R2 OTA NVRAM_EF_SIM_LOCK_LID LID attribute change
+            #if defined(__CCCIFS_SUPPORT__)
+            if((nv_header.nv_ota_header.ldi_attr != ldi->attr )&& (ldi->LID == NVRAM_EF_SIM_LOCK_LID))
+            {
+                if((nv_header.nv_ota_header.ldi_attr & NVRAM_ATTR_MULTIPLE) != (ldi->attr & NVRAM_ATTR_MULTIPLE)) 
+                {
+                    hdr_ret = nvram_update_SML_info(ldi,nv_header.nv_ota_header.record_size,nv_header.nv_ota_header.ldi_attr);
+                    if(hdr_ret == KAL_FALSE)
+                    {
+                       NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_5,0);
+                    }
+                    NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                    NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan
+                    goto find_next_file;
+                }
+            }
+            #endif
+            // check record & size
+            if((nv_header.nv_ota_header.record_size != ldi->size) || (nv_header.nv_ota_header.total_records!= ldi->total_records)) {
+                /*
+                #if defined (__NVRAM_UT_TEST__)
+                if(NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) || NVRAM_IS_CATEGORY_IMPORTANT(ldi->category)
+                   #if defined(__CCCIFS_SUPPORT__)
+                   || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)
+                   #endif
+                    )
+                    {
+                        FS_FindClose(handle);
+                    }
+                #endif                
+                */
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X size changed:record size %d -> %d\r\n",ldi->LID,nv_header.nv_ota_header.record_size,ldi->size);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]record number %d -> %d\r\n",nv_header.nv_ota_header.total_records,ldi->total_records);
+                //Calibration data and Important data sensitive to size change
+                NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_CALIBRAT(ldi->category), ldi->LID, NVRAM_LOC_CALIBRATION_SIZE_CHANGE, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records));
+                NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT(ldi->category), ldi->LID, NVRAM_LOC_IMPORTANT_SIZE_CHANGE, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records));
+                #if defined(__CCCIFS_SUPPORT__)
+                //for R1->R2 OTA SML Structure size change
+                if(ldi->LID == NVRAM_EF_SML_LID &&
+                    ((nv_header.nv_ota_header.record_size == 0x0104 && ldi->size == 0x00CC) ||(nv_header.nv_ota_header.record_size == 0x00CC && ldi->size == 0x0104))) 
+                {
+                    hdr_ret = nvram_update_SML_info(ldi,nv_header.nv_ota_header.record_size,nv_header.nv_ota_header.ldi_attr);
+                    if(hdr_ret == KAL_FALSE)
+                    {
+                       NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_2,0);
+                    }
+                    NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                    NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan
+                    goto find_next_file;
+                }
+                #if defined(__MTK_INTERNAL_ENG_USER__)
+                NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category), ldi->LID, NVRAM_LOC_INVALID_LID_SIZE_4, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records));
+                #else
+                if(NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) && (ldi->attr & NVRAM_ATTR_FAULT_ASSERT))
+                {
+                    NVRAM_EXT_ASSERT(KAL_FALSE, ldi->LID, NVRAM_LOC_INVALID_LID_SIZE_4, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records));
+                }
+                #endif
+                #endif
+                //Try to backup and restore LID
+                if(NVRAM_IS_ATTR_RESERVE_BACKWARD(nv_header.nv_ota_header.ldi_attr)) {
+                    hdr_ret = nvram_ota_backup_file(namepattern, &(nv_header.nv_ota_header));
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Backup at %d\r\n",trace_filename,__LINE__);
+                    if(!nvram_ota_restore_file(ldi)) {
+                        //bypass size change when OTA
+                        //nvram_report_reset_data_item(ldi->LID);
+                        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Restore fail\r\n", trace_filename);
+                    }
+                    else {
+                        //file restore success
+                        NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                        NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan
+                        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Restore success\r\n", trace_filename);
+                    }
+                }
+                else {
+                    //bypass size change when OTA
+                    //nvram_report_reset_data_item(ldi->LID);
+                    NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                    NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Ignore\r\n", trace_filename);
+                }
+                goto find_next_file;
+            }
+
+            #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+            if(NVRAM_IS_CATEGORY_IMPORTANT_L1(ldi->category) || (NVRAM_NVD_DATA == nvram_query_folder_index(ldi->category)))
+            {
+                if(NVRAM_IS_ATTRIBUTE_CHANGE(nv_header, ldi))
+                {
+                    nvram_report_reset_data_item(ldi->LID);
+                    NVRAM_SET_OTA_MARKED(ldi->LID);
+                    goto find_next_file;
+                }
+            }
+            
+            if(NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi) || NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi))
+            {
+                if(! kal_mem_cmp((const char*)(nv_header.nv_dbg_header.struct_chkrst), (const char*)invalid_chksum, RST_CHKSUM_SIZE))
+                {
+                    nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION);
+                    NVRAM_SET_OTA_MARKED(ldi->LID);
+                    NVRAM_SET_CREATEED_FILE_INFO(ldi->LID);
+                    goto find_next_file;
+                }
+            }
+            #endif
+
+            #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
+            if(NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi))
+            {
+                chksum_index = nvram_get_structure_chksum_index(ldi->LID);
+                if(-1 != chksum_index)
+                {
+                    if(kal_mem_cmp((const char *)(nv_header.nv_dbg_header.struct_chkrst), (const char *)(lid_structure_chksum[chksum_index].chksum), RST_CHKSUM_SIZE))
+                    {
+                        nvram_report_reset_data_item(ldi->LID);
+                        //record reset LID info
+                        if(rst_rec_ptr->structure_rst_index >= NVRAM_CHKSUM_RST_REC_NUM)
+                            rst_rec_ptr->structure_rst_index = 0;
+                        rst_rec_ptr->structure_rst[rst_rec_ptr->structure_rst_index].LID= ldi->LID;
+                        strncpy(rst_rec_ptr->structure_rst[rst_rec_ptr->structure_rst_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN);
+                        NVRAM_SET_OTA_MARKED(ldi->LID);
+                        rst_rec_ptr->structure_rst_index = (rst_rec_ptr->structure_rst_index+1)%NVRAM_CHKSUM_RST_REC_NUM;
+                        goto find_next_file;
+                    }
+                }
+                else
+                {
+                    if(rst_rec_ptr->structure_chksum_nofound_index >= NVRAM_CHKSUM_RST_REC_NUM)
+                        rst_rec_ptr->structure_chksum_nofound_index = 0;
+                    rst_rec_ptr->structure_chksum_nofound[rst_rec_ptr->structure_chksum_nofound_index].LID = ldi->LID;
+                    strncpy(rst_rec_ptr->structure_chksum_nofound[rst_rec_ptr->structure_chksum_nofound_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN);
+                    rst_rec_ptr->structure_chksum_nofound_index = (rst_rec_ptr->structure_chksum_nofound_index+1)%NVRAM_CHKSUM_RST_REC_NUM;
+                }
+            }
+            #endif
+            
+            #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+            if(NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi))
+            {
+                chksum_index = nvram_get_defval_chksum_index(ldi->LID);
+                if(-1 != chksum_index)
+                {
+                    if(kal_mem_cmp((const char *)(nv_header.nv_ota_header.defval_chkrst_h), (const char *)(lid_default_value_chksum[chksum_index].chksum), RST_CHKSUM_SIZE-6) ||
+                        kal_mem_cmp((const char *)(nv_header.nv_dbg_header.defval_chkrst_l), (const char*)(&(lid_default_value_chksum[chksum_index].chksum[RST_CHKSUM_SIZE-6])), 6))
+                    {
+                        nvram_report_reset_data_item(ldi->LID);
+                        //record reset LID info
+                        if(rst_rec_ptr->defval_rst_index >= NVRAM_CHKSUM_RST_REC_NUM)
+                            rst_rec_ptr->defval_rst_index = 0;                        
+                        rst_rec_ptr->defval_rst[rst_rec_ptr->defval_rst_index].LID = ldi->LID;
+                        strncpy(rst_rec_ptr->defval_rst[rst_rec_ptr->defval_rst_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN);
+                        NVRAM_SET_OTA_MARKED(ldi->LID);
+                        rst_rec_ptr->defval_rst_index = (rst_rec_ptr->defval_rst_index+1)%NVRAM_CHKSUM_RST_REC_NUM;
+                        goto find_next_file;
+                    }
+                }
+                else
+                {
+                    if(rst_rec_ptr->defval_chksum_nofound_index >= NVRAM_CHKSUM_RST_REC_NUM)
+                        rst_rec_ptr->defval_chksum_nofound_index = 0;
+                    rst_rec_ptr->defval_chksum_nofound[rst_rec_ptr->defval_chksum_nofound_index].LID = ldi->LID;
+                    strncpy(rst_rec_ptr->defval_chksum_nofound[rst_rec_ptr->defval_chksum_nofound_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN);
+                    rst_rec_ptr->defval_chksum_nofound_index = (rst_rec_ptr->defval_chksum_nofound_index+1)%NVRAM_CHKSUM_RST_REC_NUM;
+                }
+            }            
+            #endif
+
+            //mark resolved, bypass 2nd scan
+            NVRAM_SET_OTA_MARKED(ldi->LID);
+            // file match ldi, record to bitmap
+            NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+find_next_file:
+          NVRAM_FS_START(FS_OP_FINDNEXT);
+          result = FS_FindNext(handle, &fileinfo, filename, sizeof(filename));
+          NVRAM_FS_END(FS_OP_FINDNEXT,result);
+        }
+        while (result == FS_NO_ERROR);
+    }
+#ifdef __NVRAM_DISK_SIZE_CHECK__
+    else
+    {
+        if (files_in_folder[folder_idx] != 0)
+        {
+            return KAL_FALSE;
+        }
+        else
+        {
+            return KAL_TRUE;
+        }
+    }
+#endif
+    NVRAM_FS_START(FS_OP_FINDCLOSE);
+    result = FS_FindClose(handle);
+    NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_construct_disk_table
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *
+ *****************************************************************************/
+static kal_bool nvram_construct_disk_table(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 loop_idx;
+    kal_uint8* rst_rec_ptr;
+    kal_bool  ret;
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    nvram_ltable_entry_struct *ldi;
+    #endif
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (!nvram_malloc_disk_table())
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA][Error]%s fail\r\n", __FUNCTION__);
+        return KAL_FALSE;
+    }
+    rst_rec_ptr = (kal_uint8*) get_ctrl_buffer(NVRAM_EF_CHKSUM_RESET_REC_SIZE);
+    kal_mem_set(rst_rec_ptr, 0x0, NVRAM_EF_CHKSUM_RESET_REC_SIZE);
+
+    for (loop_idx = NVRAM_FOLDER_TOTAL; loop_idx > NVRAM_FOLDER_BEGIN ; loop_idx--)
+    {
+        //skip scan OTA backup folder
+        if((nvram_folder_enum)(loop_idx - 1) == NVRAM_NVD_BACKUP) {
+            continue;
+        }
+        
+        ret = nvram_construct_certain_disk_table((nvram_folder_enum)(loop_idx - 1), rst_rec_ptr);
+
+        if (!ret)
+        {
+            nvram_destruct_disk_table();
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA][Error]nvram_construct_certain_disk_table() fail ret= %d", (kal_uint32)ret);
+            free_ctrl_buffer(rst_rec_ptr);
+            return KAL_FALSE;
+        }
+    }
+    
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    nvram_util_get_data_item(&ldi, NVRAM_EF_CHKSUM_RESET_REC_LID);
+    nvram_write_data_item(ldi, 1, rst_rec_ptr, KAL_FALSE);
+    #endif
+    free_ctrl_buffer(rst_rec_ptr);
+    
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_version_conflict_resolve
+ * DESCRIPTION
+ *  To perform software upgrade.
+ * PARAMETERS
+ *  sysrecord       [IN]        Sysrecord
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_version_conflict_resolve(kal_uint8 *sysrecord)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    kal_uint32 file_idx;
+    kal_uint32 index;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /*****************************************************
+        * Launch power first and show the first picture
+        ******************************************************/
+    nvram_util_poweron();
+#if !defined(__L1_STANDALONE__) && !defined(EMPTY_MMI) && !defined(EXTERNAL_MMI)
+    MMICheckDiskDisplay();
+#endif
+    
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    nvram_util_take_mutex(nvram_bitmap_mutex);
+    nvram_utile_reset_lid_bitmap();
+    nvram_util_give_mutex(nvram_bitmap_mutex);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->nvram_utile_reset_lid_bitmap()\r\n\r\n\r\n",__FUNCTION__);
+#endif
+    /*********************************************************************/
+    /****** 1st phase for loop starts here. The looping is based on the Exist File ******/
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage1 Start\r\n",__FUNCTION__);
+    if (!nvram_construct_disk_table())
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]][OTA]%s->nvram_construct_disk_table() fail\r\n",__FUNCTION__);
+        return KAL_FALSE;
+    }
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_VERSION_CONFLICT_RESOLVE_STAGE1;
+        nvram_ee_info->nvram_init_time[9] = kal_get_systicks();
+    }
+    /****** 1st phase for loop ends here ******/
+    /*===========================*/
+    
+#ifdef __NVRAM_DISK_SIZE_CHECK__
+    if (!nvram_conflict_resolve_prelim(sysrecord))
+    {
+        return nvram_destruct_disk_table();
+    }
+#endif
+
+    MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(0);   
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage1 End\r\n\r\n\r\n",__FUNCTION__);
+    /***********************************************************************/
+    /****** 2nd phase for loop starts here. The looping is based on the Code table ******/
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage2 Start\r\n",__FUNCTION__);
+    ldi = &logical_data_item_table[0];
+    do
+    {
+        /* skip pre-resolve marked lid */
+        if(NVRAM_CHK_CREATEED_FILE_INFO(ldi->LID)) { //bypass exist file            
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Skip Pre-resolved LID 0x%04X\r\n",__FUNCTION__,ldi->LID);
+            continue;
+        }        
+        /* skip special lid */
+        if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+            continue;
+        }
+
+        /* those data items need to be reset to code default values */
+        if (ldi->attr & NVRAM_ATTR_OTA_RESET)
+        {            
+            nvram_report_reset_data_item(ldi->LID);
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X with OTA_RESET->Mark Reset in Stage2\r\n",ldi->LID);
+        }
+        else
+        {
+            #ifdef __NVRAM_PSEUDO_MERGE__
+            if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+            {
+                continue;   /* this function will not deal with package lid */
+            }
+            else
+            #endif
+            //bypass 1st phase marked file
+            if(NVRAM_CHK_OTA_MARKED(ldi->LID)) {                
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Bypass LID 0x%04X marked in Stage1\r\n",ldi->LID);
+                continue;
+            }
+            nvram_file_lost_judgement(ldi, KAL_TRUE);
+            // try restore from bin region
+            #if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__)
+            if (NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category)) {
+                if (nvram_recover_data_item(ldi) == NVRAM_IO_ERRNO_OK) {
+                    NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X ->nvram_recover_data_item()Success\r\n",ldi->LID);
+                    continue;
+                }
+                else {                    
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]LID 0x%04X ->nvram_recover_data_item() Fail\r\n",ldi->LID);
+                }
+            }
+            #endif
+            // try restore from reserved folder
+            if(NVRAM_IS_ATTR_RESERVE_BACKWARD(ldi->attr)) {
+                if(nvram_ota_restore_file(ldi)) {
+                    //file restore success
+                    NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist                    
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X ->nvram_ota_restore_file() Success\r\n",ldi->LID);
+                    continue;
+                }
+                else {
+                    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]LID 0x%04X ->nvram_ota_restore_file() Fail\r\n",ldi->LID);
+                }
+            }
+            
+            nvram_report_reset_data_item(ldi->LID);            
+            NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X ->Mark Reset in Stage2\r\n",ldi->LID);
+        }        
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->nvram_util_next_data_item \r\n",__FUNCTION__);
+    }while(nvram_util_next_data_item(&ldi));
+
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)    
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->take nvram_bitmap_mutex\r\n",__FUNCTION__);
+    nvram_util_take_mutex(nvram_bitmap_mutex);
+    nvram_delete_bitmap_file();
+    nvram_write_bitmap_into_file();
+    nvram_util_give_mutex(nvram_bitmap_mutex);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->give nvram_bitmap_mutex\r\n",__FUNCTION__);
+#endif
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_VERSION_CONFLICT_RESOLVE_STAGE2;
+        nvram_ee_info->nvram_init_time[10] = kal_get_systicks();
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage2 End\r\n\r\n\r\n",__FUNCTION__);
+    MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(1);
+    /****** 2nd phase for loop ends here ******/
+    /*===========================*/
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage3 Start\r\n",__FUNCTION__);
+    nvram_create_report_file();
+
+    /*************************************************************************/
+    /******** 3rd phase for loop starts here. The looping is based on LIDResetCnt ********/
+    for (index = 1; index <= LIDResetCnt; index++)
+    {
+        file_idx = LIDResetArray[index];
+
+        nvram_util_get_data_item(&ldi, file_idx);
+
+        if (!ldi)
+        {
+            continue;
+        }
+    #ifdef __NVRAM_BACKUP_DISK__
+        if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_ATTR_BACKUP_RAW(ldi->attr))
+        {
+            if (nvram_recover_image_by_lid(ldi) == NVRAM_ERRNO_SUCCESS)
+            {
+                continue;
+            }
+        }
+    #endif
+
+        if (!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]%s-> nvram_reset_data_items() Fail \r\n",__FUNCTION__);
+            return nvram_destruct_disk_table();
+        }
+        NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s-> nvram_reset_data_items() Success \r\n",__FUNCTION__);
+    }
+    /****** 3rd phase for loop ends here ******/
+    /*===========================*/
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_VERSION_CONFLICT_RESOLVE_STAGE3;
+        nvram_ee_info->nvram_init_time[11] = kal_get_systicks();
+    }
+    MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(3);
+    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage3 End\r\n\r\n\r\n",__FUNCTION__);
+    
+    /****** rewrite system records ******/
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+    if (!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]%s-> Reset NVRAM_EF_SYS_LID Fail\r\n",__FUNCTION__);
+        return nvram_destruct_disk_table();
+    }
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_RESET_SYS_LID_FILE_DONE;
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID);
+    nvram_write_data_item(ldi, 1, nvram_ptr->build_time, KAL_TRUE);
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_UPDATE_BUILD_TIME_FILE_DONE;
+    }
+
+    #ifdef __NV_CHKSUM_ENHANCE__
+    nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_CHKSUM_INFO_LID);
+    if(ldi == NULL)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]%s->LINE 0x%04x :lid is NULL\r\n", __FUNCTION__, __LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE, NVRAM_EF_CORE_CHKSUM_INFO_LID, NVRAM_LOC_INVALID_LID_6, 0, __LINE__);
+    }
+    nvram_write_data_item(ldi, 1, (kal_uint8 *)(&(chksum_algo_ptr->cur_algo)), KAL_TRUE);
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_UPDATE_CHKSUM_INFO_FILE_DONE;
+    }
+    #endif
+    MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(4);
+
+    return nvram_destruct_disk_table();
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_system_record
+ * DESCRIPTION
+ *  This function is used to write system record
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+
+kal_bool nvram_write_system_record(nvram_lock_state_enum lock_state)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool write_status = KAL_FALSE;
+    nvram_ltable_entry_struct *ldi;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (lock_state == NVRAM_LOCK_DISABLE)
+    {
+        nvram_ptr->lock = KAL_FALSE;
+    }
+    else if (lock_state == NVRAM_LOCK_ENABLE)
+    {
+        nvram_ptr->lock = KAL_TRUE;
+    }
+    else
+    {
+        /* use default value assigned by custom */
+        nvram_ptr->lock = nvram_custom_lock_status();
+    }
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock;
+    }
+    nvram_assign_system_record_default_value((kal_char *)nvram_ptr->coded_version, release_verno());
+    nvram_update_lock_state(nvram_ptr->lock);
+	
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+    write_status = nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records);   
+    /* Fatal error. Cannot write system-level record!? */
+    NVRAM_EXT_ASSERT(write_status == KAL_TRUE, 0, NVRAM_LOC_WRITE_SYS_LID_FAIL, nvram_ptr->state);
+
+    return write_status;
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_supplementary_check_data_item_for_fw
+ * DESCRIPTION
+ *  do the supplementary check :build time check
+ * PARAMETERS
+ *  LIDtoCheck      [IN]        Should be the record to check
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static kal_bool nvram_supplementary_check_data_item_for_fw()
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    kal_bool result = KAL_FALSE;
+    kal_uint8 *buffer = NULL;
+    kal_uint8 *default_value = NULL; 
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+    
+    buffer = (kal_uint8*) get_ctrl_buffer(ldi->size);
+    default_value = (kal_uint8*) get_ctrl_buffer(ldi->size);
+    nvram_get_default_value_to_write(ldi, 4, default_value, ldi->size); //get the build time
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID);
+    if (nvram_read_data_item(ldi, 1, 1, buffer, ldi->size) == NVRAM_IO_ERRNO_OK)
+    {
+        if (kal_mem_cmp((kal_char*) buffer, (kal_char*) default_value, ldi->size) != 0)
+        {
+            result = KAL_FALSE;
+        }
+        else
+        {
+            result = KAL_TRUE;
+        }
+    }
+    else
+    {
+        result = KAL_FALSE;
+    }    
+    free_ctrl_buffer(default_value);
+    free_ctrl_buffer(buffer);
+    return result;
+}
+
+void update_old_md_version_to_nvram_ee_info()
+{
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 *buffer = NULL;
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+    buffer = (kal_uint8*) get_ctrl_buffer(4*ldi->size);
+    kal_mem_set(buffer,0,4*ldi->size);
+    //rec_id:1->code version;rec_id:2->NVRAM_EF_BRANCH_VERNO_LID;
+    //rec_id:3->NVRAM_EF_FLAVOR_VERNO_LID;4->NVRAM_EF_BUILD_TIME_LID
+    if (nvram_read_data_item(ldi, 1, 4, buffer, 4*ldi->size) == NVRAM_IO_ERRNO_OK)
+    {
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_START;
+            kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_coded_version), (kal_uint8*)buffer, NVRAM_MD_VERSION_INFO_SIZE);
+            kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_branch_version), (kal_uint8*)(buffer+ldi->size), NVRAM_MD_VERSION_INFO_SIZE);
+            kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_flavor_version), (kal_uint8*)(buffer+2*ldi->size), NVRAM_MD_VERSION_INFO_SIZE);
+            kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_build_time), (kal_uint8*)(buffer+3*ldi->size), NVRAM_MD_VERSION_INFO_SIZE);
+            nvram_ee_info->nvram_init_time[8] = kal_get_systicks();            
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old coded_version: %s \r\n",nvram_ee_info->nvram_init_context.old_coded_version);        
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old branch_version: %s \r\n",nvram_ee_info->nvram_init_context.old_branch_version);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old flavor_version: %s \r\n",nvram_ee_info->nvram_init_context.old_flavor_version);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old build_time: %s \r\n",nvram_ee_info->nvram_init_context.old_build_time);        
+        }
+    }
+    free_ctrl_buffer(buffer);
+    return;
+}
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_supplementary_check_data_item
+ * DESCRIPTION
+ *  do some supplementary check, such as branch or customer package
+ * PARAMETERS
+ *  LIDtoCheck      [IN]        Should be the record to check
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static kal_bool nvram_supplementary_check_data_item(nvram_lid_enum LIDtoCheck)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    kal_bool result = KAL_FALSE;
+    kal_uint16 rec_id = 1;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    
+    switch(LIDtoCheck)
+    {
+        case NVRAM_EF_SYS_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 1;
+            break;
+        case NVRAM_EF_BRANCH_VERNO_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 2;
+            break;
+        case NVRAM_EF_FLAVOR_VERNO_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 3;
+            break;
+        case NVRAM_EF_BUILD_TIME_LID:
+            nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+            rec_id = 4;
+            break;
+        default:
+            nvram_util_get_data_item(&ldi, LIDtoCheck);
+            break;
+    }
+    
+    {
+        kal_uint8 *buffer = (kal_uint8*) get_ctrl_buffer(ldi->size);
+
+        if (nvram_read_data_item(ldi, rec_id, 1, buffer, ldi->size) == NVRAM_IO_ERRNO_OK)
+        {
+            kal_uint8 *default_value = (kal_uint8*) get_ctrl_buffer(ldi->size);    
+            
+            nvram_get_default_value_to_write(ldi, rec_id, default_value, ldi->size);
+            
+            if (kal_mem_cmp((kal_char*) buffer, (kal_char*) default_value, ldi->size) != 0)
+            {
+                result = KAL_FALSE;
+            }
+            else
+            {
+                result = KAL_TRUE;
+            }
+            free_ctrl_buffer(default_value);
+        }
+        else
+        {
+            result = KAL_FALSE;
+        }
+        free_ctrl_buffer(buffer);
+    }
+
+    return result;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_supplementary_check
+ * DESCRIPTION
+ *  do some supplementary check, such as branch or customer package
+ * PARAMETERS
+ *
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static kal_bool nvram_supplementary_check(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool temp_result = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /* Step 1: handle branch(flavor)/BIN change */
+    /* branch and flavor must all same with before, or else reset branch */
+    if ((!nvram_supplementary_check_data_item(NVRAM_EF_BRANCH_VERNO_LID))
+        || (!nvram_supplementary_check_data_item(NVRAM_EF_FLAVOR_VERNO_LID)))
+    {
+        MD_TRC_FUNC_NVRAM_SUPPLEMENTARY_CHECK(0);
+    #if defined(__CCCIFS_SUPPORT__)
+        // [Smart Phone Modem][Telephony Load Reduction] && [Data Card][RNDIS/HOSTED Dongle]
+        // Skip flavor checks, because of LID sharing between modems.
+    #else
+        temp_result = nvram_reset_data_items(NVRAM_RESET_BRANCH, NVRAM_APP_RESERVED, NULL, 0, 0);
+    #endif
+        nvram_ptr->sw_status |= NVRAM_SW_BRANCH_CHANGE;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+        }
+    }
+
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+    /* Step 2: handle custpack change */
+    if (!nvram_supplementary_check_data_item(NVRAM_EF_CUSTPACK_VERNO_LID))
+    {
+        MD_TRC_FUNC_NVRAM_SUPPLEMENTARY_CHECK(1);
+        temp_result = nvram_reset_data_items(NVRAM_RESET_CUSTPACK, NVRAM_APP_RESERVED, NULL, 0, 0);
+        nvram_ptr->sw_status |= NVRAM_SW_CUSTPACK_CHANGE;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+        }
+    }
+#endif
+
+    return temp_result;
+}
+
+#if !defined(__MTK_INTERNAL_ENG_USER__) && defined(__NVRAM_INIT_ACTIVE_RECOVER__)
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_all_ldi
+ * DESCRIPTION
+ *  Recover select category from bin region
+ *
+ * PARAMETERS
+ *  category          [IN]
+ * RETURNS
+ *  KAL_TRUE if success, KAL_FALSE otherwise.
+ *****************************************************************************/
+static kal_bool nvram_recover_all_ldi(nvram_category_enum category)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi;
+    NVRAM_FILE_NAME nvramname;
+    nvram_folder_enum folder_index;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    //check nvram lock flag
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_LOCK_LID);
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    if(nvram_drv_fat_auto_recover(nvramname, folder_index) != NVRAM_ERRNO_SUCCESS) {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s nvram_drv_fat_auto_recover NVRAM_EF_NVRAM_LOCK_LID fail\r\n",__FUNCTION__);
+        return KAL_FALSE;
+    }
+
+    //try to recover category
+    ldi = &logical_data_item_table[0];
+    do
+    {
+        if (!(ldi->category & category) || (ldi->LID == NVRAM_EF_NVRAM_LOCK_LID)) {
+            continue;
+        }
+        folder_index = nvram_query_folder_index(ldi->category);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+        nvram_drv_fat_auto_recover(nvramname, folder_index);
+    }while(nvram_util_next_data_item(&ldi));
+    
+    return KAL_TRUE;
+}
+#endif
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_init_all_ldi
+ * DESCRIPTION
+ *  Formats device by invoking drv_format() function. Re-initialize all logical data items to
+ *  default value.
+ *
+ *  This function is supposed to be called only when:
+ *  1> unformatted device.
+ *  2> system level record read error.
+ *  3> incompatible version.
+ * PARAMETERS
+ *  reset_category          [IN]
+ *  is_after_format(?)      [IN]        Only when device is just re-formatted will this value be true.
+ * RETURNS
+ *  Result of writing system records. KAL_TRUE if success, KAL_FALSE otherwise.
+ *****************************************************************************/
+static kal_bool nvram_init_all_ldi(nvram_reset_category_enum reset_category)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    /*****************************************************
+        * Launch power first and show the first picture
+        ******************************************************/
+    nvram_util_poweron();
+#if !defined(__L1_STANDALONE__) && !defined(EMPTY_MMI) && !defined(EXTERNAL_MMI)
+    MMICheckDiskDisplay();
+#endif
+
+#ifdef __NVRAM_WRITE_WITH_FILE_SIZE__
+    bResetNvramData = KAL_TRUE;
+#endif
+
+    MD_TRC_FUNC_NVRAM_INIT_ALL(reset_category);
+    reset_category = NVRAM_RESET_ALL;
+    if (reset_category == NVRAM_RESET_ALL)
+    {
+        if (nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT)
+        {
+            nvram_delete_all_nvram_files(NVRAM_FIRST_BOOTUP);
+        }
+        else
+        {
+            nvram_delete_all_nvram_files(NVRAM_NORMAL_BOOTUP);
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTOR_BOOT_DELETE_NVDATA_DONE;
+                nvram_ee_info->nvram_init_time[5] = kal_get_systicks();
+            }
+        }
+    }
+
+    nvram_reset_data_items(reset_category, NVRAM_APP_RESERVED, NULL, 0, 0);
+    nvram_write_system_record((nvram_lock_state_enum)nvram_ptr->lock);
+    if(nvram_ee_info != NULL){
+        if(nvram_ee_info->nvram_init_step ==NVRAM_CORE_INIT_FIRST_BOOT_RESET_ALL_FILE_DONE){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_RESET_SYS_LID_FILE_DONE;
+        }
+        else if(nvram_ee_info->nvram_init_step ==NVRAM_CORE_INIT_FACTOR_BOOT_RESET_NON_CRITICAL_FILE_DONE){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTOR_BOOT_RESET_SYS_LID_FILE_DONE;
+            nvram_ee_info->nvram_init_time[6] = kal_get_systicks();
+        }
+    }
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_test_lock
+ * DESCRIPTION
+ *  get lock state from nvram context.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  KAL_TRUE if locked, else KAL_FALSE
+ *****************************************************************************/
+kal_bool nvram_test_lock(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    return nvram_ptr->lock;
+}
+
+kal_bool nvram_sec_check(void){
+#ifdef __NVRAM_SEC_CHECK_EN__
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8* sec_pattern=NULL;
+    kal_uint8* record_buf_ptr;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 idx = 0;
+    kal_uint32 record_sz, record_cnt, sec_pattern_sz;
+
+     record_sz = NVRAM_SEC_CHECK_LEN;
+     record_cnt = NVRAM_EF_NVRAM_SEC_CHECK_TOTAL; 
+     sec_pattern_sz = record_sz*record_cnt;
+	
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    sec_pattern = (kal_uint8*) get_ctrl_buffer(sec_pattern_sz);
+
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_SEC_CHECK_LID);
+    kal_mem_set(sec_pattern, 0, sec_pattern_sz);
+    nvram_read_data_item(ldi, 1, record_cnt, sec_pattern, sec_pattern_sz);
+
+    record_buf_ptr = sec_pattern;
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32)(record_buf_ptr), record_sz, nvram_ptr->secret_key, record_buf_ptr);
+    for(idx= 0; idx<record_sz/2; idx++){
+	if(record_buf_ptr[idx]!=((~(record_buf_ptr[idx+record_sz/2]))&0xFF)){
+		NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_ERRNO_MSP_CHECK_ERROR,0, free_ctrl_buffer(sec_pattern));
+	}
+    }
+#endif
+   record_buf_ptr = &sec_pattern[record_sz];
+    nvram_AES_decrypt(record_buf_ptr, record_sz);
+
+    for(idx= 0; idx<record_sz/2; idx++){
+	if(record_buf_ptr[idx]!=((~(record_buf_ptr[idx+record_sz/2]))&0xFF)){
+		NVRAM_EXT_ASSERT(KAL_FALSE,0,NVRAM_ERRNO_CONF_CHECK_ERROR,0, free_ctrl_buffer(sec_pattern));
+	}
+   }
+
+	free_ctrl_buffer(sec_pattern);
+#endif
+	return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_init
+ * DESCRIPTION
+ *  This is init() function of NVRAM module.
+ *  This function initialize all the context variables required for NVRAM module
+ * PARAMETERS
+ *  task_indx       [IN]
+ * RETURNS
+ *  True if succeed.
+ *****************************************************************************/
+kal_bool nvram_init(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool ld_init_result = KAL_TRUE;
+    nvram_drv_status_enum drv_init_result = NVRAM_ERRNO_SUCCESS;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 Ret = 0;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* Assume that BytesPerCluster still not initialized if BytesPerCluster==0 */        
+    
+	nvram_ee_info_init();
+    nvram_get_trace_configuration();
+    NVRAM_INIT_TIME_UT_STAMP(0);
+    if (BytesPerCluster == 0)
+    {
+        /* Please do not remove this code if NVRAM still use kal_tmp_mem_alloc
+           The detail reason please see nvram_malloc_disk_table */
+        FS_DiskInfo DI;
+        NVRAM_FS_START_EX(FS_OP_GETDISKINFO, L"Z:\\");
+        Ret = FS_GetDiskInfo((const WCHAR*)L"Z:\\", &DI, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
+        NVRAM_FS_END(FS_OP_GETDISKINFO,Ret);
+        /* Set BytesPerCluster to the accurate value */
+        BytesPerCluster = DI.BytesPerSector * DI.SectorsPerCluster;
+    }
+	
+#if defined (__NVRAM_UT_TEST__)
+    nvram_ptr->state = NVRAM_STATE_NOT_READY;
+    if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))
+    {} //do not create mutex again, otherwise fatal error happen
+    else
+#endif
+    {
+        g_nvram_impt_mutex = kal_create_mutex("NV_IMPT");
+        g_nvram_fs_mutex = kal_create_mutex("NV_FS");
+        g_nvram_trace_mutex = kal_create_mutex("NV_TRACE");
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        nvram_gpt_handle = DclSGPT_Open(DCL_GPT_CB, FLAGS_NONE);
+        #endif
+    }
+
+    nvram_ptr->sw_status = 0;
+
+    /*****************************************************
+     * NVRAM get custoemr checksum algorithm config value
+     ******************************************************/
+    #ifdef __NV_CHKSUM_ENHANCE__
+    nvram_cfg_crrnt_chksum_algo();
+    #endif
+    /*****************************************************
+     * Construct NVRAM table and init some default value
+     ******************************************************/
+    nvram_pre_init();
+
+#if defined(__NVRAM_MONITOR_ENABLED__)
+    /*****************************************
+     * NVRAM Monitor Init
+     *********************************************/
+    #if defined (__NVRAM_UT_TEST__)
+    if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))
+    {} //do not create mutex again, otherwise fatal error happen
+    else
+    #endif
+    {
+        nvram_mon_init();
+    }
+#endif
+    if(nvram_ee_info != NULL){
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Core Init Start at %d\r\n",__LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"build_time: %s \r\n",build_date_time());
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"branch_version: %s \r\n",release_branch());
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"flavor_version: %s \r\n",release_flavor());
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"coded_version: %s \r\n",nvram_ptr->coded_version);
+        nvram_ee_info->nvram_init_step = NVRAM_PRE_INIT_DONE;
+        nvram_ee_info->nvram_init_time[1] = kal_get_systicks();
+    }        
+#ifdef __NVRAM_BACKUP_DISK__
+    /*****************************************
+     * Init Backup partition
+     *********************************************/
+    nvram_init_backup_disk();
+#endif
+
+
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+    /****************************************************
+     * Init Secure Data Storage and get the storage mode
+     ******************************************************/
+    if (nvram_sds_status() == NVRAM_ERRNO_SDS_EMPTY)
+    {
+        MD_TRC_FUNC_NVRAM_INIT(0, 0);
+        nvram_ptr->sw_status |= NVRAM_SW_EMPTY_SDS;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+        }
+        nvram_sds_init_start();
+        //nvram_init_all_ldi(NVRAM_RESET_SDS);
+        nvram_sds_init_end();
+    }
+#endif
+
+    /*****************************************
+     * Init FAT
+     *  if the secure storage is empty => software version ... and many data is missing
+     *  => format all
+     *********************************************/
+#if !defined(__MTK_INTERNAL_ENG_USER__) && defined(__NVRAM_INIT_ACTIVE_RECOVER__)
+    REINIT_FAT:
+#endif
+   if ((drv_init_result = nvram_drv_fat_status()) == NVRAM_DRV_UNFORMATTED)
+    {
+    #if !defined(__MTK_INTERNAL_ENG_USER__) && defined(__NVRAM_INIT_ACTIVE_RECOVER__)
+        if(nvram_recover_all_ldi(NVRAM_CATEGORY_IMPORTANT)) {
+            goto REINIT_FAT;
+        }
+    #endif
+    #if defined (__NVRAM_UT_TEST__)
+        nvram_boot_trace |= BOOT_TRACE_DRV_UNFORMATTED;
+    #endif
+        MD_TRC_FUNC_NVRAM_INIT(1, 0);
+        nvram_ptr->sw_status |= NVRAM_SW_EMPTY_FAT;
+        nvram_drv_fat_init_start();
+
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+        nvram_util_init_info_file();
+#endif
+        nvram_init_all_ldi(NVRAM_RESET_ALL);
+        nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID);
+        nvram_write_data_item(ldi, 1, nvram_ptr->build_time, KAL_TRUE);
+        nvram_drv_fat_init_end();
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_END;
+            nvram_ee_info->nvram_init_time[4] = kal_get_systicks();
+        }
+    }
+    else if (drv_init_result == NVRAM_DRV_FOLDER_NOT_READY)
+    {
+    #if defined (__NVRAM_UT_TEST__)
+        nvram_boot_trace |= BOOT_TRACE_FOLDER_NOT_READY;
+    #endif
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_CHECK_DONE;
+        }
+        nvram_create_all_folder();
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_CREATE_ALL_FOLDER_DONE;
+        }
+    }
+    else if (drv_init_result == NVRAM_DRV_DRIVE_BROKEN || drv_init_result == NVRAM_DRV_DRIVE_VNOERR)
+    {
+    #if defined (__NVRAM_UT_TEST__)
+        nvram_boot_trace |= BOOT_TRACE_DRIVE_BROKEN_VNOERR;
+    #endif
+        MD_TRC_FUNC_NVRAM_INIT(2, 0);
+        nvram_ptr->dev_broken = KAL_TRUE;
+        goto INIT_END;
+    }
+
+    /*****************************************
+     * Init OTP
+     *********************************************/
+#ifdef __NVRAM_OTP__
+    nvram_otp_construct();
+#endif
+
+    /*****************************************
+     * Check system record and do version compatible
+     *********************************************/
+    if ((nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT)
+    #ifdef __NVRAM_SECURE_DATA_STORAGE__
+        && (nvram_ptr->sw_status & NVRAM_SW_EMPTY_SDS)
+    #endif
+        )
+    {
+
+        MD_TRC_FUNC_NVRAM_INIT(3, 0);
+        goto INIT_END;
+    }
+
+  
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+    nvram_util_init_info_file();
+#endif
+    NVRAM_INIT_TIME_UT_STAMP(1);
+
+    /* Read back system-level record to retrieve software-lock status and data version
+     *
+     * 1. Read failed:
+     *        NVRAM Layer must re-initialize all logical data items
+     *            b'coz we could not ensure the healthy of all ldi, and return.
+     * 2. Read success but incompatible versions:
+     *        Step 1: NVRAM Layer must re-initialize all 'USER' category logical data items.
+     *        Step 2: According the result of step 1, jump step 3 or step 4
+     *        Step 3: Step 1 is success, Must assue following version don't re-initialize in step 1.
+     *             3.1 check branch version
+     *             3.2 check flavor version
+     *             3.3 check custpack version
+     *             3.4 check secupack version
+     *        Step 4: Step 1 is fail
+     *             4.1 Initial all data item
+     * 3. Read success and compatible versions:
+     *        3.1 check branch version
+     *        3.2 check flavor version
+     *        3.3 check custpack version
+     *        3.4 check secupack version
+     */
+	nvram_sec_check();
+
+    #ifdef __NV_CHKSUM_ENHANCE__
+    if(NVRAM_IO_ERRNO_OK != nvram_chksum_def_algo_check())
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM checksum algorithm checked %d.\r\n", __FUNCTION__,__LINE__);
+    #if defined (__NVRAM_UT_TEST__)
+		return KAL_FALSE;
+	#endif
+    }
+	#endif
+
+    nvram_ptr->lock = nvram_decrypt_lock_state();
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock;
+    }
+    kal_mem_set(nvram_ptr->old_coded_version, 0, NVRAM_EF_SYS_SIZE + 1);
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID);
+    if((nvram_read_data_item(ldi, 1, 1, nvram_ptr->old_coded_version, NVRAM_EF_SYS_SIZE) != NVRAM_IO_ERRNO_OK) || is_nvram_factory_reset)
+    {
+        MD_TRC_FUNC_NVRAM_INIT(5, 0);
+    #ifndef __NVRAM_MULTI_FOLDERS__
+        nvram_ptr->sw_status |= NVRAM_SW_EMPTY_FAT;
+    #else
+        nvram_ptr->sw_status |= NVRAM_SW_VERSION_CHANGE;
+    #endif
+        nvram_init_all_ldi(NVRAM_RESET_FAT);
+        is_nvram_factory_reset = KAL_FALSE;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_time[7] = kal_get_systicks();
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_END;
+            nvram_ee_info->nvram_init_type |= NVRAM_INIT_FACTORY_BOOT_UP;
+            nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+        }
+        NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_READ_VERSION_FAIL);
+    #if defined (__NVRAM_UT_TEST__)
+        nvram_boot_trace |= BOOT_TRACE_READ_SYS_LID_FAIL;
+    #endif
+    }
+#if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)
+    else if (ccci_queryBootAttributes(BOOT_ATTR_IS_CLEAN_BOOT))
+    {
+        MD_TRC_FUNC_NVRAM_INIT(6, 0);
+        nvram_init_all_ldi(NVRAM_RESET_FAT);
+        NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_CLEAN_BOOT);
+    }
+#endif
+    // Always check if it's version upgrade (in case factory reset and upgrade at one time)
+    // Factory reset and OTA upgrade may happen at one time
+    {
+    /* Initial pseudo merge first */
+    #ifdef __NVRAM_PSEUDO_MERGE__
+        if (!nvram_pseudo_merge())
+        {
+            NVRAM_FS_START_EX(FS_OP_DELETE,L"z:\\NVRAM\\NVD_DATA\\INFOALID");
+            Ret = FS_Delete(L"z:\\NVRAM\\NVD_DATA\\INFOALID");
+            NVRAM_FS_END(FS_OP_DELETE,Ret);
+            NVRAM_FS_START_EX(FS_OP_DELETE,L"z:\\NVRAM\\NVD_DATA\\PACKALID");
+            Ret = FS_Delete(L"z:\\NVRAM\\NVD_DATA\\PACKALID");
+            NVRAM_FS_END(FS_OP_DELETE,Ret);
+            nvram_pseudo_merge();
+        }
+    #endif
+
+        /* maintain the lock status even after software upgrade */
+        //nvram_ptr->lock = nvram_decrypt_lock_state();
+
+        MD_TRC_FUNC_NVRAM_INIT(7, nvram_ptr->lock);
+        nvram_assign_system_record_default_value((kal_char *)nvram_ptr->coded_version, release_verno());
+
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_START;
+            kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_coded_version), (kal_uint8*)nvram_ptr->old_coded_version, NVRAM_MD_VERSION_INFO_SIZE);            
+            update_old_md_version_to_nvram_ee_info();
+        }
+        
+        /*
+        * Read system record success, Compare code version first
+        */
+        if (strncmp((kal_char*) nvram_ptr->old_coded_version, (kal_char*) nvram_ptr->coded_version, CODED_DATA_VERSION_SIZE) != 0 ||
+             (!nvram_supplementary_check_data_item(NVRAM_EF_BUILD_TIME_LID)) || (!nvram_supplementary_check_data_item_for_fw()))
+        {
+            MD_TRC_FUNC_NVRAM_INIT(8, 0);
+        
+            nvram_ptr->sw_status |= NVRAM_SW_VERSION_CHANGE;
+            #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+            is_nvram_first_restore = KAL_TRUE;
+            is_nvram_in_ota_flow = KAL_TRUE;
+            #endif
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+                nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_CHECK_DONE;
+            }
+            ld_init_result = nvram_version_conflict_resolve(nvram_ptr->old_coded_version);
+            #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__
+            is_nvram_in_ota_flow = KAL_FALSE;
+            #endif
+            #if 0
+/* under construction !*/
+            #if !defined(__CCCIFS_SUPPORT__)
+/* under construction !*/
+            #else
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+            #endif
+            #endif
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_END;
+                nvram_ee_info->nvram_init_type |= NVRAM_INIT_OTA_BOOT_UP;
+                nvram_ee_info->nvram_init_time[12] = kal_get_systicks();
+            }
+            if (ld_init_result)
+            {
+                MD_TRC_FUNC_NVRAM_INIT(9, 0);                
+                ld_init_result = nvram_supplementary_check();
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]nvram_supplementary_check() Success,result=%d\r\n",ld_init_result);
+            }
+            else
+            {
+                MD_TRC_FUNC_NVRAM_INIT(10, 0);
+                /* if errors happen during conflict resolution, initialize all LIDs */
+                ld_init_result = nvram_init_all_ldi(NVRAM_RESET_ALL);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]nvram_init_all_ldi() Fail %d -> nvram_init_all_ldi()\r\n", (kal_uint32)ld_init_result);
+            }
+
+            #if defined (__NVRAM_UT_TEST__)
+                nvram_boot_trace |= BOOT_TRACE_SW_VERNO_CONFLICT;
+            #endif
+            /* switch the mode back to SDS mode if need */
+            NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_VERSION_CHANGE);
+        }
+        else    /* version compatible */
+        {
+            /*
+             * Read sys record success and version compatible
+             * This case means handset is power on normally:
+             * So, nvram should only query restore factory in this case
+             */
+            MD_TRC_FUNC_NVRAM_INIT(12, 0);
+            //Fast MD booting feature for Modem only load 
+            //Note:
+            // 1. You need to download the correct RAMDISK image to EVB 
+            //   a. RAMDISK image can be dump with META
+            //   b. FDD/TDD have different RAMDISK image
+            // 2. Mark nvram_scan_all_ldi        
+            ld_init_result = nvram_supplementary_check();
+
+            if ((ld_init_result == KAL_TRUE) && nvram_check_restore_factory_flag())
+            {
+                MD_TRC_FUNC_NVRAM_INIT(13, 0);
+                NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Check:%d nvram_check_restore_factory_flag fail\r\n",ld_init_result);
+                nvram_reset_data_items(NVRAM_RESET_FACTORY, NVRAM_APP_RESERVED, 0, 0, 0);
+            }
+            NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_NORMAL_BOOT);
+            #if defined (__NVRAM_UT_TEST__)
+                nvram_boot_trace |= BOOT_TRACE_SW_VERNO_COMPATIBLE;
+            #endif
+
+        }   /* version compatible */
+    }
+
+    MD_TRC_FUNC_NVRAM_INIT(14, 0);    
+
+INIT_END:
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Core Init Done at %d\r\n",__LINE__);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Post Init Start at %d\r\n\r\n",__LINE__);
+    nvram_ptr->state = NVRAM_STATE_READY;
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_context.state = NVRAM_STATE_READY;
+        nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_START;
+    }
+    nvram_write_bitmap_into_file();
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_WRITE_BITMAP_DONE;
+        nvram_ee_info->nvram_init_time[13] = kal_get_systicks();
+    }
+    NVRAM_INIT_TIME_UT_STAMP(2);
+#if !defined (__NVRAM_UT_TEST__)    
+    mcf_full_ota_status = mcf_do_ota_full();
+#endif
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_MCF_OTA_DONE;
+        nvram_ee_info->nvram_init_time[14] = kal_get_systicks();
+    }
+    NVRAM_INIT_TIME_UT_STAMP(3);
+#if defined(__NVRAM_INIT_LID_BUFFER__)
+    nvram_init_lid_buffer_prepare();
+#endif
+
+#ifdef __NVRAM_LID_PREREAD__
+    nvram_pre_read_white_list_lid();
+#endif
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CACHE_PREREAD_DONE;
+        nvram_ee_info->nvram_init_time[15] = kal_get_systicks();
+    }
+#if defined (__NVRAM_UT_TEST__)
+    if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))
+    {} //do nothing here
+    else
+#endif
+    {
+        NVRAM_INIT_TIME_UT_STAMP(4);
+        custom_em_nvram_config_com_port();
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CUSTOM_EM_NVRAM_CONFIG_DONE;
+            nvram_ee_info->nvram_init_time[16] = kal_get_systicks();
+        }
+        NVRAM_INIT_TIME_UT_STAMP(5);
+        custom_nvram_config();
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CUSTOM_NVRAM_CONFIG_DONE;
+            nvram_ee_info->nvram_init_time[17] = kal_get_systicks();
+        }
+
+        NVRAM_INIT_TIME_UT_STAMP(6);
+        custom_default_mode_config();
+        NVRAM_INIT_TIME_UT_STAMP(7);
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CUSTOM_DEFAULT_MODE_CONFIG;
+            nvram_ee_info->nvram_init_time[18] = kal_get_systicks();
+        }
+#ifdef __NVRAM_CRYPT_TEST__ 
+        {
+            kal_uint8 array_t[NVRAM_MSP_TEST_LEN];
+            nvram_external_read_data(NVRAM_EF_NVRAM_MSP_TEST_LID,
+                                     1,
+                                     (kal_uint8*)array_t,
+                                     NVRAM_EF_NVRAM_MSP_TEST_SIZE);
+        }
+#endif
+    }
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_END;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Post Init Done at %d\r\n\r\n",__LINE__);
+    }
+    return KAL_TRUE;
+}   /* end of nvram_init function */
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_reset
+ * DESCRIPTION
+ *  This is reset() function of NVRAM module.
+ * PARAMETERS
+ *  task_indx       [IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_bool nvram_reset(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#if !defined(__MTK_TARGET__)
+    nvram_ptr->state = NVRAM_STATE_NULL;
+#endif
+    return KAL_TRUE;
+}   /* end of nvram_reset function */
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_report_last_exception
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  task_name_p     [?]
+ *  type_p          [?]
+ *  time_p          [?]
+ *  status_p        [?]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_report_last_exception(void *task_name_p, void *type_p, void *time_p, void *status_p)
+{
+}  
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_first_bootup_name
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_create_first_bootup_name(kal_char *prefix, kal_wchar* filename)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint8 *working_buffer = (kal_uint8*) get_ctrl_buffer(32);
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    memset(working_buffer, 0, 32);
+    strncpy((kal_char*)working_buffer, release_verno(), 32);
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer, 32, nvram_ptr->secret_key, (kal_uint8*)working_buffer);
+#else
+    //custom_nvram_encrypt(nvram_ptr->secret_key, (unsigned char *)working_buffer, 32, 0);
+    nvram_AES_encrypt((unsigned char *)working_buffer, 32);
+#endif
+    kal_wsprintf(filename, "Z:\\%s%02X%02X%02X%02X.log", prefix, working_buffer[4], working_buffer[5], working_buffer[6], working_buffer[7]);
+
+    free_ctrl_buffer(working_buffer);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_first_bootup_file
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_create_first_bootup_log(kal_char *prefix)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 result = FS_NO_ERROR;
+    FS_HANDLE handle;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_create_first_bootup_name(prefix, filename);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename); 
+    handle = FS_Open(filename, FS_READ_WRITE | FS_CREATE_ALWAYS);
+    NVRAM_FS_END(FS_OP_OPEN,handle);
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(handle);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_check_first_bootup_log
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_bool nvram_check_first_bootup_log(kal_char *prefix)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_create_first_bootup_name(prefix, filename);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    result = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+    if (result >= FS_NO_ERROR)
+    {
+        return KAL_TRUE;
+    }
+    else
+    {
+        return KAL_FALSE;
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_delete_first_bootup_log
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_delete_first_bootup_log(kal_char *prefix)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_create_first_bootup_name(prefix, filename);
+    NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+    result = FS_Delete(filename);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+}
+
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_access_sds
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_int32 nvram_access_sds(nvram_sds_access_enum access_mode)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+
+    nvram_errno_enum result = NVRAM_ERRNO_SUCCESS;
+
+    if (access_mode == NVRAM_SDS_ACCESS_BACKUP)
+    {
+        result = nvram_sds_backup();
+    }
+    else
+    {
+        result = nvram_sds_restore();
+    }
+
+    
+    return result;
+}
+#endif
diff --git a/mcu/service/nvram/src/nvram_mml1def.c b/mcu/service/nvram/src/nvram_mml1def.c
new file mode 100644
index 0000000..a234c4d
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_mml1def.c
@@ -0,0 +1,41 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ *	nvram_mml1_default.c
+ *
+ * Project:
+ * --------
+ *   MT7206RF
+ *
+ * Description:
+ * ------------
+ *   
+ *
+ * Author:
+ * -------
+ *	
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+ #if (defined __MD93__)  
+#include "nvram_mml1def_md93.c"
+#elif (defined __MD95__)
+#include "nvram_mml1def_md95.c"
+#elif (defined __MD97__) || (defined __MD97P__)
+#include "nvram_mml1def_md97.c"
+#else
+#error "Should define at least a kind of BB being used."
+#endif
+
diff --git a/mcu/service/nvram/src/nvram_mml1def_md93.c b/mcu/service/nvram/src/nvram_mml1def_md93.c
new file mode 100644
index 0000000..7b5c256
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_mml1def_md93.c
@@ -0,0 +1,220 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ *	nvram_mml1_default.c
+ *
+ * Project:
+ * --------
+ *   MT7206RF
+ *
+ * Description:
+ * ------------
+ *   
+ *
+ * Author:
+ * -------
+ *	
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+
+#include "mml1_rf_global.h"
+
+#include "mml1_custom_drdi.h"
+
+#include "mml1_fe_public.h"
+#include "mml1_nvram_def.h"
+
+kal_bool mmrf_drdiHadDone = KAL_FALSE;
+
+void nvram_mmrf_drdiPointerInit(kal_uint16 setIdx)
+{
+#ifdef __MTK_TARGET__
+   mmrf_mipiData_ptr = &(mml1CustomMipiData[setIdx]);
+   mmrf_rfData_ptr   = &(mml1CustomRfData[setIdx]);
+   mmrf_feData_ptr   = &(mml1CustomFeData[setIdx]);
+
+   #if defined(__TX_POWER_OFFSET_SUPPORT__) || defined(__SAR_TX_POWER_BACKOFF_SUPPORT__)
+   mml1_sar_swtp_data_info_ptr = &(mml1CustomRfSarSwtpData[setIdx]);
+   #endif
+
+   #if __IS_MML1_ETM_SUPPORT__
+   mmrf_mipiEtmData_ptr = &( mml1CustomMipiEtmData[ setIdx ] );
+   #endif   // #if __IS_MML1_ET_SUPPORT__
+#endif   
+}
+
+void nvram_mmrf_drdi(void)
+{
+#ifdef __MTK_TARGET__
+   #if (IS_MML1_RF_DRDI_CAPABILITY_SUPPORT)
+   if(mml1_custom_drdiEnable)
+   {
+      kal_uint16 setIdx;
+
+      setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_MMRF);
+      if (!mmrf_drdiHadDone)
+      {
+         /* set the pointer to RF custom data by set index */
+         nvram_mmrf_drdiPointerInit(setIdx);
+         mmrf_drdiHadDone = KAL_TRUE;
+      }
+   }
+   else
+   {
+      /* set the pointer to default RF custom data, set0*/
+      nvram_mmrf_drdiPointerInit(0);
+   }
+   #else
+   /* set the pointer to default RF custom data, set0*/
+   nvram_mmrf_drdiPointerInit(0);
+   #endif      
+#endif   
+}
+
+
+void nvram_get_mmL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#ifdef __MTK_TARGET__
+
+   nvram_mmrf_drdi();
+
+   switch (lid)
+   {
+      case NVRAM_EF_MML1_RF_PARAMETER_LID:
+      {
+         //kal_mem_cpy(buffer, &MML1_RF_CUSTOM_INPUT_DATA, NVRAM_EF_MML1_RF_PARAMETER_SIZE);
+         kal_mem_cpy(buffer, &mmrf_rfData_ptr->rfInputData, NVRAM_EF_MML1_RF_PARAMETER_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_ABB_CAL_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_rf_abb_cal_data_pcore, NVRAM_EF_MML1_ABB_CAL_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_PMIC_SLT_VOLTAGE_CONTROL_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_rf_pmic_slt_data_pcore, NVRAM_EF_MML1_PMIC_SLT_VOLTAGE_CONTROL_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_RF_POC_DATA_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_RF_POC_DATA, NVRAM_EF_MML1_RF_POC_DATA_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_INITIAL_CW_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->initTable_p, NVRAM_EF_MML1_MIPI_INITIAL_CW_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_USID_CHANGE_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->changeUsidTable_p, NVRAM_EF_MML1_MIPI_USID_CHANGE_SIZE);
+      }
+      break;
+   #if IS_MMRF_MIPI_HW_CHECK_SUPPORT
+      case NVRAM_EF_MML1_MIPI_HW_CHECK_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->checkHwTable_p, NVRAM_EF_MML1_MIPI_HW_CHECK_SIZE);
+      }
+      break;
+   #endif
+   #ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+      case NVRAM_EF_MML1_CUSTOM_DYNAMIC_INIT_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_rf_drdi_dynamic_init_param, NVRAM_EF_MML1_CUSTOM_DYNAMIC_INIT_SIZE);
+      }
+      break;
+   #endif
+      case NVRAM_EF_MML1_CRYSTAL_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_CRYSTAL_CTRL, NVRAM_EF_MML1_CRYSTAL_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_GPS_CO_TMS_DATA_LID:
+      {
+         kal_mem_cpy(buffer, MML1_CoTMSTbl[0], NVRAM_EF_MML1_GPS_CO_TMS_DATA_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_TEMPERATURE_DAC_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_TempDacTable, NVRAM_EF_MML1_TEMPERATURE_DAC_SIZE);
+      }
+      break;
+   #if defined(__TX_POWER_OFFSET_SUPPORT__)
+      case NVRAM_EF_MML1_TXPOWEROFFSET_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_sar_swtp_data_info_ptr->swtp, NVRAM_EF_MML1_TXPOWEROFFSET_SIZE);
+      }
+      break;
+   #endif
+   #if defined(__SAR_TX_POWER_BACKOFF_SUPPORT__)
+      case NVRAM_EF_MML1_SAR_TXPOWEROFFSET_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_sar_swtp_data_info_ptr->sar, NVRAM_EF_MML1_SAR_TXPOWEROFFSET_SIZE);
+      }
+      break;
+   #endif
+      case NVRAM_EF_MML1_MIPI_LPM_CW_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->lpmTable_p, NVRAM_EF_MML1_MIPI_LPM_CW_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_ELNA_DATABASE_LID:
+      {
+         kal_uint32 i;
+         MML1_FE_ELNA_NVRAM_T elna_nvram_data = {{0}};
+         const MML1_FE_ELNA_RAW_T *elna_rawdata_p;
+
+         elna_rawdata_p = &(mmrf_feData_ptr->feComponentsList.elna_raw_database[0]);
+         
+         for(i = 0; i < MML1_FE_ELNA_NUM; i++)
+         {
+            elna_nvram_data.elna_settling_time[i] = elna_rawdata_p->elna_config_data.elna_settling_time;
+            elna_rawdata_p++;
+         }
+         kal_mem_cpy(buffer, &(elna_nvram_data), NVRAM_EF_MML1_ELNA_DATABASE_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_EXT_VPA_INITIAL_CW_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->extVpaTable_p, NVRAM_EF_MML1_EXT_VPA_INITIAL_CW_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_ETM_INFORMATION_LID:
+      {
+      #if __IS_MML1_ETM_SUPPORT__
+         kal_mem_cpy( buffer, mmrf_mipiEtmData_ptr->infoTable_p, NVRAM_EF_MML1_MIPI_ETM_INFORMATION_SIZE );
+      #endif   // #if __IS_MML1_ETM_SUPPORT__    
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_ETM_INITIAL_CW_LID:
+      {
+      #if __IS_MML1_ETM_SUPPORT__
+         kal_mem_cpy( buffer, mmrf_mipiEtmData_ptr->initTable_p, NVRAM_EF_MML1_MIPI_ETM_INITIAL_CW_SIZE );
+      #endif   // #if __IS_MML1_ETM_SUPPORT__    
+      }
+      break;
+      default:
+         ASSERT(KAL_FALSE);
+      break;
+   }
+#endif   
+}
+
diff --git a/mcu/service/nvram/src/nvram_mml1def_md95.c b/mcu/service/nvram/src/nvram_mml1def_md95.c
new file mode 100644
index 0000000..1a781a0
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_mml1def_md95.c
@@ -0,0 +1,266 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ *	nvram_mml1_default.c
+ *
+ * Project:
+ * --------
+ *   MT7206RF
+ *
+ * Description:
+ * ------------
+ *   
+ *
+ * Author:
+ * -------
+ *	
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+
+#include "mml1_rf_global.h"
+
+#include "mml1_custom_drdi.h"
+
+#include "mml1_fe_public.h"
+#include "mml1_nvram_def.h"
+
+kal_bool mmrf_drdiHadDone = KAL_FALSE;
+
+void nvram_mmrf_drdiPointerInit(kal_uint16 setIdx)
+{
+#ifdef __MTK_TARGET__
+   mmrf_mipiData_ptr = &(mml1CustomMipiData[setIdx]);
+   mmrf_rfData_ptr   = &(mml1CustomRfData[setIdx]);
+   mmrf_feData_ptr   = &(mml1CustomFeData[setIdx]);
+
+   #if defined(__TX_POWER_OFFSET_SUPPORT__) || defined(__SAR_TX_POWER_BACKOFF_SUPPORT__)
+   mml1_sar_swtp_data_info_ptr = &(mml1CustomRfSarSwtpData[setIdx]);
+   #endif
+
+   #if __IS_MML1_ETM_SUPPORT__
+   mmrf_mipiEtmData_ptr = &( mml1CustomMipiEtmData[ setIdx ] );
+   #endif   // #if __IS_MML1_ET_SUPPORT__
+#endif   
+}
+
+void nvram_mmrf_drdi(void)
+{
+#ifdef __MTK_TARGET__
+   #if (IS_MML1_RF_DRDI_CAPABILITY_SUPPORT)
+   if(mml1_custom_drdiEnable)
+   {
+      kal_uint16 setIdx;
+
+      setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_MMRF);
+      if (!mmrf_drdiHadDone)
+      {
+         /* set the pointer to RF custom data by set index */
+         nvram_mmrf_drdiPointerInit(setIdx);
+         mmrf_drdiHadDone = KAL_TRUE;
+      }
+   }
+   else
+   {
+      /* set the pointer to default RF custom data, set0*/
+      nvram_mmrf_drdiPointerInit(0);
+   }
+   #else
+   /* set the pointer to default RF custom data, set0*/
+   nvram_mmrf_drdiPointerInit(0);
+   #endif      
+#endif   
+}
+#if IS_MML1_SUPPORT_UTAS
+MML1_FE_UTAS_NVRAM_T utas_nvram_data; 
+#endif
+
+void nvram_get_mmL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#ifdef __MTK_TARGET__
+
+   nvram_mmrf_drdi();
+
+   switch (lid)
+   {
+      case NVRAM_EF_MML1_RF_PARAMETER_LID:
+      {
+         //kal_mem_cpy(buffer, &MML1_RF_CUSTOM_INPUT_DATA, NVRAM_EF_MML1_RF_PARAMETER_SIZE);
+         kal_mem_cpy(buffer, &mmrf_rfData_ptr->rfInputData, NVRAM_EF_MML1_RF_PARAMETER_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_ABB_CAL_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_rf_abb_cal_data_pcore, NVRAM_EF_MML1_ABB_CAL_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_PMIC_SLT_VOLTAGE_CONTROL_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_rf_pmic_slt_data_pcore, NVRAM_EF_MML1_PMIC_SLT_VOLTAGE_CONTROL_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_RF_POC_DATA_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_RF_POC_DATA, NVRAM_EF_MML1_RF_POC_DATA_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_INITIAL_CW_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->initTable_p, NVRAM_EF_MML1_MIPI_INITIAL_CW_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_USID_CHANGE_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->changeUsidTable_p, NVRAM_EF_MML1_MIPI_USID_CHANGE_SIZE);
+      }
+      break;
+   #if IS_MMRF_MIPI_HW_CHECK_SUPPORT
+      case NVRAM_EF_MML1_MIPI_HW_CHECK_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->checkHwTable_p, NVRAM_EF_MML1_MIPI_HW_CHECK_SIZE);
+      }
+      break;
+   #endif
+   #ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+      case NVRAM_EF_MML1_CUSTOM_DYNAMIC_INIT_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_rf_drdi_dynamic_init_param, NVRAM_EF_MML1_CUSTOM_DYNAMIC_INIT_SIZE);
+      }
+      break;
+   #endif
+      case NVRAM_EF_MML1_CRYSTAL_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_CRYSTAL_CTRL, NVRAM_EF_MML1_CRYSTAL_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_GPS_CO_TMS_DATA_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_CoTMS_ConfigTbl_ToAP, NVRAM_EF_MML1_GPS_CO_TMS_DATA_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_TEMPERATURE_DAC_LID:
+      {
+         kal_mem_cpy(buffer, &MML1_TempDacTable, NVRAM_EF_MML1_TEMPERATURE_DAC_SIZE);
+      }
+      break;
+   #if defined(__TX_POWER_OFFSET_SUPPORT__)
+      case NVRAM_EF_MML1_TXPOWEROFFSET_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_sar_swtp_data_info_ptr->swtp, NVRAM_EF_MML1_TXPOWEROFFSET_SIZE);
+      }
+      break;
+   #endif
+   #if defined(__SAR_TX_POWER_BACKOFF_SUPPORT__)
+      case NVRAM_EF_MML1_SAR_TXPOWEROFFSET_LID:
+      {
+         kal_mem_cpy(buffer, &mml1_sar_swtp_data_info_ptr->sar, NVRAM_EF_MML1_SAR_TXPOWEROFFSET_SIZE);
+      }
+      break;
+   #endif
+      case NVRAM_EF_MML1_MIPI_LPM_CW_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->lpmTable_p, NVRAM_EF_MML1_MIPI_LPM_CW_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_ELNA_DATABASE_LID:
+      {
+         kal_uint32 i;
+         MML1_FE_ELNA_NVRAM_T elna_nvram_data = {{0}};
+         const MML1_FE_ELNA_RAW_T *elna_rawdata_p;
+
+         elna_rawdata_p = &(mmrf_feData_ptr->feComponentsList.elna_raw_database[0]);
+         
+         for(i = 0; i < MML1_FE_ELNA_NUM; i++)
+         {
+            elna_nvram_data.elna_settling_time[i] = elna_rawdata_p->elna_config_data.elna_settling_time;
+            elna_rawdata_p++;
+         }
+         kal_mem_cpy(buffer, &(elna_nvram_data), NVRAM_EF_MML1_ELNA_DATABASE_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_EXT_VPA_INITIAL_CW_LID:
+      {
+         kal_mem_cpy(buffer, mmrf_mipiData_ptr->extVpaTable_p, NVRAM_EF_MML1_EXT_VPA_INITIAL_CW_SIZE);
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_ETM_INFORMATION_LID:
+      {
+      #if __IS_MML1_ETM_SUPPORT__
+         kal_mem_cpy( buffer, mmrf_mipiEtmData_ptr->infoTable_p, NVRAM_EF_MML1_MIPI_ETM_INFORMATION_SIZE );
+      #endif   // #if __IS_MML1_ETM_SUPPORT__    
+      }
+      break;
+      case NVRAM_EF_MML1_MIPI_ETM_INITIAL_CW_LID:
+      {
+      #if __IS_MML1_ETM_SUPPORT__
+         kal_mem_cpy( buffer, mmrf_mipiEtmData_ptr->initTable_p, NVRAM_EF_MML1_MIPI_ETM_INITIAL_CW_SIZE );
+      #endif   // #if __IS_MML1_ETM_SUPPORT__    
+      }
+      break;
+	  case NVRAM_EF_MML1_GPS_CO_TMS_DATA_MD_LID:
+      {
+         kal_mem_cpy(buffer, MML1_CoTMSTbl[0], NVRAM_EF_MML1_GPS_CO_TMS_DATA_MD_SIZE);
+      }
+	  break;
+      case NVRAM_EF_MML1_UTAS_DATABASE_LID:
+      {
+      #if IS_MML1_SUPPORT_UTAS   
+         kal_uint32 i,event_count, data_count;  
+         //MML1_FE_UTAS_NVRAM_T utas_nvram_data={{{{0}}}};     
+         kal_mem_set(&utas_nvram_data,0,sizeof(MML1_FE_UTAS_NVRAM_T));           
+         for(i=0; i<MMRFD_TAS_MAX_STATE_NUM; i++)
+         {     
+            utas_nvram_data.utas_switch_raw_database.utas_switch_fe_setting[i] = *(((mmrf_feData_ptr->feComponentsList).utas_switch_raw_database.utas_switch_fe_setting)+i);             
+            for(event_count=0; event_count<MMRFD_MIPI_ANT_EVENT_NUM; event_count++)
+            {            
+               utas_nvram_data.utas_switch_raw_database.utas_switch_mipi_event_custom_table[i][event_count] = *(*((mmrf_feData_ptr->feComponentsList).utas_switch_raw_database.utas_switch_mipi_event_custom_table[i])+event_count);               
+            }
+            for(data_count=0; data_count<MMRFD_MIPI_ANT_DATA_NUM; data_count++)
+            {             
+               utas_nvram_data.utas_switch_raw_database.utas_switch_mipi_data_custom_table[i][data_count] = *(*((mmrf_feData_ptr->feComponentsList).utas_switch_raw_database.utas_switch_mipi_data_custom_table[i])+data_count);   
+            }       
+         }
+
+         for(i=0; i<MMRFD_TAS_MAX_TUNER_DATA_NUM; i++)
+         {      
+            utas_nvram_data.utas_tuner_raw_database.utas_tuner_fe_setting[i] = *(((mmrf_feData_ptr->feComponentsList).utas_tuner_raw_database.utas_tuner_fe_setting)+i);          
+            for(event_count=0; event_count<MMRFD_MIPI_ANT_EVENT_NUM; event_count++)
+            {       
+               utas_nvram_data.utas_tuner_raw_database.utas_tuner_mipi_event_custom_table[i][event_count] = *(*((mmrf_feData_ptr->feComponentsList).utas_tuner_raw_database.utas_tuner_mipi_event_custom_table[i])+event_count);
+            }
+            for(data_count=0; data_count<MMRFD_MIPI_ANT_DATA_NUM; data_count++)
+            {          
+               utas_nvram_data.utas_tuner_raw_database.utas_tuner_mipi_data_custom_table[i][data_count] = *(*((mmrf_feData_ptr->feComponentsList).utas_tuner_raw_database.utas_tuner_mipi_data_custom_table[i])+data_count);
+            }             
+         }
+         for(i=0; i<MMRFD_TAS_MAX_TUNER_CONTROL_SETTING_NUM; i++)
+         {      
+            utas_nvram_data.utas_tuner_raw_database.utas_ant_tuner_control_database.tas_tuner_db[i] = (((mmrf_feData_ptr->feComponentsList).utas_tuner_raw_database.utas_ant_tuner_control_database)->tas_tuner_db[i]);
+         }      
+         kal_mem_cpy(buffer, &utas_nvram_data, NVRAM_EF_MML1_UTAS_DATABASE_SIZE);  
+      #endif   
+      }
+      break;
+      default:
+         ASSERT(KAL_FALSE);
+      break;
+   }
+#endif   
+}
+
diff --git a/mcu/service/nvram/src/nvram_mml1def_md97.c b/mcu/service/nvram/src/nvram_mml1def_md97.c
new file mode 100644
index 0000000..e8352aa
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_mml1def_md97.c
@@ -0,0 +1,56 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ *	nvram_mml1_default.c
+ *
+ * Project:
+ * --------
+ *   MT7206RF
+ *
+ * Description:
+ * ------------
+ *   
+ *
+ * Author:
+ * -------
+ *	
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+
+#include "mml1_rf_global.h"
+
+#include "mml1_custom_drdi.h"
+
+#include "mml1_fe_public.h"
+#include "mml1_nvram_def.h"
+
+
+extern void MML1_RF_nvram_get_mmL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size);
+
+
+void nvram_get_mmL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#ifdef __MTK_TARGET__
+
+   MML1_RF_nvram_get_mmL1_default_value_to_write(lid, buffer, buffer_size);
+   
+#endif   
+}
+
diff --git a/mcu/service/nvram/src/nvram_msg_handler.c b/mcu/service/nvram/src/nvram_msg_handler.c
new file mode 100644
index 0000000..0967873
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_msg_handler.c
@@ -0,0 +1,501 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_msg_handler.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   To handle the messages sent to NVRAM
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+* Include
+*****************************************************************************/
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h" //MSBB change #include "stack_msgs.h"
+#include "nvram_msgid.h"
+
+#include "nvram_main.h"
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_image_confirm
+ * DESCRIPTION
+ *  send the create image confirm
+ * PARAMETERS
+ *  dest_id:    [IN]    the destination module
+ *  result:     [IN]    error code
+ *  nvram_create_image_req:   [IN]    the reqeuset message sent from destination module
+ * RETURNS
+ *  void
+ * RETURN VALUES
+ *  void
+ *****************************************************************************/
+ void nvram_create_image_confirm(module_type dest_id, nvram_errno_enum result, nvram_create_image_req_struct *nvram_create_image_req)
+ {
+     /*----------------------------------------------------------------*/
+     /* Local Variables                                                */
+     /*----------------------------------------------------------------*/
+     nvram_create_image_cnf_struct *nvram_create_image_cnf;
+
+     /*----------------------------------------------------------------*/
+     /* Code Body                                                      */
+     /*----------------------------------------------------------------*/
+
+     nvram_create_image_cnf = (nvram_create_image_cnf_struct*) construct_local_para(sizeof(nvram_create_image_cnf_struct), TD_RESET);
+     nvram_create_image_cnf->result = result;
+     nvram_create_image_cnf->access_id = nvram_create_image_req->access_id;
+
+     nvram_send_ilm(dest_id, MSG_ID_NVRAM_CREATE_IMAGE_CNF, nvram_create_image_cnf, NULL);
+
+     return;
+ }
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_image_handler
+ * DESCRIPTION
+ *  This function is to handle the MSG_ID_NVRAM_CREATE_IMAGE_REQ.
+ * PARAMETERS
+ *  ilm_ptr:        [IN]    the message sent from other module
+ * RETURNS
+ *  void
+ *****************************************************************************/
+ void nvram_create_image_handler(ilm_struct *ilm_ptr)
+ {
+     /*----------------------------------------------------------------*/
+     /* Local Variables                                                */
+     /*----------------------------------------------------------------*/
+     nvram_create_image_req_struct *req = (nvram_create_image_req_struct*) ilm_ptr->local_para_ptr;
+
+     /*----------------------------------------------------------------*/
+     /* Code Body                                                      */
+     /*----------------------------------------------------------------*/
+
+#ifdef __NVRAM_BACKUP_DISK_RAW__
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+        nvram_create_image_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_NOT_READY, req);
+        return;
+    }
+
+    nvram_create_image_confirm(ilm_ptr->src_mod_id, nvram_create_image(req->image_type), req);
+#else
+    nvram_create_image_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, req);
+#endif
+ }
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_image_confirm
+ * DESCRIPTION
+ *  send the recover image confirm
+ * PARAMETERS
+ *  dest_id:    [IN]    the destination module
+ *  result:     [IN]    error code
+ *  nvram_recover_image_req:   [IN]    the reqeuset message sent from destination module
+ * RETURNS
+ *  void
+ * RETURN VALUES
+ *  void
+ *****************************************************************************/
+ void nvram_recover_image_confirm(module_type dest_id, nvram_errno_enum result, nvram_recover_image_req_struct *nvram_recover_image_req)
+ {
+     /*----------------------------------------------------------------*/
+     /* Local Variables                                                */
+     /*----------------------------------------------------------------*/
+     nvram_recover_image_cnf_struct *nvram_recover_image_cnf;
+
+     /*----------------------------------------------------------------*/
+     /* Code Body                                                      */
+     /*----------------------------------------------------------------*/
+
+     nvram_recover_image_cnf = (nvram_recover_image_cnf_struct*) construct_local_para(sizeof(nvram_recover_image_cnf_struct), TD_RESET);
+     nvram_recover_image_cnf->result = result;
+     nvram_recover_image_cnf->access_id = nvram_recover_image_req->access_id;
+
+     nvram_send_ilm(dest_id, MSG_ID_NVRAM_RECOVER_IMAGE_CNF, nvram_recover_image_cnf, NULL);
+
+     return;
+ }
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_recover_image_handler
+ * DESCRIPTION
+ *  This function is to handle the MSG_ID_NVRAM_RECOVER_IMAGE_REQ.
+ * PARAMETERS
+ *  ilm_ptr:        [IN]    the message sent from other module
+ * RETURNS
+ *  void
+ *****************************************************************************/
+  void nvram_recover_image_handler(ilm_struct *ilm_ptr)
+  {
+      /*----------------------------------------------------------------*/
+      /* Local Variables                                                */
+      /*----------------------------------------------------------------*/
+      nvram_recover_image_req_struct *req = (nvram_recover_image_req_struct*) ilm_ptr->local_para_ptr;
+
+      /*----------------------------------------------------------------*/
+      /* Code Body                                                      */
+      /*----------------------------------------------------------------*/
+
+#ifdef __NVRAM_BACKUP_DISK_RAW__
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+
+        nvram_recover_image_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_NOT_READY, req);
+        return;
+    }
+
+    nvram_recover_image_confirm(ilm_ptr->src_mod_id, nvram_recover_image(req->image_type), req);
+#else
+    nvram_recover_image_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, req);
+#endif
+
+}
+
+ /*****************************************************************************
+ * FUNCTION
+ *  nvram_verify_image_confirm
+ * DESCRIPTION
+ *  send the verify image confirm
+ * PARAMETERS
+ *  dest_id:    [IN]    the destination module
+ *  result:     [IN]    error code
+ *  nvram_verify_image_eq:   [IN]    the reqeuset message sent from destination module
+ * RETURNS
+ *  void
+ * RETURN VALUES
+ *  void
+ *****************************************************************************/
+ void nvram_verify_image_confirm(module_type dest_id, nvram_errno_enum result, nvram_verify_image_req_struct *nvram_verify_image_req)
+ {
+     /*----------------------------------------------------------------*/
+     /* Local Variables                                                */
+     /*----------------------------------------------------------------*/
+     nvram_verify_image_cnf_struct *nvram_verify_image_cnf;
+
+     /*----------------------------------------------------------------*/
+     /* Code Body                                                      */
+     /*----------------------------------------------------------------*/
+
+     nvram_verify_image_cnf = (nvram_verify_image_cnf_struct*) construct_local_para(sizeof(nvram_verify_image_cnf_struct), TD_RESET);
+     nvram_verify_image_cnf->result = result;
+     nvram_verify_image_cnf->access_id = nvram_verify_image_req->access_id;
+
+     nvram_send_ilm(dest_id, MSG_ID_NVRAM_VERIFY_IMAGE_CNF, nvram_verify_image_cnf, NULL);
+
+     return;
+ }
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_verify_image_handler
+ * DESCRIPTION
+ *  This function is to handle the MSG_ID_NVRAM_VERIFY_IMAGE_REQ.
+ * PARAMETERS
+ *  ilm_ptr:        [IN]    the message sent from other module
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_verify_image_handler(ilm_struct *ilm_ptr)
+{
+   /*----------------------------------------------------------------*/
+   /* Local Variables                                                */
+   /*----------------------------------------------------------------*/
+   nvram_verify_image_req_struct *req = (nvram_verify_image_req_struct*) ilm_ptr->local_para_ptr;
+
+   /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#ifdef __NVRAM_BACKUP_DISK_RAW__
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+
+        nvram_verify_image_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_NOT_READY, req);
+        return;
+    }
+
+    nvram_verify_image_confirm(ilm_ptr->src_mod_id, nvram_verify_image(req->image_type, req->fast_verify), req);
+#else
+    nvram_verify_image_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, req);
+#endif /* __SYSDRV_BACKUP_DISK_RAW__ */
+}
+
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+ /*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_confirm
+ * DESCRIPTION
+ *  send the sds confirm
+ * PARAMETERS
+ *  dest_id:    [IN]    the destination module
+ *  result:     [IN]    error code
+ *  nvram_verify_image_eq:   [IN]    the reqeuset message sent from destination module
+ * RETURNS
+ *  void
+ * RETURN VALUES
+ *  void
+ *****************************************************************************/
+ void nvram_sds_confirm(module_type dest_id, nvram_errno_enum result, nvram_sds_req_struct *req)
+ {
+     /*----------------------------------------------------------------*/
+     /* Local Variables                                                */
+     /*----------------------------------------------------------------*/
+     nvram_sds_cnf_struct *nvram_backup_to_sds_cnf;
+
+     /*----------------------------------------------------------------*/
+     /* Code Body                                                      */
+     /*----------------------------------------------------------------*/
+
+     nvram_backup_to_sds_cnf = (nvram_sds_cnf_struct*) construct_local_para(sizeof(nvram_sds_cnf_struct), TD_RESET);
+     nvram_backup_to_sds_cnf->result = result;
+     nvram_backup_to_sds_cnf->access_id = req->access_id;
+
+     nvram_send_ilm(dest_id, MSG_ID_NVRAM_SDS_CNF, nvram_backup_to_sds_cnf, NULL);
+
+     return;
+ }
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sds_handler
+ * DESCRIPTION
+ *  This function is to handle the MSG_ID_NVRAM_SDS_REQ.
+ * PARAMETERS
+ *  ilm_ptr:        [IN]    the message sent from other module
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_sds_handler(ilm_struct *ilm_ptr)
+{
+   /*----------------------------------------------------------------*/
+   /* Local Variables                                                */
+   /*----------------------------------------------------------------*/
+   nvram_sds_req_struct *sds_req = (nvram_sds_req_struct*) ilm_ptr->local_para_ptr;
+   nvram_errno_enum result = NVRAM_ERRNO_SUCCESS;
+
+   /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (nvram_ptr->state != NVRAM_STATE_READY)
+    {
+        MD_TRC_ERROR_NVRAM_STATE();
+
+        nvram_sds_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_NOT_READY, sds_req);
+        return;
+    }
+    if (sds_req->access_mode == NVRAM_SDS_ACCESS_BACKUP)
+    {
+        result = nvram_sds_backup();
+    }
+    else
+    {
+        result = nvram_sds_restore();
+    }
+    
+    nvram_sds_confirm(ilm_ptr->src_mod_id, result, sds_req);
+
+}
+#endif /* __SYSDRV_BACKUP_DISK_RAW__ */
+
+/*****************************************************************************
+* FUNCTION
+*  nvram_ap_bin_region_confirm
+* DESCRIPTION
+*  send the ap BIN region confirm
+* PARAMETERS
+*  dest_id:    [IN]    the destination module
+*  result:     [IN]    error code
+*  nvram_verify_image_eq:   [IN]    the reqeuset message sent from destination module
+* RETURNS
+*  void
+* RETURN VALUES
+*  void
+*****************************************************************************/
+void nvram_ap_bin_region_confirm(module_type dest_id, nvram_errno_enum result, nvram_bin_region_req_struct *req)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_bin_region_cnf_struct *nvram_bin_region_cnf;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_bin_region_cnf = (nvram_bin_region_cnf_struct*) construct_local_para(sizeof(nvram_bin_region_cnf_struct), TD_RESET);
+    nvram_bin_region_cnf->result = result;
+    nvram_bin_region_cnf->access_id = req->access_id;
+
+    nvram_send_ilm(dest_id, MSG_ID_NVRAM_BIN_REGION_CNF, nvram_bin_region_cnf, NULL);
+
+    return;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_ap_bin_region_handler
+ * DESCRIPTION
+ *  This function is to handle the MSG_ID_NVRAM_BIN_REGION_REQ.
+ * PARAMETERS
+ *  ilm_ptr:        [IN]    the message sent from other module
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_ap_bin_region_handler(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_bin_region_req_struct *bin_region_req = (nvram_bin_region_req_struct*) ilm_ptr->local_para_ptr;
+    nvram_errno_enum result = NVRAM_ERRNO_SUCCESS;
+
+    /*----------------------------------------------------------------*/
+     /* Code Body                                                      */
+     /*----------------------------------------------------------------*/
+
+     if (nvram_ptr->state != NVRAM_STATE_READY)
+     {
+         MD_TRC_ERROR_NVRAM_STATE();
+
+         nvram_ap_bin_region_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_NOT_READY, bin_region_req);
+         return;
+     }
+
+     if (bin_region_req->access_mode == NVRAM_BIN_REGION_BACKUP)
+     {
+         result = nvram_ap_bin_region_backup();
+     }
+
+     nvram_ap_bin_region_confirm(ilm_ptr->src_mod_id, result, bin_region_req);
+
+}
+
diff --git a/mcu/service/nvram/src/nvram_multi_folder.c b/mcu/service/nvram/src/nvram_multi_folder.c
new file mode 100644
index 0000000..fcc9eb0
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_multi_folder.c
@@ -0,0 +1,1016 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_multi_folder.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   NVRAM feature: support multi folders
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+ * Include
+ *****************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+
+#include "fs_type.h"
+#include "fs_func.h"
+#include "fs_errcode.h"
+
+#include "nvram_main.h"
+#include "nvram_defs.h"
+#include "ex_public.h"
+#include "stdio.h"
+#include "stdarg.h"
+#include "us_timer.h"
+
+/***********************************************************
+ * Static Variable
+ ***********************************************************/
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+
+/* marco to form absolute path and filename */
+/* File System with wide character interface */
+
+#if defined (__NVRAM_UT_TEST__) && !defined (__NVRAM_LID_CACHE__)
+
+#define NVRAM_FS_MAKE_LID_PATH_FILENAME_1( buf, name )   if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_DATAITEM_PATH, name);\
+	else \
+   	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_DATAITEM_PATH, name)
+
+#ifdef __NVRAM_MULTI_FOLDERS__
+/* core folder */
+#define NVRAM_FS_MAKE_CORE_PATH_FILENAME(buf, name)   if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_COREITEM_PATH, name);\
+    else \
+	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_COREITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_CRITICAL_CALIBRAT_PATH_FILENAME(buf, name)	if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH, name);\
+    else \
+	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_CALIBRAT_DATAITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_CRITICAL_IMPT_PATH_FILENAME(buf, name)	if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_IMPT_DATAITEM_PATH, name);\
+    else \
+	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_IMPT_DATAITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_CUST_PATH_FILENAME(buf, name) if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_CUST_DATAITEM_PATH, name);\
+    else \
+	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_CUST_DATAITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME(buf, name) if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH, name);\
+    else \
+	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME2(buf, name) if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH2, name);\
+    else \
+	kal_wsprintf( buf, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH2, name)
+	
+#endif
+
+
+#else
+
+#define NVRAM_FS_MAKE_LID_PATH_FILENAME_1( buf, name )   \
+   kal_wsprintf( buf, "%s\\%s", NVRAM_FS_DATAITEM_PATH, name)
+
+#ifdef __NVRAM_MULTI_FOLDERS__
+/* core folder */
+#define NVRAM_FS_MAKE_CORE_PATH_FILENAME(buf, name)        \
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_COREITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_CRITICAL_CALIBRAT_PATH_FILENAME(buf, name)	\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_CALIBRAT_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_CRITICAL_IMPT_PATH_FILENAME(buf, name)	\
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_IMPT_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_CUST_PATH_FILENAME(buf, name) \
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_CUST_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME(buf, name) \
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME2(buf, name) \
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH2, name);
+
+#endif
+
+#endif //__NVRAM_UT_TEST__
+
+#define NVRAM_FS_MAKE_OTA_PATH_FILENAME(buf, name) \
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_OTA_DATAITEM_PATH, name);
+
+#ifdef __NVRAM_BACKUP_DISK_FAT__
+#define NVRAM_FS_MAKE_BACKUP_PATH_FILENAME(buf, name)                       \
+    kal_wsprintf( buf, "%s\\%s", NVRAM_FS_BACKUP_ROOT_PATH, name);
+#endif
+
+extern module_type stack_get_active_module_id( void );
+
+/***********************************************************
+ * Global Variable
+ **********************************************************/
+
+/***********************************************************
+ * Local Function
+ **********************************************************/
+
+/***********************************************************
+ * Global Function
+ **********************************************************/
+
+
+#define FOLDER_PATH
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_query_folder_index
+ * DESCRIPTION
+ *  Get the index of folder
+ * PARAMETERS
+ *  category
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+
+nvram_folder_enum nvram_query_folder_index_ex(nvram_category_enum category, kal_bool first_copy)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_folder_enum folder_index;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#ifdef __NVRAM_MULTI_FOLDERS__
+    if (NVRAM_IS_CATEGORY_INTERNAL(category))
+    {
+        folder_index = NVRAM_NVD_CORE;
+    }
+    else if (NVRAM_IS_CATEGORY_CALIBRAT(category))
+    {
+        folder_index = NVRAM_NVD_CALI;
+    }
+    else if (NVRAM_IS_CATEGORY_IMPORTANT(category))
+    {
+        folder_index = NVRAM_NVD_IMPT;
+    }
+  #ifdef __NVRAM_READ_RESERVED_FILE__    
+    else if (NVRAM_IS_CATEGORY_RESERVED(category))
+    {
+        folder_index = NVRAM_NVD_BACKUP;
+    }
+  #endif
+  #if defined(__CCCIFS_SUPPORT__)
+    else if (NVRAM_IS_CATEGORY_IMPORTANT_L4(category))
+    {
+    #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+        if (!first_copy)
+            folder_index = NVRAM_NVD_IMPNT2;
+        else
+    #endif
+        folder_index = NVRAM_NVD_IMPNT;
+    }
+    else if (NVRAM_IS_CATEGORY_IMPORTANT_L1(category))
+    {
+        folder_index = NVRAM_NVD_IMPNT;
+    }
+  #endif
+  #ifdef __NVRAM_CUSTOM_SENSITIVE__
+    else if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(category))
+    {
+        folder_index = NVRAM_NVD_CUST;
+    }
+  #endif
+    else
+#endif /* __NVRAM_MULTI_FOLDERS__ */
+    {
+        folder_index = NVRAM_NVD_DATA;
+    }
+
+    return folder_index;
+}
+
+nvram_folder_enum nvram_query_folder_index(nvram_category_enum category)
+{
+    return nvram_query_folder_index_ex(category, KAL_TRUE);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_query_work_path
+ * DESCRIPTION
+ *  Get the path of nvram folder
+ * PARAMETERS
+ *  folder_idx
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_char * nvram_query_work_path(nvram_folder_enum folder_idx)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch (folder_idx)
+    {
+        case NVRAM_NVD_DATA:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_DATAITEM_PATH;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_DATAITEM_PATH;
+        }
+#ifdef __NVRAM_MULTI_FOLDERS__
+        case NVRAM_NVD_CORE:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_COREITEM_PATH;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_COREITEM_PATH;
+        }
+        case NVRAM_NVD_CALI:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_CALIBRAT_DATAITEM_PATH;
+        }
+        case NVRAM_NVD_IMPT:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_IMPT_DATAITEM_PATH;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_IMPT_DATAITEM_PATH;
+        }
+        case NVRAM_NVD_BACKUP:
+        {
+            return (kal_char *)NVRAM_FS_OTA_DATAITEM_PATH;
+        }
+        #if defined(__CCCIFS_SUPPORT__)
+        case NVRAM_NVD_IMPNT:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_IMPORTNT_DATAITEM_PATH;
+        }
+
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+        case NVRAM_NVD_IMPNT2:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH2;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_IMPORTNT_DATAITEM_PATH2;
+        }
+        #endif
+
+        #endif
+        #ifdef __NVRAM_CUSTOM_SENSITIVE__
+        case NVRAM_NVD_CUST:
+        {
+		#if defined (__NVRAM_UT_TEST__)
+			if((is_insulation_access) && 
+				(nvram_test_task1_id) && 
+				(kal_get_current_task()==nvram_test_task1_id))
+				return (kal_char *)NVRAM_TEST_FS_CUST_DATAITEM_PATH;
+			else
+		#endif
+            return (kal_char *)NVRAM_FS_CUST_DATAITEM_PATH;
+        }
+        #endif
+#endif /* __NVRAM_MULTI_FOLDERS__ */
+        default:
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)folder_idx, NVRAM_LOC_INVALID_FOLDER_1, 0);
+            break;
+        }
+    }
+
+    return NULL;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_query_file_name
+ * DESCRIPTION
+ *  Get file full name
+ * PARAMETERS
+ *  folder_idx  :
+ *  nvramname   : nvram file
+ *  filename    : full name of nvram file
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_wchar * nvram_query_file_name(nvram_folder_enum folder_idx, kal_char *nvramname, kal_wchar *filename)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch (folder_idx)
+    {
+        case NVRAM_NVD_DATA:
+        {
+            NVRAM_FS_MAKE_LID_PATH_FILENAME_1(filename, nvramname);
+            break;
+        }
+    #ifdef __NVRAM_MULTI_FOLDERS__
+        case NVRAM_NVD_CORE:
+        {
+            NVRAM_FS_MAKE_CORE_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+        case NVRAM_NVD_CALI:
+        {
+            NVRAM_FS_MAKE_CRITICAL_CALIBRAT_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+        case NVRAM_NVD_IMPT:
+        {
+            NVRAM_FS_MAKE_CRITICAL_IMPT_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+        #if defined(__CCCIFS_SUPPORT__)
+        case NVRAM_NVD_IMPNT:
+        {
+            NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+
+        #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+        case NVRAM_NVD_IMPNT2:
+        {
+            NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME2(filename, nvramname);
+            break;
+        }
+        #endif
+
+        #endif
+        case NVRAM_NVD_BACKUP:
+        {
+            NVRAM_FS_MAKE_OTA_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+
+        #ifdef __NVRAM_CUSTOM_SENSITIVE__
+        case NVRAM_NVD_CUST:
+        {
+            NVRAM_FS_MAKE_CUST_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+        #endif
+    #endif /* __NVRAM_MULTI_FOLDERS__ */
+    #ifdef __NVRAM_BACKUP_DISK_FAT__
+        case NVRAM_NVD_BAK:
+        {
+            NVRAM_FS_MAKE_BACKUP_PATH_FILENAME(filename, nvramname);
+            break;
+        }
+    #endif
+        default:
+        {
+            NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)folder_idx, NVRAM_LOC_INVALID_FOLDER_2, 0);
+            break;
+        }
+    }
+
+    return filename;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_query_file_name
+ * DESCRIPTION
+ *  Get file full name
+ * PARAMETERS
+ *  folder_idx  :
+ *  nvramname   : nvram file
+ *  filename    : full name of nvram file
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_wchar * nvram_query_file_name_by_path(kal_wchar *folder_path, kal_wchar *filename)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 path_length = 0;
+    kal_wchar *temp = NULL;
+
+    path_length = kal_wstrlen(folder_path);
+    temp = folder_path + path_length;
+    while(*temp != '\\')
+    {
+        temp--;
+    }
+    temp++;
+    filename = kal_wstrcpy(filename, temp);
+    
+
+    return filename;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_query_ex_file_name
+ * DESCRIPTION
+ *  Get file full name
+ * PARAMETERS
+ *  folder_idx  :
+ *  nvramname   : nvram file
+ *  filename    : full name of nvram file
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_wchar * nvram_query_ex_file_name(nvram_folder_enum folder_idx, kal_wchar *nvramname, kal_wchar *filename)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#ifdef __NVRAM_MULTI_FOLDERS__
+    if (folder_idx == NVRAM_NVD_CORE)
+    {
+#if defined (__NVRAM_UT_TEST__)
+	if((is_insulation_access) && 
+		(nvram_test_task1_id) && 
+		(kal_get_current_task()==nvram_test_task1_id))
+		kal_wsprintf(filename, "%s\\%w", NVRAM_TEST_FS_COREITEM_PATH, nvramname);
+	else
+#endif
+        kal_wsprintf(filename, "%s\\%w", NVRAM_FS_COREITEM_PATH, nvramname);
+    }
+    else if (folder_idx == NVRAM_NVD_CALI)
+    {
+#if defined (__NVRAM_UT_TEST__)
+	if((is_insulation_access) && 
+		(nvram_test_task1_id) && 
+		(kal_get_current_task()==nvram_test_task1_id))
+		kal_wsprintf(filename, "%s\\%w", NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH, nvramname);
+	else
+#endif
+        kal_wsprintf(filename, "%s\\%w", NVRAM_FS_CALIBRAT_DATAITEM_PATH, nvramname);
+    }
+    else if (folder_idx == NVRAM_NVD_IMPT)
+    {
+#if defined (__NVRAM_UT_TEST__)
+	if((is_insulation_access) && 
+		(nvram_test_task1_id) && 
+		(kal_get_current_task()==nvram_test_task1_id))
+		kal_wsprintf(filename, "%s\\%w", NVRAM_TEST_FS_IMPT_DATAITEM_PATH, nvramname);
+	else
+#endif
+        kal_wsprintf(filename, "%s\\%w", NVRAM_FS_IMPT_DATAITEM_PATH, nvramname);
+    }
+    #if defined(__CCCIFS_SUPPORT__)
+    else if (folder_idx == NVRAM_NVD_IMPNT)
+    {
+#if defined (__NVRAM_UT_TEST__)
+	if((is_insulation_access) && 
+		(nvram_test_task1_id) && 
+		(kal_get_current_task()==nvram_test_task1_id))
+		kal_wsprintf(filename, "%s\\%w", NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH, nvramname);
+	else
+#endif
+        kal_wsprintf(filename, "%s\\%w", NVRAM_FS_IMPORTNT_DATAITEM_PATH, nvramname);
+    }
+    #endif
+    #ifdef __NVRAM_CUSTOM_SENSITIVE__
+    else if (folder_idx == NVRAM_NVD_CUST)
+    {
+#if defined (__NVRAM_UT_TEST__)
+	if((is_insulation_access) && 
+		(nvram_test_task1_id) && 
+		(kal_get_current_task()==nvram_test_task1_id))
+		kal_wsprintf(filename, "%s\\%w", NVRAM_TEST_FS_CUST_DATAITEM_PATH, nvramname);
+	else
+#endif
+        kal_wsprintf(filename, "%s\\%w", NVRAM_FS_CUST_DATAITEM_PATH, nvramname);
+    }
+    #endif
+    else if (folder_idx == NVRAM_NVD_DATA)
+#endif /* __NVRAM_MULTI_FOLDERS__ */
+    {
+#if defined (__NVRAM_UT_TEST__)
+	if((is_insulation_access) && 
+		(nvram_test_task1_id) && 
+		(kal_get_current_task()==nvram_test_task1_id))
+		kal_wsprintf(filename, "%s\\%w", NVRAM_TEST_FS_DATAITEM_PATH, nvramname);
+	else
+#endif
+        kal_wsprintf(filename, "%s\\%w", NVRAM_FS_DATAITEM_PATH, nvramname);
+    }
+
+    return filename;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_delete_certain_folder
+ * DESCRIPTION
+ *  Delete all files in certain folder
+ * PARAMETERS
+ *  folder_idx : [in]
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static nvram_errno_enum nvram_create_certain_folder(nvram_folder_enum folder_idx)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 Ret;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_wsprintf(filename, "%s", nvram_query_work_path(folder_idx));
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    Ret = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,Ret);
+    if (Ret < FS_NO_ERROR)
+    {
+        /* Return value should be FS_FILE_NOT_FOUND (-9) only, others treat as fatal error */
+        NVRAM_FS_START_EX(FS_OP_CREATEDIR,filename);
+        Ret = FS_CreateDir((const kal_wchar*)filename);
+        NVRAM_FS_END(FS_OP_CREATEDIR,Ret);
+        if (Ret == FS_NO_ERROR)
+            return NVRAM_ERRNO_SUCCESS;
+    }
+
+    MD_TRC_FUNC_NVRAM_CREATE_ALL_FOLDER(Ret);
+    return NVRAM_ERRNO_FOLDER_EXIST;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_all_folder
+ * DESCRIPTION
+ *  create all the folders
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  status
+ *****************************************************************************/
+nvram_errno_enum nvram_create_all_folder(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 loop_idx;
+    nvram_errno_enum result = NVRAM_ERRNO_SUCCESS;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    for (loop_idx = NVRAM_FOLDER_TOTAL - 1; loop_idx >= NVRAM_FOLDER_BEGIN; loop_idx--)    
+    {
+        if (nvram_create_certain_folder(loop_idx) == NVRAM_ERRNO_FOLDER_EXIST)
+        {
+            result = NVRAM_ERRNO_FOLDER_EXIST;
+        }
+
+        MD_TRC_FUNC_NVRAM_CREATE_ALL_FOLDER(loop_idx);
+    }
+
+    return result;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_delete_certain_folder
+ * DESCRIPTION
+ *  Delete all files in certain folder
+ * PARAMETERS
+ *  folder_idx : [in]
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_delete_certain_folder(nvram_folder_enum folder_idx)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE handle;
+    FS_DOSDirEntry fileinfo;
+    WCHAR namepattern[32];
+
+#if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+#else
+    WCHAR filename[NVRAM_FILE_LEN + 1];
+#endif
+    kal_int32 result = FS_NO_ERROR;
+    WCHAR fullfilename[NVRAM_MAX_PATH_LEN];
+    kal_uint32 retval;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /*
+     * FS_XDelete will cut the folder, here we can't call it.
+     */
+
+#if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+    if ((folder_idx == NVRAM_NVD_IMPNT) || (folder_idx == NVRAM_NVD_IMPNT2))
+    {   // SML should never be deleted
+        return KAL_TRUE;
+    }
+#endif
+
+    nvram_query_file_name(folder_idx, "*", namepattern);
+
+ #ifndef __LOW_COST_SUPPORT_ULC__
+    NVRAM_FS_START_EX(FS_OP_FINDFIRST, namepattern);
+    handle = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, filename, sizeof(filename));
+    NVRAM_FS_END(FS_OP_FINDFIRST,handle);
+    if (handle > 0)
+    {
+        do
+        {
+            nvram_query_ex_file_name(folder_idx, filename, fullfilename);
+
+
+            NVRAM_FS_START_EX(FS_OP_DELETE, fullfilename);
+            retval = FS_Delete(fullfilename);
+            NVRAM_FS_END(FS_OP_DELETE,retval);
+            if (retval != FS_NO_ERROR)
+            {
+                NVRAM_FS_START(FS_OP_FINDCLOSE);
+                result = FS_FindClose(handle);
+                NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+                return KAL_FALSE;
+            }
+            NVRAM_FS_START(FS_OP_FINDNEXT);
+            result = FS_FindNext(handle, &fileinfo, filename, sizeof(filename));
+            NVRAM_FS_END(FS_OP_FINDNEXT,result);
+        }
+        while (result == FS_NO_ERROR);
+    }
+    else
+    {
+        return KAL_FALSE;
+    }
+
+    NVRAM_FS_START(FS_OP_FINDCLOSE);
+    result = FS_FindClose(handle);
+    NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+#else /* __LOW_COST_SUPPORT_ULC__ */
+    while(1)
+    {
+        NVRAM_FS_START_EX(FS_OP_FINDFIRST, namepattern);
+        handle = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, filename, sizeof(filename));
+        NVRAM_FS_END(FS_OP_FINDFIRST,handle);
+        if (handle > 0)
+        {
+            NVRAM_FS_START(FS_OP_FINDCLOSE);
+            result = FS_FindClose(handle);
+            NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+
+            nvram_query_ex_file_name(folder_idx, filename, fullfilename);
+
+            NVRAM_FS_START_EX(FS_OP_DELETE,fullfilename);
+            retval = FS_Delete(fullfilename);
+            NVRAM_FS_END(FS_OP_DELETE,retval);
+            if (retval != FS_NO_ERROR)
+            {
+                return KAL_FALSE;
+            }
+        }
+        else
+        {
+            break;
+        }
+    }
+#endif /* __LOW_COST_SUPPORT_ULC__ */
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_delete_all_nvram_files
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *
+ *****************************************************************************/
+kal_bool nvram_delete_all_nvram_files(nvram_bootup_enum bootup_type)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 loop_idx;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    MD_TRC_FUNC_NVRAM_DELETE_ALL_NVRAM_FILES(bootup_type);
+    switch (bootup_type)
+    {
+        case NVRAM_FIRST_BOOTUP:
+        {
+            for (loop_idx = NVRAM_FOLDER_TOTAL - 1; loop_idx >= NVRAM_FOLDER_BEGIN; loop_idx--)                
+            {
+                nvram_delete_certain_folder(loop_idx);
+            }
+            break;
+        }
+
+        case NVRAM_NORMAL_BOOTUP:
+        {
+            nvram_delete_certain_folder(NVRAM_NVD_DATA);
+        #if !defined(__CCCIFS_SUPPORT__)
+        #ifdef __NVRAM_MULTI_FOLDERS__
+            nvram_delete_certain_folder(NVRAM_NVD_CALI);
+        #endif /* __NVRAM_MULTI_FOLDERS__ */
+        #endif
+            break;
+        }
+        
+        default:
+            break;
+    }
+
+    return KAL_TRUE;
+}
+
+
diff --git a/mcu/service/nvram/src/nvram_nl1def.c b/mcu/service/nvram/src/nvram_nl1def.c
new file mode 100644
index 0000000..65bfe51
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_nl1def.c
@@ -0,0 +1,38 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_nl1def.c
+ *
+ * Project:
+ * --------
+ *   
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+
+#if (defined __MD93__)  
+#elif (defined __MD95__)  
+#elif (defined __MD97__)  
+#include "nvram_nl1def_md97.c"
+#else
+#error "Should define at least a kind of BB being used."
+#endif
diff --git a/mcu/service/nvram/src/nvram_nl1def_md97.c b/mcu/service/nvram/src/nvram_nl1def_md97.c
new file mode 100644
index 0000000..a1c0bf9
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_nl1def_md97.c
@@ -0,0 +1,215 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_nl1def_md97.c
+ *
+ * Project:
+ * --------
+ *   
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_data_items.h"
+
+
+#include "nl1_nvram_def.h"
+#include "nl1_rfd_custom_data_dpd.h"
+#include "nl1_rfd_custom_data_et.h"
+#include "mml1_dpd_def.h"
+#include "mml1_et_def.h"
+#include "mml1_tpc_custom_data.h"
+
+void nvram_get_nL1_default_value_to_write_record(nvram_lid_core_enum lid, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+
+   kal_int32 i,j;
+
+   switch (lid)
+   {
+
+/*******************************************************************************
+* DPD part
+******************************************************************************/
+      /** NL1D DPD K data(MMDPD_CAL_DATABASE_T) set to default zero*/
+      case NVRAM_EF_NL1_DPD_CAL_DATABASE_LID:
+      {
+         #if __IS_NL1_DPD_SUPPORT__
+
+         MMDPD_CAL_DATABASE_T *p_buffer = (MMDPD_CAL_DATABASE_T*)buffer;
+         kal_mem_set(&(p_buffer->cal_result),  0, sizeof(MMDPD_NVRAM_DATA_T));
+
+         #endif /* __IS_NL1_DPD_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D DPD K data(MML1_RFFE_CAL_TX_DEFAULT_TBL_T) zero init*/
+      case NVRAM_EF_NL1_DPD_CAL_TX_DEFAULT_TBL_LID:
+      {
+         #if __IS_NL1_DPD_SUPPORT__
+
+         MML1_RFFE_CAL_TX_DEFAULT_TBL_T *p_buffer = (MML1_RFFE_CAL_TX_DEFAULT_TBL_T*)buffer;
+         kal_mem_set(&(p_buffer->band_ind),                 0, sizeof(MMRF_COMMON_BAND_IDX_E));
+
+         for(i=0; i<MMRF_CAL_MAX_BLOCK_PER_COMP_ROUTE; i++)
+         {
+            for(j=0; j<MML1_RFFE_CAL_TX_BW_NUM; j++)
+            {
+               kal_mem_set(&(p_buffer->mapping_tbl[i].block_id_bw[j]),  0, sizeof(kal_uint16));
+            }
+         }
+
+         #endif /* __IS_NL1_DPD_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D DPD NORMAL MODE AND OTFC CUSTOM PARA*/  
+      case NVRAM_EF_NL1_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_LID:
+      {
+         #if __IS_NL1_DPD_SUPPORT__
+
+         NR_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T *p_buffer = (NR_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T*)buffer;
+         kal_mem_cpy(p_buffer, p_NR_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_SetDefault, sizeof(NR_DPD_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T));
+
+         #endif /* __IS_NL1_DPD_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D DPD NORMAL MODE AND OTFC NONCUSTOM PARA*/ 
+      case NVRAM_EF_NL1_DPD_DEBUG_PARA_LID:
+      {
+         #if __IS_NL1_DPD_SUPPORT__
+
+         MMDPD_DBG_T *p_buffer = (MMDPD_DBG_T*)buffer;
+         kal_mem_cpy(&p_buffer->normal_otfc, p_NR_DPD_NORMAL_MODE_AND_OTFC_DBG_PARA, sizeof(MMDPD_NORMAL_MODE_AND_OTFC_DBG_T));
+         kal_mem_set(&p_buffer->factory, 0, sizeof(MMDPD_FAC_DBG_T));
+
+         #endif /* __IS_NL1_DPD_SUPPORT__ */
+      }
+      break;
+
+/*******************************************************************************
+* ET part
+******************************************************************************/
+      /** NL1D ET K data(MMET_CAL_DATABASE_T) set to default zero*/
+      case NVRAM_EF_NL1_ET_CAL_DATABASE_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         MMET_CAL_DATABASE_T *p_buffer = (MMET_CAL_DATABASE_T*)buffer;
+         kal_mem_set(&(p_buffer->cal_result),  0, sizeof(MMET_NVRAM_DATA_T));
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D ET K detrough(MMET_DETROUGH_T) set to default zero*/
+      case NVRAM_EF_NL1_ET_CAL_DETROUGH_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         MMET_DETROUGH_T *p_buffer = (MMET_DETROUGH_T*)buffer;
+         kal_mem_set(p_buffer,  0, sizeof(MMET_DETROUGH_T));
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D ET K pa gain subband(MMET_PA_GAIN_COMPENSATION_T) set to default zero*/
+      case NVRAM_EF_NL1_ET_CAL_PA_SUB_COMP_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         MMET_PA_GAIN_COMPENSATION_T *p_buffer = (MMET_PA_GAIN_COMPENSATION_T*)buffer;
+         kal_mem_set(p_buffer,  0, sizeof(MMET_PA_GAIN_COMPENSATION_T));
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D ET K data(MML1_RFFE_CAL_TX_DEFAULT_TBL_T) zero init*/
+      case NVRAM_EF_NL1_ET_CAL_TX_DEFAULT_TBL_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         MML1_RFFE_CAL_TX_DEFAULT_TBL_T *p_buffer = (MML1_RFFE_CAL_TX_DEFAULT_TBL_T*)buffer;
+         kal_mem_set(&(p_buffer->band_ind),                 0, sizeof(MMRF_COMMON_BAND_IDX_E));
+
+         for(i=0; i<MMRF_CAL_MAX_BLOCK_PER_COMP_ROUTE; i++)
+         {
+            for(j=0; j<MML1_RFFE_CAL_TX_BW_NUM; j++)
+            {
+               kal_mem_set(&(p_buffer->mapping_tbl[i].block_id_bw[j]),  0, sizeof(kal_uint16));
+            }
+         }
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D ET CMEAS PARA*/  
+      case NVRAM_EF_NL1_ET_CMEAS_PARA_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         NR_ET_CMEAS_PARA_T *p_buffer = (NR_ET_CMEAS_PARA_T*)buffer;
+         kal_mem_cpy(p_buffer, p_NR_ET_CMEAS_PARA_SetDefault, sizeof(NR_ET_CMEAS_PARA_T));
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D ET NORMAL MODE AND OTFC CUSTOM PARA*/  
+      case NVRAM_EF_NL1_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         NR_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T *p_buffer = (NR_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T*)buffer;
+         kal_mem_cpy(p_buffer, p_NR_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_SetDefault, sizeof(NR_ET_NORMAL_MODE_AND_OTFC_CUSTOM_PARA_T));
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      /** NL1D ET NORMAL MODE AND OTFC NONCUSTOM PARA*/ 
+      case NVRAM_EF_NL1_ET_DEBUG_PARA_LID:
+      {
+         #if __IS_NL1_ET_SUPPORT__
+
+         MMET_DBG_T *p_buffer = (MMET_DBG_T*)buffer;
+         kal_mem_cpy(&p_buffer->normal_otfc, p_NR_ET_NORMAL_MODE_AND_DBG_PARA, sizeof(MMET_NORMAL_MODE_AND_OTFC_DBG_T));
+         kal_mem_set(&p_buffer->factory, 0, sizeof(MMET_FAC_DBG_T));
+
+         #endif /* __IS_NL1_ET_SUPPORT__ */
+      }
+      break;
+
+      default:
+      {
+         ASSERT(KAL_FALSE);
+      }
+      break;
+   }
+}
+
diff --git a/mcu/service/nvram/src/nvram_pre_read.c b/mcu/service/nvram/src/nvram_pre_read.c
new file mode 100644
index 0000000..a8e59f3
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_pre_read.c
@@ -0,0 +1,167 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*
+ * Include
+ */
+
+#include <string.h>
+    
+#include "kal_general_types.h"
+#include "kal_internal_api.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+#include "fs_type.h"                /* FS_HANDLE */
+#include "fs_func.h"                /* FS_Delete */
+#include "fs_errcode.h"             /* FS_NO_ERROR */
+#include "ex_item.h"                /* EX_LOG_T */
+
+#include "tst_msgid.h"
+#include "sbp_public_utility.h"
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+
+#include "nvram_cache_interface.h"
+#include "nvram_defs.h"
+
+
+
+
+/*******************************************************
+ *  External Function
+ *******************************************************/
+extern kal_uint32 pre_read_white_list[];
+extern kal_uint16 preread_white_list_amount;
+/*******************************************************
+ * Define
+ *******************************************************/
+
+
+/*******************************************************
+ *  Typedef
+ *******************************************************/
+
+
+/*******************************************************
+ *  Global Variable
+ *******************************************************/
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+/*******************************************************
+ *  Local Function
+ *******************************************************/
+
+
+/*******************************************************
+ *  Local Variable
+ *******************************************************/
+nvram_errno_enum nvram_pre_read_white_list_lid(void)
+{
+#ifdef __NVRAM_LID_PREREAD__
+    kal_uint16 i,j;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *preread_temp_buffer = NULL;
+    kal_uint32 preread_temp_buffer_size = 0;
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    nvram_ldi_header nv_header;
+    kal_int32 rec_in_block = 0;
+
+    for(i = 0; i < preread_white_list_amount; i++)
+    {
+        if(!nvram_util_get_data_item(&ldi, pre_read_white_list[i]))
+        {
+            //NVRAM_EXT_ASSERT(pre_read_white_list[i], preread_white_list_amount, NVRAM_LOC_INIT_BUFFER_OVERFLOW, MAX_NVRAM_RECORD_SIZE);
+            continue;
+        }
+
+        if (!nvram_util_has_file_created(ldi))
+        {
+            continue;
+        }
+        preread_temp_buffer_size = ldi->size * ldi->total_records;
+        if (preread_temp_buffer_size > MAX_NVRAM_RECORD_SIZE)
+        {
+            preread_temp_buffer_size = MAX_NVRAM_RECORD_SIZE;
+        }
+        
+        preread_temp_buffer = (kal_uint8 *)get_ctrl_buffer(preread_temp_buffer_size);
+        if(preread_temp_buffer == NULL)
+        {
+            kal_prompt_trace(MOD_NVRAM, "[NVUT] %s()ldi->LID:%x LID->attr=(%x) preread_temp_buffer is NULL\n\r", __FUNCTION__, ldi->LID, ldi->attr);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]%s->LINE 0x%04x :lid=0x%x preread_temp_buffer is NULL\r\n", __FUNCTION__, __LINE__, ldi->LID);
+            continue;
+        }
+
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+        nvram_folder = nvram_query_folder_index(ldi->category);
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+        nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header, NVRAM_LDI_HEADER_SIZE);
+
+        kal_prompt_trace(MOD_NVRAM, "[NVUT] %s()ldi->LID:%x LID->attr=(%x) default_attr\n\r", __FUNCTION__, ldi->LID, ldi->attr);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]%s->LINE 0x%04x :lid=0x%x \r\n", __FUNCTION__, __LINE__, ldi->LID);
+        rec_in_block = preread_temp_buffer_size / ldi->size;
+        for (j = 1 ; j <= ldi->total_records; )
+        {
+            kal_mem_set(preread_temp_buffer, 0x00, preread_temp_buffer_size);
+            if(NVRAM_ERRNO_SUCCESS != nvram_read_data_item(ldi, j, rec_in_block, preread_temp_buffer, preread_temp_buffer_size))
+            {
+                kal_prompt_trace(MOD_NVRAM, "[NVUT] %s()ldi->LID:%x LID->attr=(%x) nvram_read_data_item\n\r", __FUNCTION__, ldi->LID, ldi->attr);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]%s->LINE 0x%04x :lid=0x%x nvram_read_data_item failed\r\n", __FUNCTION__, __LINE__, ldi->LID);
+                break;
+                //free_ctrl_buffer(preread_temp_buffer);
+                //preread_temp_buffer = NULL;
+                //NVRAM_EXT_ASSERT(pre_read_white_list[i], ldi->size, NVRAM_LOC_INIT_BUFFER_OVERFLOW, ldi->total_records);
+            }
+            j += rec_in_block;
+            rec_in_block = rec_in_block < (ldi->total_records - j + 1)? rec_in_block : (ldi->total_records - j + 1);
+        }
+        
+        free_ctrl_buffer(preread_temp_buffer);
+        preread_temp_buffer = NULL;
+    }
+#endif
+    return NVRAM_ERRNO_SUCCESS;
+}
+
diff --git a/mcu/service/nvram/src/nvram_pseudo_merge.c b/mcu/service/nvram/src/nvram_pseudo_merge.c
new file mode 100644
index 0000000..c4ba1be
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_pseudo_merge.c
@@ -0,0 +1,1866 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_pseudo_merge.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   NVRAM feature: pseudo merge
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/***************************************************************************** 
+ * Include
+ *****************************************************************************/
+#ifdef __NVRAM_PSEUDO_MERGE__
+
+#include "string.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+#include "nvram_pseudo_merge.h"
+
+
+/*
+ * FS head file
+ */
+#include "fs_type.h"
+#include "fs_func.h"
+#include "fs_errcode.h"
+
+#include "nvram_main.h"
+
+/***********************************************************
+ * Static Declaration
+ ***********************************************************/
+/*
+ * Define local variable here
+ */
+static head_info_entry *g_nvram_move_package_lid;
+static kal_bool is_need_move = KAL_FALSE;
+static kal_uint16 total_package_lid = 0;
+static head_info_struct g_head_info_file;
+
+/***********************************************************
+ * Global Variable
+ **********************************************************/
+
+/***********************************************************
+ * Global Function
+ **********************************************************/
+extern void *kal_tmp_mem_alloc(kal_uint32 size);
+extern void kal_tmp_mem_free(void *mem_ptr);
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_filename_compare
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_make_filename_compare(kal_char* buf, kal_char* prefix, kal_char* verno) 
+{
+   buf[0] = prefix[0];       
+   buf[1] = prefix[1];       
+   buf[2] = prefix[2];       
+   buf[3] = prefix[3];       
+   buf[4] = verno[0];        
+   buf[5] = verno[1];        
+   buf[6] = verno[2];        
+   buf[7] = '\0';                            
+};
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_package_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_make_package_filename(kal_char* buf, kal_char M) 
+{       
+   buf[0] = 'P';                    
+   buf[1] = 'A';                    
+   buf[2] = 'C';                    
+   buf[3] = 'K';                    
+   buf[4] = M;         
+   buf[5] = 'L';                    
+   buf[6] = 'I';                    
+   buf[7] = 'D';                    
+   buf[8] = '\0';                   
+};
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_package_info_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_make_package_info_filename(kal_char* buf, kal_char M) 
+{  
+   buf[0] = 'I';                    
+   buf[1] = 'N';                    
+   buf[2] = 'F';                    
+   buf[3] = 'O';                    
+   buf[4] = M;         
+   buf[5] = 'L';                    
+   buf[6] = 'I';                    
+   buf[7] = 'D';                    
+   buf[8] = '\0';                   
+};
+
+/*****************************************************************************
+ * FUNCTION
+ *  naram_make_temp_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void naram_make_temp_filename(kal_char* buf, kal_char M)
+{  
+   buf[0] = 'T';                    
+   buf[1] = 'E';                    
+   buf[2] = 'M';                    
+   buf[3] = 'P';                    
+   buf[4] = M;         
+   buf[5] = 'L';                    
+   buf[6] = 'I';                    
+   buf[7] = 'D';                    
+   buf[8] = '\0';                   
+};
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_sort_order_head_info
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  lid_info        [?]
+ *  info_index      [IN]        info_index [0, total_num - 1], <==> loop_index
+ *  file_index      [IN]
+ * RETURNS
+ *
+ *****************************************************************************/
+static kal_bool nvram_sort_order_head_info(LID_info_struct *lid_info, kal_uint16 info_index, nvram_lid_enum file_index)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    head_info_entry headinfo_temp;
+    kal_uint32 temp;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    headinfo_temp.file_offset = lid_info->file_offset;
+    headinfo_temp.record_size = lid_info->record_size;
+    headinfo_temp.total_records = lid_info->total_records;
+    headinfo_temp.area = lid_info->area;
+    headinfo_temp.LID = file_index;
+
+//    NVRAM_BLOCKING_ASSERT(info_index <= total_package_lid, 0, 0, 0);
+
+    if (info_index == 0)
+    {
+        g_nvram_move_package_lid[0] = headinfo_temp;
+    }
+    else
+    {
+        for (temp = (kal_uint32)info_index; temp > 0; temp--)
+        {
+            if (headinfo_temp.file_offset < g_nvram_move_package_lid[temp - 1].file_offset)     /* last one */
+            {
+                g_nvram_move_package_lid[temp] = headinfo_temp;
+                break;
+            }
+            else
+            {
+                g_nvram_move_package_lid[temp] = g_nvram_move_package_lid[temp - 1];
+                g_nvram_move_package_lid[temp - 1] = headinfo_temp;
+            }
+        }
+    }
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_compare_filename_chksum
+ * DESCRIPTION
+ *  To judge which table (core/comm/cust) has been changed (add LID or del LID)
+ *  By compare filename's chksum.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+ static kal_bool nvram_compare_filename_chksum(head_info_struct *head_info)
+ {
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    //for compatible with 10A & 11A, only use CORE variable after 11B
+    head_info->chksum_core += (head_info->chksum_comm + head_info->chksum_cust);
+    head_info->total_size_core += (head_info->total_size_comm + head_info->total_size_cust);
+    
+    //for compatible with 10A & 11A, only use CORE variable after 11B
+    if ((head_info->chksum_core != g_head_info_file.chksum_core) ||
+        (head_info->total_size_core != g_head_info_file.total_size_core))
+    {
+        nvram_ptr->sw_status |= NVRAM_SW_PACKAGE_CHANGE;
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+        }
+    }
+
+    return KAL_TRUE;
+ }
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_create_package_file
+ * DESCRIPTION
+ *  To create package_file and information_package_file.
+ * PARAMETERS
+ *  M_name      [IN]        
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_create_package_file(kal_char M_name)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME nvramname;
+
+    nvram_drv_status_enum drv_status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* open package file/backup file,if no exist, create it */
+    nvram_make_package_filename(nvramname, M_name);
+
+    drv_status = nvram_drv_fat_write(
+                    nvramname,
+                    NVRAM_NVD_DATA,
+                    0,
+                    1,
+                    1,
+                    sizeof(head_info_struct),
+                    (kal_uint8*) &g_head_info_file,
+                    NVRAM_ATTR_AVERAGE,
+                    KAL_TRUE);
+    if (drv_status != NVRAM_DRV_OK)
+    {
+        return KAL_FALSE;
+    }
+
+    /* open information file/backup file,if no exist, create it */
+    nvram_make_package_info_filename(nvramname, M_name);
+
+    drv_status = nvram_drv_fat_write(
+                    nvramname,
+                    NVRAM_NVD_DATA,
+                    0,
+                    1,
+                    1,
+                    sizeof(head_info_struct),
+                    (kal_uint8*) &g_head_info_file,
+                    NVRAM_ATTR_AVERAGE,
+                    KAL_TRUE);
+    if (drv_status != NVRAM_DRV_OK)
+    {
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_open_package_file
+ * DESCRIPTION
+ *  To open package_file and backup_package_file.
+ * PARAMETERS
+ *  nvramname       [IN]         
+ *  openOption      [IN]        
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_open_package_file(kal_char *nvramname, kal_uint32 openOption)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+
+    FS_HANDLE hFile = 0;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_query_file_name(NVRAM_NVD_DATA, nvramname, filename);
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFile = FS_Open((const kal_wchar*)filename, openOption);
+    NVRAM_FS_END(FS_OP_OPEN,hFile);
+
+    if (hFile <= FS_NO_ERROR)
+    {
+        MD_TRC_MERGE_OPEN_PKG_FILE_RESULT(hFile);
+        return KAL_FALSE;
+    }
+    NVRAM_FS_START(FS_OP_OPEN);
+    result = FS_Close(hFile);
+    NVRAM_FS_END(FS_OP_OPEN,result);
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_check_data_item
+ * DESCRIPTION
+ *  To check which data item valid. 1.Write back to file. OR 2. Create big array ?????
+ * PARAMETERS
+ *  total_num       [IN]        
+ *  data_offset     [IN/OUT]         
+ *  sw_change       [IN]        
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_check_data_item(kal_bool sw_change)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_lid_enum temp;
+    kal_uint32 package_temp;
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    kal_uint32 Offset;
+
+    LID_info_struct lid_info;
+    kal_char filename_compare[8];
+    NVRAM_FILE_NAME nvramname;
+    nvram_drv_status_enum drv_status;
+    kal_bool lid_is_valid;  /* can find in logical table, means lid is still valid */
+    kal_uint16 info_index = 0;
+
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_make_package_info_filename(nvramname, 'A');
+
+    for (package_temp = (kal_uint32)total_package_lid; package_temp > 0; package_temp--)
+    {
+        /* 1. Read LID information */
+
+        /* seek to the record start,from top to bottom */
+        Offset = (sizeof(head_info_struct) + NVRAM_CHKSUM_SIZE) + 
+                 (package_temp - 1) * (sizeof(LID_info_struct) + NVRAM_CHKSUM_SIZE); 
+        
+        lid_is_valid = KAL_FALSE;   /* first, Assume every lid is invalid */
+
+        drv_status = nvram_drv_fat_read(
+                        nvramname,
+                        NVRAM_NVD_DATA,
+                        Offset,
+                        1,
+                        1,
+                        sizeof(LID_info_struct),
+                        (kal_uint8*) &lid_info,
+                        NVRAM_DRV_READ_TYPE_DATA,
+                        NVRAM_ATTR_AVERAGE);
+        /* Success!! Great!! */
+        if (drv_status == NVRAM_DRV_OK)
+        {
+            if (lid_info.area != NVRAM_AREA_INVALID)
+            {
+                /* Step 1: try to find out corresponding LID */
+	            ldi = &logical_data_item_table[0];
+                do
+                {
+
+                    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+                    {
+                        nvram_make_filename_compare(filename_compare, ldi->fileprefix, ldi->fileverno);
+                        if (!strcmp(filename_compare, lid_info.itemname))       /* Compatible */
+                        {
+                            if (lid_info.record_size * lid_info.total_records == ldi->size * ldi->total_records)
+                            {
+                                lid_is_valid = KAL_TRUE;    /* means current LID is valid */
+                            }
+                            break;  /* break out for loop */
+                        }
+                    }
+                }while(nvram_util_next_data_item(&ldi));
+
+                /* Step 2: if software change,
+                 *     case a: item is invalid, set it as invalid and register it into g_nvram_move_package_lid
+                 *     case b: item is valid, set the offset into ltable.
+                 */
+
+                if (sw_change)
+                {
+                    if (!lid_is_valid)
+                    {
+                        is_need_move = KAL_TRUE;
+                        lid_info.area = NVRAM_AREA_INVALID;
+
+                        drv_status = nvram_drv_fat_write(
+                                        nvramname,
+                                        NVRAM_NVD_DATA,
+                                        Offset,
+                                        1,
+                                        1,
+                                        sizeof(LID_info_struct),
+                                        (kal_uint8*) &lid_info,
+                                        NVRAM_ATTR_AVERAGE,
+                                        KAL_FALSE);
+                        if (drv_status != NVRAM_DRV_OK)
+                        {
+                        }
+                    }
+
+                    //nvram_sort_order_head_info(&lid_info, info_index, temp);
+                    nvram_sort_order_head_info(&lid_info, info_index, ldi->LID);
+                    info_index++;
+                }
+                else
+                {
+                    if (lid_is_valid)
+                    {
+                        ldi->description = (kal_char *)(lid_info.file_offset);
+                    }
+                    else
+                    {
+                        NVRAM_EXT_ASSERT(KAL_FALSE,lid_info.file_offset,NVRAM_LOC_INVALID_LID_4 , lid_info.record_size);
+                        return KAL_FALSE;
+                    }
+                }
+            }
+            else
+            {
+                if (sw_change)
+                {
+                    is_need_move = KAL_TRUE;
+                    /*
+                     * If in the previous three cases, before write action poweroff suddenly happened,
+                     * when next power-on, it will run into this case. this LID will be invalid and
+                     * will be truncated in movement action.
+                     */
+                    temp = 0xFF;
+                    nvram_sort_order_head_info(&lid_info, info_index, temp);
+                    info_index++;
+                }
+            }
+        }
+        else    /* Sigh. Failed..... */
+        {
+            //NVRAM_BLOCKING_ASSERT(KAL_FALSE, 0, 0, 0);
+            return KAL_FALSE;
+        }
+
+    }
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_set_offset_to_ltable
+ * DESCRIPTION
+ *  Read out file offset from file, and set it to ltable
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_set_offset_to_ltable(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    return nvram_check_data_item(KAL_FALSE);
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_head_information
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  head_info       [IN/OUT]         
+ *  openOption      [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_read_head_information(head_info_struct *head_info, kal_uint32 openOption)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME nvramname;
+    nvram_drv_status_enum drv_status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_make_package_info_filename(nvramname, 'A');
+    
+    drv_status = nvram_drv_fat_read(
+                    nvramname,
+                    NVRAM_NVD_DATA,
+                    0,
+                    1,
+                    1,
+                    sizeof(head_info_struct),
+                    (kal_uint8*) head_info,
+                    NVRAM_DRV_READ_TYPE_DATA,
+                    NVRAM_ATTR_AVERAGE);
+
+    if (drv_status != NVRAM_DRV_OK)
+    {
+        return KAL_FALSE;
+    }                
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_calculate_write_data_offset
+ * DESCRIPTION
+ *  1. Fill in all offset to ldi->description.
+ *  2. Update the header in package file
+ *  3. Update the info file
+ *  4. return the maximum offset of the package file now. All new item will be added
+ *     after this offset.
+ * PARAMETERS
+ *  offset_for_add_lid  [OUT]   the offset to add new lid
+ *  is_init             [IN]    is init or not
+ * RETURNS
+ *  KAL_FALSE: fail
+ *  KAL_TRUE: successful
+ *****************************************************************************/
+kal_bool nvram_calculate_write_data_offset(kal_uint32 *offset_for_add_lid, kal_bool is_init)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME nvramname;
+    nvram_ltable_entry_struct *ldi;
+    LID_info_struct lid_info_temp;
+    kal_uint32 file_idx;
+    nvram_drv_status_enum drv_status;
+    kal_uint32 info_offset = 0;
+    kal_uint16 info_index = 0;
+    kal_uint32 file_offset = 0;
+
+
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (is_init)    /* write Init */
+    {
+        nvram_make_package_info_filename(nvramname, 'A');
+        nvram_create_package_file('A');
+        file_offset = sizeof(head_info_struct) + NVRAM_CHKSUM_SIZE;
+    }
+    else    /* write backup information file */
+    {
+        nvram_make_package_info_filename(nvramname, 'B');   /* 1. need move 2. add new lid */
+        nvram_create_package_file('B');
+
+        if (is_need_move)   /* 1. need move, has invalid lid */
+        {
+            file_offset = sizeof(head_info_struct) + NVRAM_CHKSUM_SIZE;
+        }
+
+        for (file_idx = 0; file_idx < total_package_lid; file_idx++)
+        {
+
+            if (g_nvram_move_package_lid[file_idx].area != NVRAM_AREA_INVALID)
+            {
+                nvram_util_get_data_item(&ldi, g_nvram_move_package_lid[file_idx].LID);
+
+                if (is_need_move)   /* 1. need move, has invalid lid */
+                {
+                    ldi->description = (kal_char *)(file_offset);
+                    file_offset += (ldi->size + NVRAM_CHKSUM_SIZE) * ldi->total_records;
+                }
+                else
+                {
+                    ldi->description = (kal_char *)(g_nvram_move_package_lid[file_idx].file_offset);
+                }
+            }
+        }
+
+
+        if (!is_need_move)    /* 2. No need move, only add new lid */
+        {
+            nvram_util_get_data_item(&ldi, g_nvram_move_package_lid[0].LID);
+            file_offset = g_nvram_move_package_lid[0].file_offset + (ldi->size + NVRAM_CHKSUM_SIZE) * ldi->total_records;
+        }
+
+    }
+
+    if (offset_for_add_lid)
+    {
+        /* Assign file_offset for add new lid */
+        *offset_for_add_lid = file_offset;
+    }
+
+    /* 2.write package LID information */
+    ldi = &logical_data_item_table[0];
+    do 
+    {
+//        if (ltable_entry)
+//        {
+//            nvram_util_get_data_item(&ldi, file_idx);
+            if (!NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+            {
+                continue;
+            }
+
+            info_offset = (sizeof(head_info_struct) + NVRAM_CHKSUM_SIZE) + info_index * (sizeof(lid_info_temp) + NVRAM_CHKSUM_SIZE);
+            info_index++;
+        
+            lid_info_temp.record_size = ldi->size;
+            lid_info_temp.total_records = ldi->total_records;
+            nvram_make_filename_compare(lid_info_temp.itemname, ldi->fileprefix, ldi->fileverno);
+        
+            if (ldi->description)   /* already in package file */
+            {
+                lid_info_temp.file_offset = (kal_uint32) (ldi->description);
+            }
+            else    /* newly add [do not set file_offset in ltable, because add_new_package_lid need this information] */
+            {                
+                ldi->description = (kal_char*) file_offset;
+                lid_info_temp.file_offset = file_offset;
+                file_offset += ((ldi->size + NVRAM_CHKSUM_SIZE) * (ldi->total_records));
+            }
+        
+            drv_status = nvram_drv_fat_write(
+                            nvramname,
+                            NVRAM_NVD_DATA,
+                            info_offset,
+                            1,
+                            1,
+                            sizeof(LID_info_struct),
+                            (kal_uint8*) &lid_info_temp,
+                            NVRAM_ATTR_AVERAGE,
+                            KAL_FALSE);
+            if (drv_status != NVRAM_DRV_OK)
+            {
+                return KAL_FALSE;
+            }
+
+//        }
+    
+    }while(nvram_util_next_data_item(&ldi));
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_init_all_package_lid
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_init_all_package_lid(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_reset_data_items(NVRAM_RESET_PACKAGE, NVRAM_APP_RESERVED, 0, 0, 0);
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_construct_head_info_table
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  total_num       [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_construct_head_info_table(kal_uint32 total_num)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    g_nvram_move_package_lid = (head_info_entry *)kal_tmp_mem_alloc(sizeof(head_info_entry) * total_num);
+
+    if (!g_nvram_move_package_lid)
+    {
+        return KAL_FALSE;
+    }
+
+    kal_mem_set(g_nvram_move_package_lid, 0, total_num * sizeof(head_info_entry));
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_destruct_head_info_table
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_destruct_head_info_table(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (g_nvram_move_package_lid)
+    {
+        kal_tmp_mem_free(g_nvram_move_package_lid);
+        g_nvram_move_package_lid = NULL;
+    }
+
+    return KAL_TRUE;
+}
+
+
+
+
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_del_rename_package_file
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_del_rename_package_file(kal_bool is_exist_package_file)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME packagename;
+    NVRAM_FILE_NAME backupname;
+    kal_wchar pack_filename[NVRAM_MAX_PATH_LEN];
+    kal_wchar back_filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 ret;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* package file */
+    if (is_exist_package_file)
+    {
+        nvram_make_package_filename(packagename, 'A');
+        nvram_make_package_filename(backupname, 'B');
+        nvram_query_file_name(NVRAM_NVD_DATA, packagename, pack_filename);
+        nvram_query_file_name(NVRAM_NVD_DATA, backupname, back_filename);
+        NVRAM_FS_START_EX(FS_OP_DELETE,pack_filename);
+        ret = FS_Delete(pack_filename);
+        NVRAM_FS_END(FS_OP_DELETE,ret);
+        if (ret < 0)
+        {
+            return KAL_FALSE;
+        }
+
+        NVRAM_FS_START_EX(FS_OP_RENAME,back_filename);
+        ret = FS_Rename(back_filename, pack_filename);
+        NVRAM_FS_END(FS_OP_RENAME,ret);
+        if (ret < 0)
+        {
+            return KAL_FALSE;
+        }
+    }
+
+    /* information file */
+    nvram_make_package_info_filename(packagename, 'A');
+    nvram_make_package_info_filename(backupname, 'B');
+    nvram_query_file_name(NVRAM_NVD_DATA, packagename, pack_filename);
+    nvram_query_file_name(NVRAM_NVD_DATA, backupname, back_filename);
+
+    NVRAM_FS_START_EX(FS_OP_DELETE,pack_filename);
+    ret = FS_Delete(pack_filename);
+    NVRAM_FS_END(FS_OP_DELETE,ret);
+    if (ret < 0)
+    {
+        return KAL_FALSE;
+    }
+
+    NVRAM_FS_START_EX(FS_OP_RENAME,back_filename);
+    ret = FS_Rename(back_filename, pack_filename);
+    NVRAM_FS_END(FS_OP_RENAME,ret);
+    if (ret < 0)
+    {
+        return KAL_FALSE;
+    }
+    
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_del_temporary_file
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_del_temporary_file(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME tempname;
+    kal_wchar temp_filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 ret;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    naram_make_temp_filename(tempname, 'A');
+    nvram_query_file_name(NVRAM_NVD_DATA, tempname, temp_filename);
+
+    NVRAM_FS_START_EX(FS_OP_DELETE,temp_filename);
+    ret = FS_Delete(temp_filename);
+    NVRAM_FS_END(FS_OP_DELETE,ret);
+    if (ret < 0)
+    {
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_write_temporary_record
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  loopindex       [IN]        moving index of g_nvram_move_package_lid[index]
+ *                              adding index of logical table[index]
+ *  Is_moving       [IN]        KAL_TRUE:  Now is moving, loopindex is moving index
+ *                              KAL_FALSE: Now is adding new LID, loopindex is adding index
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_write_temporary_record(kal_uint16 loopindex, kal_bool Is_moving)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME tempname;
+    temp_info_struct temp_info;
+    nvram_drv_status_enum drv_status;
+    
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    naram_make_temp_filename(tempname, 'A');
+
+    if (Is_moving)
+    {
+        temp_info.lid_moving_index = loopindex + 1;
+        temp_info.lid_adding_index = 0;
+    }
+    else
+    {
+        temp_info.lid_moving_index = 0;
+        temp_info.lid_adding_index = loopindex + 1;
+    }
+    
+    drv_status = nvram_drv_fat_write(
+                    tempname,
+                    NVRAM_NVD_DATA,
+                    0,
+                    1,
+                    1,
+                    sizeof(temp_info_struct),
+                    (kal_uint8 *)(&temp_info),
+                    NVRAM_ATTR_AVERAGE,
+                    KAL_FALSE);
+
+    if (drv_status != NVRAM_DRV_OK)
+    {
+        MD_TRC_MERGE_WRITE_TEMP_RESULT(
+            temp_info.lid_moving_index, 
+            temp_info.lid_adding_index, 
+            nvram_drv_fat_get_last_err(), 
+            __LINE__);
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+}
+
+ 
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_add_package_lid
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  Is_moving       [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_add_package_lid(kal_uint32 *file_offset, kal_bool Is_moving)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_drv_status_enum drv_status;
+    nvram_ltable_entry_struct *ldi;
+
+    NVRAM_FILE_NAME backupname;
+    kal_uint32 default_value_buffer_size;
+    kal_uint8 *default_value_buffer;
+
+    kal_uint32 record_index;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* Cannot allocate memory! */
+    if ((default_value_buffer_size = MAX_NVRAM_RECORD_SIZE) & 1)
+    {
+        default_value_buffer_size += 1;
+    }
+
+        default_value_buffer = (kal_uint8*) get_ctrl_buffer(default_value_buffer_size);
+    
+    if (Is_moving)
+    {
+        nvram_make_package_filename(backupname, 'B');
+    }
+    else
+    {
+        nvram_make_package_filename(backupname, 'A');
+    }
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        if (!NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+        {
+            continue;
+        }
+
+        if ((kal_uint32)ldi->description < (*file_offset))   /* Already in package file */
+        {
+            continue;
+        }
+
+
+        for (record_index = ldi->total_records; record_index > 0; record_index--)
+        {
+            nvram_get_default_value_to_write(ldi, (kal_uint16)record_index, default_value_buffer, default_value_buffer_size);
+
+            drv_status = nvram_drv_fat_write(
+                            backupname,
+                            NVRAM_NVD_DATA,
+                            (kal_uint32)(ldi->description),
+                            (kal_uint16)(record_index),
+                            1,
+                            ldi->size,
+                            default_value_buffer,
+                            //NVRAM_ATTR_AVERAGE,
+                            ldi->attr,
+                            KAL_FALSE);
+            if (drv_status == NVRAM_DRV_OK)
+            {
+            }
+            else
+            {
+                return KAL_FALSE;
+            }
+        }
+        /* write temp record, only when need moving, if just add LID, don't write temp record */
+        if (Is_moving)
+        {
+            nvram_write_temporary_record(ldi->LID, KAL_FALSE);
+        }
+    }while(nvram_util_next_data_item(&ldi));
+    
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_truncate_file
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  loopindex       [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+static kal_bool nvram_truncate_file(kal_uint16 loopindex)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_HANDLE hFileSrc = 0;
+    NVRAM_FILE_NAME packagename;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_make_package_filename(packagename, 'A');
+    nvram_query_file_name(NVRAM_NVD_DATA, packagename, filename);
+
+    NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+    hFileSrc = FS_Open(filename, FS_OPEN_NO_DIR | FS_READ_WRITE | FS_PROTECTION_MODE);
+    NVRAM_FS_END(FS_OP_OPEN,hFileSrc);
+    if (hFileSrc <= FS_NO_ERROR)
+    {
+        MD_TRC_MERGE_TRUNK_STATUS(hFileSrc);
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(hFileSrc);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        return KAL_FALSE;
+    }
+
+    NVRAM_FS_START(FS_OP_SEEK);
+    result = FS_Seek(hFileSrc, g_nvram_move_package_lid[loopindex].file_offset, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,result);
+    #if !(defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__))
+    result = FS_Truncate(hFileSrc);
+    #endif
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(hFileSrc);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_move_certain_date_item
+ * DESCRIPTION
+ *  This is nvram_move_certain_date_item() function of NVRAM module.
+ *  This function will copy certain valid data from src file to dest.
+ * PARAMETERS
+ *  loopindex   [IN]
+ * RETURNS
+ *  KAL_TRUE        if move (copy, write) successfully.
+ *  KAL_FALSE       if move (copy, write) failure.
+ *****************************************************************************/
+static kal_bool nvram_move_certain_date_item(kal_uint16 loopindex)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 record_index;
+    NVRAM_FILE_NAME packagename;
+    NVRAM_FILE_NAME backupname;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 *buffer = NULL;
+    nvram_drv_status_enum drv_status;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_make_package_filename(packagename, 'A');
+    nvram_make_package_filename(backupname, 'B');
+
+    nvram_util_get_data_item(&ldi, g_nvram_move_package_lid[loopindex].LID);
+
+    buffer = (kal_uint8 *) get_ctrl_buffer(ldi->size);
+    
+    /* g_nvram_move_package_lid[loopindex].total_records */
+    for (record_index = 0; record_index < ldi->total_records; record_index++)
+    {
+        drv_status = nvram_drv_fat_read(
+                        packagename,
+                        NVRAM_NVD_DATA,
+                        g_nvram_move_package_lid[loopindex].file_offset, 
+                        (kal_uint16)(record_index + 1), 
+//                        (kal_uint16)(record_index), 
+                        (kal_uint16)1,
+                        ldi->size, 
+                        buffer, 
+                        NVRAM_DRV_READ_TYPE_DATA, 
+                        NVRAM_ATTR_AVERAGE);
+                        
+        if (drv_status != NVRAM_DRV_OK)
+        {
+            NVRAM_EXT_ASSERT(0, DISPLAY_ERROR(drv_status), NVRAM_LOC_READ_PACKED_FILE_FAIL, ldi->LID);
+            return KAL_FALSE;
+        }
+        
+        /* Write to Dest file */
+        drv_status = nvram_drv_fat_write(
+                        backupname,
+                        NVRAM_NVD_DATA,
+                        (kal_uint32)(ldi->description),
+                        (kal_uint16)(record_index + 1),
+                        1,
+//                        (kal_uint16)(record_index), 
+                        ldi->size, 
+                        buffer, 
+                        NVRAM_ATTR_AVERAGE,
+                        //ldi->attr,
+                        KAL_FALSE);
+                        
+        if (drv_status != NVRAM_DRV_OK)
+        {
+            return KAL_FALSE;
+        }
+    }
+
+    if (buffer)
+        free_ctrl_buffer(buffer);
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_move_date_item
+ * DESCRIPTION
+ *  This is nvram_move_date_item() function of NVRAM module.
+ *  This function will copy valid data from src file to dest.
+ * PARAMETERS
+ *  temp_info          [IN]
+ *  total_package_lid  [IN]
+ *  init_move          [IN]
+ * RETURNS
+ *  KAL_TRUE        if move (copy, write) successfully.
+ *  KAL_FALSE       if move (copy, write) failure.
+ *****************************************************************************/
+static kal_bool nvram_move_data_item(temp_info_struct *temp_info, kal_bool init_move)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME packagename;
+    NVRAM_FILE_NAME backupname;
+    NVRAM_FILE_NAME tempname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 openOption = FS_OPEN_NO_DIR | FS_READ_WRITE | FS_PROTECTION_MODE;
+
+    kal_uint16 loopindex;
+    kal_uint16 loopstart;
+    kal_uint16 loopend = total_package_lid;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_make_package_filename(packagename, 'A');
+    nvram_make_package_filename(backupname, 'B');
+    naram_make_temp_filename(tempname, 'A');
+
+    if (init_move)  /* first time, move valid data *//* logical error */
+    {
+        loopstart = 0;
+    }
+    else
+    {
+        loopstart = temp_info->lid_moving_index;
+    }
+    /* step 1: open src file, if failed, reset all package lid */
+    if (nvram_open_package_file(packagename, openOption))
+    {
+        /* step 2: open/create dest file, if failed, delete src file and reset all package lid */
+        if (nvram_open_package_file(backupname, openOption))
+        {
+            /* Move valid LID package file */
+            for (loopindex = loopstart; loopindex < loopend; loopindex++)
+            {
+                if (g_nvram_move_package_lid[loopindex].area == NVRAM_AREA_INVALID)
+                {
+                
+                  /* May be suddenly power off between this two function */
+                  /* 1. truncate file 
+                   * nvram_truncate_file(loopindex);
+                   * 2. write index to file 
+                   * nvram_write_temporary_record(loopindex, KAL_TRUE);
+                   */
+                   
+                    /* 1. write index to file */
+                    nvram_write_temporary_record(loopindex, KAL_TRUE);
+                    /* 2. truncate file */
+                    nvram_truncate_file(loopindex);
+                }
+                else
+                {
+                    if (nvram_move_certain_date_item(loopindex))
+                    {
+                        /* 1. write index to file */
+                        nvram_write_temporary_record(loopindex, KAL_TRUE);
+                        /* 2. truncate file */
+                        nvram_truncate_file(loopindex);
+                    }
+                    else
+                    {
+                        /* if move certain data item failure, return KAL_FALSE, and All pachage LID will be reset */
+                        return KAL_FALSE;
+                    }
+                }
+            }
+        }
+        else
+        {
+            nvram_query_file_name(NVRAM_NVD_DATA, packagename, filename);
+            NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+            result = FS_Delete(filename);
+            NVRAM_FS_END(FS_OP_DELETE,result);
+            /* return KAL_FALSE, and All pachage LID will be reset */
+            return KAL_FALSE;
+        }
+    }
+    else
+    {
+        /* return KAL_FALSE, and All pachage LID will be reset */
+        return KAL_FALSE;
+    }
+/*  */
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_deal_with_exception
+ * DESCRIPTION
+ *
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *
+ *****************************************************************************/
+static kal_bool nvram_deal_with_exception(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    NVRAM_FILE_NAME temp_file;
+    temp_info_struct temp_info;
+    head_info_struct head_info;
+    kal_int32 openOption = FS_OPEN_NO_DIR | FS_READ_ONLY;
+    kal_uint32 data_offset = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    naram_make_temp_filename(temp_file, 'A');
+
+    nvram_drv_fat_read(
+        temp_file,
+        NVRAM_NVD_DATA,
+        0,
+        1,
+        1,
+        sizeof(temp_info_struct),
+        (kal_uint8*) &temp_info,
+        NVRAM_DRV_READ_TYPE_DATA,
+        NVRAM_ATTR_AVERAGE);
+
+    if (nvram_read_head_information(&head_info, openOption))
+    {
+        total_package_lid = head_info.total_pack_lid;
+
+        /* maybe have bug */
+        nvram_compare_filename_chksum(&head_info);
+
+        if (nvram_construct_head_info_table(total_package_lid))
+        {
+            nvram_check_data_item(KAL_TRUE);
+
+            nvram_calculate_write_data_offset(&data_offset, KAL_FALSE);
+
+            if (temp_info.lid_moving_index)    /* moving */
+            {
+                if (nvram_move_data_item(&temp_info, KAL_FALSE))
+                {
+                    /* 1. Add new LID */
+                    if (nvram_add_package_lid(&data_offset, KAL_TRUE))
+                    {
+                        /* 2. Delete Src file and Rename Dest file*/
+                        nvram_del_rename_package_file(KAL_TRUE);
+                        /* 3. Delete temp file */
+                        nvram_del_temporary_file();
+                    }
+                }
+                else
+                {
+                    /* What should i do */
+                    nvram_init_all_package_lid();
+                }
+            }
+            else    /* moved, add new lid */
+            {
+                if (nvram_add_package_lid(&data_offset, KAL_TRUE))  /* need move-->package file B */
+                {
+                    nvram_del_rename_package_file(KAL_TRUE);
+                    nvram_del_temporary_file();
+                }
+            }
+        }
+        else    /* else of nvram_construct_head_info_table */
+        {
+            nvram_init_all_package_lid();
+        }   /* end of nvram_construct_head_info_table */
+
+        nvram_destruct_head_info_table();
+    }
+    else
+    {
+        nvram_init_all_package_lid();
+    }   /* end of nvram_read_head_information */
+
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_compare_filename_chksum
+ * DESCRIPTION
+ *  To perform filename's chksum incompatible.(1. add LID 2. del LID)
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+static kal_bool nvram_chksum_conflict_resolve(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 offset_for_add_lid = 0;
+    kal_bool result=KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (nvram_construct_head_info_table(total_package_lid))
+    {
+        if (!nvram_check_data_item(KAL_TRUE))
+        {
+            result=KAL_FALSE;
+            goto out;
+        }
+
+        /* After check out all valid LID, need moving or not */
+        if (is_need_move)
+        {
+            if (nvram_create_package_file('B'))
+            {
+                temp_info_struct temp_info;
+
+                nvram_calculate_write_data_offset(&offset_for_add_lid, KAL_FALSE);
+                if (nvram_move_data_item(&temp_info, KAL_TRUE))
+                {
+                    /* 1.Add new LID */
+                    if (nvram_add_package_lid(&offset_for_add_lid, is_need_move))    /* is_need_move =KAL_TRUE */
+                    {
+                        /* 2.Delete Src file and Rename Dest file */
+                        nvram_del_rename_package_file(KAL_TRUE);
+                        /* 3.Delete temp file */
+                        nvram_del_temporary_file();
+                    }
+                }
+                else
+                {
+                    nvram_init_all_package_lid();
+                }
+            }
+            else    /* Create back file failure */
+            {
+                nvram_init_all_package_lid();
+            }   /* end of nvram_create_package_file */
+        }   /* is_need_move */
+        else
+        {
+            nvram_calculate_write_data_offset(&offset_for_add_lid, KAL_FALSE);
+            if (nvram_add_package_lid(&offset_for_add_lid, is_need_move))        /* is_need_move =KAL_FALSE */
+            {
+                nvram_del_rename_package_file(KAL_FALSE);
+                /* nvram_del_temporary_file(); *//* in this case, not have temp file */
+            }
+        }   /* is_need_move = KAL_FALSE */
+    }
+    else
+    {
+        /* What should i do */
+        //NVRAM_BLOCKING_ASSERT(0, total_package_lid, 0, 0);
+        NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)g_nvram_move_package_lid,NVRAM_LOC_BUFFER_PTR_IS_NULL_7 , 0);
+        return KAL_FALSE;
+    }   /* nvram_construct_head_info_table(&head_info) */
+
+out:
+
+    nvram_destruct_head_info_table();
+
+    return result;
+}
+
+#define NVRAM_PSEUDO_MERGE_EXTERN_FUNCTION
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_calculate_filename_chksum
+ * DESCRIPTION
+ *  Calculate chksum, and turn off attr multiple, turn on attr package
+ * PARAMETERS
+ *  chksum          [IN/OUT]
+ *  ldi             [IN/OUT]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+kal_uint32 nvram_calculate_filename_chksum(nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 chksum = 0;
+    kal_uint16 *word_chksum = (kal_uint16 *) &chksum;
+    kal_uint8 checksum_buf[8];
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    *(word_chksum + 1) = nvram_util_caculate_checksum((kal_uint8 *)ldi->fileverno, 3, checksum_buf);
+    *word_chksum = nvram_util_caculate_checksum((kal_uint8 *)ldi->fileprefix, 4, checksum_buf);
+    
+    return chksum;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_query_lid_merge
+ * DESCRIPTION
+ *  Query certain data item should be merge or not
+ * PARAMETERS
+ *  ldi             [IN]
+ *  lid_size        [OUT]
+ * RETURNS
+ *  KAL_TRUE    : merge
+ *  KAL_FALSE   : not merge
+ *****************************************************************************/
+kal_bool nvram_query_lid_merge(nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 lid_size;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    lid_size = (ldi->size + NVRAM_CHKSUM_SIZE) * ldi->total_records;
+
+    if (!NVRAM_IS_CATEGORY_INTERNAL(ldi->category) &&
+        !NVRAM_IS_CATEGORY_SECUPACK(ldi->category) &&
+        !NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) &&
+        !NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) &&
+    #ifdef __NVRAM_CUSTOM_SENSITIVE__
+        !NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) &&
+    #endif
+    #ifdef __NVRAM_CUSTOM_DISK__
+        !NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category) &&
+    #endif
+          lid_size < NVRAM_CLUSTER_SIZE)
+    {
+        return KAL_TRUE;
+    }
+    else
+    {
+        return KAL_FALSE;
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_assign_package_entry
+ * DESCRIPTION
+ *  calculate the checksum and setup the attribute
+ * PARAMETERS
+ *  area        [IN]    in MT/MP/Custom table
+ *  ldi         [IN]    data item
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_assign_package_entry(nvram_ltable_entry_struct *ldi)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 ldi_size;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    g_head_info_file.total_pack_lid++;
+
+    ldi_size = (ldi->size + NVRAM_CHKSUM_SIZE) * ldi->total_records;
+
+    //for compatible with 10A & 11A, only use CORE variable after 11B
+    g_head_info_file.total_size_core += ldi_size;
+    g_head_info_file.chksum_core += nvram_calculate_filename_chksum(ldi);
+    
+     //for compatible with 10A & 11A, only use CORE variable after 11B
+    g_head_info_file.total_size_comm = 0;
+    g_head_info_file.chksum_comm = 0;
+
+    g_head_info_file.total_size_cust = 0;
+    g_head_info_file.chksum_cust = 0;
+
+
+    ldi->attr |= NVRAM_ATTR_PACKAGE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_pseudo_merge
+ * DESCRIPTION
+ *  pseudo merge init function
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Success or Fail
+ *****************************************************************************/
+kal_bool nvram_pseudo_merge(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_int32 openOption = FS_OPEN_NO_DIR | FS_READ_ONLY;
+    NVRAM_FILE_NAME pack_file;
+    head_info_struct head_info;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    naram_make_temp_filename(pack_file, 'A');
+    nvram_query_file_name(NVRAM_NVD_DATA, pack_file, filename);
+    NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+    result = FS_GetAttributes(filename);
+    NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+    if (result >= FS_NO_ERROR) /* can find backup file, indicate suddenly power off last time */
+    {
+        nvram_deal_with_exception();
+    }
+    else    /* no find, last time is OK */
+    {
+        nvram_make_package_filename(pack_file, 'A');        /* 'A' means package file */
+        nvram_query_file_name(NVRAM_NVD_DATA, pack_file, filename);
+        NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename);
+        result = FS_GetAttributes(filename);
+        NVRAM_FS_END(FS_OP_GETATTRIBUTES,result);
+        if (result >= FS_NO_ERROR)
+        {
+            /* 1. Read out head information */
+            /* 2. Compare three chksum */
+
+            if (nvram_read_head_information(&head_info, openOption))
+            {
+                total_package_lid = head_info.total_pack_lid;
+                nvram_compare_filename_chksum(&head_info);
+
+                if (nvram_ptr->sw_status)
+                {
+                    /* chksum error, deal with it */
+                    return nvram_chksum_conflict_resolve();
+                }
+                else    /* No change, but also need know file offset */
+                {
+                    return nvram_set_offset_to_ltable();
+                }   /* end of nvram_ptr->sw_status */
+            }
+            else
+            {
+                /* Read fail,Assume all chksum error */
+                nvram_ptr->sw_status |= NVRAM_SW_PACKAGE_CHANGE;
+                if(nvram_ee_info != NULL){
+                    nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status;
+                }
+                /* nvram should init all package LID */
+                nvram_init_all_package_lid();
+            }   /* end of read head information */
+        }
+        else    /* can not find package file, indicate first power on */
+        {
+            /* nvram should init all package LID */
+            nvram_init_all_package_lid();
+        }
+    }
+
+    return KAL_TRUE;
+}
+
+#endif /* __NVRAM_PSEUDO_MERGE__ */
+
diff --git a/mcu/service/nvram/src/nvram_tl1def.c b/mcu/service/nvram/src/nvram_tl1def.c
new file mode 100644
index 0000000..0d9fbd9
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_tl1def.c
@@ -0,0 +1,226 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2001
+*
+*******************************************************************************/
+
+/*******************************************************************************
+ *
+ * Filename:
+ * ---------
+ *	nvram_mml1_default.c
+ *
+ * Project:
+ * --------
+ *   MT7206RF
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ *
+ *
+ *******************************************************************************/
+/*===============================================================================================*/
+#ifdef __AST_TL1_TDD__
+
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+//#include "nvram_data_items.h"
+#include "td_nvram_def.h"
+#include "tl1d_custom_drdi.h"
+#ifdef __TAS_SUPPORT__
+#include "tl1d_custom_rf_tas_struct.h"
+#endif
+
+const tl1CustomDynamicInitMipiData *tl1_mipiData_ptr;
+kal_uint16 gSetIdx = 0xf;
+kal_uint16 gDefaultPath = 0xf;
+
+#ifdef __TAS_SUPPORT__
+
+const T_TD_CUSTOMIZATION_TAS_STRUCT_P *tl1_TasData_ptr;
+extern void tl1d_rf_tas_data_setting_customer_structure_data(T_TD_CUSTOMIZATION_TAS_STRUCT * dest_ptr,T_TD_CUSTOMIZATION_TAS_STRUCT_P* src_ptr);
+
+#if defined(__MTK_TARGET__)
+extern T_TD_CUSTOMIZATION_TAS_STRUCT   g_tl1_d_tl_tas_param;
+#endif
+extern void tl1_custom_point_empty_check(void * express,kal_uint16 flag,kal_uint16 value1, kal_uint16 value2);
+
+void td_tl1_rf_tas_param_updatere(void)
+{
+#if defined(__MTK_TARGET__)
+	tl1_custom_point_empty_check((void *)tl1_mipiData_ptr,gSetIdx,gDefaultPath , 0x1 );
+	tl1_custom_point_empty_check((void *)tl1_TasData_ptr, gSetIdx,gDefaultPath , 0x2 );
+	
+	tl1d_rf_tas_data_setting_customer_structure_data( &g_tl1_d_tl_tas_param,(void *)tl1_TasData_ptr);
+
+#endif
+}
+#endif
+
+//const tl1CustomDynamicInitMipiData tl1CustomMipiDataDefault[] = {{
+//       &AST_TL1_RF_PARAMETER_DEFAULT_SetDefault[0],
+//	     &AST_TL1_RFFE_PARAMETER_DEFAULT_SetDefault[0],
+//	     &AST_TL1_SEQ_DEFAULT_SetDefault[0],
+//       &tl1CustomDATData_SetDefault
+//}};
+
+kal_bool tl1d_DRDI_had_done = KAL_FALSE;
+
+//#ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+void nvram_tl1_drdiPointerInit(kal_uint16 setIdx)
+{
+    tl1_mipiData_ptr = &(tl1CustomMipiData[setIdx]);
+#ifdef __TAS_SUPPORT__
+    tl1_TasData_ptr  = tl1CustomTASData_drdi_point[setIdx];
+    tl1_custom_point_empty_check((void *)tl1_TasData_ptr, setIdx, 0, 0x2);
+#endif
+
+    tl1_custom_point_empty_check((void *)tl1_mipiData_ptr,setIdx, 0, 0x1);
+}
+//#endif
+
+//void nvram_tl1_drdiPointerInitDefault(kal_uint16 setIdx)
+//{
+//     tl1_mipiData_ptr = &(tl1CustomMipiDataDefault[0]);
+//#ifdef __TAS_SUPPORT__
+//     tl1_TasData_ptr  = &(tl1CustomTASData_SetDefault);
+//#endif
+//}
+
+void nvram_tl1_drdi(void)
+{
+#ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+    if(gTdsDrdiFlag)
+    {
+        if(!tl1d_DRDI_had_done)
+        {
+            if(MML1_RF_DRDI_CUSTOM_IsDynamicInitEnable())
+            {
+                kal_uint16 setIdx;
+                setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_TDD);
+                /* set the pointer to RF custom data by set index */
+                gSetIdx = setIdx;
+                nvram_tl1_drdiPointerInit(setIdx);
+            }
+            else
+            {
+           	    nvram_tl1_drdiPointerInit(0);
+            }
+            tl1d_DRDI_had_done = KAL_TRUE;
+        }
+    }
+    else
+#endif //#ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+    {
+        nvram_tl1_drdiPointerInit(0);
+        gDefaultPath = 0xc;
+    }
+#ifdef __TAS_SUPPORT__
+    td_tl1_rf_tas_param_updatere();
+#endif
+
+//#else  //#ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+//       nvram_tl1_drdiPointerInit(0);
+//#ifdef __TAS_SUPPORT__
+//       td_tl1_rf_tas_param_updatere();
+//#endif
+//       gDefaultPath = 0xb;
+//#endif //#ifdef __RF_DRDI_CAPABILITY_SUPPORT__
+}
+
+void nvram_get_tL1_default_value_to_write(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+   nvram_tl1_drdi();
+
+   //tl1_mipiData_ptr->rfTable_p->tReserverData.uwPadding[0] = gSetIdx;
+   //tl1_mipiData_ptr->rfTable_p->tReserverData.uwPadding[1] = gDefaultPath;
+
+   switch (lid)
+   {
+      case NVRAM_EF_AST_TL1_RF_PARAM_LID:
+      {
+          T_TD_CUSTOMIZATION_STRUCT *rf_param_ptr = (T_TD_CUSTOMIZATION_STRUCT *)buffer;
+          kal_mem_cpy(rf_param_ptr, tl1_mipiData_ptr->rfTable_p, NVRAM_EF_AST_TL1_RF_PARAM_SIZE);
+#if  defined(__MD93__)||defined(__MD95__)
+          rf_param_ptr->tReserverData.uwPadding[0] = gSetIdx;
+          rf_param_ptr->tReserverData.uwPadding[1] = gDefaultPath;
+#else
+          rf_param_ptr->tFunctionData.tl1d_function15 = gSetIdx;
+          rf_param_ptr->tFunctionData.tl1d_function16 = gDefaultPath;
+
+#endif
+      }
+      break;
+      case NVRAM_EF_AST_TL1_RFFE_PARAM_LID:
+      {
+          kal_mem_cpy(buffer, tl1_mipiData_ptr->mipiTable_p, NVRAM_EF_AST_TL1_RFFE_PARAM_SIZE);
+      }
+      break;
+      case NVRAM_EF_AST_TL1_RF_TIMESEQ_LID:
+      {
+          kal_mem_cpy(buffer, tl1_mipiData_ptr->timingTable_p, NVRAM_EF_AST_TL1_RF_TIMESEQ_SIZE);
+      }
+      break;
+#ifdef __TAS_SUPPORT__
+      case NVRAM_EF_AST_TL1_TAS_CUSTOM_PARAMES_LID:
+      {
+#if defined(__MTK_TARGET__)
+         kal_mem_cpy(buffer, &g_tl1_d_tl_tas_param, NVRAM_EF_AST_TL1_TAS_CUSTOM_PARAMES_SIZE);
+#endif
+      }
+      break;
+#endif
+      case NVRAM_EF_AST_TL1_DAT_PARAM_LID:
+      {
+         T_TD_CUSTOMIZATION_DAT_STRUCT *gDatData = (T_TD_CUSTOMIZATION_DAT_STRUCT *)buffer;
+
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CONFIG), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CONFIG, sizeof(T_TD_CUSTOMIZATION_DAT_CONFIG));
+#if  defined(__MD93__)
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CATA_BPI_TABLE), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CATA_BPI_TABLE, sizeof(TL1D_CUSTOM_DAT_FE_CAT_A_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG0_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_EventSet[0], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG1_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_EventSet[1], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG2_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_EventSet[2], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG3_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_EventSet[3], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG0_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_DataSet[0], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG1_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_DataSet[1], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG2_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_DataSet[2], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_A_CONFIG3_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_A_MIPI_DataSet[3], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CATB_BPI_TABLE), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CATB_BPI_TABLE, sizeof(TL1D_CUSTOM_DAT_FE_CAT_B_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG0_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[0], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG1_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[1], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG2_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[2], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG3_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[3], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG4_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[4], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG5_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[5], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG6_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[6], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG7_MIPIEVENT[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_EventSet[7], TL1D_DAT_MAX_MIPI_EVNET_NUM*sizeof(TL1D_DAT_MIPI_EVENT_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG0_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[0], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG1_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[1], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG2_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[2], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG3_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[3], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG4_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[4], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG5_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[5], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG6_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[6], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         kal_mem_cpy(&(gDatData->TL1D_DAT_CAT_B_CONFIG7_MIPIDATA[0]), tl1_mipiData_ptr->datTable_p->TL1D_DAT_CAT_B_MIPI_DataSet[7], TL1D_DAT_MAX_MIPI_DATA_NUM*sizeof(TL1D_DAT_MIPI_DATA_TABLE_T));
+         #endif
+         //kal_mem_cpy(buffer, &gDatData, NVRAM_EF_AST_TL1_DAT_PARAM_SIZE);
+      }
+      break;
+
+      default:
+         ASSERT(KAL_FALSE);
+      break;
+   }
+}
+
+#endif  //#ifdef __AST_TL1_TDD__
diff --git a/mcu/service/nvram/src/nvram_tst.c b/mcu/service/nvram/src/nvram_tst.c
new file mode 100644
index 0000000..68d7ef5
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_tst.c
@@ -0,0 +1,1843 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_msg_handler.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   To handle the messages sent to NVRAM
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#include "nvram_main.h"
+#include "nvram_interface.h"
+#include "nvram_io.h"
+
+#ifdef __LTE_RAT__
+#define nvram_lid_info_structure nvram_ltable_entry_struct
+#include "kal_debug.h"
+#else
+#include "custom_nvram_editor_data_item.h"
+#endif
+
+#ifdef __NVRAM_UNIT_TEST__
+#define __NVRAM_PERFORMANCE_TEST__
+#endif
+
+#ifdef __NVRAM_PERFORMANCE_TEST__
+    #ifdef __MTK_TARGET__
+    static kal_uint32 starttime, endtime;
+    #define PERFORMANCE_START() kal_get_time(&starttime)
+    #define PERFORMANCE_STOP() kal_get_time(&endtime)
+    #define PERFORMANCE_TIME_PASS   (endtime-starttime)
+       #ifndef __LTE_RAT__
+    #define PERFORMANCE_SHOW_TIME_PASS(x, y1) do{PERFORMANCE_STOP();kal_wap_trace(MOD_NVRAM, TRACE_FUNC, x, y1);}while(0)
+       #else //__LTE_RAT__
+          #define PERFORMANCE_SHOW_TIME_PASS kal_printf
+       #endif //__LTE_RAT__
+    #else
+    #include "time.h"
+    static clock_t startclock, endclock;
+    #define PERFORMANCE_START()   startclock = clock()
+    #define PERFORMANCE_STOP() endclock = clock()
+    #define PERFORMANCE_TIME_PASS (endclock-startclock)
+    #define PERFORMANCE_SHOW_TIME_PASS(x, y1) do{PERFORMANCE_STOP();printf(x, y1);}while(0)
+    #endif
+#else
+    #define PERFORMANCE_PRINT1(x, y1)
+    #define PERFORMANCE_START()
+    #define PERFORMANCE_END()
+    #define PERFORMANCE_SHOW_TIME_PASS(x, y1)
+#endif
+
+#ifdef __NVRAM_UNIT_TEST__
+#define A(x) L##x
+#define WIDE_STR(x) A(x)
+
+#ifndef __MTK_TARGET__
+#define UNIT_TEST_THROW_EXCEPTION(number)   \
+    printf("test case#%d fail\n", number);
+#else
+#define UNIT_TEST_THROW_EXCEPTION(number)   \
+    kal_wap_trace(MOD_NVRAM, TRACE_FUNC, "test case#%d fail\n", number);
+#endif
+
+#define NVUT(__test_block__)         \
+{                                               \
+    if (!(__test_block__))                      \
+    {                                           \
+        UNIT_TEST_THROW_EXCEPTION(__LINE__);    \
+        unit_test_result = KAL_FALSE;           \
+    }                                           \
+}
+
+kal_uint8 buffer1[4096 * 5];
+kal_uint8 buffer2[4096 * 5];
+nvram_errno_enum ut_io_status = NVRAM_IO_ERRNO_OK;
+nvram_drv_status_enum ut_drv_status = NVRAM_DRV_OK;
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_read_default_value
+ * DESCRIPTION
+ *  This function is used to read the default value of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  LID:            [IN]    NVRAM LID
+ *  rec_index:      [IN]    record index, start from 1, but if the value is 0,
+ *                          this function will return all default value of each record
+ *  buffer:         [OUT]   buffer pointer, cannot be NULL
+ *  buffer_size:    [IN]    buffer size
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  NVRAM_ERRNO_SUCCESS:            no error
+ *  NVRAM_IO_ERRNO_INVALID_LID:     invalid LID
+ *  NVRAM_IO_ERRNO_INVALID_SIZE:    buffer size is too small
+ *****************************************************************************/
+kal_int32 nvram_read_default_value(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    nvram_ltable_entry_struct *ldi;
+    int i;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    if (rec_index > ldi->total_records)
+    {
+        return NVRAM_IO_ERRNO_INVALID_RECORD;
+    }
+
+    if (rec_index == 0)
+    {
+        if (buffer_size < ldi->size * ldi->total_records)
+        {
+            return NVRAM_IO_ERRNO_INVALID_SIZE;
+        }
+    }
+    else
+    {
+        if (buffer_size < ldi->size)
+        {
+            return NVRAM_IO_ERRNO_INVALID_SIZE;
+        }
+    }
+
+    if (rec_index == 0)
+    {
+        for(i = 0; i < ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i + 1, buffer + i * ldi->size, ldi->size);
+        }
+    }
+    else
+    {
+        nvram_get_default_value_to_write(ldi, rec_index, buffer, ldi->size);
+    }
+
+
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_compare_to_default_value
+ * DESCRIPTION
+ *  This function is used to compare the value in nvram file to default value
+ * PARAMETERS
+ *  LID:       [IN]    NVRAM LID
+ *  info:      [OUT]   output the information of an nvram item
+ * RETURNS
+ *  nvram_errno_enum
+ * RETURN VALUES
+ *  NVRAM_ERRNO_SUCCESS:            no error
+ *  NVRAM_IO_ERRNO_INVALID_LID:     lid is invalid
+ *****************************************************************************/
+kal_int32 nvram_get_lid_info(nvram_lid_enum LID, nvram_lid_info_structure *info)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    nvram_ltable_entry_struct *ldi;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (!NVRAM_IS_LID_VALID(LID))
+    {
+        return NVRAM_IO_ERRNO_INVALID_LID;
+    }
+
+    nvram_util_get_data_item(&ldi, LID);
+
+    memset(info, 0, sizeof(nvram_lid_info_structure));
+
+    info->LID = LID;
+    info->size = ldi->size;
+    info->total_records = ldi->total_records;
+    info->attr = ldi->attr;
+    info->category = ldi->category;
+    strncpy(info->fileprefix, ldi->fileprefix, FILE_PREFIX_LEN);
+    strncpy(info->fileverno, ldi->fileverno, FILE_VERNO_LEN);
+    strncpy(info->description, ldi->description, NVRAM_MAX_DESC_LEN);
+
+    return NVRAM_ERRNO_SUCCESS;
+}
+
+kal_int32 nvram_unit_test_get_drv_status(kal_int32 status)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (ut_drv_status == NVRAM_DRV_OK)
+    {
+        return status;
+    }
+    else if (ut_drv_status == NVRAM_DRV_CHECKSUM_ERROR)
+    {
+        ut_drv_status = NVRAM_DRV_OK;
+        return NVRAM_DRV_CHECKSUM_ERROR;
+    }
+
+    return ut_drv_status;
+}
+
+kal_int32 nvram_unit_test_get_io_status(kal_int32 status)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (ut_io_status == NVRAM_IO_ERRNO_OK)
+    {
+        return status;
+    }
+    return ut_io_status;
+}
+
+static kal_bool nvram_unit_test_hidden_file(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH),          KAL_FALSE) == KAL_FALSE);
+#ifdef __NVRAM_MULTI_FOLDERS__
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CALIBRAT_DATAITEM_PATH), KAL_FALSE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_COREITEM_PATH),          KAL_FALSE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH),     KAL_FALSE) == KAL_TRUE);
+#endif
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH),          KAL_TRUE) == KAL_FALSE);
+#ifdef __NVRAM_MULTI_FOLDERS__
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CALIBRAT_DATAITEM_PATH), KAL_TRUE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_COREITEM_PATH),          KAL_TRUE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH),     KAL_TRUE) == KAL_FALSE);
+#endif
+
+#ifdef __NVRAM_MULTI_FOLDERS__
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_COREITEM_PATH)L"\\MT00_000", KAL_FALSE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_COREITEM_PATH)L"\\MT00_000", KAL_TRUE)  == KAL_FALSE);
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\MP0B_004", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\MP0B_004", KAL_TRUE)  == KAL_FALSE)
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\ST33A002", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\ST33B002", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\ST33A002", KAL_TRUE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\ST33B002", KAL_TRUE) == KAL_FALSE);
+#else
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\MT00_000", KAL_FALSE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\MT00_000", KAL_TRUE)  == KAL_FALSE);
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\MP0B_004", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\MP0B_004", KAL_TRUE)  == KAL_FALSE)
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\ST33A002", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\ST33B002", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\ST33A002", KAL_TRUE) == KAL_FALSE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\ST33B002", KAL_TRUE) == KAL_FALSE);
+#endif
+
+#ifdef __NVRAM_CUSTOM_SENSITIVE__
+    ldi->category = NVRAM_CATEGORY_CUSTOM_SENSITIVE;
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    ldi->attr |= NVRAM_ATTR_MSP;
+    #endif
+    ldi->attr |= NVRAM_ATTR_CONFIDENTIAL;
+    ldi->attr |= NVRAM_ATTR_MULTIPLE;
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CUST_DATAITEM_PATH),             KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CUST_DATAITEM_PATH),             KAL_TRUE)  == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CUST_DATAITEM_PATH)L"\\NV00A000", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CUST_DATAITEM_PATH)L"\\NV00B000", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CUST_DATAITEM_PATH)L"\\NV00A000", KAL_TRUE)  == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CUST_DATAITEM_PATH)L"\\NV00B000", KAL_TRUE)  == KAL_TRUE);
+
+    ldi->category = NVRAM_CATEGORY_USER;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+
+#endif
+
+    nvram_ptr->lock = KAL_TRUE;
+
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH),          KAL_FALSE) == KAL_TRUE);
+#ifdef __NVRAM_MULTI_FOLDERS__
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_CALIBRAT_DATAITEM_PATH), KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_COREITEM_PATH),          KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH),     KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_COREITEM_PATH)L"\\MT00_000", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\MP0A_001", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_IMPT_DATAITEM_PATH)L"\\ST1DA002", KAL_FALSE) == KAL_TRUE);
+#else
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\MT00_000", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\MP0A_001", KAL_FALSE) == KAL_TRUE);
+    NVUT(nvram_check_hidden_file(WIDE_STR(NVRAM_FS_DATAITEM_PATH)L"\\ST1DA002", KAL_FALSE) == KAL_TRUE);
+#endif
+
+    nvram_ptr->lock = KAL_FALSE;
+
+    return unit_test_result;
+}
+
+static kal_bool nvram_unit_test_basic_1(kal_uint32 size, kal_uint16 total_records)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 i, j = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    ldi->size = size;
+    ldi->total_records = total_records;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    memset(buffer1, 0, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    memset(buffer1, 0xFF, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        for (j = 0 ;j < ldi->size; j+=2)
+        {
+            buffer1[ldi->size * i + j] = (ldi->size * i + j) & 0xFF;
+            buffer1[ldi->size * i + j + 1] = ((ldi->size * i + j) >> 8) & 0xFF;
+        }
+    }
+    ldi->default_value = buffer1;
+
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: mutiple backup */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_MULTIPLE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: multi default + mutiple backup */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_MULTIPLE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: confidential */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: confidential + multi_default*/
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_MSP;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_MSP;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+#endif
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT;
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item(ldi,  i + 1, 1, buffer2 + i * ldi->size, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIPLE;
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item(ldi,  i + 1, 1, buffer2 + i * ldi->size, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    ldi->size = NVRAM_EF_NVRAM_UNIT_TEST_SIZE;
+    ldi->total_records = NVRAM_EF_NVRAM_UNIT_TEST_TOTAL;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    return unit_test_result;
+}
+
+static kal_bool nvram_unit_test_basic_2(kal_uint32 size, kal_uint16 total_records)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 i, j = 0;
+    kal_uint8 chksum1[8], *chksum2;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    ldi->size = size;
+    ldi->total_records = total_records;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    memset(buffer1, 0, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    memset(buffer1, 0xFF, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size,chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        for (j = 0 ;j < ldi->size; j+=2)
+        {
+            buffer1[ldi->size * i + j] = (ldi->size * i + j) & 0xFF;
+            buffer1[ldi->size * i + j + 1] = ((ldi->size * i + j) >> 8) & 0xFF;
+        }
+    }
+    ldi->default_value = buffer1;
+
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: mutiple backup */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_MULTIPLE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: multi default + mutiple backup */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_MULTIPLE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: confidential */
+    /* we cannot test confidential here, because checksum value is calculated via ciphertext */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+
+    /* Reset: confidential + multi_default*/
+    /* we cannot test confidential here, because checksum value is calculated via ciphertext */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_MSP;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_MSP;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+#endif
+
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT;
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item_chksum(ldi,  i + 1, 1, (buffer2 + i * NVRAM_CHKSUM_SIZE), sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIPLE;
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item_chksum(ldi,  i + 1, 1, (buffer2 + i * NVRAM_CHKSUM_SIZE), sizeof(buffer2), KAL_TRUE) == NVRAM_IO_ERRNO_OK);
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    ldi->size = NVRAM_EF_NVRAM_UNIT_TEST_SIZE;
+    ldi->total_records = NVRAM_EF_NVRAM_UNIT_TEST_TOTAL;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    return unit_test_result;
+}
+
+
+static kal_bool nvram_unit_test_basic_3(kal_uint32 size, kal_uint16 total_records)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 i, j = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    ldi->size = size;
+    ldi->total_records = total_records;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    memset(buffer1, 0xFF, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        for (j = 0 ;j < ldi->size; j+=2)
+        {
+            buffer1[ldi->size * i + j] = (ldi->size * i + j) & 0xFF;
+            buffer1[ldi->size * i + j + 1] = ((ldi->size * i + j) >> 8) & 0xFF;
+        }
+    }
+
+    /* write / read */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ;
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item(ldi, i + 1, 1, buffer2 + i * ldi->size, ldi->size) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size) == 0);
+    }
+
+    /* write / read */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item(ldi, i + 1, 1, buffer2 + i * ldi->size, ldi->size) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size) == 0);
+    }
+
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    /* write / read */
+    ldi->attr = NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+        NVUT(nvram_read_data_item(ldi, i + 1, 1, buffer2 + i * ldi->size, ldi->size) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size) == 0);
+    }
+#endif
+
+    /* read fail -> read backup*/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ;
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        ut_drv_status = NVRAM_DRV_CHECKSUM_ERROR;
+        NVUT(nvram_read_data_item(ldi,  i + 1, 1, buffer2 + i * ldi->size, ldi->size) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size) == 0);
+    }
+
+    ldi->size = NVRAM_EF_NVRAM_UNIT_TEST_SIZE;
+    ldi->total_records = NVRAM_EF_NVRAM_UNIT_TEST_TOTAL;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    return unit_test_result;
+}
+
+static kal_bool nvram_unit_test_basic(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+start_test:
+    NVUT(nvram_unit_test_basic_1(10, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic(10,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_1(128, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic(128,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_1(256, 10) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic(256,10): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_1(MAX_NVRAM_RECORD_SIZE - NVRAM_CHKSUM_SIZE, 1) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic(max,10): %d\n", PERFORMANCE_TIME_PASS);
+
+#ifdef __NVRAM_LARGE_RECORD_SIZE__
+    NVUT(nvram_unit_test_basic_1(4096, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic(4096,5): %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+    NVUT(nvram_unit_test_basic_2(10, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- read_chksum(10,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_2(128, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- read_chksum(128,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_2(256, 10) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- read_chksum(256,10): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_2(MAX_NVRAM_RECORD_SIZE - NVRAM_CHKSUM_SIZE, 1) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- read_chksum(max,10): %d\n", PERFORMANCE_TIME_PASS);
+
+#ifdef __NVRAM_LARGE_RECORD_SIZE__
+    NVUT(nvram_unit_test_basic_2(4096, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- read_chksum(4096,5): %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+    if (ut_io_status == NVRAM_IO_ERRNO_OK)
+    {
+        ut_io_status = NVRAM_IO_ERRNO_CHK;
+        goto start_test;
+    }
+
+    ut_io_status = NVRAM_IO_ERRNO_OK;
+    ut_drv_status = NVRAM_DRV_OK;
+
+    NVUT(nvram_unit_test_basic_3(10, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic3(10,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_3(128, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic3(128,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_3(256, 10) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic3(256,10): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_basic_3(MAX_NVRAM_RECORD_SIZE - NVRAM_CHKSUM_SIZE, 1) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic3(max,10): %d\n", PERFORMANCE_TIME_PASS);
+
+    return unit_test_result;
+}
+
+#ifdef __NVRAM_BACKUP_DISK_FAT__
+static kal_bool nvram_unit_test_backup_disk_fat(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    return unit_test_result;
+}
+#endif
+
+#ifdef __NVRAM_BACKUP_DISK_RAW__
+static kal_bool nvram_unit_test_backup_disk_raw(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    kal_wchar *filename;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8* buffer;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    NVUT(nvram_create_image(NVRAM_IMAGE_TYPE_DEFAULT) == NVRAM_ERRNO_SUCCESS);
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_TRUE) == NVRAM_ERRNO_SUCCESS);
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_FALSE) == NVRAM_ERRNO_SUCCESS);
+    NVUT(nvram_recover_image(NVRAM_IMAGE_TYPE_DEFAULT) == NVRAM_ERRNO_SUCCESS);
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_TRUE) == NVRAM_ERRNO_SUCCESS);
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_FALSE) == NVRAM_ERRNO_SUCCESS);
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            NVUT(nvram_recover_image_by_lid(ldi) == NVRAM_ERRNO_SUCCESS);
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    filename = (kal_wchar *)get_ctrl_buffer(NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+    buffer = (kal_uint8*) get_ctrl_buffer(MAX_NVRAM_RECORD_SIZE);
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+
+        if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+            nvram_query_file_name(NVRAM_NVD_CALI, nvramname , filename);
+
+            NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+            kal_int32 fs_result =FS_Delete(filename)
+            NVRAM_FS_END(FS_OP_DELETE,fs_result);
+
+            NVUT(nvram_read_data_item(ldi, 1, ldi->total_records, buffer, MAX_NVRAM_RECORD_SIZE) == NVRAM_IO_ERRNO_OK);
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_FALSE) == NVRAM_ERRNO_SUCCESS);
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+            nvram_query_file_name(NVRAM_NVD_CALI, nvramname , filename);
+
+            NVUT(nvram_read_data_item(ldi, 1, ldi->total_records, buffer, MAX_NVRAM_RECORD_SIZE) == NVRAM_IO_ERRNO_OK);
+
+            buffer[0] = ~buffer[0];
+
+            nvram_write_data_item(ldi, 1, buffer, KAL_FALSE);
+
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_FALSE) == NVRAM_ERRNO_IMAGE_DATA_NOT_SYNC);
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+
+        if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+
+            nvram_query_file_name(NVRAM_NVD_CALI, nvramname , filename);
+
+            NVUT(nvram_read_data_item(ldi, 1, ldi->total_records, buffer, MAX_NVRAM_RECORD_SIZE) == NVRAM_IO_ERRNO_OK);
+
+            buffer[0] = ~buffer[0];
+
+            nvram_write_data_item(ldi, 1, buffer, KAL_FALSE);
+
+        }
+    }while(nvram_util_next_data_item(&ldi));
+
+    NVUT(nvram_verify_image(NVRAM_IMAGE_TYPE_DEFAULT, KAL_FALSE) == NVRAM_ERRNO_SUCCESS);
+
+    free_ctrl_buffer(buffer);
+    free_ctrl_buffer(filename);
+
+    return unit_test_result;
+
+}
+#endif
+
+#ifdef __NVRAM_BACKUP_DISK__
+static kal_bool nvram_unit_test_backup_disk(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#ifdef __NVRAM_BACKUP_DISK_FAT__
+    NVUT(nvram_unit_test_backup_disk_fat() == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- backup disk(FAT) %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+#ifdef __NVRAM_BACKUP_DISK_RAW__
+    NVUT(nvram_unit_test_backup_disk_raw() == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- backup disk(RAW) %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+    return unit_test_result;
+}
+#endif
+
+static kal_bool nvram_unit_test_compare_to_default_value(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    int i;
+    kal_int8 *buffer1, *buffer2;
+    nvram_lid_info_structure info;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (! (nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT) )
+    {
+        return KAL_TRUE;
+    }
+
+    ldi = &logical_data_item_table[0];
+    do
+    {
+
+        buffer1 = (kal_int8*) get_ctrl_buffer(ldi->size);
+        buffer2 = (kal_int8*) get_ctrl_buffer(ldi->size);
+
+        for (i = 0 ;i < ldi->total_records; i++)
+        {
+            NVUT(nvram_compare_to_default_value(ldi->LID, i + 1) == NVRAM_ERRNO_SUCCESS);
+
+            nvram_read_default_value(ldi->LID, i + 1, buffer1, ldi->size);
+            nvram_read_data_item(ldi, i + 1, 1, buffer2, ldi->size);
+
+            NVUT(memcmp(buffer1, buffer2, ldi->size) == 0);
+
+        }
+
+        free_ctrl_buffer(buffer1);
+        free_ctrl_buffer(buffer2);
+
+
+        nvram_get_lid_info(ldi->LID, &info);
+
+        NVUT(info.attr == ldi->attr);
+        NVUT(info.category == ldi->category);
+        NVUT(strncmp(info.description, ldi->description, NVRAM_MAX_DESC_LEN)==0);
+
+    }while(nvram_util_next_data_item(&ldi));
+    return unit_test_result;
+
+}
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+static kal_bool nvram_unit_test_pseudo_merge_1(kal_uint32 size, kal_uint16 total_records)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 i, j = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    ldi->size = size;
+    ldi->total_records = total_records;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    memset(buffer1, 0, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    memset(buffer1, 0xFF, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        for (j = 0 ;j < ldi->size; j+=2)
+        {
+            buffer1[ldi->size * i + j] = (ldi->size * i + j) & 0xFF;
+            buffer1[ldi->size * i + j + 1] = ((ldi->size * i + j) >> 8) & 0xFF;
+        }
+    }
+    ldi->default_value = buffer1;
+
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: confidential */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /* Reset: confidential + multi_default*/
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+
+    ldi->size = NVRAM_EF_NVRAM_UNIT_TEST_SIZE;
+    ldi->total_records = NVRAM_EF_NVRAM_UNIT_TEST_TOTAL;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    return unit_test_result;
+}
+
+static kal_bool nvram_unit_test_pseudo_merge_2(kal_uint32 size, kal_uint16 total_records)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 i, j = 0;
+    kal_uint8 chksum1[8], *chksum2;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    ldi->size = size;
+    ldi->total_records = total_records;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    memset(buffer1, 0, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    memset(buffer1, 0xFF, ldi->total_records * ldi->size);
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        for (j = 0 ;j < ldi->size; j+=2)
+        {
+            buffer1[ldi->size * i + j] = (ldi->size * i + j) & 0xFF;
+            buffer1[ldi->size * i + j + 1] = ((ldi->size * i + j) >> 8) & 0xFF;
+        }
+    }
+    ldi->default_value = buffer1;
+
+    /* Reset: basic */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: multi_default */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: confidential */
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    nvram_util_caculate_checksum(ldi, buffer1, ldi->size, chksum1);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    /* Reset: confidential + multi_default*/
+    ldi->attr = NVRAM_ATTR_PACKAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_CONFIDENTIAL;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    NVUT(nvram_read_data_item_chksum(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        nvram_util_caculate_checksum(ldi, buffer1 + ldi->size * i, ldi->size, chksum1);
+        chksum2 = (kal_uint8*) (buffer2 + NVRAM_CHKSUM_SIZE * i);
+        NVUT((kal_mem_cmp(chksum1, chksum2, NVRAM_CHECKSUM_SIZE )==0);
+    }
+
+    ldi->size = NVRAM_EF_NVRAM_UNIT_TEST_SIZE;
+    ldi->total_records = NVRAM_EF_NVRAM_UNIT_TEST_TOTAL;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    return unit_test_result;
+}
+
+static kal_bool nvram_unit_test_pseudo_merge(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+start_test:
+    NVUT(nvram_unit_test_pseudo_merge_1(10, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- Pseudo merge(10,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_pseudo_merge_1(128, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- Pseudo merge(128,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_pseudo_merge_2(10, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- Pseudo merge read_chksum(10,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_pseudo_merge_2(128, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- Pseudo merge read_chksum(128,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    if (ut_io_status == NVRAM_IO_ERRNO_OK)
+    {
+        ut_io_status = NVRAM_IO_ERRNO_CHK;
+        goto start_test;
+    }
+
+    ut_io_status = NVRAM_IO_ERRNO_OK;
+
+    return unit_test_result;
+}
+
+#endif
+
+
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+static kal_bool nvram_unit_test_sds_1(kal_uint32 size, kal_uint16 total_records)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 i, j = 0;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_UNIT_TEST_LID);
+
+    ldi->size = size;
+    ldi->total_records = total_records;
+    ldi->category = NVRAM_CATEGORY_BACKUP_SDS;
+
+/*********************************************
+ *   1. Backup & Reset function
+ ********************************************/
+        
+    /**************************************************
+     *   1-1. Defaul value is NVRAM_EF_ZERO_DEFAULT
+     **************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    //Write 0x00 to the LID and the SDS
+    memset(buffer1, 0x00, ldi->total_records * ldi->size);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0xFF to the LID
+    memset(buffer2, 0xFF, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, 1, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reset the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+    
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+    
+    /**************************************************
+     *   1-2. Defaul value is NVRAM_EF_FF_DEFAULT
+     **************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+    //Write 0xFF to the LID and the SDS
+    memset(buffer1, 0xFF, ldi->total_records * ldi->size);
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }
+    
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, 1, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reset the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /**************************************************
+     *   1-2-2. Generate new default value for next case
+     **************************************************/   
+    for(i = 0 ;i < ldi->total_records; i++)
+    {
+        for (j = 0 ;j < ldi->size; j+=2)
+        {
+            buffer1[ldi->size * i + j] = (ldi->size * i + j) & 0xFF;
+            buffer1[ldi->size * i + j + 1] = ((ldi->size * i + j) >> 8) & 0xFF;
+        }
+    }
+    ldi->default_value = buffer1;
+
+    /**************************************************
+     *   1-3. Single default
+     **************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    //Write to the LID and the SDS
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reset the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /**************************************************
+     *   1-4. Multiple default
+     **************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->attr |= NVRAM_ATTR_MULTI_DEFAULT;
+    //Write to the LID and the SDS
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reser the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+
+    /**************************************************
+     *   1-5. Confidential single default
+     **************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->attr |= NVRAM_ATTR_CONFIDENTIAL;
+    //Write to the LID and the SDS
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reser the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    /**************************************************
+     *   1-6. Confidential multiple default
+     **************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->attr |= (NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_CONFIDENTIAL);
+    //Write to the LID and the SDS
+    for(i = 0; i < ldi->total_records; i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reser the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+    
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    /********************************************************************************
+     * 1-7: Default value is single & (MSP + Confidentail)
+     *********************************************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->attr |= (NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_MSP);
+    //Write to the LID and the SDS
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reser the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+    /********************************************************************************
+     * 1-8: Default value is multiple & (MSP + Confidentail)
+     *********************************************************************************/
+    ldi->attr = NVRAM_ATTR_MULTIPLE | NVRAM_ATTR_MULTIREC_READ | NVRAM_ATTR_AVERAGE;
+    ldi->attr |= NVRAM_ATTR_MULTI_DEFAULT;
+    //Write to the LID and the SDS
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }    
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_BACKUP);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+
+    //Reser the LID
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) == KAL_TRUE);
+
+    //Read the LID
+    NVUT(nvram_read_data_item(ldi,  1, ldi->total_records, buffer2, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+
+    //Compare the buffer, it should be 0x00
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(kal_mem_cmp(buffer1, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+#endif    
+
+/*********************************************
+ *   2. Restore function
+ ********************************************/
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT;
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_write_data_item(ldi, i + 1, buffer1 + i * ldi->size, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    }
+
+    nvram_access_sds(NVRAM_SDS_ACCESS_RESTORE);
+
+    //Write 0x00 to the LID
+    memset(buffer2, 0x00, ldi->total_records * ldi->size);
+    NVUT(nvram_write_data_item(ldi, ldi->total_records, buffer2, KAL_FALSE) == NVRAM_IO_ERRNO_OK);
+    
+    nvram_access_sds(NVRAM_SDS_ACCESS_RESTORE);
+
+    for(i = 0 ;i < ldi->total_records;i++)
+    {
+        NVUT(nvram_read_data_item(ldi,  i + 1, 1, buffer2 + i * ldi->size, sizeof(buffer2)) == NVRAM_IO_ERRNO_OK);
+        NVUT(kal_mem_cmp(buffer1 + i * ldi->size, buffer2 + i * ldi->size, ldi->size)==0);
+    }
+
+    ldi->size = NVRAM_EF_NVRAM_UNIT_TEST_SIZE;
+    ldi->total_records = NVRAM_EF_NVRAM_UNIT_TEST_TOTAL;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->category = NVRAM_CATEGORY_USER;
+    
+
+    return unit_test_result;
+}
+
+
+static kal_bool nvram_unit_test_sds(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    NVUT(nvram_unit_test_sds_1(10, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- secure data storage(10,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    NVUT(nvram_unit_test_sds_1(128, 5) == KAL_TRUE);
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- secure data storage(128,5): %d\n", PERFORMANCE_TIME_PASS);
+
+    return unit_test_result;
+}
+
+#endif
+
+static kal_bool nvram_unit_test_reset_function(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result  = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+#ifdef __NVRAM_SUPPORT_CUSTPACK__
+    NVUT(nvram_reset_data_items(NVRAM_RESET_CUSTPACK, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+#endif
+    NVUT(nvram_reset_data_items(NVRAM_RESET_SECUPACK, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+    NVUT(nvram_reset_data_items(NVRAM_RESET_BRANCH, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+#ifdef __NVRAM_PSEUDO_MERGE__
+    NVUT(nvram_reset_data_items(NVRAM_RESET_PACKAGE, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+#endif
+    NVUT(nvram_reset_data_items(NVRAM_RESET_FAT, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+
+    nvram_ptr->state = NVRAM_STATE_NOT_READY;
+    NVUT(nvram_reset_data_items(NVRAM_RESET_FACTORY, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+    nvram_ptr->state = NVRAM_STATE_READY;
+
+
+    NVUT(nvram_reset_data_items(NVRAM_RESET_ALL, NVRAM_APP_RESERVED, NULL, 0, 0) == KAL_TRUE);
+
+    return unit_test_result;
+}
+
+static kal_bool nvram_unit_test_ota_reserved(void)
+{
+/*
+    nvram_external_search_reserved_lid(0, "001", 0, 0);
+    nvram_external_read_data(NVRAM_EF_READ_RESERVED_LID,
+                             1,
+                             &sbp_data_config,
+                             0x22);
+    nvram_external_read_chksum(NVRAM_EF_READ_RESERVED_LID,
+                             1,
+                             1,
+                             &sbp_data_config,
+                             0x22);
+*/
+    return KAL_TRUE;
+}
+
+kal_bool nvram_unit_test(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_bool unit_test_result = KAL_TRUE;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    PERFORMANCE_START();
+
+    unit_test_result &= nvram_unit_test_hidden_file();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- hidden file: %d\n", PERFORMANCE_TIME_PASS);
+
+    unit_test_result &= nvram_unit_test_basic();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- basic: %d\n", PERFORMANCE_TIME_PASS);
+
+#ifdef __NVRAM_BACKUP_DISK__
+    unit_test_result &= nvram_unit_test_backup_disk();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- backup_disk: %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+    unit_test_result &= nvram_unit_test_compare_to_default_value();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- compare to default value: %d\n", PERFORMANCE_TIME_PASS);
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    unit_test_result &= nvram_unit_test_pseudo_merge();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- pseudo merge: %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+#ifdef __NVRAM_SECURE_DATA_STORAGE__
+    unit_test_result &= nvram_unit_test_sds();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- secure data storage: %d\n", PERFORMANCE_TIME_PASS);
+#endif
+
+    unit_test_result &= nvram_unit_test_reset_function();
+    PERFORMANCE_SHOW_TIME_PASS("nvram unit test -- reset function %d\n", PERFORMANCE_TIME_PASS);
+
+    return unit_test_result;
+}
+#endif
+
diff --git a/mcu/service/nvram/src/nvram_ul1def.c b/mcu/service/nvram/src/nvram_ul1def.c
new file mode 100644
index 0000000..2541f24
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ul1def.c
@@ -0,0 +1,492 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2007
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ul1def.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *    This file provides a fuction for NVRAM Task to get UL1 default value
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+  *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+
+#if (defined __MD93__)  
+#include "nvram_ul1def_md93.c"
+#elif (defined __MD95__)
+#include "nvram_ul1def_md95.c"
+#elif (defined __MD97__)
+#include "nvram_ul1def_md97.c"
+#else
+#error "Should define at least a kind of BB being used."
+#endif
+
+
diff --git a/mcu/service/nvram/src/nvram_ul1def_md93.c b/mcu/service/nvram/src/nvram_ul1def_md93.c
new file mode 100644
index 0000000..5b77aac
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ul1def_md93.c
@@ -0,0 +1,2995 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2007
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ul1def.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *    This file provides a fuction for NVRAM Task to get UL1 default value
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+  *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_enums.h"
+
+#if defined(__UMTS_RAT__) && defined(__MTK_UL1_FDD__)
+
+#ifdef __MTK_TARGET__
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+#if defined (__UL1_PLATFORM__)
+#include "common_nvram_editor_data_item.h"
+#include "ul1d_rf_public.h"
+#endif
+
+#include "nvram_interface.h"
+#include "hal_ul1_def.h"
+
+// Fix NVRAM RHR activity side-effect
+#include "nvram_editor_data_item.h"
+#include "ul1_nvram_editor.h"  // LID struct definition
+
+
+/* UL1 calibration data defination */
+#include "ul1d_rf_public.h"
+#include "ul1d_mipi_public.h"
+#include "ul1cal.h"
+#include "l1cal.h"
+
+#include "nvram_data_items.h"
+#include "nvram_main.h"
+
+#include "ul1_nvram_def.h"
+#include "ul1d_rf_cid.h"
+
+#include "wcustomdata.h"
+#include "mml1_dpd_def.h"
+
+#if __IS_UL1D_ETM_SUPPORT__
+#include "ul1d_custom_mipi_etm.h"
+#endif   // #if __IS_UL1D_ETM_SUPPORT_
+
+#define UNUSED(x)                      (void)x
+
+#define countof(x)                  ((sizeof(x))/(sizeof(*x)))
+
+//extern kal_uint8 UL1D_RF_CalDataGetBand(UMTSBand rf_band_in_question, kal_bool nvram_init);
+
+void nvram_init_uL1_AfcData(void)
+{
+   kal_bool error_no;
+   extern kal_int16 afc_dac_default;
+   extern kal_uint32 afc_inv_slope;
+
+   l1cal_afcData_T *afc = (l1cal_afcData_T *)get_ctrl_buffer( sizeof( l1cal_afcData_T ) );
+
+   /* Get RF customization data from NVRAM (customer's input) */
+   error_no = nvram_external_read_data(NVRAM_EF_L1_AFCDATA_LID, 1, (kal_uint8 *)afc, NVRAM_EF_L1_AFCDATA_SIZE);
+
+   #if IS_3G_MML1_AFC_TADC_SUPPORT
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_AFCDAC_LID, 1, (kal_uint8 *)afc, NVRAM_EF_UL1_AFCDAC_SIZE);
+   #endif
+
+   ASSERT(error_no == KAL_TRUE);
+   afc_dac_default = afc->dacValue;
+   afc_inv_slope = afc->slopeInv;
+   free_ctrl_buffer( afc );
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_send_uL1_cal
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_send_uL1_cal(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+   /**
+    *    file_idx should be the first L1 element in the logical data item ID enum
+    *    Currently, L1 calibration data element is as following:
+    *    NVRAM_EF_L1_AGCPATHLOSS_LID, NVRAM_EF_L1_RAMPTABLE_GSM900_LID,
+    *    NVRAM_EF_L1_RAMPTABLE_DCS1800_LID, NVRAM_EF_L1_RAMPTABLE_PCS1900_LID, 
+    *    NVRAM_EF_L1_AFCDATA_LID, VRAM_EF_L1_L1SPFC_LID, 
+    */
+
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    peer_buff_struct *peer_buf_ptr;
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_length;
+    nvram_read_req_struct *local_data;
+
+    /* Move the calling to nvram_init_uL1_rfCustomizationData() to nvram_special_service() */
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+
+    for (file_idx = NVRAM_EF_UL1_START; file_idx <= NVRAM_EF_UL1_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TEMP_DAC_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND1_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND2_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND3_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND4_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND5_LID:
+            //case NVRAM_EF_UL1_PATHLOSS_BAND6_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND7_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND8_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND9_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND10_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND11_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND19_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND1_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND2_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND3_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND4_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND5_LID:
+            //case NVRAM_EF_UL1_TXDAC_BAND6_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND7_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND8_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND9_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND10_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND11_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    /* PA 8-level contrl */
+    for (file_idx = NVRAM_EF_UL1_TXPAOCTLEV_START; file_idx <= NVRAM_EF_UL1_TXPAOCTLEV_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND2_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND3_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND4_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND5_LID:
+            //case NVRAM_EF_UL1_TXPAOCTLEV_BAND6_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND7_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND8_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND9_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND10_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND11_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+    /* End of PA 8-level contrl */
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+#if defined(__UMTS_R8__) //Jay
+    for (file_idx = NVRAM_EF_UL1_PATHLOSS2_START; file_idx <= NVRAM_EF_UL1_PATHLOSS2_END; file_idx++)
+    {
+       if (!NVRAM_IS_LID_VALID(file_idx))
+       {
+          continue;
+       }
+        
+       switch(file_idx)
+       {
+          case NVRAM_EF_UL1_PATHLOSS2_BAND1_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND2_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND3_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND4_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND5_LID:
+          //case NVRAM_EF_UL1_PATHLOSS2_BAND6_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND7_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND8_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND9_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND10_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND11_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND19_LID:
+          {
+              nvram_util_get_data_item(&ldi, file_idx);
+
+              local_data->access_id = 0;
+              local_data->file_idx = file_idx;
+              local_data->para = 1;
+          
+              pdu_length = ldi->size;
+              peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+              ASSERT(peer_buf_ptr != NULL);
+          
+              pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+              ASSERT(pdu_ptr != NULL);
+          
+          #ifdef __MULTI_BOOT__
+              if (FACTORY_BOOT == kal_query_boot_mode())
+              {        
+                  nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              else
+          #endif /* __MULTI_BOOT__ */
+              {
+                  nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              break;
+          }         
+       }
+    }
+
+    // add by wilson for PA drift compensation
+
+    for (file_idx = NVRAM_EF_UL1_TXPADRIFTCOMP_START; file_idx <= NVRAM_EF_UL1_TXPADRIFTCOMP_END; file_idx++)
+    {
+       if (!NVRAM_IS_LID_VALID(file_idx))
+       {
+          continue;
+       }
+        
+       switch(file_idx)
+       {
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND2_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND3_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND4_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND5_LID:
+          //case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND6_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND7_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND8_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND9_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND10_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND11_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND19_LID:
+          {
+              nvram_util_get_data_item(&ldi, file_idx);
+
+              local_data->access_id = 0;
+              local_data->file_idx = file_idx;
+              local_data->para = 1;
+          
+              pdu_length = ldi->size;
+              peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+              ASSERT(peer_buf_ptr != NULL);
+          
+              pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+              ASSERT(pdu_ptr != NULL);
+          
+          #ifdef __MULTI_BOOT__
+              if (FACTORY_BOOT == kal_query_boot_mode())
+              {        
+                  nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              else
+          #endif /* __MULTI_BOOT__ */
+              {
+                  nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              break;
+          }         
+       }
+    }
+#endif
+
+    /** Tx PRACH TM Compensation */
+    for (file_idx = NVRAM_EF_UL1_TXPRACHTMCOMP_START; file_idx <= NVRAM_EF_UL1_TXPRACHTMCOMP_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND2_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND3_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND4_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND5_LID:
+            //case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND6_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND7_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND8_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND9_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND10_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND11_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+
+    /** AFCDAC */
+    for (file_idx = NVRAM_EF_UL1_AFCDAC_START; file_idx <= NVRAM_EF_UL1_AFCDAC_END; file_idx++)
+    {
+            if (!NVRAM_IS_LID_VALID(file_idx))
+            {
+                continue;
+            }
+
+            switch(file_idx)
+            {
+                case NVRAM_EF_UL1_AFCDAC_LID:
+                {
+                    nvram_util_get_data_item(&ldi, file_idx);
+
+                    local_data->access_id = 0;
+                    local_data->file_idx = file_idx;
+                    local_data->para = 1;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    ASSERT(peer_buf_ptr != NULL);
+
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    ASSERT(pdu_ptr != NULL);
+
+            #ifdef __MULTI_BOOT__
+                    if (FACTORY_BOOT == kal_query_boot_mode())
+                    {
+                        nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    else
+            #endif /* __MULTI_BOOT__ */
+                    {
+                        nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    break;
+             }
+        }
+    }
+
+    /** AFCCAP */
+    for (file_idx = NVRAM_EF_UL1_AFCCAP_START; file_idx <= NVRAM_EF_UL1_AFCCAP_END; file_idx++)
+    {
+            if (!NVRAM_IS_LID_VALID(file_idx))
+            {
+                continue;
+            }
+
+            switch(file_idx)
+            {
+                case NVRAM_EF_UL1_AFCCAP_LID:
+                {
+                    nvram_util_get_data_item(&ldi, file_idx);
+
+                    local_data->access_id = 0;
+                    local_data->file_idx = file_idx;
+                    local_data->para = 1;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    ASSERT(peer_buf_ptr != NULL);
+
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    ASSERT(pdu_ptr != NULL);
+
+             #ifdef __MULTI_BOOT__
+                    if (FACTORY_BOOT == kal_query_boot_mode())
+                    {
+                        nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    else
+             #endif /* __MULTI_BOOT__ */
+                    {
+                        nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    break;
+             }
+        }
+    }
+
+    /** Tx Power Offset */
+    for (file_idx = NVRAM_EF_UL1_TXPOWEROFFSET_START; file_idx <= NVRAM_EF_UL1_TXPOWEROFFSET_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            /* Tx power offset table */
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND1_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND2_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND3_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND4_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND5_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND6_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND7_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND8_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND9_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND10_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND11_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+#ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+#endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+    free_local_para((local_para_struct*) local_data);
+
+}   /* end of nvram_send_L1_cal function */
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+void nvram_init_uL1_mipiTxData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_txData_T *ul1_rf_mipi_tx_data_buffer = (ul1mipi_txData_T *)get_ctrl_buffer(sizeof(ul1mipi_txData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_TX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_TX_DATA_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipi_txData_T));
+       ASSERT(error_no == KAL_TRUE);
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_DATA_START);
+       kal_mem_cpy(UMTS_MIPI_TX_DATA_PCORE_TABLE[tableIdx], ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipi_txData_T));
+   }
+   free_ctrl_buffer(ul1_rf_mipi_tx_data_buffer);
+
+}
+
+void nvram_init_uL1_mipiTxEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_txEvent_T *ul1_rf_mipi_tx_event_buffer = (ul1mipi_txEvent_T *)get_ctrl_buffer(sizeof(ul1mipi_txEvent_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_TX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_TX_EVENT_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipi_txEvent_T));
+       ASSERT(error_no == KAL_TRUE);
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_EVENT_START);
+       kal_mem_cpy(UMTS_MIPI_TX_EVENT_PCORE_TABLE[tableIdx], ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipi_txEvent_T));
+   }
+   free_ctrl_buffer(ul1_rf_mipi_tx_event_buffer);
+
+}
+
+void nvram_init_uL1_mipiRxData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_rxData_T *ul1_rf_mipi_rx_data_buffer = (ul1mipi_rxData_T *)get_ctrl_buffer(sizeof(ul1mipi_rxData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_RX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_RX_DATA_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_rx_data_buffer, sizeof(ul1mipi_rxData_T));
+       ASSERT(error_no == KAL_TRUE);
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_DATA_START);
+       kal_mem_cpy(UMTS_MIPI_RX_DATA_PCORE_TABLE[tableIdx], ul1_rf_mipi_rx_data_buffer, sizeof(ul1mipi_rxData_T));
+   }
+   free_ctrl_buffer(ul1_rf_mipi_rx_data_buffer);
+
+}
+
+void nvram_init_uL1_mipiRxEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_rxEvent_T *ul1_rf_mipi_rx_event_buffer = (ul1mipi_rxEvent_T *)get_ctrl_buffer(sizeof(ul1mipi_rxEvent_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_RX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_RX_EVENT_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_rx_event_buffer, sizeof(ul1mipi_rxEvent_T));
+       ASSERT(error_no == KAL_TRUE);
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_EVENT_START);
+       kal_mem_cpy(UMTS_MIPI_RX_EVENT_PCORE_TABLE[tableIdx], ul1_rf_mipi_rx_event_buffer, sizeof(ul1mipi_rxEvent_T));
+   }
+   free_ctrl_buffer(ul1_rf_mipi_rx_event_buffer);
+
+}
+
+void nvram_init_uL1_mipiAsmIso(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_asmIsoData_T *ul1_rf_mipi_asm_iso_buffer = (ul1mipi_asmIsoData_T *)get_ctrl_buffer(sizeof(ul1mipi_asmIsoData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_ASM_ISOLATION_START; lid <= NVRAM_EF_UL1_MIPI_ASM_ISOLATION_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_asm_iso_buffer, sizeof(ul1mipi_asmIsoData_T));
+       ASSERT(error_no == KAL_TRUE);
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ASM_ISOLATION_START);
+       kal_mem_cpy(UMTS_MIPI_ASM_ISOLATION_DATA_PCORE_TABLE[tableIdx], ul1_rf_mipi_asm_iso_buffer, sizeof(ul1mipi_asmIsoData_T));
+   }
+   free_ctrl_buffer(ul1_rf_mipi_asm_iso_buffer);
+
+}
+
+void nvram_init_uL1_mipiInitCw(void)
+{
+   kal_bool error_no;
+
+   ul1mipi_initCwData_T *ul1_rf_mipi_init_buffer = (ul1mipi_initCwData_T *)get_ctrl_buffer(sizeof(ul1mipi_initCwData_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_MIPI_INIT_CW_LID, 1, (kal_uint8 *)ul1_rf_mipi_init_buffer, sizeof(ul1mipi_initCwData_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   kal_mem_cpy(UMTS_MIPI_INITIAL_CW_PCORE_ptr, ul1_rf_mipi_init_buffer, sizeof(ul1mipi_initCwData_T));
+   free_ctrl_buffer(ul1_rf_mipi_init_buffer);
+}
+
+void nvram_init_uL1_mipiSleepCw(void)
+{
+   kal_bool error_no;
+      
+   ul1mipi_sleepCwData_T *ul1_rf_mipi_sleep_buffer = (ul1mipi_sleepCwData_T *)get_ctrl_buffer(sizeof(ul1mipi_sleepCwData_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_MIPI_SLEEP_CW_LID, 1, (kal_uint8 *)ul1_rf_mipi_sleep_buffer, sizeof(ul1mipi_sleepCwData_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   kal_mem_cpy(UMTS_MIPI_SLEEP_CW_PCORE_ptr, ul1_rf_mipi_sleep_buffer, sizeof(ul1mipi_sleepCwData_T));
+   free_ctrl_buffer(ul1_rf_mipi_sleep_buffer);
+}
+
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tpcData_T *ul1_rf_mipi_data_buffer = (ul1mipi_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipi_tpcData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_TPC_START; lid <= NVRAM_EF_UL1_MIPI_TPC_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_data_buffer, sizeof(ul1mipi_tpcData_T));
+       ASSERT(error_no == KAL_TRUE);
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TPC_START);
+       kal_mem_cpy(UMTS_MIPI_TPC_PCORE_TABLE[tableIdx], ul1_rf_mipi_data_buffer, sizeof(ul1mipi_tpcData_T));
+   }
+   free_ctrl_buffer(ul1_rf_mipi_data_buffer);
+    
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+   nvram_init_uL1_mipiTxData();
+   nvram_init_uL1_mipiTxEvent();
+   nvram_init_uL1_mipiRxData();
+   nvram_init_uL1_mipiRxEvent();
+   nvram_init_uL1_mipiAsmIso();
+   nvram_init_uL1_mipiInitCw();
+   nvram_init_uL1_mipiSleepCw();
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+
+}
+#endif
+
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+void nvram_init_uL1_datFeatureByRat(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T *ul1_dat_feature_by_rat_buffer = (UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FEATURE_BY_RAT_LID, 1, (kal_uint8 *)ul1_dat_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_DAT_FEATURE_BY_RAT_PCORE_ptr, ul1_dat_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+   free_ctrl_buffer(ul1_dat_feature_by_rat_buffer);
+}
+
+void nvram_init_uL1_datFeatureByRoute(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T *ul1_dat_fe_route_db_buffer = (UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FE_ROUTE_DATABASE_LID, 1, (kal_uint8 *)ul1_dat_fe_route_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_DAT_FE_ROUTE_DATABASE_PCORE_ptr, ul1_dat_fe_route_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+   free_ctrl_buffer(ul1_dat_fe_route_db_buffer);
+}
+
+void nvram_init_uL1_datFeDb(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_DAT_FE_DATABASE_T *ul1_dat_fe_db_buffer = (UMTS_CUSTOM_DAT_FE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FE_DATABASE_LID, 1, (kal_uint8 *)ul1_dat_fe_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_DAT_FE_DATABASE_PCORE_ptr, ul1_dat_fe_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+   free_ctrl_buffer(ul1_dat_fe_db_buffer);
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiDatAEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_A_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_datEvent_CatA_T *ul1_rf_mipi_dat_event_buffer = (ul1mipi_datEvent_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_datEvent_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_DAT_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_A_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_event_buffer->mipiDatEventRoute[tableIdx]), sizeof(ul1mipi_datEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_event_buffer);
+}
+
+void nvram_init_uL1_mipiDatAData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_A_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_datData_CatA_T *ul1_rf_mipi_dat_data_buffer = (ul1mipi_datData_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_datData_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_DAT_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_A_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_data_buffer->mipiDatDataRoute[tableIdx]), sizeof(ul1mipi_datSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_data_buffer);
+}
+
+void nvram_init_uL1_mipiDatBEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_B_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_datEvent_CatB_T *ul1_rf_mipi_dat_event_buffer = (ul1mipi_datEvent_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_datEvent_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_DAT_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_B_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_event_buffer->mipiDatEventRoute[tableIdx]), sizeof(ul1mipi_datEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_event_buffer);
+}
+
+void nvram_init_uL1_mipiDatBData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_B_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_datData_CatB_T *ul1_rf_mipi_dat_data_buffer = (ul1mipi_datData_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_datData_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_DAT_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_B_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_data_buffer->mipiDatDataRoute[tableIdx]), sizeof(ul1mipi_datSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_data_buffer);
+}
+#endif
+#endif
+
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+void nvram_init_uL1_tasFeatureByRat(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T *ul1_tas_feature_by_rat_buffer = (UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FEATURE_BY_RAT_LID, 1, (kal_uint8 *)ul1_tas_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_TAS_FEATURE_BY_RAT_PCORE_ptr, ul1_tas_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+   free_ctrl_buffer(ul1_tas_feature_by_rat_buffer);
+}
+
+void nvram_init_uL1_tasFeatureByRoute(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T *ul1_tas_fe_route_db_buffer = (UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FE_ROUTE_DATABASE_LID, 1, (kal_uint8 *)ul1_tas_fe_route_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_TAS_FE_ROUTE_DATABASE_PCORE_ptr, ul1_tas_fe_route_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+   free_ctrl_buffer(ul1_tas_fe_route_db_buffer);
+}
+
+void nvram_init_uL1_tasFeDb(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_TAS_FE_DATABASE_T *ul1_tas_fe_db_buffer = (UMTS_CUSTOM_TAS_FE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FE_DATABASE_LID, 1, (kal_uint8 *)ul1_tas_fe_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_TAS_FE_DATABASE_PCORE_ptr, ul1_tas_fe_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+   free_ctrl_buffer(ul1_tas_fe_db_buffer);
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiTasAEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_A_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatA_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+}
+
+void nvram_init_uL1_mipiTasAData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_A_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatA_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_A_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+}
+
+void nvram_init_uL1_mipiTasBEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_B_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatB_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+}
+
+void nvram_init_uL1_mipiTasBData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_B_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatB_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_B_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+}
+
+void nvram_init_uL1_mipiTasCEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_C_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatC_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatC_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatC_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatC_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_C_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+}
+
+void nvram_init_uL1_mipiTasCData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_C_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatC_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatC_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatC_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatC_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_C_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_C_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+}
+#endif
+
+#if IS_3G_TAS_INHERIT_4G_ANT
+void nvram_init_uL1_tasInheritLteAnt(void)
+{
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T *ul1_tas_inherit_lte_bnad_buffer = (UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_INHERIT_LTE_ANT_LID, 1, (kal_uint8 *)ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_PCORE_ptr, ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+   free_ctrl_buffer(ul1_tas_inherit_lte_bnad_buffer);
+}
+#endif
+#endif
+
+#if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+void nvram_init_uL1_TpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+
+   U_sTXPOWEROFFSETDATA *ul1_tpo_data_buffer = (U_sTXPOWEROFFSETDATA *) get_ctrl_buffer(sizeof(U_sTXPOWEROFFSETDATA));
+
+   for(lid = NVRAM_EF_UL1_TXPOWEROFFSET_START; lid<= NVRAM_EF_UL1_TXPOWEROFFSET_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_tpo_data_buffer, sizeof(U_sTXPOWEROFFSETDATA));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPOWEROFFSET_START);
+      kal_mem_cpy(UMTS_TX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1_tpo_data_buffer, sizeof(U_sTXPOWEROFFSETDATA));
+   }
+   free_ctrl_buffer(ul1_tpo_data_buffer);
+}
+#endif
+
+#if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+void nvram_init_uL1_RpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+
+   U_sRXPOWEROFFSETDATA *ul1_rpo_data_buffer = (U_sRXPOWEROFFSETDATA *) get_ctrl_buffer(sizeof(U_sRXPOWEROFFSETDATA));
+
+   for(lid = NVRAM_EF_UL1_RXPOWEROFFSET_START; lid<= NVRAM_EF_UL1_RXPOWEROFFSET_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rpo_data_buffer, sizeof(U_sRXPOWEROFFSETDATA));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RXPOWEROFFSET_START);
+      kal_mem_cpy(UMTS_RX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1_rpo_data_buffer, sizeof(U_sRXPOWEROFFSETDATA));
+   }
+   free_ctrl_buffer(ul1_rpo_data_buffer);
+}
+#endif
+
+
+#if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+void nvram_init_uL1_vpaSrcSel(void)
+{
+  kal_bool error_no;
+  nvram_lid_enum lid;
+  kal_uint32 tableIdx;
+
+  ul1vpa_sel_T *ul1_rf_vpa_src_sel_buffer = (ul1vpa_sel_T *)get_ctrl_buffer(sizeof(ul1vpa_sel_T));
+
+  for (lid = NVRAM_EF_UL1_VPA_SRC_SEL_START; lid <= NVRAM_EF_UL1_VPA_SRC_SEL_END; lid++)
+  {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_vpa_src_sel_buffer, sizeof(ul1vpa_sel_T));
+      ASSERT(error_no == KAL_TRUE);
+  
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_VPA_SRC_SEL_START);
+      kal_mem_cpy(UMTS_VPA_SRC_SEL_PCORE_TABLE[tableIdx], ul1_rf_vpa_src_sel_buffer, sizeof(ul1vpa_sel_T));
+  }
+  free_ctrl_buffer(ul1_rf_vpa_src_sel_buffer);
+}
+#endif/*IS_3G_VPA_SEL_BY_BAND_SUPPORT*/
+
+kal_uint8 nvram_init_uL1_dpd_band_mapping_rf_bandind(kal_uint8 index_select)
+{
+   kal_uint8 dpd_bandind = 0;
+   kal_uint8 rf_bandind = 0;
+   
+   dpd_bandind = ul1d_BandInfo[index_select-UMTSBand1];
+
+   if(dpd_bandind == UMTSBandNone)
+   {
+      rf_bandind = 0;
+   }
+   else
+   {
+      rf_bandind = RF_GET_CAL_DATA_ARRAY_BAND_IDX((UMTSBand)dpd_bandind, KAL_FALSE);
+   }
+   
+   return(rf_bandind);
+}
+
+void nvram_init_uL1_dpdData(void)
+{
+
+#if __IS_UL1D_DPD_SUPPORT__
+
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+
+   void *ul1_dpd_data_buffer;
+
+   /*********** DPD custom input data **********/
+   #if IS_URF_PCORE
+   ul1_dpd_data_buffer = (U_sUl1dDpdCustomInputData *)get_ctrl_buffer(sizeof(U_sUl1dDpdCustomInputData));
+   
+   U_sUl1dDpdCustomInputData *temp_ptr = (U_sUl1dDpdCustomInputData *)ul1_dpd_data_buffer;
+   
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DPD_PARAMETER_LID, 1, (kal_uint8 *)ul1_dpd_data_buffer, NVRAM_EF_UL1_DPD_PARAMETER_SIZE);
+   ASSERT(error_no == KAL_TRUE);
+   kal_mem_cpy(UMTS_DPD_CUSTOM_INPUT_DATA_PCORE_ptr, (const void*) temp_ptr, sizeof(U_sUl1dDpdCustomInputData));         
+
+   free_ctrl_buffer( ul1_dpd_data_buffer );
+   #endif
+   
+   /*********** DPD CTRL DATA ***********/
+   ul1_dpd_data_buffer = (U_sDPD_COMMON_CTRL *) get_ctrl_buffer(sizeof(U_sDPD_COMMON_CTRL));
+
+   for(lid = NVRAM_EF_UL1_DPD_CTRL_DATA_START; lid<= NVRAM_EF_UL1_DPD_CTRL_DATA_END; lid++)
+   {
+      U_sDPD_COMMON_CTRL *temp_ptr = (U_sDPD_COMMON_CTRL *)ul1_dpd_data_buffer;
+
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_dpd_data_buffer, sizeof(U_sDPD_COMMON_CTRL));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CTRL_DATA_START);      
+      kal_mem_cpy(&(U_DPD_GROUP_PCORE_TABLE[tableIdx]->wcdma_dpd_common_ctrl), (const void*) temp_ptr, sizeof(U_sDPD_COMMON_CTRL));    
+   }
+   free_ctrl_buffer(ul1_dpd_data_buffer);
+   
+   /*********** DPD CAL DATA ***********/
+   ul1_dpd_data_buffer = (U_sDPD_GROUP_CAL *) get_ctrl_buffer(sizeof(U_sDPD_GROUP_CAL));
+
+   for(lid = NVRAM_EF_UL1_DPD_CAL_DATA_START; lid<= NVRAM_EF_UL1_DPD_CAL_DATA_END; lid++)
+   {
+      U_sDPD_GROUP_CAL *temp_ptr = (U_sDPD_GROUP_CAL *)ul1_dpd_data_buffer;
+   
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_dpd_data_buffer, sizeof(U_sDPD_GROUP_CAL));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CAL_DATA_START);
+      
+      kal_mem_cpy(&(U_DPD_GROUP_PCORE_TABLE[tableIdx]->wcdma_dpd_group_cal), (const void*)temp_ptr, sizeof(U_sDPD_GROUP_CAL));     
+      
+   }
+   free_ctrl_buffer(ul1_dpd_data_buffer);
+
+   /*********** DPD MIPI TPC DATA ***********/
+#if (IS_3G_MIPI_SUPPORT)   
+   ul1_dpd_data_buffer = (ul1mipi_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipi_tpcData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_DPD_TPC_START; lid <= NVRAM_EF_UL1_MIPI_DPD_TPC_END; lid++)
+
+   {
+      ul1mipi_tpcData_T *temp_ptr = (ul1mipi_tpcData_T *)ul1_dpd_data_buffer;
+   
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_dpd_data_buffer, sizeof(ul1mipi_tpcData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_DPD_TPC_START);
+      kal_mem_cpy(UMTS_MIPI_DPD_TPC_PCORE_TABLE[tableIdx], (const void*) temp_ptr, sizeof(ul1mipi_tpcData_T));
+   }
+   free_ctrl_buffer(ul1_dpd_data_buffer);
+#endif
+
+   /* Update WCDMA DPD enable to SHM */
+   (*UMTS_DPD_ENABLE_PCORE_ptr) = UMTS_DPD_ENABLE_PCORE;
+
+#endif
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiEtmData(void)
+{
+#if __IS_UL1D_ETM_SUPPORT__
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   ul1mipiEtm_txEvent_T  *ul1_rf_mipi_tx_event_buffer;
+   ul1mipiEtm_txData_T   *ul1_rf_mipi_tx_data_buffer;
+   ul1mipiEtm_tpcEvent_T *ul1_rf_mipi_tpc_event_buffer;
+   ul1mipiEtm_tpcData_T  *ul1_rf_mipi_tpc_data_buffer;
+
+   ul1_rf_mipi_tx_event_buffer = (ul1mipiEtm_txEvent_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_txEvent_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipiEtm_txEvent_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TX_EVENT_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tx_event_buffer, sizeof( ul1mipiEtm_txEvent_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tx_event_buffer );
+
+   ul1_rf_mipi_tx_data_buffer = (ul1mipiEtm_txData_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_txData_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TX_DATA_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipiEtm_txData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_DATA_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TX_DATA_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tx_data_buffer, sizeof( ul1mipiEtm_txData_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tx_data_buffer );
+
+   ul1_rf_mipi_tpc_event_buffer = (ul1mipiEtm_tpcEvent_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_tpcEvent_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tpc_event_buffer, sizeof(ul1mipiEtm_tpcEvent_T));
+      ASSERT(error_no == KAL_TRUE);
+   
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TPC_EVENT_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tpc_event_buffer, sizeof( ul1mipiEtm_tpcEvent_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tpc_event_buffer );
+
+   ul1_rf_mipi_tpc_data_buffer = (ul1mipiEtm_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_tpcData_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tpc_data_buffer, sizeof(ul1mipiEtm_tpcData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TPC_DATA_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tpc_data_buffer, sizeof( ul1mipiEtm_tpcData_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tpc_data_buffer );
+
+#endif   // #if __IS_UL1D_ETM_SUPPORT__
+}
+#endif   // #if (IS_3G_MIPI_SUPPORT)
+
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+void nvram_init_uL1_rfeqCoefData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+
+   hs_dsch_rfeq_info_band_T *ul1_rfeqCoef_data_buffer = (hs_dsch_rfeq_info_band_T *) get_ctrl_buffer(sizeof(hs_dsch_rfeq_info_band_T));
+
+   for(lid = NVRAM_EF_UL1_RFEQ_COEF_START; lid<= NVRAM_EF_UL1_RFEQ_COEF_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rfeqCoef_data_buffer, sizeof(hs_dsch_rfeq_info_band_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_COEF_START);
+      kal_mem_cpy(UMTS_RFEQ_COEF_PCORE_TABLE[tableIdx], ul1_rfeqCoef_data_buffer, sizeof(hs_dsch_rfeq_info_band_T));
+   }
+   free_ctrl_buffer(ul1_rfeqCoef_data_buffer);
+}
+#endif
+
+#if (IS_3G_RFEQ_REAL_COEF_TEST)
+void nvram_init_uL1_rfeqRealCoefCustom(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+
+   URXDFE_REAL_RFEQ_CUSTOM_BAND_T *ul1_rfeqRealCoef_data_buffer = (URXDFE_REAL_RFEQ_CUSTOM_BAND_T *) get_ctrl_buffer(sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+
+   for(lid = NVRAM_EF_UL1_RFEQ_REAL_COEF_START; lid<= NVRAM_EF_UL1_RFEQ_REAL_COEF_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rfeqRealCoef_data_buffer, sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_REAL_COEF_START);
+      kal_mem_cpy(UMTS_RFEQ_REAL_COEF_PCORE_TABLE[tableIdx], ul1_rfeqRealCoef_data_buffer, sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+   }
+   free_ctrl_buffer(ul1_rfeqRealCoef_data_buffer);
+}
+#endif
+
+#endif /* __MTK_TARGET__ */ 
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_L1_default_value_to_write
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  lid         [IN]        
+ *  buffer      [?]         
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#ifdef __MTK_TARGET__
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+   /********************************************************/
+   /* MT6573 3G RF Customization for Modem Bin Update Tool */
+   /********************************************************/
+const kal_uint16 UL_BAND_MIN_UARFCN[] = {0, 9612, 9262, 937, 1312, 4132, 4162, 2012, 2712, 8762, 2887, 3487, 3617, 3792, 3892, 0, 0, 0, 0, 312, 4287, 462, 4437};
+const kal_uint16 UL_BAND_MAX_UARFCN[] = {0, 9888, 9538, 1288, 1513, 4233, 4188, 2338, 2863, 8912, 3163, 3562, 3678, 3818, 3918, 0, 0, 0, 0, 363, 4413, 512, 4813};
+const kal_uint16 UL_BAND_MIN_UARFCN_ADDITIONAL[] = {0, 0, 12, 0, 1662, 782, 812, 2362, 0, 0, 3187, 0, 3707, 3842, 3942, 0, 0, 0, 0, 387, 0, 0, 0};
+const kal_uint16 UL_BAND_MAX_UARFCN_ADDITIONAL[] = {0, 0, 287, 0, 1862, 862, 837, 2687, 0, 0, 3462, 0, 3767, 3867, 3967, 0, 0, 0, 0, 437, 0, 0, 0};
+kal_uint8 band_to_bandInd_map_table[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+void nvram_sort_uL1_band_bandind_mapping(kal_uint8 band_indicator)
+{
+    kal_uint8 table_index;
+
+    if ( band_indicator > UMTSBandNone )
+    {
+       table_index = RF_GET_CAL_DATA_ARRAY_BAND_IDX((UMTSBand)band_indicator, KAL_FALSE);
+       band_to_bandInd_map_table[band_indicator] = table_index;
+    }
+}
+
+
+#endif /* #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__) */
+
+#endif /* __MTK_TARGET__ */
+
+#if (IS_3G_DRDI_SUPPORT)
+kal_bool ul1d_DRDI_had_done = KAL_FALSE;
+
+/****************************************************************************
+ * Custom Data Pointer Array Extern
+ ****************************************************************************/
+const Ul1CustomDynamicInitMipiData *ul1d_mipiData_array_ptr;
+#if __IS_UL1D_ETM_SUPPORT__
+const Ul1CustomDynamicInitMipiEtmData *ul1d_mipiEtmData_array_ptr;
+#endif   // #if __IS_UL1D_ETM_SUPPORT__
+const Ul1CustomDynamicInitUmtsFeSettingData *ul1d_RfFeRoute_array_ptr;
+const Ul1CustomDynamicInitUmtsCalData *ul1d_rf_calData_ptr;
+const Ul1CustomDynamicRfParameter *ul1d_rf_parameter_ptr;
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+const Ul1CustomDynamicDatRoute *ul1d_rf_dat_route_ptr;
+const Ul1CustomDynamicDatDb *ul1d_rf_dat_db_ptr;
+const Ul1CustomDynamicDatFeatureByRat *ul1d_rf_dat_byRat_ptr;
+#if (IS_3G_MIPI_SUPPORT)
+const Ul1CustomDynamicDatMipiData *ul1d_rf_dat_mipiData_ptr;
+#endif
+#endif
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+const Ul1CustomDynamicTasRoute *ul1d_rf_tas_route_ptr;
+const Ul1CustomDynamicTasDb *ul1d_rf_tas_db_ptr;
+const Ul1CustomDynamicTasFeatureByRat *ul1d_rf_tas_byRat_ptr;
+#if (IS_3G_MIPI_SUPPORT)
+const Ul1CustomDynamicTasMipiData *ul1d_rf_tas_mipiData_ptr;
+#endif
+#if IS_3G_TAS_INHERIT_4G_ANT
+const Ul1CustomDynamicTasInheritLteAnt *ul1d_rf_tas_inherit_lte_ant_ptr;
+#endif
+#endif
+#if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+const Ul1CustomDynamicTpoData *ul1d_rf_tpoData_ptr;
+#endif
+#if(IS_3G_RX_POWER_OFFSET_SUPPORT)
+const Ul1CustomDynamicRpoData *ul1d_rf_rpoData_ptr;
+#endif
+#if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+const Ul1CustomDynamicVpaSrcSelData *ul1d_rf_VpaSrcSelData_ptr;
+#endif
+#if IS_3G_ELNA_SUPPORT
+const Ul1CustomDynamicElnaData *ul1d_rf_elnadata_ptr;
+#endif
+#if (__IS_UL1D_DPD_SUPPORT__)
+const Ul1CustomDynamicInitUmtsDpdfactoryData *ul1d_rf_dpd_data_ptr;
+#endif
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+const Ul1CustomDynamicRfeqCoefData *ul1d_rf_rfeqCoefData_ptr;
+#endif
+#if IS_3G_RFEQ_REAL_COEF_TEST
+const Ul1CustomDynamicRealRfeqCoefData *ul1d_rf_realRfeqCoefData_ptr;
+#endif
+#endif/*IS_3G_DRDI_SUPPORT*/
+
+
+void nvram_UL1D_DrdiPWRONCAL(kal_uint16 setIdx)
+{
+#if (IS_3G_DRDI_SUPPORT)
+   UMTS_PWRON_CAL_DATA_PTR[1] = ul1PwrOnCalData[setIdx][0];
+   UMTS_PWRON_CAL_DATA_PTR[2] = ul1PwrOnCalData[setIdx][1];
+   UMTS_PWRON_CAL_DATA_PTR[3] = ul1PwrOnCalData[setIdx][2];
+   UMTS_PWRON_CAL_DATA_PTR[4] = ul1PwrOnCalData[setIdx][3];
+   UMTS_PWRON_CAL_DATA_PTR[5] = ul1PwrOnCalData[setIdx][4];
+#endif/*IS_3G_DRDI_SUPPORT*/
+}
+
+void nvram_UL1D_DrdiPointerInit(kal_uint16 setIdx)
+{
+#if (IS_3G_DRDI_SUPPORT)
+   /*Band indicator assign*/ 
+   ul1d_BandInfo[0] = ul1CustomBand[setIdx][0];
+   ul1d_BandInfo[1] = ul1CustomBand[setIdx][1];
+   ul1d_BandInfo[2] = ul1CustomBand[setIdx][2];
+   ul1d_BandInfo[3] = ul1CustomBand[setIdx][3];
+   ul1d_BandInfo[4] = ul1CustomBand[setIdx][4];   
+
+   /*calibration data pointer table assign*/ 
+   ul1d_rf_calData_ptr = &(ul1CustomUmtsCalData[setIdx]);
+   
+   #if (IS_3G_MIPI_SUPPORT)
+   /*MIPI data pointer table assign*/ 
+   ul1d_mipiData_array_ptr = &(ul1CustomMipiData[setIdx]);
+   #if __IS_UL1D_ETM_SUPPORT__
+   ul1d_mipiEtmData_array_ptr = &( ul1CustomMipiEtmData[ setIdx ] );
+   #endif   // #if __IS_UL1D_ETM_SUPPORT__   
+   #endif
+
+   /*RF Front end route table pointer assign*/ 
+   ul1d_RfFeRoute_array_ptr = &(ul1CustomUmtsFeSettingData[setIdx]);
+
+   /*RF Parameter*/
+   ul1d_rf_parameter_ptr = &(ul1CustomUmtsRfParameter[setIdx]);
+
+   #if (IS_3G_DAT_UL1_CUSTOM_SUPPORT)
+   ul1d_rf_dat_route_ptr = &(ul1CustomDatRoute[setIdx]);
+   ul1d_rf_dat_db_ptr = &(ul1CustomDatDb[setIdx]);
+   ul1d_rf_dat_byRat_ptr = &(ul1CustomDatByRat[setIdx]);
+   #if (IS_3G_MIPI_SUPPORT)
+   ul1d_rf_dat_mipiData_ptr = &(ul1CustomDatMipiData[setIdx]);
+   #endif
+   #endif
+
+   #if (IS_3G_TAS_UL1_CUSTOM_SUPPORT)
+   ul1d_rf_tas_route_ptr = &(ul1CustomTasRoute[setIdx]);
+   ul1d_rf_tas_db_ptr = &(ul1CustomTasDb[setIdx]);
+   ul1d_rf_tas_byRat_ptr = &(ul1CustomTasByRat[setIdx]);
+   #if (IS_3G_MIPI_SUPPORT)
+   ul1d_rf_tas_mipiData_ptr = &(ul1CustomTasMipiData[setIdx]);
+   #endif
+   #if IS_3G_TAS_INHERIT_4G_ANT
+   ul1d_rf_tas_inherit_lte_ant_ptr= &(ul1CustomTasInheritLteAnt[setIdx]);
+   #endif
+   #endif
+
+   #if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+   ul1d_rf_tpoData_ptr = &(ul1CustomTpoData[setIdx]);
+   #endif
+   
+   #if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+   ul1d_rf_rpoData_ptr = &(ul1CustomRpoData[setIdx]);
+   #endif
+  
+   #if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+   ul1d_rf_VpaSrcSelData_ptr= &(ul1CustomVpaSrcSelData[setIdx]);
+   #endif
+   #if IS_3G_ELNA_SUPPORT
+   ul1d_rf_elnadata_ptr = &(ul1CustomElnaData[setIdx]);
+   #endif
+   #if __IS_UL1D_DPD_SUPPORT__
+   ul1d_rf_dpd_data_ptr = &(ul1CustomUmtsDpdFactoryData[setIdx]);  
+   #endif   
+
+   #if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+   ul1d_rf_rfeqCoefData_ptr = &(ul1CustomRfeqCoefData[setIdx]);
+   #endif
+
+   #if (IS_3G_RFEQ_REAL_COEF_TEST)
+   ul1d_rf_realRfeqCoefData_ptr = &(ul1CustomRealRfeqCoefData[setIdx]);
+   #endif
+
+#endif/*IS_3G_DRDI_SUPPORT*/
+}
+
+void nvram_UL1D_Drdi(void)
+{
+#if (IS_3G_DRDI_SUPPORT)
+   if(!ul1d_DRDI_had_done)
+   {
+      if(isWcdmaDrdiEnable)
+      {
+         kal_uint16 setIdx;
+         setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);
+         /* set the pointer to RF custom data by set index */
+         nvram_UL1D_DrdiPointerInit(setIdx);
+         UL1D_RF_DynamicCustomTable_Update(ul1d_RfFeRoute_array_ptr);
+         UL1D_RF_DynamicSetRfBandSupport(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE);
+         UL1D_RF_DynamicSetRfParameter(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE,ul1d_rf_parameter_ptr);
+         nvram_UL1D_DrdiPWRONCAL(setIdx);
+   #if IS_3G_ELNA_SUPPORT
+         UL1D_RF_DynamicElna_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE, ul1d_rf_elnadata_ptr);
+   #endif
+	
+   #if IS_3G_RX_POWER_OFFSET_SUPPORT
+	      UL1D_RF_DynamicRxPowerOffset_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE, ul1d_rf_rpoData_ptr);
+   #endif
+      }
+      else
+      {
+         nvram_UL1D_DrdiPointerInit(0);
+      }
+      ul1d_DRDI_had_done = KAL_TRUE;
+   }
+#endif/*IS_3G_DRDI_SUPPORT*/
+}
+
+void nvram_get_uL1_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#ifdef __MTK_TARGET__
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+//chliu
+    UMTSBand uband = UMTSBandNone;
+    kal_uint8 index_select;
+    ul1cal_tempdacData_T  *tempdac;
+    ul1cal_pathlossData_T *pathloss;
+    ul1cal_txdacData_T    *txdac;
+/* end of chliu */
+    ul1cal_txPrachTmCompData_T *txPrachTmComp;
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    ul1cal_txPaOctLevData_T *pacoctlev_handle;
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T  *pwroncal;
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+   nvram_UL1D_Drdi();
+
+   /* Do not need to get band indicator prior to get UL1 default value if user
+    * modifies setting by Modem Bin Update Tool, since in MT6573/MT6276 3G RF
+    * customization scenario the band indicator in run-time directly modified
+    * by customer via Modem Bin Update tool or via ul1d_custom_rf.h
+    */
+   ul1d_BandInfo[0] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB1;
+   ul1d_BandInfo[1] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB2;
+   ul1d_BandInfo[2] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB3;
+   ul1d_BandInfo[3] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.LB1;
+   ul1d_BandInfo[4] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.LB2;    
+
+#if defined (__UL1_HS_PLUS_PLATFORM__)
+   /* Produce band to band indicator mapping array */
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[0]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[1]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[2]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[3]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[4]);
+#else
+   nvram_sort_uL1_band_bandind_mapping(rxHighBand1Indicator);
+   nvram_sort_uL1_band_bandind_mapping(rxHighBand2Indicator);
+   nvram_sort_uL1_band_bandind_mapping(rxLowBand1Indicator);
+   #if IS_RF_MT6162
+   nvram_sort_uL1_band_bandind_mapping(rxLowBand2Indicator);
+   #endif
+#endif
+
+#endif /* #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__) */
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch (lid)
+    {
+//chliu
+        case NVRAM_EF_UL1_TEMP_DAC_LID:
+            #if 0
+/* under construction !*/
+/* under construction !*/
+            #else
+               #if (IS_3G_DRDI_SUPPORT)
+            kal_mem_cpy(buffer, ul1d_rf_calData_ptr->TempDac_p, sizeof(ul1cal_tempdacData_T));            
+            UNUSED(tempdac);
+               #else
+            kal_mem_cpy(buffer, U_TEMP_DAC_SetDefault, sizeof(ul1cal_tempdacData_T));            
+            UNUSED(tempdac);
+               #endif
+            #endif
+            break;
+        case NVRAM_EF_UL1_PATHLOSS_BAND1_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND2_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND3_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND4_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND5_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND6_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND7_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND8_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND9_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND10_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND11_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND19_LID:
+            {
+               pathloss = (ul1cal_pathlossData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PATHLOSS_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RxPathLoss_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RxPathLoss_p[index_select], sizeof(ul1cal_pathlossData_T));
+                  UNUSED(pathloss);
+               }
+            #else
+               if (U_AGC_PATHLOSS_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_AGC_PATHLOSS_TABLE_SetDefault[index_select], sizeof(ul1cal_pathlossData_T));
+                  UNUSED(pathloss);
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_TXDAC_BAND1_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND2_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND3_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND4_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND5_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND6_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND7_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND8_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND9_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND10_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND11_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND19_LID:
+            {
+               txdac = (ul1cal_txdacData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXDAC_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RampData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RampData_p[index_select], sizeof(U_sRAMPDATA));
+                  UNUSED(txdac);
+               }
+            #else
+               if (UMTS_RampData_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RampData_SetDefault[index_select], sizeof(U_sRAMPDATA));
+                  UNUSED(txdac);
+               }
+            #endif
+            }
+            break;
+/* end of chliu */
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+        /* PA 8-level control */
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND2_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND3_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND4_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND5_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND6_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND7_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND8_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND9_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND10_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND11_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND19_LID:
+            {
+               pacoctlev_handle = (ul1cal_txPaOctLevData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID);         
+               index_select = RF_GET_CAL_DATA_ARRAY_BAND_IDX(uband, KAL_TRUE);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaOctLev_p[index_select] != 0)
+               {
+                   kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaOctLev_p[index_select], sizeof(U_sPAOCTLVLSETTING));
+                   UNUSED(pacoctlev_handle);
+               }
+            #else
+               if (U_PA_OCTLEV_TABLE_SetDefault[index_select] != 0)
+               {
+                   kal_mem_cpy(buffer, U_PA_OCTLEV_TABLE_SetDefault[index_select], sizeof(U_sPAOCTLVLSETTING));
+                   UNUSED(pacoctlev_handle);
+               }
+            #endif
+            }
+            break;
+        /* End of PA 8-level control */
+        case NVRAM_EF_UL1_3G_RF_PARAMETER_LID:
+            UL1D_RF_UpdateDatabaseTable();
+            UL1D_RF_CA_CustomData_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE);
+            kal_mem_cpy(buffer, &UMTS_RF_CUSTOM_INPUT_DATA_PCORE, sizeof(U_sUl1dRfCustomInputData));            
+            break;
+
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+#if defined(__UMTS_R8__) //add by Jay
+        case NVRAM_EF_UL1_PATHLOSS2_BAND1_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND2_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND3_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND4_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND5_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND6_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND7_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND8_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND9_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND10_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND11_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND19_LID:
+            {
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PATHLOSS2_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RxDPathLoss_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RxDPathLoss_p[index_select], sizeof(ul1cal_pathlossRxdData_T));
+               }
+            #else
+               if (U_AGC_PATHLOSS_RXD_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_AGC_PATHLOSS_RXD_TABLE_SetDefault[index_select], sizeof(ul1cal_pathlossRxdData_T));
+               }
+            #endif
+            }
+            break;
+   //add by wilson for pa drift compensation
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND2_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND3_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND4_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND5_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND6_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND7_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND8_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND9_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND10_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND11_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND19_LID:
+            {
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaDrift_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaDrift_p[index_select], sizeof(ul1cal_txPaDriftCompData_T));
+               }
+            #else
+               if (U_PA_DRIFT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_PA_DRIFT_TABLE_SetDefault[index_select], sizeof(ul1cal_txPaDriftCompData_T));
+               }
+            #endif
+            }
+            break;
+#endif //defined(__UMTS_R8__)
+
+        /** Tx PRACH TM Compensation */
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND2_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND3_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND4_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND5_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND6_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND7_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND8_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND9_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND10_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND11_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND19_LID:
+            {
+               txPrachTmComp = (ul1cal_txPrachTmCompData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaRachComp_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaRachComp_p[index_select], sizeof(ul1cal_txPrachTmCompData_T));
+                  UNUSED(txPrachTmComp);
+               }
+            #else
+               if (U_PA_RACH_COMP_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_PA_RACH_COMP_TABLE_SetDefault[index_select], sizeof(ul1cal_txPrachTmCompData_T));
+                  UNUSED(txPrachTmComp);
+               }
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_AFCDAC_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_calData_ptr->AfcDac_p, sizeof(ul1cal_afcDacData_T));
+            #else
+               kal_mem_cpy(buffer, &U_AFC_DAC_SetDefault, sizeof(ul1cal_afcDacData_T));
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_AFCCAP_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_calData_ptr->AfcCap_p, sizeof(ul1cal_afcCapData_T));
+            #else
+               kal_mem_cpy(buffer, &U_AFC_CAP_SetDefault, sizeof(ul1cal_afcCapData_T));
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_PWRONCAL_BAND1_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND2_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND3_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND4_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND5_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND6_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND7_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND8_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND9_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND10_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND11_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND19_LID:
+            {
+               pwroncal = (UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PWRONCAL_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+
+               if (UMTS_PWRON_CAL_DATA_PTR[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_PWRON_CAL_DATA_PTR[index_select], sizeof(UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T));
+                  UNUSED(pwroncal);
+               }
+            }
+            break;
+
+
+#if (IS_3G_MIPI_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_TPC_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TPC_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->tpcTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->tpcTable_p[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #else
+               if (UMTS_MIPI_TPC_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TPC_TABLE_SetDefault[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #endif
+            }
+            break;
+#endif
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_EVENT_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->rxEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->rxEventTable_p[index_select], sizeof(ul1mipi_rxEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_RX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_RX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_rxEvent_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_RX_DATA_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_DATA_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->rxDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->rxDataTable_p[index_select], sizeof(ul1mipi_rxData_T));
+               }
+            #else
+               if (UMTS_MIPI_RX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_RX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_rxData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_EVENT_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->txEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->txEventTable_p[index_select], sizeof(ul1mipi_txEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_TX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_txEvent_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_TX_DATA_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_DATA_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->txDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->txDataTable_p[index_select], sizeof(ul1mipi_txData_T));
+               }
+            #else
+               if (UMTS_MIPI_TX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_txData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ASM_ISOLATION_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->asmIsoTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->asmIsoTable_p[index_select], sizeof(ul1mipi_asmIsoData_T));
+               }
+            #else
+               if (UMTS_MIPI_ASM_ISOLATION_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ASM_ISOLATION_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_asmIsoData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_INIT_CW_LID:
+            {
+               /*Useless NVRAM ID(Moved to MML1), do nothing*/
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_SLEEP_CW_LID:
+            {
+               /*Useless NVRAM ID(Moved to MML1), do nothing*/
+            }
+            break;
+
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+#if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+        case NVRAM_EF_UL1_VPA_SRC_SEL_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_LOWBAND1_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_VPA_SRC_SEL_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_VpaSrcSelData_ptr->vpaSrcSelTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_VpaSrcSelData_ptr->vpaSrcSelTable_p[index_select], sizeof(ul1vpa_sel_T));            
+               }
+            #else
+               if (UMTS_VPA_SRC_SEL_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_VPA_SRC_SEL_TABLE_SetDefault[index_select], sizeof(ul1vpa_sel_T));
+               }
+            #endif
+            }
+            break;
+#endif/*IS_3G_VPA_SEL_BY_BAND_SUPPORT*/
+
+#if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+         /* Tx power offset table 1 */
+         case NVRAM_EF_UL1_TXPOWEROFFSET_HIGHBAND1_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_HIGHBAND2_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_HIGHBAND3_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_LOWBAND1_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPOWEROFFSET_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_tpoData_ptr->TpoData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_tpoData_ptr->TpoData_p[index_select], sizeof(U_sTXPOWEROFFSETDATA));
+               }
+            #else
+               if (U_TX_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_TX_POWER_OFFSET_TABLE_SetDefault[index_select], sizeof(U_sTXPOWEROFFSETDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_TX_POWER_OFFSET_SUPPORT */
+
+#if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+         /* Rx power offset table */
+         case NVRAM_EF_UL1_RXPOWEROFFSET_HIGHBAND1_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_HIGHBAND2_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_HIGHBAND3_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_LOWBAND1_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RXPOWEROFFSET_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_rpoData_ptr->RpoData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_rpoData_ptr->RpoData_p[index_select], sizeof(U_sRXPOWEROFFSETDATA));
+               }
+            #else
+               if (U_RX_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_RX_POWER_OFFSET_TABLE_SetDefault[index_select], sizeof(U_sRXPOWEROFFSETDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RX_POWER_OFFSET_SUPPORT */
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+       case NVRAM_EF_UL1_DAT_FEATURE_BY_RAT_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, &ul1d_rf_dat_byRat_ptr->dat_feature_byRat, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_DAT_FEATURE_BY_RAT_SetDefault, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_FE_ROUTE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_dat_route_ptr->dat_fe_route, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_DAT_FE_ROUTE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_FE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_a_fe_db, ul1d_rf_dat_db_ptr->dat_cat_a_fe_db, sizeof(UMTS_CUSTOM_DAT_FE_CAT_A_T));
+               kal_mem_cpy(&UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_b_fe_db, ul1d_rf_dat_db_ptr->dat_cat_b_fe_db, sizeof(UMTS_CUSTOM_DAT_FE_CAT_B_T));
+            #else
+               UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_a_fe_db = UMTS_DAT_CAT_A_DATABASE_SetDefault;
+               UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_b_fe_db = UMTS_DAT_CAT_B_DATABASE_SetDefault;
+            #endif
+               kal_mem_cpy(buffer, &UMTS_DAT_FE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+            }
+            break;
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+       case NVRAM_EF_UL1_DAT_CAT_A_MIPI_EVENT_LID:
+            {
+               static ul1mipi_datEvent_CatA_T ul1_rf_mipi_dat_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catA_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], ul1d_rf_dat_mipiData_ptr->catA_eventTable_p[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], UMTS_DAT_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_CAT_A_MIPI_DATA_LID:
+            {
+               static ul1mipi_datData_CatA_T ul1_rf_mipi_dat_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catA_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], ul1d_rf_dat_mipiData_ptr->catA_dataTable_p[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], UMTS_DAT_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_CAT_B_MIPI_EVENT_LID:
+            {
+               static ul1mipi_datEvent_CatB_T ul1_rf_mipi_dat_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catB_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], ul1d_rf_dat_mipiData_ptr->catB_eventTable_p[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], UMTS_DAT_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_CAT_B_MIPI_DATA_LID:
+            {
+               static ul1mipi_datData_CatB_T ul1_rf_mipi_dat_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catB_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], ul1d_rf_dat_mipiData_ptr->catB_dataTable_p[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], UMTS_DAT_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatB_T));
+            }
+            break;
+#endif
+#endif
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+       case NVRAM_EF_UL1_TAS_FEATURE_BY_RAT_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, &ul1d_rf_tas_byRat_ptr->tas_feature_byRat, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_TAS_FEATURE_BY_RAT_SetDefault, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_FE_ROUTE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_tas_route_ptr->tas_fe_route, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_TAS_FE_ROUTE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_FE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_a_fe_db, ul1d_rf_tas_db_ptr->tas_cat_a_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_A_T));
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_b_fe_db, ul1d_rf_tas_db_ptr->tas_cat_b_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_B_T));
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_c_fe_db, ul1d_rf_tas_db_ptr->tas_cat_c_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_C_T));
+            #else
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_a_fe_db = UMTS_TAS_CAT_A_DATABASE_SetDefault;
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_b_fe_db = UMTS_TAS_CAT_B_DATABASE_SetDefault;
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_c_fe_db = UMTS_TAS_CAT_C_DATABASE_SetDefault;
+            #endif
+               kal_mem_cpy(buffer, &UMTS_TAS_FE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+            }
+            break;
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+       case NVRAM_EF_UL1_TAS_CAT_A_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatA_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catA_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catA_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_A_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatA_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catA_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catA_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_B_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatB_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catB_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catB_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_B_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatB_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catB_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catB_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_C_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatC_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_C_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catC_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catC_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatC_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_C_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatC_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_C_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catC_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catC_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_C_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_C_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatC_T));
+            }
+            break;
+#endif
+#if IS_3G_TAS_INHERIT_4G_ANT
+       case NVRAM_EF_UL1_TAS_INHERIT_LTE_ANT_LID:
+            {
+               UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T ul1d_rf_tas_inherit_lte_ant_buffer;
+               
+               for(index_select=0; index_select<UMTS_TAS_MAX_FE_ROUTE_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  ul1d_rf_tas_inherit_lte_transform_bitmap(ul1d_rf_tas_inherit_lte_ant_ptr->inheritLteAntTable_p[index_select], &(ul1d_rf_tas_inherit_lte_ant_buffer.inherit_lte_band_bitmap_route[index_select]));
+               #else
+                  ul1d_rf_tas_inherit_lte_transform_bitmap(UMTS_TAS_INHERIT_LTE_ANT_TABLE_SetDefault[index_select], &(ul1d_rf_tas_inherit_lte_ant_buffer.inherit_lte_band_bitmap_route[index_select]));
+               #endif
+               }
+               kal_mem_cpy(buffer, &ul1d_rf_tas_inherit_lte_ant_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+            }
+            break;
+#endif
+#endif
+      case NVRAM_EF_UL1_DPD_PARAMETER_LID:
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               static U_sUl1dDpdCustomInputData ul1_rf_dpd_parameter_buffer;            
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_noncustom_para, &UMTS_DPD_CUSTOM_INPUT_DATA_PCORE.pcfe_dpdotfc_noncustom_para, sizeof(U_Ul1D_PCFE_DPD_OTFC_NONCUSTOM_PARA_T));  
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_custom_para   , ul1d_rf_dpd_data_ptr->DpdPcfeCustomData_p                    , sizeof(U_UL1D_PCFE_DPD_OTFC_CUSTOM_PARA_T));
+            #else
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_noncustom_para, &UMTS_DPD_CUSTOM_INPUT_DATA_PCORE.pcfe_dpdotfc_noncustom_para, sizeof(U_Ul1D_PCFE_DPD_OTFC_NONCUSTOM_PARA_T));  
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_custom_para   , &ul1d_pcfe_dpd_otfc_custom_para_SetDefault                   , sizeof(U_UL1D_PCFE_DPD_OTFC_CUSTOM_PARA_T));
+            #endif
+               kal_mem_cpy(buffer, &ul1_rf_dpd_parameter_buffer, sizeof(U_sUl1dDpdCustomInputData));  
+            #endif
+            }
+            break;
+
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_HIGHBAND1_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_HIGHBAND2_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_HIGHBAND3_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_LOWBAND1_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CTRL_DATA_START);
+               
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_dpd_data_ptr->DpdCtrlData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_dpd_data_ptr->DpdCtrlData_p[index_select], sizeof(U_sDPD_COMMON_CTRL));
+               }
+            #else
+               if (UMTS_DPD_CommonCtrlData_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_DPD_CommonCtrlData_SetDefault[index_select], sizeof(U_sDPD_COMMON_CTRL));
+               }
+            #endif
+            #endif
+            }
+            break;
+      case NVRAM_EF_UL1_DPD_CAL_DATA_HIGHBAND1_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_HIGHBAND2_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_HIGHBAND3_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_LOWBAND1_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               static U_sDPD_GROUP_CAL ul1_rf_dpd_cal_data_buffer;
+               static kal_uint8        rf_bandind;
+               
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CAL_DATA_START);
+               
+               rf_bandind = nvram_init_uL1_dpd_band_mapping_rf_bandind(index_select);
+               
+               if (UMTS_RampData_SetDefault[index_select] != 0)
+               {              
+                  kal_mem_cpy(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_ramp_data, UMTS_RampData_SetDefault[rf_bandind], sizeof(U_sRAMPDATA));
+               }               
+               if (U_PA_OCTLEV_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_pa_oct_lev_tbl, U_PA_OCTLEV_TABLE_SetDefault[rf_bandind], sizeof(U_sPAOCTLVLSETTING));
+               }             
+               kal_mem_set(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_common_cal    , 0, sizeof(U_sDPD_COMMON_CAL));               
+               kal_mem_set(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_am_lut_perband, 0, sizeof(U_sDPD_AMLUT_PERBAND));               
+               kal_mem_set(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_pm_lut_perband, 0, sizeof(U_sDPD_PMLUT_PERBAND));
+               
+               kal_mem_cpy(buffer, &ul1_rf_dpd_cal_data_buffer, sizeof(U_sDPD_GROUP_CAL));
+            #endif
+            }
+            break;         
+#if (IS_3G_MIPI_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_DPD_TPC_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_dpd_data_ptr->DpdTpcTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_dpd_data_ptr->DpdTpcTable_p[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #else
+               if (UMTS_MIPI_DPD_TPC_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_DPD_TPC_TABLE_SetDefault[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #endif
+            #endif
+            }
+            break;
+#endif            
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->txEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->txEventTable_p[index_select], sizeof(ul1mipiEtm_txEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_txEvent_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_DATA_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->txDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->txDataTable_p[index_select], sizeof(ul1mipiEtm_txData_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_txData_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->tpcEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->tpcEventTable_p[index_select], sizeof(ul1mipiEtm_tpcEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TPC_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TPC_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_tpcEvent_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_HIGHBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_HIGHBAND2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_HIGHBAND3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_LOWBAND1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_LOWBAND2_LID:
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->tpcDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->tpcDataTable_p[index_select], sizeof(ul1mipiEtm_tpcData_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TPC_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TPC_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_tpcData_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;            
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+         /* RFEQ Coefficient table 1 */
+         case NVRAM_EF_UL1_RFEQ_COEF_HIGHBAND1_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_HIGHBAND2_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_HIGHBAND3_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_LOWBAND1_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_COEF_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_rfeqCoefData_ptr->rfeqCoef_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_rfeqCoefData_ptr->rfeqCoef_p[index_select], sizeof(hs_dsch_rfeq_info_band_T));
+               }
+            #else
+               if (UMTS_RFEQ_COEF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RFEQ_COEF_TABLE_SetDefault[index_select], sizeof(hs_dsch_rfeq_info_band_T));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RFEQ_COEF_SUBBAND_SUPPORT */
+#if (IS_3G_RFEQ_REAL_COEF_TEST)
+         /* RFEQ Coefficient table 1 */
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_HIGHBAND1_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_HIGHBAND2_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_HIGHBAND3_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_LOWBAND1_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_LOWBAND2_LID:
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_REAL_COEF_HIGHBAND1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_realRfeqCoefData_ptr->realRfeqCoef_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_realRfeqCoefData_ptr->realRfeqCoef_p[index_select], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+               }
+            #else
+               if (UMTS_RFEQ_COEF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RFEQ_REAL_COEF_TABLE_SetDefault[index_select], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RFEQ_COEF_SUBBAND_SUPPORT */
+
+        default:
+            ASSERT(KAL_FALSE);
+            break;
+    }
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+
+
+#endif /* __UMTS_RAT__ && __MTK_UL1_FDD__ */
diff --git a/mcu/service/nvram/src/nvram_ul1def_md95.c b/mcu/service/nvram/src/nvram_ul1def_md95.c
new file mode 100644
index 0000000..4671650
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ul1def_md95.c
@@ -0,0 +1,3451 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2007
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ul1def.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *    This file provides a fuction for NVRAM Task to get UL1 default value
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+  *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_enums.h"
+
+#if defined(__UMTS_RAT__) && defined(__MTK_UL1_FDD__)
+
+#ifdef __MTK_TARGET__
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+#if defined (__UL1_PLATFORM__)
+#include "common_nvram_editor_data_item.h"
+#include "ul1d_rf_public.h"
+#endif
+
+#include "nvram_interface.h"
+#include "hal_ul1_def.h"
+
+// Fix NVRAM RHR activity side-effect
+#include "nvram_editor_data_item.h"
+#include "ul1_nvram_editor.h"  // LID struct definition
+
+
+/* UL1 calibration data defination */
+#include "ul1d_rf_public.h"
+#include "ul1d_mipi_public.h"
+#include "ul1cal.h"
+#include "l1cal.h"
+
+#include "nvram_data_items.h"
+#include "nvram_main.h"
+
+#include "ul1_nvram_def.h"
+#include "ul1d_rf_cid.h"
+
+#include "wcustomdata.h"
+#include "mml1_dpd_def.h"
+
+#if __IS_UL1D_ETM_SUPPORT__
+#include "ul1d_custom_mipi_etm.h"
+#endif   // #if __IS_UL1D_ETM_SUPPORT_
+
+#include "event_info_utility.h"  //MODEM_WARNING_MESSAGE
+
+#define UNUSED(x)                      (void)x
+
+#define countof(x)                  ((sizeof(x))/(sizeof(*x)))
+
+#define UL1_NVRAM_WARNING( st )                      MODEM_WARNING_MESSAGE( st )
+#define UL1_NVRAM_DEBUG_ASSERT( st )                 DEBUG_ASSERT( st )
+#define UL1_NVRAM_WARNING_AND_DEBUG_ASSERT( st )     UL1_NVRAM_WARNING( st );   \
+                                                     UL1_NVRAM_DEBUG_ASSERT( st );
+
+
+
+//extern kal_uint8 UL1D_RF_CalDataGetBand(UMTSBand rf_band_in_question, kal_bool nvram_init);
+
+void nvram_init_uL1_AfcData(void)
+{
+   kal_bool error_no;
+   extern kal_int16 afc_dac_default;
+   extern kal_uint32 afc_inv_slope;
+
+   l1cal_afcData_T *afc = (l1cal_afcData_T *)get_ctrl_buffer( sizeof( l1cal_afcData_T ) );
+
+   /* Get RF customization data from NVRAM (customer's input) */
+   error_no = nvram_external_read_data(NVRAM_EF_L1_AFCDATA_LID, 1, (kal_uint8 *)afc, NVRAM_EF_L1_AFCDATA_SIZE);
+
+   #if IS_3G_MML1_AFC_TADC_SUPPORT
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_AFCDAC_LID, 1, (kal_uint8 *)afc, NVRAM_EF_UL1_AFCDAC_SIZE);
+   #endif
+
+   ASSERT(error_no == KAL_TRUE);
+   afc_dac_default = afc->dacValue;
+   afc_inv_slope = afc->slopeInv;
+   free_ctrl_buffer( afc );
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_send_uL1_cal
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_send_uL1_cal(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+   /**
+    *    file_idx should be the first L1 element in the logical data item ID enum
+    *    Currently, L1 calibration data element is as following:
+    *    NVRAM_EF_L1_AGCPATHLOSS_LID, NVRAM_EF_L1_RAMPTABLE_GSM900_LID,
+    *    NVRAM_EF_L1_RAMPTABLE_DCS1800_LID, NVRAM_EF_L1_RAMPTABLE_PCS1900_LID, 
+    *    NVRAM_EF_L1_AFCDATA_LID, VRAM_EF_L1_L1SPFC_LID, 
+    */
+
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    peer_buff_struct *peer_buf_ptr;
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_length;
+    nvram_read_req_struct *local_data;
+
+    /* Move the calling to nvram_init_uL1_rfCustomizationData() to nvram_special_service() */
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+
+    for (file_idx = NVRAM_EF_UL1_START; file_idx <= NVRAM_EF_UL1_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TEMP_DAC_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND1_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND2_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND3_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND4_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND5_LID:
+            //case NVRAM_EF_UL1_PATHLOSS_BAND6_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND7_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND8_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND9_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND10_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND11_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND19_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND1_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND2_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND3_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND4_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND5_LID:
+            //case NVRAM_EF_UL1_TXDAC_BAND6_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND7_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND8_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND9_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND10_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND11_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    /* PA 8-level contrl */
+    for (file_idx = NVRAM_EF_UL1_TXPAOCTLEV_START; file_idx <= NVRAM_EF_UL1_TXPAOCTLEV_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND2_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND3_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND4_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND5_LID:
+            //case NVRAM_EF_UL1_TXPAOCTLEV_BAND6_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND7_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND8_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND9_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND10_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND11_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+    /* End of PA 8-level contrl */
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+#if defined(__UMTS_R8__) //Jay
+    for (file_idx = NVRAM_EF_UL1_PATHLOSS2_START; file_idx <= NVRAM_EF_UL1_PATHLOSS2_END; file_idx++)
+    {
+       if (!NVRAM_IS_LID_VALID(file_idx))
+       {
+          continue;
+       }
+        
+       switch(file_idx)
+       {
+          case NVRAM_EF_UL1_PATHLOSS2_BAND1_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND2_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND3_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND4_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND5_LID:
+          //case NVRAM_EF_UL1_PATHLOSS2_BAND6_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND7_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND8_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND9_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND10_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND11_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND19_LID:
+          {
+              nvram_util_get_data_item(&ldi, file_idx);
+
+              local_data->access_id = 0;
+              local_data->file_idx = file_idx;
+              local_data->para = 1;
+          
+              pdu_length = ldi->size;
+              peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+              ASSERT(peer_buf_ptr != NULL);
+          
+              pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+              ASSERT(pdu_ptr != NULL);
+          
+          #ifdef __MULTI_BOOT__
+              if (FACTORY_BOOT == kal_query_boot_mode())
+              {        
+                  nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              else
+          #endif /* __MULTI_BOOT__ */
+              {
+                  nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              break;
+          }         
+       }
+    }
+
+    // add by wilson for PA drift compensation
+
+    for (file_idx = NVRAM_EF_UL1_TXPADRIFTCOMP_START; file_idx <= NVRAM_EF_UL1_TXPADRIFTCOMP_END; file_idx++)
+    {
+       if (!NVRAM_IS_LID_VALID(file_idx))
+       {
+          continue;
+       }
+        
+       switch(file_idx)
+       {
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND2_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND3_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND4_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND5_LID:
+          //case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND6_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND7_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND8_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND9_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND10_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND11_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND19_LID:
+          {
+              nvram_util_get_data_item(&ldi, file_idx);
+
+              local_data->access_id = 0;
+              local_data->file_idx = file_idx;
+              local_data->para = 1;
+          
+              pdu_length = ldi->size;
+              peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+              ASSERT(peer_buf_ptr != NULL);
+          
+              pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+              ASSERT(pdu_ptr != NULL);
+          
+          #ifdef __MULTI_BOOT__
+              if (FACTORY_BOOT == kal_query_boot_mode())
+              {        
+                  nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              else
+          #endif /* __MULTI_BOOT__ */
+              {
+                  nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              break;
+          }         
+       }
+    }
+#endif
+
+    /** Tx PRACH TM Compensation */
+    for (file_idx = NVRAM_EF_UL1_TXPRACHTMCOMP_START; file_idx <= NVRAM_EF_UL1_TXPRACHTMCOMP_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND2_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND3_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND4_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND5_LID:
+            //case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND6_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND7_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND8_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND9_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND10_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND11_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+
+    /** AFCDAC */
+    for (file_idx = NVRAM_EF_UL1_AFCDAC_START; file_idx <= NVRAM_EF_UL1_AFCDAC_END; file_idx++)
+    {
+            if (!NVRAM_IS_LID_VALID(file_idx))
+            {
+                continue;
+            }
+
+            switch(file_idx)
+            {
+                case NVRAM_EF_UL1_AFCDAC_LID:
+                {
+                    nvram_util_get_data_item(&ldi, file_idx);
+
+                    local_data->access_id = 0;
+                    local_data->file_idx = file_idx;
+                    local_data->para = 1;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    ASSERT(peer_buf_ptr != NULL);
+
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    ASSERT(pdu_ptr != NULL);
+
+            #ifdef __MULTI_BOOT__
+                    if (FACTORY_BOOT == kal_query_boot_mode())
+                    {
+                        nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    else
+            #endif /* __MULTI_BOOT__ */
+                    {
+                        nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    break;
+             }
+        }
+    }
+
+    /** AFCCAP */
+    for (file_idx = NVRAM_EF_UL1_AFCCAP_START; file_idx <= NVRAM_EF_UL1_AFCCAP_END; file_idx++)
+    {
+            if (!NVRAM_IS_LID_VALID(file_idx))
+            {
+                continue;
+            }
+
+            switch(file_idx)
+            {
+                case NVRAM_EF_UL1_AFCCAP_LID:
+                {
+                    nvram_util_get_data_item(&ldi, file_idx);
+
+                    local_data->access_id = 0;
+                    local_data->file_idx = file_idx;
+                    local_data->para = 1;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    ASSERT(peer_buf_ptr != NULL);
+
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    ASSERT(pdu_ptr != NULL);
+
+             #ifdef __MULTI_BOOT__
+                    if (FACTORY_BOOT == kal_query_boot_mode())
+                    {
+                        nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    else
+             #endif /* __MULTI_BOOT__ */
+                    {
+                        nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    break;
+             }
+        }
+    }
+
+    /** Tx Power Offset */
+    for (file_idx = NVRAM_EF_UL1_TXPOWEROFFSET_START; file_idx <= NVRAM_EF_UL1_TXPOWEROFFSET_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            /* Tx power offset table */
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND1_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND2_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND3_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND4_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND5_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND6_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND7_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND8_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND9_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND10_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND11_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+#ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+#endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+    free_local_para((local_para_struct*) local_data);
+
+}   /* end of nvram_send_L1_cal function */
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+void nvram_init_uL1_mipiTxData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;
+   ul1mipi_txData_T *ul1_rf_mipi_tx_data_buffer = (ul1mipi_txData_T *)get_ctrl_buffer(sizeof(ul1mipi_txData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_TX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_TX_DATA_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipi_txData_T));
+
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_DATA_START);
+
+       UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+       if(error_no)
+       {
+          kal_mem_cpy(UMTS_MIPI_TX_DATA_PCORE_TABLE[tableIdx], ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipi_txData_T));
+       }
+       else
+       {
+          if(isWcdmaDrdiEnable)
+          {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+          kal_mem_cpy(UMTS_MIPI_TX_DATA_PCORE_TABLE[tableIdx], ul1CustomMipiData[setIdx].txDataTable_p[tableIdx], sizeof(ul1mipi_txData_T));
+       }
+
+   }
+   free_ctrl_buffer(ul1_rf_mipi_tx_data_buffer);
+
+}
+
+void nvram_init_uL1_mipiTxEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   ul1mipi_txEvent_T *ul1_rf_mipi_tx_event_buffer = (ul1mipi_txEvent_T *)get_ctrl_buffer(sizeof(ul1mipi_txEvent_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_TX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_TX_EVENT_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipi_txEvent_T));
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_EVENT_START);
+
+       UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+       if(error_no)
+       {
+          kal_mem_cpy(UMTS_MIPI_TX_EVENT_PCORE_TABLE[tableIdx], ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipi_txEvent_T));
+       }
+       else
+       {
+          if(isWcdmaDrdiEnable)
+          {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+          kal_mem_cpy(UMTS_MIPI_TX_EVENT_PCORE_TABLE[tableIdx], ul1CustomMipiData[setIdx].txEventTable_p[tableIdx], sizeof(ul1mipi_txEvent_T));
+       }
+
+   }
+   free_ctrl_buffer(ul1_rf_mipi_tx_event_buffer);
+
+}
+
+void nvram_init_uL1_mipiRxData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;         
+   ul1mipi_rxData_T *ul1_rf_mipi_rx_data_buffer = (ul1mipi_rxData_T *)get_ctrl_buffer(sizeof(ul1mipi_rxData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_RX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_RX_DATA_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_rx_data_buffer, sizeof(ul1mipi_rxData_T));
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_DATA_START);
+
+       UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+       if(error_no)
+       {
+          kal_mem_cpy(UMTS_MIPI_RX_DATA_PCORE_TABLE[tableIdx], ul1_rf_mipi_rx_data_buffer, sizeof(ul1mipi_rxData_T));
+       }
+       else
+       {
+          if(isWcdmaDrdiEnable)
+          {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+          kal_mem_cpy(UMTS_MIPI_RX_DATA_PCORE_TABLE[tableIdx], ul1CustomMipiData[setIdx].rxDataTable_p[tableIdx], sizeof(ul1mipi_rxData_T));
+       }
+
+   }
+   free_ctrl_buffer(ul1_rf_mipi_rx_data_buffer);
+
+}
+
+void nvram_init_uL1_mipiRxEvent(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   ul1mipi_rxEvent_T *ul1_rf_mipi_rx_event_buffer = (ul1mipi_rxEvent_T *)get_ctrl_buffer(sizeof(ul1mipi_rxEvent_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_RX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_RX_EVENT_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_rx_event_buffer, sizeof(ul1mipi_rxEvent_T));
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_EVENT_START);
+
+       UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+       if(error_no)
+       {
+          kal_mem_cpy(UMTS_MIPI_RX_EVENT_PCORE_TABLE[tableIdx], ul1_rf_mipi_rx_event_buffer, sizeof(ul1mipi_rxEvent_T));
+       }
+       else
+       {
+          if(isWcdmaDrdiEnable)
+          {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+          kal_mem_cpy(UMTS_MIPI_RX_EVENT_PCORE_TABLE[tableIdx], ul1CustomMipiData[setIdx].rxEventTable_p[tableIdx], sizeof(ul1mipi_rxEvent_T));
+       }
+
+   }
+   free_ctrl_buffer(ul1_rf_mipi_rx_event_buffer);
+
+}
+
+void nvram_init_uL1_mipiAsmIso(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   ul1mipi_asmIsoData_T *ul1_rf_mipi_asm_iso_buffer = (ul1mipi_asmIsoData_T *)get_ctrl_buffer(sizeof(ul1mipi_asmIsoData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_ASM_ISOLATION_START; lid <= NVRAM_EF_UL1_MIPI_ASM_ISOLATION_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_asm_iso_buffer, sizeof(ul1mipi_asmIsoData_T));
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ASM_ISOLATION_START);
+
+       UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+       if(error_no)
+       {
+          kal_mem_cpy(UMTS_MIPI_ASM_ISOLATION_DATA_PCORE_TABLE[tableIdx], ul1_rf_mipi_asm_iso_buffer, sizeof(ul1mipi_asmIsoData_T));
+       }
+       else
+       {
+          if(isWcdmaDrdiEnable)
+          {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+          kal_mem_cpy(UMTS_MIPI_ASM_ISOLATION_DATA_PCORE_TABLE[tableIdx], ul1CustomMipiData[setIdx].asmIsoTable_p[tableIdx], sizeof(ul1mipi_asmIsoData_T));
+       }
+
+   }
+   free_ctrl_buffer(ul1_rf_mipi_asm_iso_buffer);
+
+}
+
+void nvram_init_uL1_mipiInitCw(void)
+{
+   kal_bool error_no;
+
+   ul1mipi_initCwData_T *ul1_rf_mipi_init_buffer = (ul1mipi_initCwData_T *)get_ctrl_buffer(sizeof(ul1mipi_initCwData_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_MIPI_INIT_CW_LID, 1, (kal_uint8 *)ul1_rf_mipi_init_buffer, sizeof(ul1mipi_initCwData_T));
+   
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_MIPI_INITIAL_CW_PCORE_ptr, ul1_rf_mipi_init_buffer, sizeof(ul1mipi_initCwData_T));
+   }
+   else
+   {
+      kal_mem_set(UMTS_MIPI_INITIAL_CW_PCORE_ptr, 0, sizeof(ul1mipi_initCwData_T));
+   }
+
+   free_ctrl_buffer(ul1_rf_mipi_init_buffer);
+}
+
+void nvram_init_uL1_mipiSleepCw(void)
+{
+   kal_bool error_no;
+      
+   ul1mipi_sleepCwData_T *ul1_rf_mipi_sleep_buffer = (ul1mipi_sleepCwData_T *)get_ctrl_buffer(sizeof(ul1mipi_sleepCwData_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_MIPI_SLEEP_CW_LID, 1, (kal_uint8 *)ul1_rf_mipi_sleep_buffer, sizeof(ul1mipi_sleepCwData_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_MIPI_SLEEP_CW_PCORE_ptr, ul1_rf_mipi_sleep_buffer, sizeof(ul1mipi_sleepCwData_T));
+   }
+   else
+   {
+      kal_mem_set(UMTS_MIPI_SLEEP_CW_PCORE_ptr, 0, sizeof(ul1mipi_sleepCwData_T));
+   }
+
+   free_ctrl_buffer(ul1_rf_mipi_sleep_buffer);
+}
+
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   ul1mipi_tpcData_T *ul1_rf_mipi_data_buffer = (ul1mipi_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipi_tpcData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_TPC_START; lid <= NVRAM_EF_UL1_MIPI_TPC_END; lid++)
+   {
+       error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_data_buffer, sizeof(ul1mipi_tpcData_T));
+       tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TPC_START);
+
+       UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+       if(error_no)
+       {
+          kal_mem_cpy(UMTS_MIPI_TPC_PCORE_TABLE[tableIdx], ul1_rf_mipi_data_buffer, sizeof(ul1mipi_tpcData_T));
+       }
+       else
+       {
+          if(isWcdmaDrdiEnable)
+          {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+          kal_mem_cpy(UMTS_MIPI_TPC_PCORE_TABLE[tableIdx], ul1CustomMipiData[setIdx].tpcTable_p[tableIdx], sizeof(ul1mipi_tpcData_T));
+       }
+
+   }
+   free_ctrl_buffer(ul1_rf_mipi_data_buffer);
+    
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+   nvram_init_uL1_mipiTxData();
+   nvram_init_uL1_mipiTxEvent();
+   nvram_init_uL1_mipiRxData();
+   nvram_init_uL1_mipiRxEvent();
+   nvram_init_uL1_mipiAsmIso();
+   nvram_init_uL1_mipiInitCw();
+   nvram_init_uL1_mipiSleepCw();
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+
+}
+#endif
+
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+void nvram_init_uL1_datFeatureByRat(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T *ul1_dat_feature_by_rat_buffer = (UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FEATURE_BY_RAT_LID, 1, (kal_uint8 *)ul1_dat_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_DAT_FEATURE_BY_RAT_PCORE_ptr, ul1_dat_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_DAT_FEATURE_BY_RAT_PCORE_ptr, &(ul1CustomDatByRat[setIdx].dat_feature_byRat), sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+   }
+   
+   free_ctrl_buffer(ul1_dat_feature_by_rat_buffer);
+}
+
+void nvram_init_uL1_datFeatureByRoute(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T *ul1_dat_fe_route_db_buffer = (UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FE_ROUTE_DATABASE_LID, 1, (kal_uint8 *)ul1_dat_fe_route_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_DAT_FE_ROUTE_DATABASE_PCORE_ptr, ul1_dat_fe_route_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_DAT_FE_ROUTE_DATABASE_PCORE_ptr, ul1CustomDatRoute[setIdx].dat_fe_route, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+   }
+   
+   free_ctrl_buffer(ul1_dat_fe_route_db_buffer);
+}
+
+void nvram_init_uL1_datFeDb(void)
+{
+#if !IS_3G_UDAT_SUPPORT
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_DAT_FE_DATABASE_T *ul1_dat_fe_db_buffer = (UMTS_CUSTOM_DAT_FE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FE_DATABASE_LID, 1, (kal_uint8 *)ul1_dat_fe_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_DAT_FE_DATABASE_PCORE_ptr, ul1_dat_fe_db_buffer, sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+   free_ctrl_buffer(ul1_dat_fe_db_buffer);
+#endif
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiDatAEvent(void)
+{
+#if !IS_3G_UDAT_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_A_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_datEvent_CatA_T *ul1_rf_mipi_dat_event_buffer = (ul1mipi_datEvent_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_datEvent_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_DAT_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_A_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_event_buffer->mipiDatEventRoute[tableIdx]), sizeof(ul1mipi_datEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiDatAData(void)
+{
+#if !IS_3G_UDAT_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_A_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_datData_CatA_T *ul1_rf_mipi_dat_data_buffer = (ul1mipi_datData_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_datData_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_DAT_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_A_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_data_buffer->mipiDatDataRoute[tableIdx]), sizeof(ul1mipi_datSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_data_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiDatBEvent(void)
+{
+#if !IS_3G_UDAT_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_B_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_datEvent_CatB_T *ul1_rf_mipi_dat_event_buffer = (ul1mipi_datEvent_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_datEvent_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_DAT_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_B_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_event_buffer->mipiDatEventRoute[tableIdx]), sizeof(ul1mipi_datEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiDatBData(void)
+{
+#if !IS_3G_UDAT_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_DAT_CAT_B_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_datData_CatB_T *ul1_rf_mipi_dat_data_buffer = (ul1mipi_datData_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_datData_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_DAT_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_DAT_CAT_B_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_dat_data_buffer->mipiDatDataRoute[tableIdx]), sizeof(ul1mipi_datSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_dat_data_buffer);
+#endif
+}
+#endif
+#endif
+
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+void nvram_init_uL1_tasFeatureByRat(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T *ul1_tas_feature_by_rat_buffer = (UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FEATURE_BY_RAT_LID, 1, (kal_uint8 *)ul1_tas_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TAS_FEATURE_BY_RAT_PCORE_ptr, ul1_tas_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_TAS_FEATURE_BY_RAT_PCORE_ptr, &(ul1CustomTasByRat[setIdx].tas_feature_byRat), sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+   }
+   
+   free_ctrl_buffer(ul1_tas_feature_by_rat_buffer);
+}
+
+void nvram_init_uL1_tasFeatureByRoute(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T *ul1_tas_fe_route_db_buffer = (UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FE_ROUTE_DATABASE_LID, 1, (kal_uint8 *)ul1_tas_fe_route_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TAS_FE_ROUTE_DATABASE_PCORE_ptr, ul1_tas_fe_route_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_TAS_FE_ROUTE_DATABASE_PCORE_ptr, ul1CustomTasRoute[setIdx].tas_fe_route, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+   }
+   
+   free_ctrl_buffer(ul1_tas_fe_route_db_buffer);
+}
+
+void nvram_init_uL1_tasFeDb(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_TAS_FE_DATABASE_T *ul1_tas_fe_db_buffer = (UMTS_CUSTOM_TAS_FE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FE_DATABASE_LID, 1, (kal_uint8 *)ul1_tas_fe_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_TAS_FE_DATABASE_PCORE_ptr, ul1_tas_fe_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+   free_ctrl_buffer(ul1_tas_fe_db_buffer);
+#endif
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiTasAEvent(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_A_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatA_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasAData(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_A_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatA_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_A_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasBEvent(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_B_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatB_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasBData(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_B_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatB_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_B_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasCEvent(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_C_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatC_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatC_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatC_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatC_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_C_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasCData(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_C_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatC_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatC_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatC_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatC_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_C_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_C_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+#endif
+}
+#endif
+
+#if IS_3G_TAS_INHERIT_4G_ANT
+void nvram_init_uL1_tasInheritLteAnt(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   kal_uint32 index_select = 0;
+   UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T *ul1_tas_inherit_lte_bnad_buffer = (UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_INHERIT_LTE_ANT_LID, 1, (kal_uint8 *)ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_PCORE_ptr, ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+
+      for(index_select=0; index_select<UMTS_TAS_MAX_FE_ROUTE_NUM; index_select++)
+      {
+         ul1d_rf_tas_inherit_lte_transform_bitmap(ul1CustomTasInheritLteAnt[setIdx].inheritLteAntTable_p[index_select], &(ul1_tas_inherit_lte_bnad_buffer->inherit_lte_band_bitmap_route[index_select]));
+      }
+
+      kal_mem_cpy(UMTS_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_PCORE_ptr, ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+   }
+   
+   free_ctrl_buffer(ul1_tas_inherit_lte_bnad_buffer);
+}
+#endif
+#endif
+
+#if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+void nvram_init_uL1_TpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   U_sTXPOWEROFFSETDATA *ul1_tpo_data_buffer = (U_sTXPOWEROFFSETDATA *) get_ctrl_buffer(sizeof(U_sTXPOWEROFFSETDATA));
+
+   for(lid = NVRAM_EF_UL1_TXPOWEROFFSET_START; lid<= NVRAM_EF_UL1_TXPOWEROFFSET_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_tpo_data_buffer, sizeof(U_sTXPOWEROFFSETDATA));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPOWEROFFSET_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_TX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1_tpo_data_buffer, sizeof(U_sTXPOWEROFFSETDATA));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_TX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1CustomTpoData[setIdx].TpoData_p[tableIdx], sizeof(U_sTXPOWEROFFSETDATA));
+      }
+
+   }
+   free_ctrl_buffer(ul1_tpo_data_buffer);
+}
+#endif
+
+#if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+void nvram_init_uL1_nsftTpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TXNSFTPOWEROFFSET_LID;
+   kal_uint16 setIdx = 0;   
+   U_sTXNSFTPOWEROFFSETDATA_ALLBAND *ul1_nsfttpo_data_buffer = (U_sTXNSFTPOWEROFFSETDATA_ALLBAND *) get_ctrl_buffer(sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_nsfttpo_data_buffer, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TX_NSFT_POWER_OFFSET_PCORE_ptr, ul1_nsfttpo_data_buffer, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_TX_NSFT_POWER_OFFSET_PCORE_ptr, ul1CustomNsftTpoData[setIdx].nsftTpoData_p, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+   }
+
+   free_ctrl_buffer(ul1_nsfttpo_data_buffer);
+}
+#endif
+
+#if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+void nvram_init_uL1_RpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   U_sRXPOWEROFFSETDATA *ul1_rpo_data_buffer = (U_sRXPOWEROFFSETDATA *) get_ctrl_buffer(sizeof(U_sRXPOWEROFFSETDATA));
+
+   for(lid = NVRAM_EF_UL1_RXPOWEROFFSET_START; lid<= NVRAM_EF_UL1_RXPOWEROFFSET_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rpo_data_buffer, sizeof(U_sRXPOWEROFFSETDATA));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RXPOWEROFFSET_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_RX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1_rpo_data_buffer, sizeof(U_sRXPOWEROFFSETDATA));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_RX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1CustomRpoData[setIdx].RpoData_p[tableIdx], sizeof(U_sRXPOWEROFFSETDATA));
+      }
+
+   }
+   free_ctrl_buffer(ul1_rpo_data_buffer);
+}
+#endif
+
+
+#if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+void nvram_init_uL1_vpaSrcSel(void)
+{
+  kal_bool error_no;
+  nvram_lid_enum lid;
+  kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+  ul1vpa_sel_T *ul1_rf_vpa_src_sel_buffer = (ul1vpa_sel_T *)get_ctrl_buffer(sizeof(ul1vpa_sel_T));
+
+  for (lid = NVRAM_EF_UL1_VPA_SRC_SEL_START; lid <= NVRAM_EF_UL1_VPA_SRC_SEL_END; lid++)
+  {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_vpa_src_sel_buffer, sizeof(ul1vpa_sel_T));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_VPA_SRC_SEL_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_VPA_SRC_SEL_PCORE_TABLE[tableIdx], ul1_rf_vpa_src_sel_buffer, sizeof(ul1vpa_sel_T));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_VPA_SRC_SEL_PCORE_TABLE[tableIdx], ul1CustomVpaSrcSelData[setIdx].vpaSrcSelTable_p[tableIdx], sizeof(ul1vpa_sel_T));
+      }
+  
+  }
+  free_ctrl_buffer(ul1_rf_vpa_src_sel_buffer);
+}
+#endif/*IS_3G_VPA_SEL_BY_BAND_SUPPORT*/
+
+kal_uint8 nvram_init_uL1_dpd_band_mapping_rf_bandind(kal_uint8 index_select)
+{
+   kal_uint8 dpd_bandind = 0;
+   kal_uint8 rf_bandind = 0;
+   
+   dpd_bandind = ul1d_BandInfo[index_select-UMTSBand1];
+
+   if(dpd_bandind == UMTSBandNone)
+   {
+      rf_bandind = 0;
+   }
+   else
+   {
+      rf_bandind = RF_GET_CAL_DATA_ARRAY_BAND_IDX((UMTSBand)dpd_bandind, KAL_FALSE);
+   }
+   
+   return(rf_bandind);
+}
+
+void nvram_init_uL1_dpdData(void)
+{
+
+#if __IS_UL1D_DPD_SUPPORT__
+
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+
+   void *ul1_dpd_data_buffer;
+
+   /*********** DPD custom input data **********/
+   #if IS_URF_PCORE
+   ul1_dpd_data_buffer = (U_sUl1dDpdCustomInputData *)get_ctrl_buffer(sizeof(U_sUl1dDpdCustomInputData));
+   
+   U_sUl1dDpdCustomInputData *temp_ptr = (U_sUl1dDpdCustomInputData *)ul1_dpd_data_buffer;
+   
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DPD_PARAMETER_LID, 1, (kal_uint8 *)ul1_dpd_data_buffer, NVRAM_EF_UL1_DPD_PARAMETER_SIZE);
+   ASSERT(error_no == KAL_TRUE);
+   kal_mem_cpy(UMTS_DPD_CUSTOM_INPUT_DATA_PCORE_ptr, (const void*) temp_ptr, sizeof(U_sUl1dDpdCustomInputData));         
+
+   free_ctrl_buffer( ul1_dpd_data_buffer );
+   #endif
+   
+   /*********** DPD CTRL DATA ***********/
+   ul1_dpd_data_buffer = (U_sDPD_COMMON_CTRL *) get_ctrl_buffer(sizeof(U_sDPD_COMMON_CTRL));
+
+   for(lid = NVRAM_EF_UL1_DPD_CTRL_DATA_START; lid<= NVRAM_EF_UL1_DPD_CTRL_DATA_END; lid++)
+   {
+      U_sDPD_COMMON_CTRL *temp_ptr = (U_sDPD_COMMON_CTRL *)ul1_dpd_data_buffer;
+
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_dpd_data_buffer, sizeof(U_sDPD_COMMON_CTRL));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CTRL_DATA_START);      
+      kal_mem_cpy(&(U_DPD_GROUP_PCORE_TABLE[tableIdx]->wcdma_dpd_common_ctrl), (const void*) temp_ptr, sizeof(U_sDPD_COMMON_CTRL));    
+   }
+   free_ctrl_buffer(ul1_dpd_data_buffer);
+   
+   /*********** DPD CAL DATA ***********/
+   ul1_dpd_data_buffer = (U_sDPD_GROUP_CAL *) get_ctrl_buffer(sizeof(U_sDPD_GROUP_CAL));
+
+   for(lid = NVRAM_EF_UL1_DPD_CAL_DATA_START; lid<= NVRAM_EF_UL1_DPD_CAL_DATA_END; lid++)
+   {
+      U_sDPD_GROUP_CAL *temp_ptr = (U_sDPD_GROUP_CAL *)ul1_dpd_data_buffer;
+   
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_dpd_data_buffer, sizeof(U_sDPD_GROUP_CAL));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CAL_DATA_START);
+      
+      kal_mem_cpy(&(U_DPD_GROUP_PCORE_TABLE[tableIdx]->wcdma_dpd_group_cal), (const void*)temp_ptr, sizeof(U_sDPD_GROUP_CAL));     
+      
+   }
+   free_ctrl_buffer(ul1_dpd_data_buffer);
+
+   /*********** DPD MIPI TPC DATA ***********/
+#if (IS_3G_MIPI_SUPPORT)   
+   ul1_dpd_data_buffer = (ul1mipi_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipi_tpcData_T));
+
+   for (lid = NVRAM_EF_UL1_MIPI_DPD_TPC_START; lid <= NVRAM_EF_UL1_MIPI_DPD_TPC_END; lid++)
+
+   {
+      ul1mipi_tpcData_T *temp_ptr = (ul1mipi_tpcData_T *)ul1_dpd_data_buffer;
+   
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_dpd_data_buffer, sizeof(ul1mipi_tpcData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_DPD_TPC_START);
+      kal_mem_cpy(UMTS_MIPI_DPD_TPC_PCORE_TABLE[tableIdx], (const void*) temp_ptr, sizeof(ul1mipi_tpcData_T));
+   }
+   free_ctrl_buffer(ul1_dpd_data_buffer);
+#endif
+
+   /* Update WCDMA DPD enable to SHM */
+   (*UMTS_DPD_ENABLE_PCORE_ptr) = UMTS_DPD_ENABLE_PCORE;
+
+#endif
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiEtmData(void)
+{
+#if __IS_UL1D_ETM_SUPPORT__
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   ul1mipiEtm_txEvent_T  *ul1_rf_mipi_tx_event_buffer;
+   ul1mipiEtm_txData_T   *ul1_rf_mipi_tx_data_buffer;
+   ul1mipiEtm_tpcEvent_T *ul1_rf_mipi_tpc_event_buffer;
+   ul1mipiEtm_tpcData_T  *ul1_rf_mipi_tpc_data_buffer;
+
+   ul1_rf_mipi_tx_event_buffer = (ul1mipiEtm_txEvent_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_txEvent_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipiEtm_txEvent_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TX_EVENT_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tx_event_buffer, sizeof( ul1mipiEtm_txEvent_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tx_event_buffer );
+
+   ul1_rf_mipi_tx_data_buffer = (ul1mipiEtm_txData_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_txData_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TX_DATA_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipiEtm_txData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_DATA_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TX_DATA_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tx_data_buffer, sizeof( ul1mipiEtm_txData_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tx_data_buffer );
+
+   ul1_rf_mipi_tpc_event_buffer = (ul1mipiEtm_tpcEvent_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_tpcEvent_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tpc_event_buffer, sizeof(ul1mipiEtm_tpcEvent_T));
+      ASSERT(error_no == KAL_TRUE);
+   
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TPC_EVENT_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tpc_event_buffer, sizeof( ul1mipiEtm_tpcEvent_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tpc_event_buffer );
+
+   ul1_rf_mipi_tpc_data_buffer = (ul1mipiEtm_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_tpcData_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tpc_data_buffer, sizeof(ul1mipiEtm_tpcData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TPC_DATA_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tpc_data_buffer, sizeof( ul1mipiEtm_tpcData_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tpc_data_buffer );
+
+#endif   // #if __IS_UL1D_ETM_SUPPORT__
+}
+#endif   // #if (IS_3G_MIPI_SUPPORT)
+
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+void nvram_init_uL1_rfeqCoefData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   hs_dsch_rfeq_info_band_T *ul1_rfeqCoef_data_buffer = (hs_dsch_rfeq_info_band_T *) get_ctrl_buffer(sizeof(hs_dsch_rfeq_info_band_T));
+
+   for(lid = NVRAM_EF_UL1_RFEQ_COEF_START; lid<= NVRAM_EF_UL1_RFEQ_COEF_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rfeqCoef_data_buffer, sizeof(hs_dsch_rfeq_info_band_T));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_COEF_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_RFEQ_COEF_PCORE_TABLE[tableIdx], ul1_rfeqCoef_data_buffer, sizeof(hs_dsch_rfeq_info_band_T));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_RFEQ_COEF_PCORE_TABLE[tableIdx], ul1CustomRfeqCoefData[setIdx].rfeqCoef_p[tableIdx], sizeof(hs_dsch_rfeq_info_band_T));
+      }
+
+   }
+   free_ctrl_buffer(ul1_rfeqCoef_data_buffer);
+}
+#endif
+
+#if (IS_3G_RFEQ_REAL_COEF_TEST)
+void nvram_init_uL1_rfeqRealCoefCustom(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   URXDFE_REAL_RFEQ_CUSTOM_BAND_T *ul1_rfeqRealCoef_data_buffer = (URXDFE_REAL_RFEQ_CUSTOM_BAND_T *) get_ctrl_buffer(sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+
+   for(lid = NVRAM_EF_UL1_RFEQ_REAL_COEF_START; lid<= NVRAM_EF_UL1_RFEQ_REAL_COEF_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rfeqRealCoef_data_buffer, sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_REAL_COEF_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_RFEQ_REAL_COEF_PCORE_TABLE[tableIdx], ul1_rfeqRealCoef_data_buffer, sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_RFEQ_REAL_COEF_PCORE_TABLE[tableIdx], ul1CustomRealRfeqCoefData[setIdx].realRfeqCoef_p[tableIdx], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      }
+
+   }
+   free_ctrl_buffer(ul1_rfeqRealCoef_data_buffer);
+}
+#endif
+
+#endif /* __MTK_TARGET__ */ 
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_L1_default_value_to_write
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  lid         [IN]        
+ *  buffer      [?]         
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#ifdef __MTK_TARGET__
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+   /********************************************************/
+   /* MT6573 3G RF Customization for Modem Bin Update Tool */
+   /********************************************************/
+const kal_uint16 UL_BAND_MIN_UARFCN[] = {0, 9612, 9262, 937, 1312, 4132, 4162, 2012, 2712, 8762, 2887, 3487, 3617, 3792, 3892, 0, 0, 0, 0, 312, 4287, 462, 4437};
+const kal_uint16 UL_BAND_MAX_UARFCN[] = {0, 9888, 9538, 1288, 1513, 4233, 4188, 2338, 2863, 8912, 3163, 3562, 3678, 3818, 3918, 0, 0, 0, 0, 363, 4413, 512, 4813};
+const kal_uint16 UL_BAND_MIN_UARFCN_ADDITIONAL[] = {0, 0, 12, 0, 1662, 782, 812, 2362, 0, 0, 3187, 0, 3707, 3842, 3942, 0, 0, 0, 0, 387, 0, 0, 0};
+const kal_uint16 UL_BAND_MAX_UARFCN_ADDITIONAL[] = {0, 0, 287, 0, 1862, 862, 837, 2687, 0, 0, 3462, 0, 3767, 3867, 3967, 0, 0, 0, 0, 437, 0, 0, 0};
+kal_uint8 band_to_bandInd_map_table[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+void nvram_sort_uL1_band_bandind_mapping(kal_uint8 band_indicator)
+{
+    kal_uint8 table_index;
+
+    if ( band_indicator > UMTSBandNone )
+    {
+       table_index = RF_GET_CAL_DATA_ARRAY_BAND_IDX((UMTSBand)band_indicator, KAL_FALSE);
+       band_to_bandInd_map_table[band_indicator] = table_index;
+    }
+}
+
+
+#endif /* #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__) */
+
+#endif /* __MTK_TARGET__ */
+
+#if (IS_3G_DRDI_SUPPORT)
+kal_bool ul1d_DRDI_had_done = KAL_FALSE;
+
+/****************************************************************************
+ * Custom Data Pointer Array Extern
+ ****************************************************************************/
+const Ul1CustomDynamicInitMipiData *ul1d_mipiData_array_ptr;
+#if __IS_UL1D_ETM_SUPPORT__
+const Ul1CustomDynamicInitMipiEtmData *ul1d_mipiEtmData_array_ptr;
+#endif   // #if __IS_UL1D_ETM_SUPPORT__
+const Ul1CustomDynamicInitUmtsFeSettingData *ul1d_RfFeRoute_array_ptr;
+const Ul1CustomDynamicInitUmtsCalData *ul1d_rf_calData_ptr;
+const Ul1CustomDynamicRfParameter *ul1d_rf_parameter_ptr;
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+const Ul1CustomDynamicDatRoute *ul1d_rf_dat_route_ptr;
+const Ul1CustomDynamicDatFeatureByRat *ul1d_rf_dat_byRat_ptr;
+#if !IS_3G_UDAT_SUPPORT
+const Ul1CustomDynamicDatDb *ul1d_rf_dat_db_ptr;
+#if (IS_3G_MIPI_SUPPORT)
+const Ul1CustomDynamicDatMipiData *ul1d_rf_dat_mipiData_ptr;
+#endif
+#endif
+#endif
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+const Ul1CustomDynamicTasRoute *ul1d_rf_tas_route_ptr;
+const Ul1CustomDynamicTasFeatureByRat *ul1d_rf_tas_byRat_ptr;
+#if !IS_3G_UTAS_SUPPORT
+const Ul1CustomDynamicTasDb *ul1d_rf_tas_db_ptr;
+#if (IS_3G_MIPI_SUPPORT)
+const Ul1CustomDynamicTasMipiData *ul1d_rf_tas_mipiData_ptr;
+#endif
+#endif
+#if IS_3G_TAS_INHERIT_4G_ANT
+const Ul1CustomDynamicTasInheritLteAnt *ul1d_rf_tas_inherit_lte_ant_ptr;
+#endif
+#endif
+#if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+const Ul1CustomDynamicTpoData *ul1d_rf_tpoData_ptr;
+#endif
+#if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+const Ul1CustomDynamicNsftTpoData *ul1d_rf_nsftTpoData_ptr;
+#endif
+#if(IS_3G_RX_POWER_OFFSET_SUPPORT)
+const Ul1CustomDynamicRpoData *ul1d_rf_rpoData_ptr;
+#endif
+#if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+const Ul1CustomDynamicVpaSrcSelData *ul1d_rf_VpaSrcSelData_ptr;
+#endif
+#if IS_3G_ELNA_SUPPORT
+const Ul1CustomDynamicElnaData *ul1d_rf_elnadata_ptr;
+#endif
+#if (__IS_UL1D_DPD_SUPPORT__)
+const Ul1CustomDynamicInitUmtsDpdfactoryData *ul1d_rf_dpd_data_ptr;
+#endif
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+const Ul1CustomDynamicRfeqCoefData *ul1d_rf_rfeqCoefData_ptr;
+#endif
+#if IS_3G_RFEQ_REAL_COEF_TEST
+const Ul1CustomDynamicRealRfeqCoefData *ul1d_rf_realRfeqCoefData_ptr;
+#endif
+#endif/*IS_3G_DRDI_SUPPORT*/
+
+
+void nvram_UL1D_DrdiPWRONCAL(kal_uint16 setIdx)
+{
+#ifdef __MTK_TARGET__
+#if (IS_3G_DRDI_SUPPORT)
+#if IS_3G_SUPPORT_8_BANDINDICATOR    
+   kal_uint8 loop;
+   for(loop=0;loop<MAX_SUPPORTED_BAND_INDEX;loop++)
+   {
+      UMTS_PWRON_CAL_DATA_PTR[loop+1] = ul1PwrOnCalData[setIdx][loop];
+   }
+#else
+   UMTS_PWRON_CAL_DATA_PTR[1] = ul1PwrOnCalData[setIdx][0];
+   UMTS_PWRON_CAL_DATA_PTR[2] = ul1PwrOnCalData[setIdx][1];
+   UMTS_PWRON_CAL_DATA_PTR[3] = ul1PwrOnCalData[setIdx][2];
+   UMTS_PWRON_CAL_DATA_PTR[4] = ul1PwrOnCalData[setIdx][3];
+   UMTS_PWRON_CAL_DATA_PTR[5] = ul1PwrOnCalData[setIdx][4];
+#endif/*IS_3G_SUPPORT_8_BANDINDICATOR*/
+#endif/*IS_3G_DRDI_SUPPORT*/
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+void nvram_UL1D_DrdiPointerInit(kal_uint16 setIdx)
+{
+#ifdef __MTK_TARGET__
+#if (IS_3G_DRDI_SUPPORT)
+#if IS_3G_SUPPORT_8_BANDINDICATOR    
+   kal_uint8 loop;
+   /*Band indicator assign*/ 
+   for(loop=0;loop<MAX_SUPPORTED_BAND_INDEX;loop++)
+   {
+      ul1d_BandInfo[loop] = ul1CustomBand[setIdx][loop];
+   }
+#else    
+   ul1d_BandInfo[0] = ul1CustomBand[setIdx][0];
+   ul1d_BandInfo[1] = ul1CustomBand[setIdx][1];
+   ul1d_BandInfo[2] = ul1CustomBand[setIdx][2];
+   ul1d_BandInfo[3] = ul1CustomBand[setIdx][3];
+   ul1d_BandInfo[4] = ul1CustomBand[setIdx][4];  
+#endif  
+
+   /*calibration data pointer table assign*/ 
+   ul1d_rf_calData_ptr = &(ul1CustomUmtsCalData[setIdx]);
+   
+   #if (IS_3G_MIPI_SUPPORT)
+   /*MIPI data pointer table assign*/ 
+   ul1d_mipiData_array_ptr = &(ul1CustomMipiData[setIdx]);
+   #if __IS_UL1D_ETM_SUPPORT__
+   ul1d_mipiEtmData_array_ptr = &( ul1CustomMipiEtmData[ setIdx ] );
+   #endif   // #if __IS_UL1D_ETM_SUPPORT__   
+   #endif
+
+   /*RF Front end route table pointer assign*/ 
+   ul1d_RfFeRoute_array_ptr = &(ul1CustomUmtsFeSettingData[setIdx]);
+
+   /*RF Parameter*/
+   ul1d_rf_parameter_ptr = &(ul1CustomUmtsRfParameter[setIdx]);
+
+   #if (IS_3G_DAT_UL1_CUSTOM_SUPPORT)
+   ul1d_rf_dat_route_ptr = &(ul1CustomDatRoute[setIdx]);
+   ul1d_rf_dat_byRat_ptr = &(ul1CustomDatByRat[setIdx]);
+   #if !IS_3G_UDAT_SUPPORT
+   ul1d_rf_dat_db_ptr = &(ul1CustomDatDb[setIdx]);
+   #if (IS_3G_MIPI_SUPPORT)
+   ul1d_rf_dat_mipiData_ptr = &(ul1CustomDatMipiData[setIdx]);
+   #endif
+   #endif
+   #endif
+
+   #if (IS_3G_TAS_UL1_CUSTOM_SUPPORT)
+   ul1d_rf_tas_route_ptr = &(ul1CustomTasRoute[setIdx]);
+   ul1d_rf_tas_byRat_ptr = &(ul1CustomTasByRat[setIdx]);
+   #if !IS_3G_UTAS_SUPPORT
+   ul1d_rf_tas_db_ptr = &(ul1CustomTasDb[setIdx]);
+   #if (IS_3G_MIPI_SUPPORT)
+   ul1d_rf_tas_mipiData_ptr = &(ul1CustomTasMipiData[setIdx]);
+   #endif
+   #endif
+   #if IS_3G_TAS_INHERIT_4G_ANT
+   ul1d_rf_tas_inherit_lte_ant_ptr= &(ul1CustomTasInheritLteAnt[setIdx]);
+   #endif
+   #endif
+
+   #if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+   ul1d_rf_tpoData_ptr = &(ul1CustomTpoData[setIdx]);
+   #endif
+   
+   #if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+   ul1d_rf_nsftTpoData_ptr = &(ul1CustomNsftTpoData[setIdx]);
+   #endif
+
+   #if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+   ul1d_rf_rpoData_ptr = &(ul1CustomRpoData[setIdx]);
+   #endif
+  
+   #if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+   ul1d_rf_VpaSrcSelData_ptr= &(ul1CustomVpaSrcSelData[setIdx]);
+   #endif
+   #if IS_3G_ELNA_SUPPORT
+   ul1d_rf_elnadata_ptr = &(ul1CustomElnaData[setIdx]);
+   #endif
+   #if __IS_UL1D_DPD_SUPPORT__
+   ul1d_rf_dpd_data_ptr = &(ul1CustomUmtsDpdFactoryData[setIdx]);  
+   #endif   
+
+   #if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+   ul1d_rf_rfeqCoefData_ptr = &(ul1CustomRfeqCoefData[setIdx]);
+   #endif
+
+   #if (IS_3G_RFEQ_REAL_COEF_TEST)
+   ul1d_rf_realRfeqCoefData_ptr = &(ul1CustomRealRfeqCoefData[setIdx]);
+   #endif
+
+#endif/*IS_3G_DRDI_SUPPORT*/
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+void nvram_UL1D_Drdi(void)
+{
+#ifdef __MTK_TARGET__
+#if (IS_3G_DRDI_SUPPORT)
+   if(!ul1d_DRDI_had_done)
+   {
+      if(isWcdmaDrdiEnable)
+      {
+         kal_uint16 setIdx;
+         setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);
+         /* set the pointer to RF custom data by set index */
+         nvram_UL1D_DrdiPointerInit(setIdx);
+         UL1D_RF_DynamicCustomTable_Update(ul1d_RfFeRoute_array_ptr);
+         UL1D_RF_DynamicSetRfBandSupport(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE);
+         UL1D_RF_DynamicSetRfParameter(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE,ul1d_rf_parameter_ptr);
+         nvram_UL1D_DrdiPWRONCAL(setIdx);
+   #if IS_3G_ELNA_SUPPORT
+         UL1D_RF_DynamicElna_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE, ul1d_rf_elnadata_ptr);
+   #endif
+	
+   #if IS_3G_RX_POWER_OFFSET_SUPPORT
+	      UL1D_RF_DynamicRxPowerOffset_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE, ul1d_rf_rpoData_ptr);
+   #endif
+      }
+      else
+      {
+         nvram_UL1D_DrdiPointerInit(0);
+      }
+      ul1d_DRDI_had_done = KAL_TRUE;
+   }
+#endif/*IS_3G_DRDI_SUPPORT*/
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+void nvram_get_uL1_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#ifdef __MTK_TARGET__
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+//chliu
+    UMTSBand uband = UMTSBandNone;
+    kal_uint8 index_select;
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+    kal_uint8 loop;
+#endif
+    ul1cal_tempdacData_T  *tempdac;
+    ul1cal_pathlossData_T *pathloss;
+    ul1cal_txdacData_T    *txdac;
+/* end of chliu */
+    ul1cal_txPrachTmCompData_T *txPrachTmComp;
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    ul1cal_txPaOctLevData_T *pacoctlev_handle;
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T  *pwroncal;
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+   nvram_UL1D_Drdi();
+
+   /* Do not need to get band indicator prior to get UL1 default value if user
+    * modifies setting by Modem Bin Update Tool, since in MT6573/MT6276 3G RF
+    * customization scenario the band indicator in run-time directly modified
+    * by customer via Modem Bin Update tool or via ul1d_custom_rf.h
+    */
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+   for(loop=0;loop<MAX_SUPPORTED_BAND_INDEX;loop++)
+   {
+      ul1d_BandInfo[loop] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.BandIndicator[loop] ;     
+	  nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[loop]);
+   }
+#else
+   ul1d_BandInfo[0] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB1;
+   ul1d_BandInfo[1] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB2;
+   ul1d_BandInfo[2] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB3;
+   ul1d_BandInfo[3] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.LB1;
+   ul1d_BandInfo[4] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.LB2; 
+
+   /* Produce band to band indicator mapping array */
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[0]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[1]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[2]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[3]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[4]);
+#endif/*IS_3G_SUPPORT_8_BANDINDICATOR*/
+#endif /* #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__) */
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch (lid)
+    {
+//chliu
+        case NVRAM_EF_UL1_TEMP_DAC_LID:
+            #if 0
+/* under construction !*/
+/* under construction !*/
+            #else
+               #if (IS_3G_DRDI_SUPPORT)
+            kal_mem_cpy(buffer, ul1d_rf_calData_ptr->TempDac_p, sizeof(ul1cal_tempdacData_T));            
+            UNUSED(tempdac);
+               #else
+            kal_mem_cpy(buffer, U_TEMP_DAC_SetDefault, sizeof(ul1cal_tempdacData_T));            
+            UNUSED(tempdac);
+               #endif
+            #endif
+            break;
+        case NVRAM_EF_UL1_PATHLOSS_BAND1_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND2_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND3_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND4_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND5_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND6_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND7_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND8_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND9_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND10_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND11_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND19_LID:
+            {
+               pathloss = (ul1cal_pathlossData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PATHLOSS_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RxPathLoss_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RxPathLoss_p[index_select], sizeof(ul1cal_pathlossData_T));
+                  UNUSED(pathloss);
+               }
+            #else
+               if (U_AGC_PATHLOSS_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_AGC_PATHLOSS_TABLE_SetDefault[index_select], sizeof(ul1cal_pathlossData_T));
+                  UNUSED(pathloss);
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_TXDAC_BAND1_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND2_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND3_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND4_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND5_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND6_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND7_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND8_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND9_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND10_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND11_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND19_LID:
+            {
+               txdac = (ul1cal_txdacData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXDAC_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RampData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RampData_p[index_select], sizeof(U_sRAMPDATA));
+                  UNUSED(txdac);
+               }
+            #else
+               if (UMTS_RampData_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RampData_SetDefault[index_select], sizeof(U_sRAMPDATA));
+                  UNUSED(txdac);
+               }
+            #endif
+            }
+            break;
+/* end of chliu */
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+        /* PA 8-level control */
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND2_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND3_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND4_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND5_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND6_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND7_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND8_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND9_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND10_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND11_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND19_LID:
+            {
+               pacoctlev_handle = (ul1cal_txPaOctLevData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID);         
+               index_select = RF_GET_CAL_DATA_ARRAY_BAND_IDX(uband, KAL_TRUE);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaOctLev_p[index_select] != 0)
+               {
+                   kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaOctLev_p[index_select], sizeof(U_sPAOCTLVLSETTING));
+                   UNUSED(pacoctlev_handle);
+               }
+            #else
+               if (U_PA_OCTLEV_TABLE_SetDefault[index_select] != 0)
+               {
+                   kal_mem_cpy(buffer, U_PA_OCTLEV_TABLE_SetDefault[index_select], sizeof(U_sPAOCTLVLSETTING));
+                   UNUSED(pacoctlev_handle);
+               }
+            #endif
+            }
+            break;
+        /* End of PA 8-level control */
+        case NVRAM_EF_UL1_3G_RF_PARAMETER_LID:
+            UL1D_RF_UpdateDatabaseTable();
+            UL1D_RF_CA_CustomData_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE);
+            kal_mem_cpy(buffer, &UMTS_RF_CUSTOM_INPUT_DATA_PCORE, sizeof(U_sUl1dRfCustomInputData));            
+            break;
+
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+#if defined(__UMTS_R8__) //add by Jay
+        case NVRAM_EF_UL1_PATHLOSS2_BAND1_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND2_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND3_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND4_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND5_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND6_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND7_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND8_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND9_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND10_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND11_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND19_LID:
+            {
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PATHLOSS2_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RxDPathLoss_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RxDPathLoss_p[index_select], sizeof(ul1cal_pathlossRxdData_T));
+               }
+            #else
+               if (U_AGC_PATHLOSS_RXD_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_AGC_PATHLOSS_RXD_TABLE_SetDefault[index_select], sizeof(ul1cal_pathlossRxdData_T));
+               }
+            #endif
+            }
+            break;
+   //add by wilson for pa drift compensation
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND2_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND3_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND4_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND5_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND6_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND7_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND8_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND9_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND10_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND11_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND19_LID:
+            {
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaDrift_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaDrift_p[index_select], sizeof(ul1cal_txPaDriftCompData_T));
+               }
+            #else
+               if (U_PA_DRIFT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_PA_DRIFT_TABLE_SetDefault[index_select], sizeof(ul1cal_txPaDriftCompData_T));
+               }
+            #endif
+            }
+            break;
+#endif //defined(__UMTS_R8__)
+
+        /** Tx PRACH TM Compensation */
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND2_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND3_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND4_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND5_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND6_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND7_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND8_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND9_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND10_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND11_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND19_LID:
+            {
+               txPrachTmComp = (ul1cal_txPrachTmCompData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaRachComp_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaRachComp_p[index_select], sizeof(ul1cal_txPrachTmCompData_T));
+                  UNUSED(txPrachTmComp);
+               }
+            #else
+               if (U_PA_RACH_COMP_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_PA_RACH_COMP_TABLE_SetDefault[index_select], sizeof(ul1cal_txPrachTmCompData_T));
+                  UNUSED(txPrachTmComp);
+               }
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_AFCDAC_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_calData_ptr->AfcDac_p, sizeof(ul1cal_afcDacData_T));
+            #else
+               kal_mem_cpy(buffer, &U_AFC_DAC_SetDefault, sizeof(ul1cal_afcDacData_T));
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_AFCCAP_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_calData_ptr->AfcCap_p, sizeof(ul1cal_afcCapData_T));
+            #else
+               kal_mem_cpy(buffer, &U_AFC_CAP_SetDefault, sizeof(ul1cal_afcCapData_T));
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_PWRONCAL_BAND1_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND2_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND3_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND4_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND5_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND6_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND7_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND8_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND9_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND10_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND11_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND19_LID:
+            {
+               pwroncal = (UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PWRONCAL_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+
+               if (UMTS_PWRON_CAL_DATA_PTR[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_PWRON_CAL_DATA_PTR[index_select], sizeof(UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T));
+                  UNUSED(pwroncal);
+               }
+            }
+            break;
+
+
+#if (IS_3G_MIPI_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR			  		  		  	 			
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE8_LID: 
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TPC_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->tpcTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->tpcTable_p[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #else
+               if (UMTS_MIPI_TPC_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TPC_TABLE_SetDefault[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #endif
+            }
+            break;
+#endif
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR			
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE8_LID:	
+#endif 			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->rxEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->rxEventTable_p[index_select], sizeof(ul1mipi_rxEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_RX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_RX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_rxEvent_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR						
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE8_LID:	
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->rxDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->rxDataTable_p[index_select], sizeof(ul1mipi_rxData_T));
+               }
+            #else
+               if (UMTS_MIPI_RX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_RX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_rxData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR									
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE8_LID:	
+#endif 			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->txEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->txEventTable_p[index_select], sizeof(ul1mipi_txEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_TX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_txEvent_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR												
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE8_LID:
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->txDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->txDataTable_p[index_select], sizeof(ul1mipi_txData_T));
+               }
+            #else
+               if (UMTS_MIPI_TX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_txData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR															
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE8_LID:
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->asmIsoTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->asmIsoTable_p[index_select], sizeof(ul1mipi_asmIsoData_T));
+               }
+            #else
+               if (UMTS_MIPI_ASM_ISOLATION_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ASM_ISOLATION_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_asmIsoData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_INIT_CW_LID:
+            {
+               /*Useless NVRAM ID(Moved to MML1), do nothing*/
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_SLEEP_CW_LID:
+            {
+               /*Useless NVRAM ID(Moved to MML1), do nothing*/
+            }
+            break;
+
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+#if (IS_3G_VPA_SEL_BY_BAND_SUPPORT)
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE1_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE2_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE3_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE4_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR			
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE6_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE7_LID:
+        case NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE8_LID:
+#endif				
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_VPA_SRC_SEL_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_VpaSrcSelData_ptr->vpaSrcSelTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_VpaSrcSelData_ptr->vpaSrcSelTable_p[index_select], sizeof(ul1vpa_sel_T));            
+               }
+            #else
+               if (UMTS_VPA_SRC_SEL_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_VPA_SRC_SEL_TABLE_SetDefault[index_select], sizeof(ul1vpa_sel_T));
+               }
+            #endif
+            }
+            break;
+#endif/*IS_3G_VPA_SEL_BY_BAND_SUPPORT*/
+
+#if (IS_3G_TX_POWER_OFFSET_SUPPORT || IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT)
+         /* Tx power offset table 1 */
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE1_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE2_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE3_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE4_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR					 	
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE6_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE7_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE8_LID:
+#endif		 	
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_tpoData_ptr->TpoData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_tpoData_ptr->TpoData_p[index_select], sizeof(U_sTXPOWEROFFSETDATA));
+               }
+            #else
+               if (U_TX_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_TX_POWER_OFFSET_TABLE_SetDefault[index_select], sizeof(U_sTXPOWEROFFSETDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_TX_POWER_OFFSET_SUPPORT */
+
+#if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+         /* Tx NSFT power offset table */
+         case NVRAM_EF_UL1_TXNSFTPOWEROFFSET_LID:
+            {
+               U_sTXNSFTPOWEROFFSETDATA_ALLBAND nsftTpo_allband;
+
+               for(index_select = 0; index_select<UL1D_RF_CUSTOM_BAND; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if (ul1d_rf_nsftTpoData_ptr->nsftTpoData_p[index_select] != 0)
+                  {
+                     nsftTpo_allband.nsftTpoTable[index_select] = *(ul1d_rf_nsftTpoData_ptr->nsftTpoData_p[index_select]);
+                  }
+               #else
+                  if (U_TX_NSFT_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+                  {
+                     nsftTpo_allband.nsftTpoTable[index_select] = *(U_TX_NSFT_POWER_OFFSET_TABLE_SetDefault[index_select]);
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &nsftTpo_allband, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+            }
+            break;
+#endif
+
+#if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+         /* Rx power offset table */
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE1_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE2_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE3_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE4_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR					 	
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE6_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE7_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE8_LID:	
+#endif		 	
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_rpoData_ptr->RpoData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_rpoData_ptr->RpoData_p[index_select], sizeof(U_sRXPOWEROFFSETDATA));
+               }
+            #else
+               if (U_RX_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_RX_POWER_OFFSET_TABLE_SetDefault[index_select], sizeof(U_sRXPOWEROFFSETDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RX_POWER_OFFSET_SUPPORT */
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+       case NVRAM_EF_UL1_DAT_FEATURE_BY_RAT_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, &ul1d_rf_dat_byRat_ptr->dat_feature_byRat, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_DAT_FEATURE_BY_RAT_SetDefault, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_FE_ROUTE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_dat_route_ptr->dat_fe_route, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_DAT_FE_ROUTE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_DAT_FE_ROUTE_DATABASE_T));
+            #endif
+            }
+            break;
+#if !IS_3G_UDAT_SUPPORT
+       case NVRAM_EF_UL1_DAT_FE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_a_fe_db, ul1d_rf_dat_db_ptr->dat_cat_a_fe_db, sizeof(UMTS_CUSTOM_DAT_FE_CAT_A_T));
+               kal_mem_cpy(&UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_b_fe_db, ul1d_rf_dat_db_ptr->dat_cat_b_fe_db, sizeof(UMTS_CUSTOM_DAT_FE_CAT_B_T));
+            #else
+               UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_a_fe_db = UMTS_DAT_CAT_A_DATABASE_SetDefault;
+               UMTS_DAT_FE_DATABASE_SetDefault.dat_cat_b_fe_db = UMTS_DAT_CAT_B_DATABASE_SetDefault;
+            #endif
+               kal_mem_cpy(buffer, &UMTS_DAT_FE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_DAT_FE_DATABASE_T));
+            }
+            break;
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+       case NVRAM_EF_UL1_DAT_CAT_A_MIPI_EVENT_LID:
+            {
+               static ul1mipi_datEvent_CatA_T ul1_rf_mipi_dat_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catA_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], ul1d_rf_dat_mipiData_ptr->catA_eventTable_p[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], UMTS_DAT_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_CAT_A_MIPI_DATA_LID:
+            {
+               static ul1mipi_datData_CatA_T ul1_rf_mipi_dat_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catA_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], ul1d_rf_dat_mipiData_ptr->catA_dataTable_p[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], UMTS_DAT_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_CAT_B_MIPI_EVENT_LID:
+            {
+               static ul1mipi_datEvent_CatB_T ul1_rf_mipi_dat_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catB_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], ul1d_rf_dat_mipiData_ptr->catB_eventTable_p[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_event_buffer.mipiDatEventRoute[index_select], UMTS_DAT_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_datEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_event_buffer, sizeof(ul1mipi_datEvent_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_DAT_CAT_B_MIPI_DATA_LID:
+            {
+               static ul1mipi_datData_CatB_T ul1_rf_mipi_dat_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_DAT_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_dat_mipiData_ptr->catB_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], ul1d_rf_dat_mipiData_ptr->catB_dataTable_p[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #else
+                  if(UMTS_DAT_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_dat_data_buffer.mipiDatDataRoute[index_select], UMTS_DAT_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_datSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_dat_data_buffer, sizeof(ul1mipi_datData_CatB_T));
+            }
+            break;
+#endif /*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+#endif /*!IS_3G_UDAT_SUPPORT*/
+#endif /*IS_3G_DAT_UL1_CUSTOM_SUPPORT*/
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+       case NVRAM_EF_UL1_TAS_FEATURE_BY_RAT_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, &ul1d_rf_tas_byRat_ptr->tas_feature_byRat, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_TAS_FEATURE_BY_RAT_SetDefault, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_FE_ROUTE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_tas_route_ptr->tas_fe_route, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_TAS_FE_ROUTE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATABASE_T));
+            #endif
+            }
+            break;
+#if !IS_3G_UTAS_SUPPORT
+       case NVRAM_EF_UL1_TAS_FE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_a_fe_db, ul1d_rf_tas_db_ptr->tas_cat_a_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_A_T));
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_b_fe_db, ul1d_rf_tas_db_ptr->tas_cat_b_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_B_T));
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_c_fe_db, ul1d_rf_tas_db_ptr->tas_cat_c_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_C_T));
+            #else
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_a_fe_db = UMTS_TAS_CAT_A_DATABASE_SetDefault;
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_b_fe_db = UMTS_TAS_CAT_B_DATABASE_SetDefault;
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_c_fe_db = UMTS_TAS_CAT_C_DATABASE_SetDefault;
+            #endif
+               kal_mem_cpy(buffer, &UMTS_TAS_FE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+            }
+            break;
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+       case NVRAM_EF_UL1_TAS_CAT_A_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatA_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catA_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catA_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_A_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatA_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catA_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catA_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_B_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatB_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catB_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catB_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_B_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatB_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catB_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catB_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_C_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatC_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_C_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catC_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catC_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatC_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_C_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatC_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_C_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catC_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catC_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_C_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_C_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatC_T));
+            }
+            break;
+#endif
+#endif
+#if IS_3G_TAS_INHERIT_4G_ANT
+       case NVRAM_EF_UL1_TAS_INHERIT_LTE_ANT_LID:
+            {
+               UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T ul1d_rf_tas_inherit_lte_ant_buffer;
+               
+               for(index_select=0; index_select<UMTS_TAS_MAX_FE_ROUTE_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  ul1d_rf_tas_inherit_lte_transform_bitmap(ul1d_rf_tas_inherit_lte_ant_ptr->inheritLteAntTable_p[index_select], &(ul1d_rf_tas_inherit_lte_ant_buffer.inherit_lte_band_bitmap_route[index_select]));
+               #else
+                  ul1d_rf_tas_inherit_lte_transform_bitmap(UMTS_TAS_INHERIT_LTE_ANT_TABLE_SetDefault[index_select], &(ul1d_rf_tas_inherit_lte_ant_buffer.inherit_lte_band_bitmap_route[index_select]));
+               #endif
+               }
+               kal_mem_cpy(buffer, &ul1d_rf_tas_inherit_lte_ant_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+            }
+            break;
+#endif
+#endif
+      case NVRAM_EF_UL1_DPD_PARAMETER_LID:
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               static U_sUl1dDpdCustomInputData ul1_rf_dpd_parameter_buffer;            
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_noncustom_para, &UMTS_DPD_CUSTOM_INPUT_DATA_PCORE.pcfe_dpdotfc_noncustom_para, sizeof(U_Ul1D_PCFE_DPD_OTFC_NONCUSTOM_PARA_T));  
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_custom_para   , ul1d_rf_dpd_data_ptr->DpdPcfeCustomData_p                    , sizeof(U_UL1D_PCFE_DPD_OTFC_CUSTOM_PARA_T));
+            #else
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_noncustom_para, &UMTS_DPD_CUSTOM_INPUT_DATA_PCORE.pcfe_dpdotfc_noncustom_para, sizeof(U_Ul1D_PCFE_DPD_OTFC_NONCUSTOM_PARA_T));  
+               kal_mem_cpy(&ul1_rf_dpd_parameter_buffer.pcfe_dpdotfc_custom_para   , &ul1d_pcfe_dpd_otfc_custom_para_SetDefault                   , sizeof(U_UL1D_PCFE_DPD_OTFC_CUSTOM_PARA_T));
+            #endif
+               kal_mem_cpy(buffer, &ul1_rf_dpd_parameter_buffer, sizeof(U_sUl1dDpdCustomInputData));  
+            #endif
+            }
+            break;
+
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE1_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE2_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE3_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE4_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE6_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE7_LID:
+      case NVRAM_EF_UL1_DPD_CTRL_DATA_ROUTE8_LID:
+#endif  // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CTRL_DATA_START);
+               
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_dpd_data_ptr->DpdCtrlData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_dpd_data_ptr->DpdCtrlData_p[index_select], sizeof(U_sDPD_COMMON_CTRL));
+               }
+            #else
+               if (UMTS_DPD_CommonCtrlData_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_DPD_CommonCtrlData_SetDefault[index_select], sizeof(U_sDPD_COMMON_CTRL));
+               }
+            #endif
+            #endif
+            }
+            break;
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE1_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE2_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE3_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE4_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE6_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE7_LID:
+      case NVRAM_EF_UL1_DPD_CAL_DATA_ROUTE8_LID:
+#endif  // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               static U_sDPD_GROUP_CAL ul1_rf_dpd_cal_data_buffer;
+               static kal_uint8        rf_bandind;
+               
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_DPD_CAL_DATA_START);
+               
+               rf_bandind = nvram_init_uL1_dpd_band_mapping_rf_bandind(index_select);
+               
+               if (UMTS_RampData_SetDefault[index_select] != 0)
+               {              
+                  kal_mem_cpy(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_ramp_data, UMTS_RampData_SetDefault[rf_bandind], sizeof(U_sRAMPDATA));
+               }               
+               if (U_PA_OCTLEV_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_pa_oct_lev_tbl, U_PA_OCTLEV_TABLE_SetDefault[rf_bandind], sizeof(U_sPAOCTLVLSETTING));
+               }             
+               kal_mem_set(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_common_cal    , 0, sizeof(U_sDPD_COMMON_CAL));               
+               kal_mem_set(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_am_lut_perband, 0, sizeof(U_sDPD_AMLUT_PERBAND));               
+               kal_mem_set(&ul1_rf_dpd_cal_data_buffer.wcdma_dpd_pm_lut_perband, 0, sizeof(U_sDPD_PMLUT_PERBAND));
+               
+               kal_mem_cpy(buffer, &ul1_rf_dpd_cal_data_buffer, sizeof(U_sDPD_GROUP_CAL));
+            #endif
+            }
+            break;         
+#if (IS_3G_MIPI_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE5_LID:
+   #if IS_3G_SUPPORT_8_BANDINDICATOR
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE8_LID:
+   #endif  // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_DPD_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_DPD_TPC_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_dpd_data_ptr->DpdTpcTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_dpd_data_ptr->DpdTpcTable_p[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #else
+               if (UMTS_MIPI_DPD_TPC_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_DPD_TPC_TABLE_SetDefault[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #endif
+            #endif
+            }
+            break;
+#endif            
+
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE8_LID:         
+#endif   // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->txEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->txEventTable_p[index_select], sizeof(ul1mipiEtm_txEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_txEvent_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE8_LID:  
+#endif   // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_DATA_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->txDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->txDataTable_p[index_select], sizeof(ul1mipiEtm_txData_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_txData_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;
+
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR			 			
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE8_LID: 
+#endif   // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->tpcEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->tpcEventTable_p[index_select], sizeof(ul1mipiEtm_tpcEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TPC_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TPC_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_tpcEvent_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;
+
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE8_LID:         
+#endif   // IS_3G_SUPPORT_8_BANDINDICATOR
+            {
+            #if __IS_UL1D_ETM_SUPPORT__
+
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiEtmData_array_ptr->tpcDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiEtmData_array_ptr->tpcDataTable_p[index_select], sizeof(ul1mipiEtm_tpcData_T));
+               }
+            #else
+               if (UMTS_MIPI_ETM_TPC_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ETM_TPC_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipiEtm_tpcData_T));
+               }
+            #endif   // #if (IS_3G_DRDI_SUPPORT)
+            #endif   // #if __IS_UL1D_ETM_SUPPORT__               
+            }
+            break;            
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+         /* RFEQ Coefficient table 1 */
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE1_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE2_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE3_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE4_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE6_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE7_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE8_LID:
+#endif
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_COEF_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_rfeqCoefData_ptr->rfeqCoef_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_rfeqCoefData_ptr->rfeqCoef_p[index_select], sizeof(hs_dsch_rfeq_info_band_T));
+               }
+            #else
+               if (UMTS_RFEQ_COEF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RFEQ_COEF_TABLE_SetDefault[index_select], sizeof(hs_dsch_rfeq_info_band_T));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RFEQ_COEF_SUBBAND_SUPPORT */
+#if (IS_3G_RFEQ_REAL_COEF_TEST)
+         /* RFEQ Coefficient table 1 */
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE1_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE2_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE3_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE4_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE6_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE7_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE8_LID:
+#endif
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_realRfeqCoefData_ptr->realRfeqCoef_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_realRfeqCoefData_ptr->realRfeqCoef_p[index_select], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+               }
+            #else
+               if (UMTS_RFEQ_COEF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RFEQ_REAL_COEF_TABLE_SetDefault[index_select], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RFEQ_COEF_SUBBAND_SUPPORT */
+
+        default:
+            UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(KAL_FALSE);
+            break;
+    }
+#endif /* #ifdef __MTK_TARGET__ */
+}
+#endif /* __UMTS_RAT__ && __MTK_UL1_FDD__ */
diff --git a/mcu/service/nvram/src/nvram_ul1def_md97.c b/mcu/service/nvram/src/nvram_ul1def_md97.c
new file mode 100644
index 0000000..276091b
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ul1def_md97.c
@@ -0,0 +1,2718 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2007
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ul1def.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *    This file provides a fuction for NVRAM Task to get UL1 default value
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+  *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_public_defs.h"
+#include "nvram_enums.h"
+
+#if defined(__UMTS_RAT__) && defined(__MTK_UL1_FDD__)
+
+#ifdef __MTK_TARGET__
+
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+
+#if defined (__UL1_PLATFORM__)
+#include "common_nvram_editor_data_item.h"
+#include "ul1d_rf_public.h"
+#endif
+
+#include "nvram_interface.h"
+#include "hal_ul1_def.h"
+
+// Fix NVRAM RHR activity side-effect
+#include "nvram_editor_data_item.h"
+#include "ul1_nvram_editor.h"  // LID struct definition
+
+
+/* UL1 calibration data defination */
+#include "ul1d_rf_public.h"
+#include "ul1d_mipi_public.h"
+#include "ul1cal.h"
+#include "l1cal.h"
+
+#include "nvram_data_items.h"
+#include "nvram_main.h"
+
+#include "ul1_nvram_def.h"
+#include "ul1d_rf_cid.h"
+
+#include "wcustomdata.h"
+#include "mml1_dpd_def.h"
+
+#if __IS_UL1D_ETM_SUPPORT__
+#include "ul1d_custom_mipi_etm.h"
+#endif   // #if __IS_UL1D_ETM_SUPPORT_
+
+#include "event_info_utility.h"  //MODEM_WARNING_MESSAGE
+
+#define UNUSED(x)                      (void)x
+
+#define countof(x)                  ((sizeof(x))/(sizeof(*x)))
+
+#define UL1_NVRAM_WARNING( st )                      MODEM_WARNING_MESSAGE( st )
+#define UL1_NVRAM_DEBUG_ASSERT( st )                 DEBUG_ASSERT( st )
+#define UL1_NVRAM_WARNING_AND_DEBUG_ASSERT( st )     UL1_NVRAM_WARNING( st );   \
+                                                     UL1_NVRAM_DEBUG_ASSERT( st );
+
+
+
+//extern kal_uint8 UL1D_RF_CalDataGetBand(UMTSBand rf_band_in_question, kal_bool nvram_init);
+
+void nvram_init_uL1_AfcData(void)
+{
+   kal_bool error_no;
+   extern kal_int16 afc_dac_default;
+   extern kal_uint32 afc_inv_slope;
+
+   l1cal_afcData_T *afc = (l1cal_afcData_T *)get_ctrl_buffer( sizeof( l1cal_afcData_T ) );
+
+   /* Get RF customization data from NVRAM (customer's input) */
+   error_no = nvram_external_read_data(NVRAM_EF_L1_AFCDATA_LID, 1, (kal_uint8 *)afc, NVRAM_EF_L1_AFCDATA_SIZE);
+
+   #if IS_3G_MML1_AFC_TADC_SUPPORT
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_AFCDAC_LID, 1, (kal_uint8 *)afc, NVRAM_EF_UL1_AFCDAC_SIZE);
+   #endif
+
+   ASSERT(error_no == KAL_TRUE);
+   afc_dac_default = afc->dacValue;
+   afc_inv_slope = afc->slopeInv;
+   free_ctrl_buffer( afc );
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_send_uL1_cal
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_send_uL1_cal(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+   /**
+    *    file_idx should be the first L1 element in the logical data item ID enum
+    *    Currently, L1 calibration data element is as following:
+    *    NVRAM_EF_L1_AGCPATHLOSS_LID, NVRAM_EF_L1_RAMPTABLE_GSM900_LID,
+    *    NVRAM_EF_L1_RAMPTABLE_DCS1800_LID, NVRAM_EF_L1_RAMPTABLE_PCS1900_LID, 
+    *    NVRAM_EF_L1_AFCDATA_LID, VRAM_EF_L1_L1SPFC_LID, 
+    */
+
+    nvram_lid_enum file_idx;
+    nvram_ltable_entry_struct *ldi;
+    peer_buff_struct *peer_buf_ptr;
+    kal_uint8 *pdu_ptr;
+    kal_uint16 pdu_length;
+    nvram_read_req_struct *local_data;
+
+    /* Move the calling to nvram_init_uL1_rfCustomizationData() to nvram_special_service() */
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+
+    for (file_idx = NVRAM_EF_UL1_START; file_idx <= NVRAM_EF_UL1_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TEMP_DAC_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND1_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND2_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND3_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND4_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND5_LID:
+            //case NVRAM_EF_UL1_PATHLOSS_BAND6_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND7_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND8_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND9_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND10_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND11_LID:
+            case NVRAM_EF_UL1_PATHLOSS_BAND19_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND1_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND2_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND3_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND4_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND5_LID:
+            //case NVRAM_EF_UL1_TXDAC_BAND6_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND7_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND8_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND9_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND10_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND11_LID:
+            case NVRAM_EF_UL1_TXDAC_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    /* PA 8-level contrl */
+    for (file_idx = NVRAM_EF_UL1_TXPAOCTLEV_START; file_idx <= NVRAM_EF_UL1_TXPAOCTLEV_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND2_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND3_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND4_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND5_LID:
+            //case NVRAM_EF_UL1_TXPAOCTLEV_BAND6_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND7_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND8_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND9_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND10_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND11_LID:
+            case NVRAM_EF_UL1_TXPAOCTLEV_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+    /* End of PA 8-level contrl */
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+#if defined(__UMTS_R8__) //Jay
+    for (file_idx = NVRAM_EF_UL1_PATHLOSS2_START; file_idx <= NVRAM_EF_UL1_PATHLOSS2_END; file_idx++)
+    {
+       if (!NVRAM_IS_LID_VALID(file_idx))
+       {
+          continue;
+       }
+        
+       switch(file_idx)
+       {
+          case NVRAM_EF_UL1_PATHLOSS2_BAND1_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND2_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND3_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND4_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND5_LID:
+          //case NVRAM_EF_UL1_PATHLOSS2_BAND6_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND7_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND8_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND9_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND10_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND11_LID:
+          case NVRAM_EF_UL1_PATHLOSS2_BAND19_LID:
+          {
+              nvram_util_get_data_item(&ldi, file_idx);
+
+              local_data->access_id = 0;
+              local_data->file_idx = file_idx;
+              local_data->para = 1;
+          
+              pdu_length = ldi->size;
+              peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+              ASSERT(peer_buf_ptr != NULL);
+          
+              pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+              ASSERT(pdu_ptr != NULL);
+          
+          #ifdef __MULTI_BOOT__
+              if (FACTORY_BOOT == kal_query_boot_mode())
+              {        
+                  nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              else
+          #endif /* __MULTI_BOOT__ */
+              {
+                  nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              break;
+          }         
+       }
+    }
+
+    // add by wilson for PA drift compensation
+
+    for (file_idx = NVRAM_EF_UL1_TXPADRIFTCOMP_START; file_idx <= NVRAM_EF_UL1_TXPADRIFTCOMP_END; file_idx++)
+    {
+       if (!NVRAM_IS_LID_VALID(file_idx))
+       {
+          continue;
+       }
+        
+       switch(file_idx)
+       {
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND2_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND3_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND4_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND5_LID:
+          //case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND6_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND7_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND8_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND9_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND10_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND11_LID:
+          case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND19_LID:
+          {
+              nvram_util_get_data_item(&ldi, file_idx);
+
+              local_data->access_id = 0;
+              local_data->file_idx = file_idx;
+              local_data->para = 1;
+          
+              pdu_length = ldi->size;
+              peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+              ASSERT(peer_buf_ptr != NULL);
+          
+              pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+              ASSERT(pdu_ptr != NULL);
+          
+          #ifdef __MULTI_BOOT__
+              if (FACTORY_BOOT == kal_query_boot_mode())
+              {        
+                  nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              else
+          #endif /* __MULTI_BOOT__ */
+              {
+                  nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+              }
+              break;
+          }         
+       }
+    }
+#endif
+
+    /** Tx PRACH TM Compensation */
+    for (file_idx = NVRAM_EF_UL1_TXPRACHTMCOMP_START; file_idx <= NVRAM_EF_UL1_TXPRACHTMCOMP_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND2_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND3_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND4_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND5_LID:
+            //case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND6_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND7_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND8_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND9_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND10_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND11_LID:
+            case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+            #ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+            #endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+
+    /** AFCDAC */
+    for (file_idx = NVRAM_EF_UL1_AFCDAC_START; file_idx <= NVRAM_EF_UL1_AFCDAC_END; file_idx++)
+    {
+            if (!NVRAM_IS_LID_VALID(file_idx))
+            {
+                continue;
+            }
+
+            switch(file_idx)
+            {
+                case NVRAM_EF_UL1_AFCDAC_LID:
+                {
+                    nvram_util_get_data_item(&ldi, file_idx);
+
+                    local_data->access_id = 0;
+                    local_data->file_idx = file_idx;
+                    local_data->para = 1;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    ASSERT(peer_buf_ptr != NULL);
+
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    ASSERT(pdu_ptr != NULL);
+
+            #ifdef __MULTI_BOOT__
+                    if (FACTORY_BOOT == kal_query_boot_mode())
+                    {
+                        nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    else
+            #endif /* __MULTI_BOOT__ */
+                    {
+                        nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    break;
+             }
+        }
+    }
+
+    /** AFCCAP */
+    for (file_idx = NVRAM_EF_UL1_AFCCAP_START; file_idx <= NVRAM_EF_UL1_AFCCAP_END; file_idx++)
+    {
+            if (!NVRAM_IS_LID_VALID(file_idx))
+            {
+                continue;
+            }
+
+            switch(file_idx)
+            {
+                case NVRAM_EF_UL1_AFCCAP_LID:
+                {
+                    nvram_util_get_data_item(&ldi, file_idx);
+
+                    local_data->access_id = 0;
+                    local_data->file_idx = file_idx;
+                    local_data->para = 1;
+
+                    pdu_length = ldi->size;
+                    peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                    ASSERT(peer_buf_ptr != NULL);
+
+                    pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                    ASSERT(pdu_ptr != NULL);
+
+             #ifdef __MULTI_BOOT__
+                    if (FACTORY_BOOT == kal_query_boot_mode())
+                    {
+                        nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    else
+             #endif /* __MULTI_BOOT__ */
+                    {
+                        nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                    }
+                    break;
+             }
+        }
+    }
+
+    /** Tx Power Offset */
+    for (file_idx = NVRAM_EF_UL1_TXPOWEROFFSET_START; file_idx <= NVRAM_EF_UL1_TXPOWEROFFSET_END; file_idx++)
+    {
+        if (!NVRAM_IS_LID_VALID(file_idx))
+        {
+            continue;
+        }
+        
+        switch(file_idx)
+        {
+            /* Tx power offset table */
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND1_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND2_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND3_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND4_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND5_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND6_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND7_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND8_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND9_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND10_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND11_LID:
+            case NVRAM_EF_UL1_TXPOWEROFFSET_BAND19_LID:
+            {
+                nvram_util_get_data_item(&ldi, file_idx);
+        
+                local_data->access_id = 0;
+                local_data->file_idx = file_idx;
+                local_data->para = 1;
+        
+                pdu_length = ldi->size;
+                peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL);
+                ASSERT(peer_buf_ptr != NULL);
+        
+                pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length);
+                ASSERT(pdu_ptr != NULL);
+        
+#ifdef __MULTI_BOOT__
+                if (FACTORY_BOOT == kal_query_boot_mode())
+                {        
+                    nvram_read_confirm(MOD_FT, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                else
+#endif /* __MULTI_BOOT__ */   
+                {
+                    nvram_read_confirm(MOD_UL1, nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), local_data, ldi->size, peer_buf_ptr);
+                }
+                break;
+            }
+        }
+    }
+
+    free_local_para((local_para_struct*) local_data);
+
+}   /* end of nvram_send_L1_cal function */
+
+
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+void nvram_init_uL1_datFeatureByRat(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T *ul1_dat_feature_by_rat_buffer = (UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_DAT_FEATURE_BY_RAT_LID, 1, (kal_uint8 *)ul1_dat_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_DAT_FEATURE_BY_RAT_PCORE_ptr, ul1_dat_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_DAT_FEATURE_BY_RAT_PCORE_ptr, &(ul1CustomDatByRat[setIdx].dat_feature_byRat), sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+   }
+   
+   free_ctrl_buffer(ul1_dat_feature_by_rat_buffer);
+}
+#endif
+
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+void nvram_init_uL1_tasFeatureByRat(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T *ul1_tas_feature_by_rat_buffer = (UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FEATURE_BY_RAT_LID, 1, (kal_uint8 *)ul1_tas_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TAS_FEATURE_BY_RAT_PCORE_ptr, ul1_tas_feature_by_rat_buffer, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_TAS_FEATURE_BY_RAT_PCORE_ptr, &(ul1CustomTasByRat[setIdx].tas_feature_byRat), sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+   }
+   
+   free_ctrl_buffer(ul1_tas_feature_by_rat_buffer);
+}
+
+void nvram_init_uL1_tasFeatureByRoute(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T *ul1_tas_fe_route_db_buffer = (UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FE_ROUTE_DATABASE_LID, 1, (kal_uint8 *)ul1_tas_fe_route_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T));
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TAS_FE_ROUTE_DATABASE_PCORE_ptr, ul1_tas_fe_route_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_TAS_FE_ROUTE_DATABASE_PCORE_ptr, ul1CustomTasRoute[setIdx].tas_fe_route, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T));
+   }
+   
+   free_ctrl_buffer(ul1_tas_fe_route_db_buffer);
+}
+
+void nvram_init_uL1_tasFeDb(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+      
+   UMTS_CUSTOM_TAS_FE_DATABASE_T *ul1_tas_fe_db_buffer = (UMTS_CUSTOM_TAS_FE_DATABASE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_FE_DATABASE_LID, 1, (kal_uint8 *)ul1_tas_fe_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+   ASSERT(error_no == KAL_TRUE);
+   
+   kal_mem_cpy(UMTS_TAS_FE_DATABASE_PCORE_ptr, ul1_tas_fe_db_buffer, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+   free_ctrl_buffer(ul1_tas_fe_db_buffer);
+#endif
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiTasAEvent(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_A_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatA_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasAData(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_A_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatA_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatA_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatA_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatA_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_A_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_A_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasBEvent(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_B_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatB_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasBData(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_B_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatB_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatB_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatB_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatB_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_B_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_B_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasCEvent(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_C_MIPI_EVENT_LID;
+   kal_uint32 tableIdx;
+
+   ul1mipi_tasEvent_CatC_T *ul1_rf_mipi_tas_event_buffer = (ul1mipi_tasEvent_CatC_T *)get_ctrl_buffer(sizeof(ul1mipi_tasEvent_CatC_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatC_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for (tableIdx = 0; tableIdx < UL1_MIPI_TAS_ROUTE_C_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_event_buffer->mipiTasEventRoute[tableIdx]), sizeof(ul1mipi_tasEvent_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_event_buffer);
+#endif
+}
+
+void nvram_init_uL1_mipiTasCData(void)
+{
+#if !IS_3G_UTAS_SUPPORT
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TAS_CAT_C_MIPI_DATA_LID;
+   kal_uint32 tableIdx;
+      
+   ul1mipi_tasData_CatC_T *ul1_rf_mipi_tas_data_buffer = (ul1mipi_tasData_CatC_T *)get_ctrl_buffer(sizeof(ul1mipi_tasData_CatC_T));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatC_T));
+   ASSERT(error_no == KAL_TRUE);
+
+   for(tableIdx=0; tableIdx < UL1_MIPI_TAS_ROUTE_C_NUM; tableIdx++)
+      kal_mem_cpy(UMTS_TAS_CAT_C_MIPI_DATA_TABLE_PCORE_ptr[tableIdx], &(ul1_rf_mipi_tas_data_buffer->mipiTasDataRoute[tableIdx]), sizeof(ul1mipi_tasSubBandData_T));
+
+   free_ctrl_buffer(ul1_rf_mipi_tas_data_buffer);
+#endif
+}
+#endif
+
+#if IS_3G_TAS_INHERIT_4G_ANT
+void nvram_init_uL1_tasInheritLteAnt(void)
+{
+   kal_bool error_no;
+   kal_uint16 setIdx = 0;   
+   kal_uint32 index_select = 0;
+   UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T *ul1_tas_inherit_lte_bnad_buffer = (UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T *)get_ctrl_buffer(sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+
+   error_no = nvram_external_read_data(NVRAM_EF_UL1_TAS_INHERIT_LTE_ANT_LID, 1, (kal_uint8 *)ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_PCORE_ptr, ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+
+      for(index_select=0; index_select<UMTS_TAS_MAX_FE_ROUTE_NUM; index_select++)
+      {
+         ul1d_rf_tas_inherit_lte_transform_bitmap(ul1CustomTasInheritLteAnt[setIdx].inheritLteAntTable_p[index_select], &(ul1_tas_inherit_lte_bnad_buffer->inherit_lte_band_bitmap_route[index_select]));
+      }
+
+      kal_mem_cpy(UMTS_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_PCORE_ptr, ul1_tas_inherit_lte_bnad_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+   }
+   
+   free_ctrl_buffer(ul1_tas_inherit_lte_bnad_buffer);
+}
+#endif
+#endif
+
+#if IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT
+void nvram_init_uL1_SARBackoffData(void)
+{   
+    kal_bool error_no;   
+    nvram_lid_enum lid;   
+    kal_uint32 tableIdx;   
+    
+    U_sSARBackoffDATA *ul1_sar_backoff_data_buffer = (U_sSARBackoffDATA *) get_ctrl_buffer(sizeof(U_sSARBackoffDATA));   
+    for(lid = NVRAM_EF_UL1_SARBACKOFF_START; lid<= NVRAM_EF_UL1_SARBACKOFF_END; lid++)   
+    {   
+        error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_sar_backoff_data_buffer, sizeof(U_sSARBackoffDATA));      
+        tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_SARBACKOFF_START);      
+        UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);      
+        if(error_no)      
+        {         
+            kal_mem_cpy(UMTS_SAR_BACKOFF_PCORE_TABLE[tableIdx], ul1_sar_backoff_data_buffer, sizeof(U_sSARBackoffDATA));      
+        }      
+        else      
+        {     
+            kal_uint16 setIdx = 0;
+            if(isWcdmaDrdiEnable)         
+            {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }         
+            kal_mem_cpy(UMTS_SAR_BACKOFF_PCORE_TABLE[tableIdx], ul1CustomSARBackoffData[setIdx].sarBackoffData_p[tableIdx], sizeof(U_sSARBackoffDATA));      
+        }   
+    }   
+    free_ctrl_buffer(ul1_sar_backoff_data_buffer);
+}
+#endif//IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT
+
+
+#if IS_3G_TX_POWER_OFFSET_SUPPORT 
+void nvram_init_uL1_TpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   U_sTXPOWEROFFSETDATA *ul1_tpo_data_buffer = (U_sTXPOWEROFFSETDATA *) get_ctrl_buffer(sizeof(U_sTXPOWEROFFSETDATA));
+
+   for(lid = NVRAM_EF_UL1_TXPOWEROFFSET_START; lid<= NVRAM_EF_UL1_TXPOWEROFFSET_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_tpo_data_buffer, sizeof(U_sTXPOWEROFFSETDATA));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPOWEROFFSET_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_TX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1_tpo_data_buffer, sizeof(U_sTXPOWEROFFSETDATA));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_TX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1CustomTpoData[setIdx].TpoData_p[tableIdx], sizeof(U_sTXPOWEROFFSETDATA));
+      }
+
+   }
+   free_ctrl_buffer(ul1_tpo_data_buffer);
+}
+#endif
+
+#if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+void nvram_init_uL1_nsftTpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid = NVRAM_EF_UL1_TXNSFTPOWEROFFSET_LID;
+   kal_uint16 setIdx = 0;   
+   U_sTXNSFTPOWEROFFSETDATA_ALLBAND *ul1_nsfttpo_data_buffer = (U_sTXNSFTPOWEROFFSETDATA_ALLBAND *) get_ctrl_buffer(sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+
+   error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_nsfttpo_data_buffer, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+
+   UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+   if(error_no)
+   {
+      kal_mem_cpy(UMTS_TX_NSFT_POWER_OFFSET_PCORE_ptr, ul1_nsfttpo_data_buffer, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+   }
+   else
+   {
+      if(isWcdmaDrdiEnable)
+      {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+      kal_mem_cpy(UMTS_TX_NSFT_POWER_OFFSET_PCORE_ptr, ul1CustomNsftTpoData[setIdx].nsftTpoData_p, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+   }
+
+   free_ctrl_buffer(ul1_nsfttpo_data_buffer);
+}
+#endif
+
+#if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+void nvram_init_uL1_RpoData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   U_sRXPOWEROFFSETDATA *ul1_rpo_data_buffer = (U_sRXPOWEROFFSETDATA *) get_ctrl_buffer(sizeof(U_sRXPOWEROFFSETDATA));
+
+   for(lid = NVRAM_EF_UL1_RXPOWEROFFSET_START; lid<= NVRAM_EF_UL1_RXPOWEROFFSET_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rpo_data_buffer, sizeof(U_sRXPOWEROFFSETDATA));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RXPOWEROFFSET_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_RX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1_rpo_data_buffer, sizeof(U_sRXPOWEROFFSETDATA));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_RX_POWER_OFFSET_PCORE_TABLE[tableIdx], ul1CustomRpoData[setIdx].RpoData_p[tableIdx], sizeof(U_sRXPOWEROFFSETDATA));
+      }
+
+   }
+   free_ctrl_buffer(ul1_rpo_data_buffer);
+}
+#endif
+
+kal_uint8 nvram_init_uL1_dpd_band_mapping_rf_bandind(kal_uint8 index_select)
+{
+   kal_uint8 dpd_bandind = 0;
+   kal_uint8 rf_bandind = 0;
+   
+   dpd_bandind = ul1d_BandInfo[index_select-UMTSBand1];
+
+   if(dpd_bandind == UMTSBandNone)
+   {
+      rf_bandind = 0;
+   }
+   else
+   {
+      rf_bandind = RF_GET_CAL_DATA_ARRAY_BAND_IDX((UMTSBand)dpd_bandind, KAL_FALSE);
+   }
+   
+   return(rf_bandind);
+}
+
+void nvram_init_uL1_dpdData(void)
+{
+
+#if __IS_UL1D_DPD_SUPPORT__
+
+
+
+#endif
+}
+
+#if (IS_3G_MIPI_SUPPORT)
+void nvram_init_uL1_mipiEtmData(void)
+{
+#if __IS_UL1D_ETM_SUPPORT__
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   ul1mipiEtm_txEvent_T  *ul1_rf_mipi_tx_event_buffer;
+   ul1mipiEtm_txData_T   *ul1_rf_mipi_tx_data_buffer;
+   ul1mipiEtm_tpcEvent_T *ul1_rf_mipi_tpc_event_buffer;
+   ul1mipiEtm_tpcData_T  *ul1_rf_mipi_tpc_data_buffer;
+
+   ul1_rf_mipi_tx_event_buffer = (ul1mipiEtm_txEvent_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_txEvent_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_event_buffer, sizeof(ul1mipiEtm_txEvent_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_EVENT_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TX_EVENT_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tx_event_buffer, sizeof( ul1mipiEtm_txEvent_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tx_event_buffer );
+
+   ul1_rf_mipi_tx_data_buffer = (ul1mipiEtm_txData_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_txData_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TX_DATA_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TX_DATA_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tx_data_buffer, sizeof(ul1mipiEtm_txData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TX_DATA_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TX_DATA_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tx_data_buffer, sizeof( ul1mipiEtm_txData_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tx_data_buffer );
+
+   ul1_rf_mipi_tpc_event_buffer = (ul1mipiEtm_tpcEvent_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_tpcEvent_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tpc_event_buffer, sizeof(ul1mipiEtm_tpcEvent_T));
+      ASSERT(error_no == KAL_TRUE);
+   
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_EVENT_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TPC_EVENT_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tpc_event_buffer, sizeof( ul1mipiEtm_tpcEvent_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tpc_event_buffer );
+
+   ul1_rf_mipi_tpc_data_buffer = (ul1mipiEtm_tpcData_T *)get_ctrl_buffer(sizeof(ul1mipiEtm_tpcData_T));
+   for( lid = NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_START; lid <= NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_END; lid++ )
+   {
+      error_no = nvram_external_read_data( lid, 1, (kal_uint8 *)ul1_rf_mipi_tpc_data_buffer, sizeof(ul1mipiEtm_tpcData_T));
+      ASSERT(error_no == KAL_TRUE);
+
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ETM_TPC_DATA_START);
+      kal_mem_cpy( UMTS_MIPI_ETM_TPC_DATA_PCORE_TABLE[ tableIdx ], ul1_rf_mipi_tpc_data_buffer, sizeof( ul1mipiEtm_tpcData_T ) );
+   }
+   free_ctrl_buffer( ul1_rf_mipi_tpc_data_buffer );
+
+#endif   // #if __IS_UL1D_ETM_SUPPORT__
+}
+#endif   // #if (IS_3G_MIPI_SUPPORT)
+
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+void nvram_init_uL1_rfeqCoefData(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   hs_dsch_rfeq_info_band_T *ul1_rfeqCoef_data_buffer = (hs_dsch_rfeq_info_band_T *) get_ctrl_buffer(sizeof(hs_dsch_rfeq_info_band_T));
+
+   for(lid = NVRAM_EF_UL1_RFEQ_COEF_START; lid<= NVRAM_EF_UL1_RFEQ_COEF_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rfeqCoef_data_buffer, sizeof(hs_dsch_rfeq_info_band_T));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_COEF_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_RFEQ_COEF_PCORE_TABLE[tableIdx], ul1_rfeqCoef_data_buffer, sizeof(hs_dsch_rfeq_info_band_T));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_RFEQ_COEF_PCORE_TABLE[tableIdx], ul1CustomRfeqCoefData[setIdx].rfeqCoef_p[tableIdx], sizeof(hs_dsch_rfeq_info_band_T));
+      }
+
+   }
+   free_ctrl_buffer(ul1_rfeqCoef_data_buffer);
+}
+#endif
+
+#if (IS_3G_RFEQ_REAL_COEF_TEST)
+void nvram_init_uL1_rfeqRealCoefCustom(void)
+{
+   kal_bool error_no;
+   nvram_lid_enum lid;
+   kal_uint32 tableIdx;
+   kal_uint16 setIdx = 0;   
+   URXDFE_REAL_RFEQ_CUSTOM_BAND_T *ul1_rfeqRealCoef_data_buffer = (URXDFE_REAL_RFEQ_CUSTOM_BAND_T *) get_ctrl_buffer(sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+
+   for(lid = NVRAM_EF_UL1_RFEQ_REAL_COEF_START; lid<= NVRAM_EF_UL1_RFEQ_REAL_COEF_END; lid++)
+   {
+      error_no = nvram_external_read_data(lid, 1, (kal_uint8 *)ul1_rfeqRealCoef_data_buffer, sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      tableIdx = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_REAL_COEF_START);
+
+      UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(error_no);
+      if(error_no)
+      {
+         kal_mem_cpy(UMTS_RFEQ_REAL_COEF_PCORE_TABLE[tableIdx], ul1_rfeqRealCoef_data_buffer, sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      }
+      else
+      {
+         if(isWcdmaDrdiEnable)
+         {   setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);   }
+         kal_mem_cpy(UMTS_RFEQ_REAL_COEF_PCORE_TABLE[tableIdx], ul1CustomRealRfeqCoefData[setIdx].realRfeqCoef_p[tableIdx], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+      }
+
+   }
+   free_ctrl_buffer(ul1_rfeqRealCoef_data_buffer);
+}
+#endif
+
+#endif /* __MTK_TARGET__ */ 
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_L1_default_value_to_write
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  lid         [IN]        
+ *  buffer      [?]         
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#ifdef __MTK_TARGET__
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+   /********************************************************/
+   /* MT6573 3G RF Customization for Modem Bin Update Tool */
+   /********************************************************/
+const kal_uint16 UL_BAND_MIN_UARFCN[] = {0, 9612, 9262, 937, 1312, 4132, 4162, 2012, 2712, 8762, 2887, 3487, 3617, 3792, 3892, 0, 0, 0, 0, 312, 4287, 462, 4437};
+const kal_uint16 UL_BAND_MAX_UARFCN[] = {0, 9888, 9538, 1288, 1513, 4233, 4188, 2338, 2863, 8912, 3163, 3562, 3678, 3818, 3918, 0, 0, 0, 0, 363, 4413, 512, 4813};
+const kal_uint16 UL_BAND_MIN_UARFCN_ADDITIONAL[] = {0, 0, 12, 0, 1662, 782, 812, 2362, 0, 0, 3187, 0, 3707, 3842, 3942, 0, 0, 0, 0, 387, 0, 0, 0};
+const kal_uint16 UL_BAND_MAX_UARFCN_ADDITIONAL[] = {0, 0, 287, 0, 1862, 862, 837, 2687, 0, 0, 3462, 0, 3767, 3867, 3967, 0, 0, 0, 0, 437, 0, 0, 0};
+kal_uint8 band_to_bandInd_map_table[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+void nvram_sort_uL1_band_bandind_mapping(kal_uint8 band_indicator)
+{
+    kal_uint8 table_index;
+
+    if ( band_indicator > UMTSBandNone )
+    {
+       table_index = RF_GET_CAL_DATA_ARRAY_BAND_IDX((UMTSBand)band_indicator, KAL_FALSE);
+       band_to_bandInd_map_table[band_indicator] = table_index;
+    }
+}
+
+
+#endif /* #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__) */
+
+#endif /* __MTK_TARGET__ */
+
+#if (IS_3G_DRDI_SUPPORT)
+kal_bool ul1d_DRDI_had_done = KAL_FALSE;
+
+/****************************************************************************
+ * Custom Data Pointer Array Extern
+ ****************************************************************************/
+//const Ul1CustomDynamicInitMipiData *ul1d_mipiData_array_ptr;
+#if __IS_UL1D_ETM_SUPPORT__
+const Ul1CustomDynamicInitMipiEtmData *ul1d_mipiEtmData_array_ptr;
+#endif   // #if __IS_UL1D_ETM_SUPPORT__
+//const Ul1CustomDynamicInitUmtsFeSettingData *ul1d_RfFeRoute_array_ptr;
+const Ul1CustomDynamicInitUmtsCalData *ul1d_rf_calData_ptr;
+const Ul1CustomDynamicRfParameter *ul1d_rf_parameter_ptr;
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+const Ul1CustomDynamicDatFeatureByRat *ul1d_rf_dat_byRat_ptr;
+#endif
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+const Ul1CustomDynamicTasRoute *ul1d_rf_tas_route_ptr;
+const Ul1CustomDynamicTasFeatureByRat *ul1d_rf_tas_byRat_ptr;
+#if !IS_3G_UTAS_SUPPORT
+const Ul1CustomDynamicTasDb *ul1d_rf_tas_db_ptr;
+#if (IS_3G_MIPI_SUPPORT)
+const Ul1CustomDynamicTasMipiData *ul1d_rf_tas_mipiData_ptr;
+#endif
+#endif
+#if IS_3G_TAS_INHERIT_4G_ANT
+const Ul1CustomDynamicTasInheritLteAnt *ul1d_rf_tas_inherit_lte_ant_ptr;
+#endif
+#endif
+
+#if IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT
+const Ul1CustomDynamicSARBackoffData *ul1d_rf_SARBackoffData_ptr;
+#endif
+
+#if IS_3G_TX_POWER_OFFSET_SUPPORT
+const Ul1CustomDynamicTpoData *ul1d_rf_tpoData_ptr;
+#endif
+#if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+const Ul1CustomDynamicNsftTpoData *ul1d_rf_nsftTpoData_ptr;
+#endif
+#if(IS_3G_RX_POWER_OFFSET_SUPPORT)
+const Ul1CustomDynamicRpoData *ul1d_rf_rpoData_ptr;
+#endif
+#if (__IS_UL1D_DPD_SUPPORT__)
+const Ul1CustomDynamicInitUmtsDpdfactoryData *ul1d_rf_dpd_data_ptr;
+#endif
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+const Ul1CustomDynamicRfeqCoefData *ul1d_rf_rfeqCoefData_ptr;
+#endif
+#if IS_3G_RFEQ_REAL_COEF_TEST
+const Ul1CustomDynamicRealRfeqCoefData *ul1d_rf_realRfeqCoefData_ptr;
+#endif
+#endif/*IS_3G_DRDI_SUPPORT*/
+
+
+void nvram_UL1D_DrdiPWRONCAL(kal_uint16 setIdx)
+{
+#ifdef __MTK_TARGET__
+#if (IS_3G_DRDI_SUPPORT)
+#if IS_3G_SUPPORT_8_BANDINDICATOR    
+   kal_uint8 loop;
+   for(loop=0;loop<MAX_SUPPORTED_BAND_INDEX;loop++)
+   {
+      UMTS_PWRON_CAL_DATA_PTR[loop+1] = ul1PwrOnCalData[setIdx][loop];
+   }
+#else
+   UMTS_PWRON_CAL_DATA_PTR[1] = ul1PwrOnCalData[setIdx][0];
+   UMTS_PWRON_CAL_DATA_PTR[2] = ul1PwrOnCalData[setIdx][1];
+   UMTS_PWRON_CAL_DATA_PTR[3] = ul1PwrOnCalData[setIdx][2];
+   UMTS_PWRON_CAL_DATA_PTR[4] = ul1PwrOnCalData[setIdx][3];
+   UMTS_PWRON_CAL_DATA_PTR[5] = ul1PwrOnCalData[setIdx][4];
+#endif/*IS_3G_SUPPORT_8_BANDINDICATOR*/
+#endif/*IS_3G_DRDI_SUPPORT*/
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+void nvram_UL1D_DrdiPointerInit(kal_uint16 setIdx)
+{
+#ifdef __MTK_TARGET__
+#if (IS_3G_DRDI_SUPPORT)
+#if IS_3G_SUPPORT_8_BANDINDICATOR    
+   kal_uint8 loop;
+   /*Band indicator assign*/ 
+   for(loop=0;loop<MAX_SUPPORTED_BAND_INDEX;loop++)
+   {
+      ul1d_BandInfo[loop] = ul1CustomBand[setIdx][loop];
+   }
+#else    
+   ul1d_BandInfo[0] = ul1CustomBand[setIdx][0];
+   ul1d_BandInfo[1] = ul1CustomBand[setIdx][1];
+   ul1d_BandInfo[2] = ul1CustomBand[setIdx][2];
+   ul1d_BandInfo[3] = ul1CustomBand[setIdx][3];
+   ul1d_BandInfo[4] = ul1CustomBand[setIdx][4];  
+#endif  
+
+   /*calibration data pointer table assign*/ 
+   ul1d_rf_calData_ptr = &(ul1CustomUmtsCalData[setIdx]);
+   
+   #if (IS_3G_MIPI_SUPPORT)
+   /*MIPI data pointer table assign*/ 
+   //ul1d_mipiData_array_ptr = &(ul1CustomMipiData[setIdx]);
+   #if __IS_UL1D_ETM_SUPPORT__
+   ul1d_mipiEtmData_array_ptr = &( ul1CustomMipiEtmData[ setIdx ] );
+   #endif   // #if __IS_UL1D_ETM_SUPPORT__   
+   #endif
+
+   /*RF Front end route table pointer assign*/ 
+   //ul1d_RfFeRoute_array_ptr = &(ul1CustomUmtsFeSettingData[setIdx]);
+
+   /*RF Parameter*/
+   ul1d_rf_parameter_ptr = &(ul1CustomUmtsRfParameter[setIdx]);
+
+   #if (IS_3G_DAT_UL1_CUSTOM_SUPPORT)
+   ul1d_rf_dat_byRat_ptr = &(ul1CustomDatByRat[setIdx]);
+   #endif
+
+   #if (IS_3G_TAS_UL1_CUSTOM_SUPPORT)
+   ul1d_rf_tas_route_ptr = &(ul1CustomTasRoute[setIdx]);
+   ul1d_rf_tas_byRat_ptr = &(ul1CustomTasByRat[setIdx]);
+   #if !IS_3G_UTAS_SUPPORT
+   ul1d_rf_tas_db_ptr = &(ul1CustomTasDb[setIdx]);
+   #if (IS_3G_MIPI_SUPPORT)
+   ul1d_rf_tas_mipiData_ptr = &(ul1CustomTasMipiData[setIdx]);
+   #endif
+   #endif
+   #if IS_3G_TAS_INHERIT_4G_ANT
+   ul1d_rf_tas_inherit_lte_ant_ptr= &(ul1CustomTasInheritLteAnt[setIdx]);
+   #endif
+   #endif
+
+    #if IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT
+      ul1d_rf_SARBackoffData_ptr = &(ul1CustomSARBackoffData[setIdx]);
+   #endif
+   
+
+   #if IS_3G_TX_POWER_OFFSET_SUPPORT 
+   ul1d_rf_tpoData_ptr = &(ul1CustomTpoData[setIdx]);
+   #endif
+   
+   #if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+   ul1d_rf_nsftTpoData_ptr = &(ul1CustomNsftTpoData[setIdx]);
+   #endif
+
+   #if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+   ul1d_rf_rpoData_ptr = &(ul1CustomRpoData[setIdx]);
+   #endif
+
+   #if __IS_UL1D_DPD_SUPPORT__
+   ul1d_rf_dpd_data_ptr = &(ul1CustomUmtsDpdFactoryData[setIdx]);  
+   #endif   
+
+   #if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+   ul1d_rf_rfeqCoefData_ptr = &(ul1CustomRfeqCoefData[setIdx]);
+   #endif
+
+   #if (IS_3G_RFEQ_REAL_COEF_TEST)
+   ul1d_rf_realRfeqCoefData_ptr = &(ul1CustomRealRfeqCoefData[setIdx]);
+   #endif
+
+#endif/*IS_3G_DRDI_SUPPORT*/
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+void nvram_UL1D_Drdi(void)
+{
+#ifdef __MTK_TARGET__
+#if (IS_3G_DRDI_SUPPORT)
+   if(!ul1d_DRDI_had_done)
+   {
+      if(isWcdmaDrdiEnable)
+      {
+         kal_uint16 setIdx;
+         setIdx = MML1_RF_DRDI_Dynamic_GetParamAddr(MML1_RF_3G_FDD);
+         /* set the pointer to RF custom data by set index */
+         nvram_UL1D_DrdiPointerInit(setIdx);
+         //UL1D_RF_DynamicCustomTable_Update(ul1d_RfFeRoute_array_ptr);
+         UL1D_RF_DynamicSetRfBandSupport(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE);
+         UL1D_RF_DynamicSetRfParameter(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE,ul1d_rf_parameter_ptr);
+         nvram_UL1D_DrdiPWRONCAL(setIdx);
+	
+   #if IS_3G_RX_POWER_OFFSET_SUPPORT
+	      UL1D_RF_DynamicRxPowerOffset_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE, ul1d_rf_rpoData_ptr);
+   #endif
+      }
+      else
+      {
+         nvram_UL1D_DrdiPointerInit(0);
+      }
+      ul1d_DRDI_had_done = KAL_TRUE;
+   }
+#endif/*IS_3G_DRDI_SUPPORT*/
+#endif /* #ifdef __MTK_TARGET__ */
+}
+
+void nvram_get_uL1_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+#ifdef __MTK_TARGET__
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+//chliu
+    UMTSBand uband = UMTSBandNone;
+    kal_uint8 index_select;
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+    kal_uint8 loop;
+#endif
+    ul1cal_tempdacData_T  *tempdac;
+    ul1cal_pathlossData_T *pathloss;
+    ul1cal_txdacData_T    *txdac;
+/* end of chliu */
+    ul1cal_txPrachTmCompData_T *txPrachTmComp;
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    ul1cal_txPaOctLevData_T *pacoctlev_handle;
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+    UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T  *pwroncal;
+
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+   nvram_UL1D_Drdi();
+
+   /* Do not need to get band indicator prior to get UL1 default value if user
+    * modifies setting by Modem Bin Update Tool, since in MT6573/MT6276 3G RF
+    * customization scenario the band indicator in run-time directly modified
+    * by customer via Modem Bin Update tool or via ul1d_custom_rf.h
+    */
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+   for(loop=0;loop<MAX_SUPPORTED_BAND_INDEX;loop++)
+   {
+      ul1d_BandInfo[loop] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.BandIndicator[loop] ;     
+	  nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[loop]);
+   }
+#else
+   ul1d_BandInfo[0] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB1;
+   ul1d_BandInfo[1] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB2;
+   ul1d_BandInfo[2] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.HB3;
+   ul1d_BandInfo[3] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.LB1;
+   ul1d_BandInfo[4] = UMTS_RF_CUSTOM_INPUT_DATA_PCORE.umtsBandIndicator.LB2; 
+
+   /* Produce band to band indicator mapping array */
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[0]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[1]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[2]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[3]);
+   nvram_sort_uL1_band_bandind_mapping(ul1d_BandInfo[4]);
+#endif/*IS_3G_SUPPORT_8_BANDINDICATOR*/
+#endif /* #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__) */
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch (lid)
+    {
+//chliu
+        case NVRAM_EF_UL1_TEMP_DAC_LID:
+            #if 0
+/* under construction !*/
+/* under construction !*/
+            #else
+               #if (IS_3G_DRDI_SUPPORT)
+            kal_mem_cpy(buffer, ul1d_rf_calData_ptr->TempDac_p, sizeof(ul1cal_tempdacData_T));            
+            UNUSED(tempdac);
+               #else
+            kal_mem_cpy(buffer, U_TEMP_DAC_SetDefault, sizeof(ul1cal_tempdacData_T));            
+            UNUSED(tempdac);
+               #endif
+            #endif
+            break;
+        case NVRAM_EF_UL1_PATHLOSS_BAND1_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND2_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND3_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND4_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND5_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND6_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND7_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND8_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND9_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND10_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND11_LID:
+        case NVRAM_EF_UL1_PATHLOSS_BAND19_LID:
+            {
+               pathloss = (ul1cal_pathlossData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PATHLOSS_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RxPathLoss_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RxPathLoss_p[index_select], sizeof(ul1cal_pathlossData_T));
+                  UNUSED(pathloss);
+               }
+            #else
+               if (U_AGC_PATHLOSS_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_AGC_PATHLOSS_TABLE_SetDefault[index_select], sizeof(ul1cal_pathlossData_T));
+                  UNUSED(pathloss);
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_TXDAC_BAND1_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND2_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND3_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND4_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND5_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND6_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND7_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND8_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND9_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND10_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND11_LID:
+        case NVRAM_EF_UL1_TXDAC_BAND19_LID:
+            {
+               txdac = (ul1cal_txdacData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXDAC_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RampData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RampData_p[index_select], sizeof(U_sRAMPDATA));
+                  UNUSED(txdac);
+               }
+            #else
+               if (UMTS_RampData_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RampData_SetDefault[index_select], sizeof(U_sRAMPDATA));
+                  UNUSED(txdac);
+               }
+            #endif
+            }
+            break;
+/* end of chliu */
+#if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+        /* PA 8-level control */
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND2_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND3_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND4_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND5_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND6_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND7_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND8_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND9_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND10_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND11_LID:
+        case NVRAM_EF_UL1_TXPAOCTLEV_BAND19_LID:
+            {
+               pacoctlev_handle = (ul1cal_txPaOctLevData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPAOCTLEV_BAND1_LID);         
+               index_select = RF_GET_CAL_DATA_ARRAY_BAND_IDX(uband, KAL_TRUE);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaOctLev_p[index_select] != 0)
+               {
+                   kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaOctLev_p[index_select], sizeof(U_sPAOCTLVLSETTING));
+                   UNUSED(pacoctlev_handle);
+               }
+            #else
+               if (U_PA_OCTLEV_TABLE_SetDefault[index_select] != 0)
+               {
+                   kal_mem_cpy(buffer, U_PA_OCTLEV_TABLE_SetDefault[index_select], sizeof(U_sPAOCTLVLSETTING));
+                   UNUSED(pacoctlev_handle);
+               }
+            #endif
+            }
+            break;
+        /* End of PA 8-level control */
+        case NVRAM_EF_UL1_3G_RF_PARAMETER_LID:
+            //UL1D_RF_UpdateDatabaseTable();
+            //UL1D_RF_CA_CustomData_Update(&UMTS_RF_CUSTOM_INPUT_DATA_PCORE);
+            kal_mem_cpy(buffer, &UMTS_RF_CUSTOM_INPUT_DATA_PCORE, sizeof(U_sUl1dRfCustomInputData));            
+            break;
+
+#endif // #if defined (__UL1_HS_PLATFORM__) || defined (__UL1_HS_PLUS_PLATFORM__)
+
+#if defined(__UMTS_R8__) //add by Jay
+        case NVRAM_EF_UL1_PATHLOSS2_BAND1_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND2_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND3_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND4_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND5_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND6_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND7_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND8_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND9_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND10_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND11_LID:
+        case NVRAM_EF_UL1_PATHLOSS2_BAND19_LID:
+            {
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PATHLOSS2_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->RxDPathLoss_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->RxDPathLoss_p[index_select], sizeof(ul1cal_pathlossRxdData_T));
+               }
+            #else
+               if (U_AGC_PATHLOSS_RXD_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_AGC_PATHLOSS_RXD_TABLE_SetDefault[index_select], sizeof(ul1cal_pathlossRxdData_T));
+               }
+            #endif
+            }
+            break;
+   //add by wilson for pa drift compensation
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND2_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND3_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND4_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND5_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND6_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND7_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND8_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND9_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND10_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND11_LID:
+        case NVRAM_EF_UL1_TXPADRIFTCOMP_BAND19_LID:
+            {
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPADRIFTCOMP_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaDrift_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaDrift_p[index_select], sizeof(ul1cal_txPaDriftCompData_T));
+               }
+            #else
+               if (U_PA_DRIFT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_PA_DRIFT_TABLE_SetDefault[index_select], sizeof(ul1cal_txPaDriftCompData_T));
+               }
+            #endif
+            }
+            break;
+#endif //defined(__UMTS_R8__)
+
+        /** Tx PRACH TM Compensation */
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND2_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND3_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND4_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND5_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND6_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND7_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND8_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND9_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND10_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND11_LID:
+        case NVRAM_EF_UL1_TXPRACHTMCOMP_BAND19_LID:
+            {
+               txPrachTmComp = (ul1cal_txPrachTmCompData_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPRACHTMCOMP_BAND1_LID);
+
+               index_select = band_to_bandInd_map_table[uband];
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_calData_ptr->PaRachComp_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_calData_ptr->PaRachComp_p[index_select], sizeof(ul1cal_txPrachTmCompData_T));
+                  UNUSED(txPrachTmComp);
+               }
+            #else
+               if (U_PA_RACH_COMP_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_PA_RACH_COMP_TABLE_SetDefault[index_select], sizeof(ul1cal_txPrachTmCompData_T));
+                  UNUSED(txPrachTmComp);
+               }
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_AFCDAC_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_calData_ptr->AfcDac_p, sizeof(ul1cal_afcDacData_T));
+            #else
+               kal_mem_cpy(buffer, &U_AFC_DAC_SetDefault, sizeof(ul1cal_afcDacData_T));
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_AFCCAP_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_calData_ptr->AfcCap_p, sizeof(ul1cal_afcCapData_T));
+            #else
+               kal_mem_cpy(buffer, &U_AFC_CAP_SetDefault, sizeof(ul1cal_afcCapData_T));
+            #endif
+            }
+            break;
+
+        case NVRAM_EF_UL1_PWRONCAL_BAND1_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND2_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND3_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND4_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND5_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND6_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND7_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND8_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND9_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND10_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND11_LID:
+        case NVRAM_EF_UL1_PWRONCAL_BAND19_LID:
+            {
+               pwroncal = (UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T*) buffer;
+               uband = UMTSBand1 + (lid - NVRAM_EF_UL1_PWRONCAL_BAND1_LID);
+               index_select = band_to_bandInd_map_table[uband];
+
+               if (UMTS_PWRON_CAL_DATA_PTR[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_PWRON_CAL_DATA_PTR[index_select], sizeof(UMTS_RF_POWER_ON_CAL_DATA_PER_BAND_T));
+                  UNUSED(pwroncal);
+               }
+            }
+            break;
+
+#if IS_3G_REMOVE_MIPI
+#if (IS_3G_MIPI_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR			  		  		  	 			
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_TPC_ROUTE8_LID: 
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TPC_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->tpcTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->tpcTable_p[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #else
+               if (UMTS_MIPI_TPC_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TPC_TABLE_SetDefault[index_select], sizeof(ul1mipi_tpcData_T));            
+               }
+            #endif
+            }
+            break;
+#endif
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR			
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE8_LID:	
+#endif 			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_EVENT_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->rxEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->rxEventTable_p[index_select], sizeof(ul1mipi_rxEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_RX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_RX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_rxEvent_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR						
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE8_LID:	
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_RX_DATA_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->rxDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->rxDataTable_p[index_select], sizeof(ul1mipi_rxData_T));
+               }
+            #else
+               if (UMTS_MIPI_RX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_RX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_rxData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR									
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE8_LID:	
+#endif 			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_EVENT_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->txEventTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->txEventTable_p[index_select], sizeof(ul1mipi_txEvent_T));
+               }
+            #else
+               if (UMTS_MIPI_TX_EVENT_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TX_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_txEvent_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR												
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE8_LID:
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_TX_DATA_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->txDataTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->txDataTable_p[index_select], sizeof(ul1mipi_txData_T));
+               }
+            #else
+               if (UMTS_MIPI_TX_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_TX_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_txData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE1_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE2_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE3_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE4_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR															
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE6_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE7_LID:
+        case NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE8_LID:
+#endif			
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_MIPI_ASM_ISOLATION_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_mipiData_array_ptr->asmIsoTable_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_mipiData_array_ptr->asmIsoTable_p[index_select], sizeof(ul1mipi_asmIsoData_T));
+               }
+            #else
+               if (UMTS_MIPI_ASM_ISOLATION_DATA_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_MIPI_ASM_ISOLATION_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_asmIsoData_T));
+               }
+            #endif
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_INIT_CW_LID:
+            {
+               /*Useless NVRAM ID(Moved to MML1), do nothing*/
+            }
+            break;
+        case NVRAM_EF_UL1_MIPI_SLEEP_CW_LID:
+            {
+               /*Useless NVRAM ID(Moved to MML1), do nothing*/
+            }
+            break;
+
+#endif/*IS_3G_MIPI_NVRAM_FULL_SUPPORT*/
+#endif/*IS_3G_REMOVE_MIPI*/
+
+#if IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT
+         /* Tx power offset table 1 */
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE1_LID:
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE2_LID:
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE3_LID:
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE4_LID:
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR					 	
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE6_LID:
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE7_LID:
+         case NVRAM_EF_UL1_SARBACKOFF_ROUTE8_LID:
+#endif
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_SARBACKOFF_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_SARBackoffData_ptr->sarBackoffData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_SARBackoffData_ptr->sarBackoffData_p[index_select], sizeof(U_sSARBackoffDATA));
+               }
+            #else
+               if (U_SAR_BACKOFF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_SAR_BACKOFF_TABLE_SetDefault[index_select], sizeof(U_sSARBackoffDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_SAR_TX_POWER_BACKOFF_SUPPORT */
+
+
+#if IS_3G_TX_POWER_OFFSET_SUPPORT 
+         /* Tx power offset table 1 */
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE1_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE2_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE3_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE4_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR					 	
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE6_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE7_LID:
+         case NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE8_LID:
+#endif		 	
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_TXPOWEROFFSET_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_tpoData_ptr->TpoData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_tpoData_ptr->TpoData_p[index_select], sizeof(U_sTXPOWEROFFSETDATA));
+               }
+            #else
+               if (U_TX_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_TX_POWER_OFFSET_TABLE_SetDefault[index_select], sizeof(U_sTXPOWEROFFSETDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_TX_POWER_OFFSET_SUPPORT */
+
+#if IS_3G_TX_NSFT_POWER_OFFSET_SUPPORT
+         /* Tx NSFT power offset table */
+         case NVRAM_EF_UL1_TXNSFTPOWEROFFSET_LID:
+            {
+               U_sTXNSFTPOWEROFFSETDATA_ALLBAND nsftTpo_allband;
+
+               for(index_select = 0; index_select<UL1D_RF_CUSTOM_BAND; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if (ul1d_rf_nsftTpoData_ptr->nsftTpoData_p[index_select] != 0)
+                  {
+                     nsftTpo_allband.nsftTpoTable[index_select] = *(ul1d_rf_nsftTpoData_ptr->nsftTpoData_p[index_select]);
+                  }
+               #else
+                  if (U_TX_NSFT_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+                  {
+                     nsftTpo_allband.nsftTpoTable[index_select] = *(U_TX_NSFT_POWER_OFFSET_TABLE_SetDefault[index_select]);
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &nsftTpo_allband, sizeof(U_sTXNSFTPOWEROFFSETDATA_ALLBAND));
+            }
+            break;
+#endif
+
+#if (IS_3G_RX_POWER_OFFSET_SUPPORT)
+         /* Rx power offset table */
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE1_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE2_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE3_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE4_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR					 	
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE6_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE7_LID:
+         case NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE8_LID:	
+#endif		 	
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RXPOWEROFFSET_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_rpoData_ptr->RpoData_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_rpoData_ptr->RpoData_p[index_select], sizeof(U_sRXPOWEROFFSETDATA));
+               }
+            #else
+               if (U_RX_POWER_OFFSET_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, U_RX_POWER_OFFSET_TABLE_SetDefault[index_select], sizeof(U_sRXPOWEROFFSETDATA));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RX_POWER_OFFSET_SUPPORT */
+#if IS_3G_DAT_UL1_CUSTOM_SUPPORT
+       case NVRAM_EF_UL1_DAT_FEATURE_BY_RAT_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, &ul1d_rf_dat_byRat_ptr->dat_feature_byRat, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_DAT_FEATURE_BY_RAT_SetDefault, sizeof(UMTS_CUSTOM_DAT_FEATURE_BY_RAT_T));
+            #endif
+            }
+            break;
+#endif /*IS_3G_DAT_UL1_CUSTOM_SUPPORT*/
+#if IS_3G_TAS_UL1_CUSTOM_SUPPORT
+       case NVRAM_EF_UL1_TAS_FEATURE_BY_RAT_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, &ul1d_rf_tas_byRat_ptr->tas_feature_byRat, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_TAS_FEATURE_BY_RAT_SetDefault, sizeof(UMTS_CUSTOM_TAS_FEATURE_BY_RAT_T));
+            #endif
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_FE_ROUTE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(buffer, ul1d_rf_tas_route_ptr->tas_fe_route, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T));
+            #else
+               kal_mem_cpy(buffer, &UMTS_TAS_FE_ROUTE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_TAS_FE_ROUTE_DATA_T));
+            #endif
+            }
+            break;
+#if !IS_3G_UTAS_SUPPORT
+       case NVRAM_EF_UL1_TAS_FE_DATABASE_LID:
+            {
+            #if (IS_3G_DRDI_SUPPORT)
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_a_fe_db, ul1d_rf_tas_db_ptr->tas_cat_a_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_A_T));
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_b_fe_db, ul1d_rf_tas_db_ptr->tas_cat_b_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_B_T));
+               kal_mem_cpy(&UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_c_fe_db, ul1d_rf_tas_db_ptr->tas_cat_c_fe_db, sizeof(UMTS_CUSTOM_TAS_FE_CAT_C_T));
+            #else
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_a_fe_db = UMTS_TAS_CAT_A_DATABASE_SetDefault;
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_b_fe_db = UMTS_TAS_CAT_B_DATABASE_SetDefault;
+               UMTS_TAS_FE_DATABASE_SetDefault.tas_cat_c_fe_db = UMTS_TAS_CAT_C_DATABASE_SetDefault;
+            #endif
+               kal_mem_cpy(buffer, &UMTS_TAS_FE_DATABASE_SetDefault, sizeof(UMTS_CUSTOM_TAS_FE_DATABASE_T));
+            }
+            break;
+
+#if (IS_3G_MIPI_NVRAM_FULL_SUPPORT)
+       case NVRAM_EF_UL1_TAS_CAT_A_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatA_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catA_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catA_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_A_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_A_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatA_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_A_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catA_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catA_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_A_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatA_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_B_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatB_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catB_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catB_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_B_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_B_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatB_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_B_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catB_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catB_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_B_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatB_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_C_MIPI_EVENT_LID:
+            {
+               static ul1mipi_tasEvent_CatC_T ul1_rf_mipi_tas_event_buffer;
+               
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_C_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catC_eventTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], ul1d_rf_tas_mipiData_ptr->catC_eventTable_p[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_event_buffer.mipiTasEventRoute[index_select], UMTS_TAS_CAT_C_MIPI_EVENT_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasEvent_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_event_buffer, sizeof(ul1mipi_tasEvent_CatC_T));
+            }
+            break;
+
+       case NVRAM_EF_UL1_TAS_CAT_C_MIPI_DATA_LID:
+            {
+               static ul1mipi_tasData_CatC_T ul1_rf_mipi_tas_data_buffer;
+ 
+               for(index_select=0; index_select<UL1_MIPI_TAS_ROUTE_C_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  if(ul1d_rf_tas_mipiData_ptr->catC_dataTable_p[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], ul1d_rf_tas_mipiData_ptr->catC_dataTable_p[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #else
+                  if(UMTS_TAS_CAT_C_MIPI_DATA_TABLE_SetDefault[index_select] != 0)
+                  {
+                     kal_mem_cpy(&ul1_rf_mipi_tas_data_buffer.mipiTasDataRoute[index_select], UMTS_TAS_CAT_C_MIPI_DATA_TABLE_SetDefault[index_select], sizeof(ul1mipi_tasSubBandData_T));
+                  }
+               #endif
+               }
+
+               kal_mem_cpy(buffer, &ul1_rf_mipi_tas_data_buffer, sizeof(ul1mipi_tasData_CatC_T));
+            }
+            break;
+#endif
+#endif
+#if IS_3G_TAS_INHERIT_4G_ANT
+       case NVRAM_EF_UL1_TAS_INHERIT_LTE_ANT_LID:
+            {
+               UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T ul1d_rf_tas_inherit_lte_ant_buffer;
+               
+               for(index_select=0; index_select<UMTS_TAS_MAX_FE_ROUTE_NUM; index_select++)
+               {
+               #if (IS_3G_DRDI_SUPPORT)
+                  ul1d_rf_tas_inherit_lte_transform_bitmap(ul1d_rf_tas_inherit_lte_ant_ptr->inheritLteAntTable_p[index_select], &(ul1d_rf_tas_inherit_lte_ant_buffer.inherit_lte_band_bitmap_route[index_select]));
+               #else
+                  ul1d_rf_tas_inherit_lte_transform_bitmap(UMTS_TAS_INHERIT_LTE_ANT_TABLE_SetDefault[index_select], &(ul1d_rf_tas_inherit_lte_ant_buffer.inherit_lte_band_bitmap_route[index_select]));
+               #endif
+               }
+               kal_mem_cpy(buffer, &ul1d_rf_tas_inherit_lte_ant_buffer, sizeof(UMTS_CUSTOM_TAS_INHERIT_LTE_BAND_BITMAP_TABLE_T));
+            }
+            break;
+#endif
+#endif
+#if (IS_3G_RFEQ_COEF_SUBBAND_SUPPORT)
+         /* RFEQ Coefficient table 1 */
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE1_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE2_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE3_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE4_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE6_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE7_LID:
+         case NVRAM_EF_UL1_RFEQ_COEF_ROUTE8_LID:
+#endif
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_COEF_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_rfeqCoefData_ptr->rfeqCoef_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_rfeqCoefData_ptr->rfeqCoef_p[index_select], sizeof(hs_dsch_rfeq_info_band_T));
+               }
+            #else
+               if (UMTS_RFEQ_COEF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RFEQ_COEF_TABLE_SetDefault[index_select], sizeof(hs_dsch_rfeq_info_band_T));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RFEQ_COEF_SUBBAND_SUPPORT */
+#if (IS_3G_RFEQ_REAL_COEF_TEST)
+         /* RFEQ Coefficient table 1 */
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE1_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE2_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE3_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE4_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE5_LID:
+#if IS_3G_SUPPORT_8_BANDINDICATOR
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE6_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE7_LID:
+         case NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE8_LID:
+#endif
+            {
+               index_select = UMTSBand1 + (lid - NVRAM_EF_UL1_RFEQ_REAL_COEF_ROUTE1_LID);
+            #if (IS_3G_DRDI_SUPPORT)
+               if (ul1d_rf_realRfeqCoefData_ptr->realRfeqCoef_p[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, ul1d_rf_realRfeqCoefData_ptr->realRfeqCoef_p[index_select], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+               }
+            #else
+               if (UMTS_RFEQ_COEF_TABLE_SetDefault[index_select] != 0)
+               {
+                  kal_mem_cpy(buffer, UMTS_RFEQ_REAL_COEF_TABLE_SetDefault[index_select], sizeof(URXDFE_REAL_RFEQ_CUSTOM_BAND_T));
+               }
+            #endif
+            }
+            break;
+#endif /* IS_3G_RFEQ_COEF_SUBBAND_SUPPORT */
+
+        default:
+            UL1_NVRAM_WARNING_AND_DEBUG_ASSERT(KAL_FALSE);
+            break;
+    }
+#endif /* #ifdef __MTK_TARGET__ */
+}
+#endif /* __UMTS_RAT__ && __MTK_UL1_FDD__ */
diff --git a/mcu/service/nvram/src/nvram_unzip.c b/mcu/service/nvram/src/nvram_unzip.c
new file mode 100644
index 0000000..659540d
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_unzip.c
@@ -0,0 +1,385 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *  nvram_unzip.c
+ *
+ * Project:
+ * -------- 
+ *  MAUI
+ *
+ * Description:
+ * ------------
+ *  	nvram default value  unzip interface, the zilb working buffer is form PLUTOMMI, 
+ *		so this feature only can be supported on PLUTOMMI right now.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#ifdef __NVRAM_COMPRESS_SUPPORT__
+
+/*****************************************************************************
+ * Header file  
+ *****************************************************************************/
+#include "kal_general_types.h"
+#include "kal_trace.h"
+
+#include "nvram_defs.h"
+#include "nvram_trc.h"
+#include "nvram_util.h"
+
+#include "app_zlib.h"
+#include "simple_memory_manager.h"
+#include "nvram_default_value.h"
+#include "nvram_enums.h"
+#include "nvram_main.h"
+
+/*****************************************************************************
+ * Typedef  
+ *****************************************************************************/
+typedef enum{
+	RET_OK, 
+	RET_STOP, 
+	RET_OOM, 
+	RET_TOTAL
+	}Ret;
+	
+typedef Ret (*visit_funcptr)(void *data, void* usr_data);
+
+/*****************************************************************************
+ * Define
+ *****************************************************************************/
+#ifndef NVRAM_DEBUG
+#define NVRAM_UNZIP_LOG0(grp) 			  NVRAM_LOG0(TRACE_FUNC, grp);
+#define NVRAM_UNZIP_LOG1(grp, x) 		  NVRAM_LOG1(TRACE_FUNC, grp, x);
+#define NVRAM_UNZIP_LOG3(grp, x1, x2, x3) NVRAM_LOG3(TRACE_FUNC, grp, x1, x2, x3);
+#else
+#define NVRAM_UNZIP_LOG0(grp) 			  nvram_trace_to_file(__LINE__, 0, 0, 308);
+#define NVRAM_UNZIP_LOG1(grp, x) 		  nvram_trace_to_file(__LINE__, x, 0, 308);
+#define NVRAM_UNZIP_LOG3(grp, x1, x2, x3) nvram_trace_to_file(__LINE__, x1, x2, x3);
+#endif
+
+#define NVRAM_ZLIB_BUFF_SIZE (80*1024)
+#define RETURN_IF_FAIL(p) if(!(p)){NVRAM_UNZIP_LOG1(ABNORMAL_RETURN, __LINE__); return;}
+#define RETURN_VAL_IF_FAIL(p, val) if(!(p)){NVRAM_UNZIP_LOG1(ABNORMAL_RETURN, __LINE__); return val;}
+
+#define CONV_4BYTES_TO_INT(b, i) (i = ((b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3]))
+#define CONV_INT_TO_4BYTES(b, i) \
+			b[0] = (kal_uint8)(i >> 24); \
+			b[1] = (kal_uint8)(i >> 16); \
+			b[2] = (kal_uint8)(i >> 8); \
+			b[3] = (kal_uint8)i;
+
+
+#define NVRAM_UNZIP_BUFFER_SIZE (NVRAM_MAX_DEFAULE_VALUE_SIZE + 32)
+
+/*****************************************************************************
+ * Global Variables 
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ * Global Function 
+ *****************************************************************************/
+/* Before MMI task init, we can use this pool */
+extern kal_uint8* mmi_frm_scrmem_get_pool(kal_uint32 *size);
+
+/*****************************************************************************
+ * Local Variables 
+ *****************************************************************************/
+
+static STSMM nvram_unzip_smm;
+static kal_uint32 g_nvram_curr_lid;
+
+/*****************************************************************************
+ * Local Function 
+ *****************************************************************************/
+static void *nvram_unzip_mem_malloc(void *opaque, kal_uint32 items, kal_uint32 size);
+static void nvram_unzip_mem_free(void *opaque, void *address);
+
+/*****************************************************************************
+ * FUNCTION
+*   nvram_unzip_org_size
+ * DESCRIPTION
+*   To check whether the entry can be compressed
+ * PARAMETERS
+*   entry		[IN]		the logical table
+ * RETURNS
+ *  kal_bool
+ *****************************************************************************/
+kal_uint32 nvram_unzip_org_size(const ltable_entry_struct *entry)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                					   */
+    /*----------------------------------------------------------------*/
+	
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      					   */
+    /*----------------------------------------------------------------*/
+    RETURN_VAL_IF_FAIL(entry != NULL, KAL_FALSE);
+
+	g_nvram_curr_lid = entry->LID;
+    if (NVRAM_IS_ATTR_MULTI_DEFAULT(entry->attr))
+    {
+		return (entry->size * entry->total_records);
+    }
+	
+    return entry->size;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_unzip_default_value
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *	unzip_buffer	[OUT]	just a pointer, the memory will be keep at working buffer.
+ *	unzip_size	[OUT]
+ *	buffer		[IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void nvram_unzip_default_value(kal_uint8 **unzip_buffer, kal_uint32 *unzip_size, kal_uint8 const *buffer)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                					   */
+    /*----------------------------------------------------------------*/
+	kal_uint32 out_size;
+	kal_int32 ret, i;
+	kal_uint32 compress_len;
+	kal_uint32 buffer_len;
+	kal_uint8 *out_ptr;
+	
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      					   */
+    /*----------------------------------------------------------------*/
+	RETURN_IF_FAIL(unzip_buffer != NULL);
+	RETURN_IF_FAIL(buffer != NULL);
+
+	out_ptr = mmi_frm_scrmem_get_pool(&buffer_len);
+	smmInit(&nvram_unzip_smm, out_ptr + NVRAM_UNZIP_BUFFER_SIZE, buffer_len);
+
+	CONV_4BYTES_TO_INT(buffer, compress_len);
+    NVRAM_EXT_ASSERT(buffer_len > compress_len,(kal_uint32)buffer_len,NVRAM_LOC_BUFFER_SIZE_NOT_ENOUGH_4, compress_len);
+
+	out_size = NVRAM_UNZIP_BUFFER_SIZE;
+	
+	ret = uncompress_mtk(out_ptr,	 
+					    (uLongf *)&out_size,
+					    buffer + 4, /* sizeof(kal_uint32) = 4*/
+					    compress_len,
+					    nvram_unzip_mem_malloc, 
+					    nvram_unzip_mem_free);	
+
+	NVRAM_UNZIP_LOG3(UNZIP_RESULT, compress_len, out_size, ret);
+	
+    NVRAM_EXT_ASSERT (ret == Z_OK, ret, NVRAM_LOC_ACCESS_UNCOMPRESS_FILE_FAIL_1, g_nvram_curr_lid);
+
+    /* user prepare the output buffer by themselves */
+    if (*unzip_size && *unzip_buffer)
+    {
+        NVRAM_EXT_ASSERT(*unzip_size == out_size, *unzip_size, NVRAM_LOC_BUFFER_SIZE_NOT_ENOUGH_5, out_size);
+        kal_mem_cpy(*unzip_buffer, out_ptr, out_size);
+    }
+    else
+    {
+    	*unzip_size = out_size;
+    	*unzip_buffer = out_ptr;
+    }
+}
+
+
+/*****************************************************************************
+* FUNCTION
+*   nvram_unzip_check
+* DESCRIPTION
+*   To check whether the entry can be compressed
+* PARAMETERS
+*   entry		[IN]		the logical table
+* RETURNS
+*   kal_bool
+*****************************************************************************/
+kal_bool nvram_unzip_check(const ltable_entry_struct *entry)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                					   */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      					   */
+    /*----------------------------------------------------------------*/
+	RETURN_VAL_IF_FAIL(entry != NULL, KAL_FALSE);
+
+	/* No data */
+	if (entry->LID == 0 || 
+		entry->size == 0 || 
+		entry->total_records == 0)
+	{
+		return KAL_FALSE;
+	}
+	
+	/* always compress custpack entry */
+	if (NVRAM_IS_CATEGORY_CUSTPACK(entry->category) ||
+		NVRAM_IS_ATTR_ZIP_DEFAULT(entry->attr))
+	{
+		return KAL_TRUE;
+	}
+
+	return KAL_FALSE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_unzip_mem_malloc
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  opaque	[IN]
+ *  items		[IN]
+ *  size		[IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void *nvram_unzip_mem_malloc(void *opaque, kal_uint32 items, kal_uint32 size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                					   */
+    /*----------------------------------------------------------------*/
+	unsigned int total_bytes;
+	void *buffer_ptr;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      					   */
+    /*----------------------------------------------------------------*/
+   if (opaque)
+   {
+	  items += size - size;   /// make compiler happy
+   }
+   total_bytes = items * size;
+
+#if 1
+   buffer_ptr = smmMallocAligned(&nvram_unzip_smm, total_bytes, 4);
+#else
+/* under construction !*/
+#endif
+
+   return buffer_ptr;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_unzip_mem_free
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  opaque	[IN]
+ *  address	[IN]
+ * RETURNS
+ *  void
+ *****************************************************************************/
+static void nvram_unzip_mem_free(void *opaque, void *address)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                					   */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      					   */
+    /*----------------------------------------------------------------*/
+   return;
+}
+
+#endif /* __NVRAM_COMPRESS_SUPPORT__ */
+
diff --git a/mcu/service/nvram/src/nvram_ut_test.c b/mcu/service/nvram/src/nvram_ut_test.c
new file mode 100644
index 0000000..23f2c4d
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_ut_test.c
@@ -0,0 +1,16322 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_ut_test.c
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ ****************************************************************************/
+#if defined (__NVRAM_UT_TEST__)
+
+
+#include "nvram_main.h"
+#include "nvram_interface.h"
+#include "nvram_struct.h"
+#include "nvram_msgid.h"
+#include "nvram_io.h"
+#include "syscomp_config.h"
+#include "svc_sap.h"
+#include "nvram_editor_data_item.h"
+#include "nvram_group_editor.h" //add for break group files from header file
+#include "us_timer.h"
+#include "tst_sap.h"
+#include "tst_msgid.h"
+#include "math.h"
+#include "stdlib.h"
+
+#ifdef __NVRAM_LID_CACHE__
+#include "nvram_cache_interface.h"
+#endif
+
+#include "ex_public.h"
+
+#define nvram_ut_trace(...) kal_prompt_trace(MOD_NVRAM, __VA_ARGS__)
+#define NVRAM_MAX_OP_BUFFER_SIZE    63*1024
+#define NVRAM_EF_SW_VERNO_LID   NVRAM_EF_SYS_LID
+#define SW_VERNO_RECORD_NUMBER  1
+#define RECORD_CHANGE_SIZE  2
+
+
+/*
+2 is an error number
+this define is used to make meesage and external API return back value agreement
+External API: KAL_TRUE: success, KAL_FALSE: fail
+Message: 0: success, others: fail
+*/
+#define agreement_return_value(value) \
+        if(KAL_TRUE == value)\
+            value = NVRAM_ERRNO_SUCCESS;\
+        else\
+            value = 0x2\
+
+typedef kal_bool (*ut_testcase_fn_ptr)(kal_uint32 flags, void *param);
+typedef struct
+{
+    ut_testcase_fn_ptr _main_fn;
+    kal_uint32         flags;
+    void               *para;
+    kal_char           *description;
+    kal_char           *testplan_section;
+}ut_testcase_struct;
+
+typedef struct
+{
+    kal_uint32 test_case_lst[10][20];
+    kal_uint8 break_test_case_num; //user may set test case list as: 2.1 2.2 2.3
+    kal_uint8 sub_test_case_num; //test may break at 2.2.1.1, and this is sub case of 2.2
+    kal_uint8 valid_test_case_num_total;
+    kal_uint8 context_is_valid; //mark whether this log is valid
+    kal_uint32 tst_time_consume;
+    kal_uint32 total_case_number;
+    kal_uint32 fail_case_number;
+}factory_test_context_struct;
+
+typedef struct
+{
+    kal_uint32 start_record_size; //from start_record_size to end_record_size will full cover
+    kal_uint32 end_record_size;
+}record_size_boundary_struct;
+
+typedef struct
+{
+    kal_uint32 start_record_number; //from start_record_size to end_record_size will full cover
+    kal_uint32 end_record_number;
+}record_number_boundary_struct;
+
+
+kal_uint32 test_lid_enum[]=
+{
+    NVRAM_EF_NVRAM_TEST_1_LID,
+    NVRAM_EF_NVRAM_TEST_2_LID,
+    NVRAM_EF_NVRAM_TEST_3_LID,
+    NVRAM_EF_NVRAM_TEST_4_LID,
+    NVRAM_EF_NVRAM_TEST_5_LID,
+    NVRAM_EF_NVRAM_TEST_6_LID,
+};
+
+#ifdef __NVRAM_LID_CACHE__
+kal_uint32 cache_test_lid_enum[]=
+{
+    NVRAM_EF_INTERNAL_13_LID,
+    NVRAM_EF_INTERNAL_TEST_14_LID,    
+    NVRAM_EF_INTERNAL_TEST_16_LID,
+};
+kal_uint8 cache_test_lid_number = sizeof(cache_test_lid_enum)/sizeof(kal_uint32);
+#endif
+
+//  __NVRAM_ENHANCE_CHKSUM_ALGORITHM__
+#ifdef __NV_CHKSUM_ENHANCE__
+kal_uint32 chksum_algo_test_lid_list[] = 
+{
+	NVRAM_EF_NVRAM_TEST_1_LID,
+	NVRAM_EF_NVRAM_TEST_2_LID,
+	NVRAM_EF_NVRAM_TEST_3_LID,	//calibrate
+	NVRAM_EF_NVRAM_TEST_4_LID,	//important
+	NVRAM_EF_NVRAM_TEST_5_LID,
+	NVRAM_EF_NVRAM_TEST_6_LID,
+	NVRAM_EF_NVRAM_TEST_8_LID,
+	NVRAM_EF_INTERNAL_TEST_14_LID,
+	NVRAM_EF_INTERNAL_TEST_16_LID,	//calibrate
+	NVRAM_EF_INTERNAL_TEST_17_LID,
+};
+
+kal_uint32 chksum_algo_normal_list[] = 
+{
+	NVRAM_EF_NVRAM_TEST_1_LID,
+	NVRAM_EF_NVRAM_TEST_2_LID,
+	NVRAM_EF_NVRAM_TEST_5_LID,
+	NVRAM_EF_NVRAM_TEST_6_LID,
+	NVRAM_EF_NVRAM_TEST_8_LID,
+	NVRAM_EF_INTERNAL_13_LID,
+	NVRAM_EF_INTERNAL_TEST_17_LID
+};
+
+kal_uint32 chksum_algo_special_list[] = 
+{
+	NVRAM_EF_NVRAM_TEST_3_LID,
+	NVRAM_EF_NVRAM_TEST_4_LID,
+	NVRAM_EF_INTERNAL_TEST_16_LID
+};
+
+kal_uint8 chksum_algo_test_lid_number = sizeof(chksum_algo_test_lid_list)/sizeof(kal_uint32);
+kal_uint8 chksum_algo_normal_len = sizeof(chksum_algo_normal_list)/ sizeof(kal_uint32);
+kal_uint8 chksum_algo_special_len = sizeof(chksum_algo_special_list)/sizeof(kal_uint32);
+#endif
+// ------
+
+kal_uint8 test_case_list[10][20];
+kal_uint8 valid_test_case_num;
+kal_uint8 is_clean_boot_test;
+kal_taskid nvram_test_task1_id;
+kal_uint8 is_insulation_access;
+kal_uint32 nvram_ut_assert_flag;
+kal_uint8 factory_test_reboot_finish; //factory reset will reboot SP, this flag is used for mark reboot finish
+kal_uint8 manual_ota_reboot_finish;
+kal_uint8 test_number, sub_test_number; //mark test which test case is runing
+kal_uint32 nvram_boot_trace;
+kal_uint8 test_lid_number = sizeof(test_lid_enum)/sizeof(kal_uint32);
+//--------------------------------------------------------------------------------------------------------------------
+//kal_uint32 data_buffer[NVRAM_EF_TEST_LID_RECORD_TOTAL*NVRAM_EF_TEST_LID_SIZE/4 + 256]; //test LID total size + 4KB
+//kal_uint32 cmp_buffer[NVRAM_EF_TEST_LID_RECORD_TOTAL*NVRAM_EF_TEST_LID_SIZE/4 + 256];
+#define NVRAM_UT_BUFFER_SIZE (70 * 1024)
+kal_uint8 large_buffer[NVRAM_UT_BUFFER_SIZE]; // large buffer is for RAW data test, shared with data_buffer & cmp_buffer
+kal_uint32 *data_buffer = (kal_uint32*)large_buffer; 
+kal_uint32 *cmp_buffer = (kal_uint32*)(large_buffer + (NVRAM_EF_TEST_LID_RECORD_TOTAL*NVRAM_EF_TEST_LID_SIZE + 8192));
+#ifdef __NV_CHKSUM_ENHANCE__
+nvram_checksum_config chksum_config_backup;	//
+#endif
+
+typedef unsigned int nvram_large_buffer_check[NVRAM_UT_BUFFER_SIZE - 2*(NVRAM_EF_TEST_LID_RECORD_TOTAL*NVRAM_EF_TEST_LID_SIZE + 4096)];
+//--------------------------------------------------------------------------------------------------------------------
+kal_uint32 fail_case_num, total_case_num;
+kal_uint32 start_test_time, end_test_time, test_time_consume;
+kal_uint8 const table_default[NVRAM_EF_TEST_LID_RECORD_TOTAL][NVRAM_EF_TEST_LID_SIZE] = {
+    {0x01, },
+    {0x02, },
+    {0x03, },
+    {0x04, },
+    {0x05, },
+    {0x06, },
+    {0x07, },
+    {0x08, },
+    {0x09, },
+    {0x0A, },
+};
+
+extern void SST_Secure_Algo(kal_uint8 Direction, kal_uint32 ContentAddr,
+                        kal_uint32 ContentLen, kal_uint8 *CustomSeed,
+                        kal_uint8 *ResText); 
+extern kal_bool nvram_external_read_chksum_8b(nvram_lid_enum LID, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size);
+extern module_type stack_get_active_module_id( void );
+extern void nvram_internal_test_fun_default_value(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size);
+extern kal_mutexid g_nvram_fs_mutex;
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+#ifdef __NV_CHKSUM_ENHANCE__
+extern nvram_algo_info *chksum_algo_ptr;
+extern nvram_checksum_config NVRAM_CHK_CONFIG;
+#endif
+
+
+
+#ifdef __NVRAM_LID_CACHE__
+kal_bool check_lid_all_record_is_undirty_bit(nvram_ltable_entry_struct* ldi);
+kal_bool check_lid_all_record_is_invalid_bit(nvram_ltable_entry_struct* ldi);
+kal_bool unmask_lid_all_record_valid_bit(nvram_ltable_entry_struct* ldi);
+kal_bool unmask_lid_all_record_dirty_bit(nvram_ltable_entry_struct* ldi);
+kal_bool check_lid_all_record_is_valid_bit(nvram_ltable_entry_struct* ldi);
+kal_bool check_lid_all_record_is_dirty_bit(nvram_ltable_entry_struct* ldi);
+#endif
+
+void nvram_ut_get_default_value(nvram_lid_core_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size)
+{
+    kal_mem_set(buffer, 0x55, buffer_size);
+}
+
+/*
+    For factory reset, we want to the LIDs backup to binregion is not default value.
+    So this function will be called at nvram_init() end to modify the LID value.
+*/
+kal_bool nvram_write_test_lids()
+{
+    kal_uint8 i, j;
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    kal_mem_set(data_buffer, 0, NVRAM_EF_TEST_LID_SIZE);
+    data_buffer[0] = 0x1; //modify one data
+    
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            if(!nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+            {
+                return KAL_FALSE;
+            }
+        }
+    }
+    for(i = 0; i < cache_test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, cache_test_lid_enum[i]);
+        nvram_ut_trace("[NVUT] %s()ldi->LID:%x LID->attr=(%x) default_attr\n\r", __FUNCTION__, ldi->LID, ldi->attr);
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+            kal_mem_set(data_buffer, 0, ldi->size);
+            data_buffer[0] = j;
+            if(!nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+            {
+                return KAL_FALSE;
+            }
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+/*
+Description: nvram_lid_cmpt_operation is used to merge several LID operations together and return result.
+Parameters:
+    LID: LID enum value
+    operation_flag: this is 32-bit parameter and each 8-bit stand one kind of operation, parsing will start from high 8-bit -> low 8-bit
+        0x1: reset, 0x2: read(just read API return success), 0x3: write, 0x4: read(read back default value)--------0x01020300 stands do reset, read, write one by one
+    access_way: by message or external API
+        0x1: external API, 0x2: message
+Return Value:
+    return value is a 32-bit vaule and each 8-bit respond to the operation_flag result.
+        0x0: success, 0x1: fail--------0x00000000 stands all the operations are success
+Important Note: 
+    To simple the flow, this API make some assue: if send a message to NVRAM to read/write/reset,
+    the next message in the task extq we assue it is the result of the last operation.
+*/
+#define CMPT_OP_FLAG_NULL       0x0
+#define CMPT_OP_FLAG_RESET      0x1
+#define CMPT_OP_FLAG_READ       0x2
+#define CMPT_OP_FLAG_WRITE      0x3
+#define CMPT_OP_FLAG_READBACK   0x4
+#define CMPT_OP_FLAG_SET_LOCK     0x5
+#define CMPT_OP_FLAG_SET_UNLOCK     0x6
+
+#define CMPT_OP_WAY_API         0x1
+#define CMPT_OP_WAY_MSG         0x2
+
+#define CMPT_OP_FLAG_GEN(v1, v2, v3, v4)    ((v1 << 24) | (v2 << 16) | (v3 << 8) | v4)
+
+kal_uint32 nvram_lid_cmpt_op_push(kal_uint32 value, kal_uint8 operation_flag)
+{
+    value <<= 8;
+    value |= (operation_flag & 0xFF);
+    return value;
+}
+
+kal_uint32 nvram_lid_cmpt_op_pop(kal_uint32 value, kal_uint8 *operation_flag)
+{
+    *operation_flag = (value >> 24);
+    return (value << 8);
+}
+
+kal_uint32 nvram_lid_cmpt_operation(nvram_lid_enum LID, kal_uint32 operation_flag, kal_uint8 access_way, kal_uint32 start_record, kal_uint32 end_record)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 temp_result = 0, final_result = 0, i;
+    kal_uint8 *d_buffer, *c_buffer;
+    nvram_reset_req_struct *reset_req;
+    nvram_reset_cnf_struct *nvram_reset_cnf;
+    nvram_read_req_struct *read_req;
+    nvram_read_cnf_struct *nvram_read_cnf;
+    nvram_write_req_struct *write_req;
+    nvram_write_cnf_struct *nvram_write_cnf;
+    nvram_set_lock_req_struct *nvram_set_lock_req;
+    nvram_set_lock_cnf_struct *nvram_set_lock_cnf;
+    kal_uint8 *pdu_write_buffer;
+    ilm_struct current_ilm;
+    kal_uint8 op_val;
+
+    if((access_way != CMPT_OP_WAY_API) && (access_way != CMPT_OP_WAY_MSG))
+    {
+        return 0xFFFFFFFF;
+    }
+
+    if(!NVRAM_IS_LID_VALID(LID))
+    {
+        return 0x0FFFFFFF;
+    }
+    nvram_util_get_data_item(&ldi, LID);
+
+    if(start_record < 1 || start_record > ldi->total_records)
+    {
+        return 0xFF0FFFFF;
+    }
+
+    if(end_record < 1 || end_record > ldi->total_records)
+    {
+        return 0xFFF0FFFF;
+    }
+
+    if(ldi->size > NVRAM_MAX_OP_BUFFER_SIZE)
+    {
+        return 0xF0FFFFFF;
+    }
+
+    do
+    {
+        operation_flag = nvram_lid_cmpt_op_pop(operation_flag, &op_val);
+        switch(op_val)
+        {
+            case CMPT_OP_FLAG_RESET: //reset
+                #ifdef __NVRAM_LID_CACHE__
+                if (check_nvram_cache_ready())
+                {
+                    while(check_lid_all_record_is_undirty_bit(ldi) != KAL_TRUE)
+                    {
+                    }
+                }
+                #endif
+                if(CMPT_OP_WAY_API == access_way) //external API
+                {
+                    temp_result = nvram_external_reset_data(ldi->LID, start_record, end_record-start_record+1);
+                    agreement_return_value(temp_result);
+                }
+                else if(CMPT_OP_WAY_MSG == access_way) //message
+                {
+                    reset_req = (nvram_reset_req_struct *)construct_local_para(sizeof(nvram_reset_req_struct), TD_CTRL);
+                    reset_req->ref_count = 1;
+                    reset_req->LID = ldi->LID;
+                    reset_req->rec_index = start_record;
+                    reset_req->rec_amount = end_record-start_record+1;
+                    reset_req->reset_category = NVRAM_RESET_CERTAIN;
+                    reset_req->app_id = NVRAM_APP_RESERVED;
+
+                    msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_RESET_REQ, 
+                            (local_para_struct*)reset_req, NULL);
+                    msg_receive_extq(&current_ilm);
+                    nvram_reset_cnf = (nvram_reset_cnf_struct*)current_ilm.local_para_ptr;
+                    temp_result = nvram_reset_cnf->result; //NVRAM_ERRNO_SUCCESS(0) stands success
+                    destroy_ilm(&current_ilm);
+                }
+                
+                if(NVRAM_ERRNO_SUCCESS == temp_result)
+                {   
+                    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                    c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);                    
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        kal_mem_set(d_buffer, 0, ldi->size);
+                        kal_mem_set(c_buffer, 0, ldi->size);
+                        nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+                        temp_result = nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+                        agreement_return_value(temp_result);
+                        if(NVRAM_ERRNO_SUCCESS == temp_result)
+                        {   
+                            /*if buffer data is the same kal_mem_cmp will return 0 (NVRAM_ERRNO_SUCCESS)*/
+                            temp_result = kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size);
+                        }
+                        else
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): reset-read fail!\n\r");
+                        }
+                        
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): reset-read is not default value!\n\r");
+                            break;
+                        }
+                    }
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    d_buffer = NULL;
+                    c_buffer = NULL;
+                }
+                else
+                {
+                    nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): reset-reset fail!\n\r");
+                }
+                break;
+                
+            case CMPT_OP_FLAG_READ: //read
+                if(CMPT_OP_WAY_API == access_way) //external API
+                {
+                    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                    kal_mem_set(d_buffer, 0, ldi->size);
+                    /*for read operation we just judge return value, if it is NVRAM_ERRNO_SUCCESS, we assue it success*/
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        temp_result = nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+                        agreement_return_value(temp_result);
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): api_read-read fail!\n\r");
+                            break;
+                        }
+                    }
+                    free_ctrl_buffer(d_buffer);
+                }
+                else if(CMPT_OP_WAY_MSG == access_way) //message
+                {
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+                        read_req->ref_count = 1;
+                        read_req->file_idx = ldi->LID;
+                        read_req->para = i;
+                        read_req->rec_amount = 1;
+                        msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_READ_REQ, 
+                            (local_para_struct*)read_req, NULL);    
+                        msg_receive_extq(&current_ilm);
+                        nvram_read_cnf = (nvram_read_cnf_struct*)current_ilm.local_para_ptr;
+                        temp_result = nvram_read_cnf->result; //NVRAM_ERRNO_SUCCESS(0) stands success
+                        destroy_ilm(&current_ilm);
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): msg_read-read fail!\n\r");
+                            break;
+                        }
+                    }
+                }
+                break;
+                
+            case CMPT_OP_FLAG_WRITE: //write
+                if(CMPT_OP_WAY_API == access_way) //external API
+                {
+                    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                    kal_mem_set(d_buffer, 0, ldi->size);
+                    d_buffer[0] = 0x1; //modify some data
+                    if(ldi->size >= 3)
+                    {
+                        d_buffer[1] = 0x2;
+                        d_buffer[2] = 0x3;
+                    }
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        temp_result = nvram_external_write_data(ldi->LID, i, d_buffer, ldi->size);
+                        agreement_return_value(temp_result);
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): api_write-write fail!\n\r");
+                            break;
+                        }
+                    }
+
+                    if(NVRAM_ERRNO_SUCCESS == temp_result)
+                    {
+                        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                        for(i = start_record; i <= end_record; i++)
+                        {
+                            kal_mem_set(c_buffer, 0, ldi->size);
+                            temp_result = nvram_external_read_data(ldi->LID, i, c_buffer, ldi->size);
+                            agreement_return_value(temp_result);
+                            if(NVRAM_ERRNO_SUCCESS == temp_result)
+                            {
+                                /*if buffer data is the same kal_mem_cmp will return 0 (NVRAM_ERRNO_SUCCESS)*/
+                                temp_result = kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size);                             
+                            }
+                            else
+                            {
+                                nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): api_write-read fail!\n\r");
+                            }
+                            
+                            if(NVRAM_ERRNO_SUCCESS != temp_result)
+                            {
+                                nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): api_write-read back is not expect!\n\r");
+                                break;
+                            }
+                        }
+                        free_ctrl_buffer(d_buffer);
+                        free_ctrl_buffer(c_buffer);
+                        d_buffer = NULL;
+                        c_buffer = NULL;
+                    }
+                    else
+                    {
+                        free_ctrl_buffer(d_buffer);
+                        d_buffer = NULL;
+                    }
+                }
+                else if(CMPT_OP_WAY_MSG == access_way) //message
+                {
+                    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                    kal_mem_set(d_buffer, 0, ldi->size);
+                    d_buffer[0] = 0x1; //make some modify
+                    if(ldi->size >= 3)
+                    {
+                        d_buffer[1] = 0x2;
+                        d_buffer[2] = 0x3;
+                    }
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        write_req = (nvram_write_req_struct *)construct_local_para(sizeof(nvram_write_req_struct), TD_CTRL);
+                        pdu_write_buffer = (kal_uint8 *)construct_peer_buff(ldi->size, 0, 0, TD_CTRL);
+                        kal_mem_cpy(get_peer_buff_pdu((peer_buff_struct*)pdu_write_buffer, 0), d_buffer, ldi->size);
+                        write_req->ref_count = 1;
+                        write_req->file_idx = ldi->LID;
+                        write_req->para = i;
+                        msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_WRITE_REQ, 
+                                (local_para_struct*)write_req, (peer_buff_struct*)pdu_write_buffer);
+                        msg_receive_extq(&current_ilm);
+                        nvram_write_cnf = (nvram_write_cnf_struct*)current_ilm.local_para_ptr;
+                        temp_result = nvram_write_cnf->result; //NVRAM_ERRNO_SUCCESS(0) stands success
+                        destroy_ilm(&current_ilm);
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): msg_write-write fail!\n\r");
+                            break;
+                        }
+                    }
+
+                    if(NVRAM_ERRNO_SUCCESS == temp_result)
+                    {
+                        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                        for(i = start_record; i <= end_record; i++)
+                        {
+                            kal_mem_set(c_buffer, 0, ldi->size);
+                            temp_result = nvram_external_read_data(ldi->LID, i, c_buffer, ldi->size);
+                            agreement_return_value(temp_result);
+                            if(NVRAM_ERRNO_SUCCESS == temp_result)
+                            {   
+                                /*if buffer data is the same kal_mem_cmp will return 0 (NVRAM_ERRNO_SUCCESS)*/
+                                temp_result = kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size);
+                            }
+                            else
+                            {
+                                nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): msg_write-read fail!\n\r");
+                            }
+                            if(NVRAM_ERRNO_SUCCESS != temp_result)
+                            {
+                                nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): msg_write-read is not expect!\n\r");
+                                break;
+                            }                           
+                        }
+                        free_ctrl_buffer(d_buffer);
+                        free_ctrl_buffer(c_buffer);
+                        d_buffer = NULL;
+                        c_buffer = NULL;
+                    }
+                    else
+                    {
+                        free_ctrl_buffer(d_buffer);
+                        d_buffer = NULL;
+                    }
+                }
+                break;
+                
+            case CMPT_OP_FLAG_READBACK: //read back default value
+                if(CMPT_OP_WAY_API == access_way) //external API
+                {
+                    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                    c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+                    /*for read operation we just judge return value, if it is NVRAM_ERRNO_SUCCESS, we assue it success*/
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        kal_mem_set(d_buffer, 0, ldi->size);
+                        kal_mem_set(c_buffer, 0, ldi->size);
+                        temp_result = nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+                        agreement_return_value(temp_result);
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): api_dread-read fail!\n\r");
+                            break;
+                        }
+                        
+                        nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+                        temp_result = kal_mem_cmp(c_buffer, d_buffer, ldi->size);
+                        if(0 != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): api_dread-read back is not default value!\n\r");
+                            break;
+                        }
+                    }
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    d_buffer = NULL;
+                    c_buffer = NULL;
+                }
+                else if(CMPT_OP_WAY_MSG == access_way) //message
+                {
+                    c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);                    
+                    for(i = start_record; i <= end_record; i++)
+                    {
+                        read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+                        read_req->ref_count = 1;
+                        read_req->file_idx = ldi->LID;
+                        read_req->para = i;
+                        read_req->rec_amount = 1;
+                        msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_READ_REQ, 
+                            (local_para_struct*)read_req, NULL);    
+                        msg_receive_extq(&current_ilm);
+                        nvram_read_cnf = (nvram_read_cnf_struct*)current_ilm.local_para_ptr;
+                        temp_result = nvram_read_cnf->result; //NVRAM_ERRNO_SUCCESS(0) stands success
+                        if(NVRAM_ERRNO_SUCCESS != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): msg_dread-read fail!\n\r");
+                            break;
+                        }
+                        kal_mem_set(c_buffer, 0, ldi->size);
+                        nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+                        temp_result = kal_mem_cmp(c_buffer, 
+                                                  get_peer_buff_pdu((peer_buff_struct*)current_ilm.peer_buff_ptr, 0), 
+                                                  ldi->size);
+                        destroy_ilm(&current_ilm);
+                        if(0 != temp_result)
+                        {
+                            nvram_ut_trace("[NVUT] nvram_lid_cmpt_operation(): msg_dread-read back is not defalut value!\n\r");
+                            break;
+                        }
+                    }
+                    free_ctrl_buffer(c_buffer);
+                    c_buffer = NULL;
+                }
+                break;
+            case CMPT_OP_FLAG_SET_LOCK:
+                if(CMPT_OP_WAY_MSG == access_way) //message
+                {
+                    nvram_set_lock_req = (nvram_set_lock_req_struct *)construct_local_para(sizeof(nvram_set_lock_req_struct), TD_CTRL);
+                    nvram_set_lock_req->lock_en = NVRAM_LOCK_ENABLE;
+                    msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_SET_LOCK_REQ, 
+                            (local_para_struct*)nvram_set_lock_req, NULL);
+                    msg_receive_extq(&current_ilm);
+                    nvram_set_lock_cnf = (nvram_set_lock_cnf_struct*)current_ilm.local_para_ptr;
+                    temp_result = nvram_set_lock_cnf->result; //NVRAM_ERRNO_SUCCESS(0) stands success
+                    destroy_ilm(&current_ilm);
+                }
+                break;
+            case CMPT_OP_FLAG_SET_UNLOCK:
+                if(CMPT_OP_WAY_MSG == access_way) //message
+                {
+                    nvram_set_lock_req = (nvram_set_lock_req_struct *)construct_local_para(sizeof(nvram_set_lock_req_struct), TD_CTRL);
+                    nvram_set_lock_req->lock_en = NVRAM_LOCK_DISABLE;
+                    msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_SET_LOCK_REQ, 
+                            (local_para_struct*)nvram_set_lock_req, NULL);
+                    msg_receive_extq(&current_ilm);
+                    nvram_set_lock_cnf = (nvram_set_lock_cnf_struct*)current_ilm.local_para_ptr;
+                    temp_result = nvram_set_lock_cnf->result; //NVRAM_ERRNO_SUCCESS(0) stands success
+                    destroy_ilm(&current_ilm);
+                }
+                break;    
+            default:
+                break;
+        }
+        final_result = nvram_lid_cmpt_op_push(final_result, temp_result);
+        
+    }while(operation_flag != CMPT_OP_FLAG_NULL);
+
+    return final_result;
+    
+}
+
+
+/*
+This function is used to reset the NVRAM UT test LIDs to default seetings.
+Default settings value please refer to test plan.
+Input:
+    One of NVRAM_EF_NVRAM_TEST_1_LID~NVRAM_EF_NVRAM_TEST_6_LID
+Output:
+    KAL_TRUE: success
+    KAL_FALSE: fail
+*/
+extern kal_uint8 NVRAM_EF_TEST_8_DEFAULT[NVRAM_EF_TEST_8_LID_RECORD_TOTAL][NVRAM_EF_TEST_8_LID_SIZE];
+kal_bool reset_test_lid_default_setting(nvram_lid_enum LID)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    if(!NVRAM_IS_LID_VALID(LID))
+    {
+        return KAL_FALSE;
+    }
+    nvram_util_get_data_item(&ldi, LID);
+    
+    switch(ldi->LID)
+    {
+        case NVRAM_EF_NVRAM_TEST_1_LID:
+            ldi->category = NVRAM_CATEGORY_USER;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT;
+            ldi->size = 1024;
+            ldi->total_records = 10;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT; 
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_1_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_2_LID:
+            ldi->category = NVRAM_CATEGORY_INTERNAL;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT;
+            ldi->size = 1024;
+            ldi->total_records = 10;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_2_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_3_LID:
+            ldi->category = NVRAM_CATEGORY_CALIBRAT;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT;
+            ldi->size = 1024;
+            ldi->total_records = 10;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_3_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_4_LID:
+            ldi->category = NVRAM_CATEGORY_IMPORTANT;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT;
+            ldi->size = 1024;
+            ldi->total_records = 10;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_4_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_5_LID:
+            ldi->category = NVRAM_CATEGORY_IMPORTANT_L1;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT;
+            ldi->size = 1024;
+            ldi->total_records = 10;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_5_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_6_LID:
+            ldi->category = NVRAM_CATEGORY_IMPORTANT_L4;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_CHKSUM_INTEGRATE;
+            ldi->size = 1024;
+            ldi->total_records = 10;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_6_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_7_LID:
+            ldi->category = NVRAM_CATEGORY_CALIBRAT;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_RAW_DATA;
+            ldi->size = NVRAM_EF_TEST_LID_SIZE;
+            ldi->total_records = 1;
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_7_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_NVRAM_TEST_8_LID:
+            ldi->category = NVRAM_CATEGORY_USER;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_CHKSUM_INTEGRATE;
+            ldi->size = NVRAM_EF_TEST_8_LID_SIZE;
+            ldi->total_records = NVRAM_EF_TEST_8_LID_RECORD_TOTAL;
+            ldi->default_value = NVRAM_NORMAL(NVRAM_EF_TEST_8_DEFAULT);
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_NVRAM_TEST_8_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_INTERNAL_13_LID:
+            ldi->category = NVRAM_CATEGORY_IMPORTANT_L1;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT;
+            ldi->size = NVRAM_EF_TEST_13_LID_SIZE;
+            ldi->total_records = NVRAM_EF_TEST_13_LID_RECORD_TOTAL;
+            ldi->default_value = NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT);
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_INTERNAL_13_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_INTERNAL_TEST_14_LID:
+            ldi->category = NVRAM_CATEGORY_USER | NVRAM_CATEGORY_FUNC_DEFAULT;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT;
+            ldi->size = NVRAM_EF_TEST_14_LID_SIZE;
+            ldi->total_records = NVRAM_EF_TEST_14_LID_RECORD_TOTAL;
+            ldi->default_value = NVRAM_DEFAULT_FUNC(nvram_internal_test_fun_default_value);
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_INTERNAL_TEST_14_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_INTERNAL_TEST_16_LID:
+            ldi->category = NVRAM_CATEGORY_CALIBRAT;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_CHKSUM_INTEGRATE | NVRAM_ATTR_FAULT_ASSERT;
+            ldi->size = NVRAM_EF_INTERNAL_TEST_16_LID_SIZE;
+            ldi->total_records = NVRAM_EF_INTERNAL_TEST_16_LID_RECORD_TOTAL;
+            ldi->default_value = NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT);
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_INTERNAL_TEST_16_LID_VERNO, 3);
+            break;
+        case NVRAM_EF_INTERNAL_TEST_17_LID:
+            ldi->category = NVRAM_CATEGORY_USER;
+            ldi->attr = NVRAM_ATTR_AVERAGE | NVRAM_ATTR_MULTIPLE;
+            ldi->size = NVRAM_EF_TEST_LID_SIZE;
+            ldi->total_records = NVRAM_EF_TEST_LID_RECORD_TOTAL;
+            ldi->default_value = NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT);
+            kal_mem_cpy(ldi->fileverno, NVRAM_EF_INTERNAL_TEST_17_LID_VERNO, 3);
+            break;
+        default:
+            return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+}
+
+kal_bool lid_verno_increase_one(nvram_lid_enum LID)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 overflow_flag, i;
+    
+    if(!NVRAM_IS_LID_VALID(LID))
+    {
+        return KAL_FALSE;
+    }
+    nvram_util_get_data_item(&ldi, LID);
+
+    for(i = 0, overflow_flag = 1; (i < 3) && (overflow_flag); i++)
+    {   
+        if((ldi->fileverno[2-i] - '0') < 9)
+        {
+            ldi->fileverno[2-i] += 1;
+            overflow_flag = 0;
+        }
+        else
+        {
+            ldi->fileverno[2-i] = '0';
+            overflow_flag = 1;
+        }
+    }
+    
+    return KAL_TRUE;
+}
+
+kal_bool modify_md_sw_version()
+{
+    kal_uint8 *d_buffer;
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SW_VERNO_LID);
+    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    if(!nvram_external_read_data(ldi->LID, SW_VERNO_RECORD_NUMBER, d_buffer, ldi->size))
+    {
+        free_ctrl_buffer(d_buffer);
+        return KAL_FALSE;
+    }
+    d_buffer[0] += 0x1; //modify one uint in the buffer
+    if(!nvram_external_write_data(ldi->LID, SW_VERNO_RECORD_NUMBER, d_buffer, ldi->size))
+    {
+        free_ctrl_buffer(d_buffer);
+        return KAL_FALSE;
+    }
+    free_ctrl_buffer(d_buffer);
+    #ifdef __NVRAM_LID_CACHE__
+    if (check_nvram_cache_ready())
+    {
+        while(check_lid_all_record_is_undirty_bit(ldi))
+        {        
+        }
+    }
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool delete_special_version_lid(nvram_lid_enum LID, kal_uint32 start_version, kal_uint32 end_version)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint32 i;
+    kal_uint8 lid_verno_bak[3];
+    
+    if(!NVRAM_IS_LID_VALID(LID))
+    {
+        return KAL_FALSE;
+    }
+
+    if((start_version > end_version) || (end_version > 999))
+    {
+        return KAL_FALSE;
+    }
+    
+    nvram_util_get_data_item(&ldi, LID);
+    #ifdef __NVRAM_LID_CACHE__
+    if (check_nvram_cache_ready())
+    {
+        while(check_lid_all_record_is_undirty_bit(ldi) != KAL_TRUE)
+        {
+        }
+    }
+    #endif
+    kal_mem_cpy(lid_verno_bak, ldi->fileverno, 3);
+    ldi->fileverno[0] = '0'; //set LID verno as "000"
+    ldi->fileverno[1] = '0';
+    ldi->fileverno[2] = '0';
+
+    for(i = 0; i < start_version; i++) //skip to start_version
+    {
+        lid_verno_increase_one(LID);
+    }
+
+    for(i = start_version; i <= end_version; i++) //delete related LID version
+    {
+        folder_index = nvram_query_folder_index(ldi->category);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+        nvram_query_file_name(folder_index, nvramname, filename);
+		#ifdef __NVRAM_LID_CACHE__
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+		#endif
+        nvram_util_mark_file_uncreated(ldi);
+        FS_Delete(filename);
+        
+        if(ldi->attr & NVRAM_ATTR_MULTIPLE)
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+            nvram_query_file_name(folder_index, nvramname, filename);
+            FS_Delete(filename);
+        }
+		#ifdef __NVRAM_LID_CACHE__
+        nvram_util_give_mutex(g_nvram_fs_mutex);
+		#endif
+        lid_verno_increase_one(LID);
+    }
+    kal_mem_cpy(ldi->fileverno, lid_verno_bak, 3);
+    
+    return KAL_TRUE;
+}
+
+kal_bool first_boot_basic_access(kal_uint32 flags, void *param)
+{
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_uint8 i;
+
+/*  default settings is OK
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_USER;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->size = 1024;
+    ldi->total_records = 10;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    ldi->category = NVRAM_CATEGORY_INTERNAL;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->size = 1024;
+    ldi->total_records = 10;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    ldi->category = NVRAM_CATEGORY_CALIBRAT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->size = 1024;
+    ldi->total_records = 10;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    ldi->category = NVRAM_CATEGORY_IMPORTANT;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->size = 1024;
+    ldi->total_records = 10;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    ldi->category = NVRAM_CATEGORY_IMPORTANT_L1;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->size = 1024;
+    ldi->total_records = 10;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    ldi->category = NVRAM_CATEGORY_IMPORTANT_L4;
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+    ldi->size = 1024;
+    ldi->total_records = 10;
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+*/
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    is_insulation_access = 1;
+
+    NVRAM_FS_MAKE_ROOT_PATH(filename);
+    FS_XDelete(filename, (FS_FILE_TYPE | FS_DIR_TYPE | FS_RECURSIVE_TYPE), NULL, 0);
+#if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+    FS_XDelete((const WCHAR*)L"X:\\NV_TEST", (FS_FILE_TYPE|FS_DIR_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+    FS_XDelete((const WCHAR*)L"Y:\\NV_TEST", (FS_FILE_TYPE|FS_DIR_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+#endif  
+
+    nvram_init();
+
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i], 
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                         CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+        {
+            nvram_ut_trace("[NVUT] first_boot_basic_access(): LID cmpt operations fail!\n\r");
+            is_insulation_access = 0;
+            return KAL_FALSE;
+        }
+    }
+
+    FS_XDelete(filename, (FS_FILE_TYPE | FS_DIR_TYPE | FS_RECURSIVE_TYPE), NULL, 0);
+#if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__)
+    FS_XDelete((const WCHAR*)L"X:\\NV_TEST", (FS_FILE_TYPE|FS_DIR_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+    FS_XDelete((const WCHAR*)L"Y:\\NV_TEST", (FS_FILE_TYPE|FS_DIR_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+#endif
+
+    is_insulation_access = 0;
+
+    return KAL_TRUE;
+}
+
+
+/*
+store test logs to LID6, and this LID is stored in protect_f partition
+*/
+void save_context_notify_tester()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    factory_test_context_struct *test_context;
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    test_context = (factory_test_context_struct*)data_buffer;
+    test_context->context_is_valid = 0xAB; //a special value we appoint
+    test_context->break_test_case_num = test_number;
+    test_context->sub_test_case_num = sub_test_number;
+    test_context->valid_test_case_num_total = valid_test_case_num;
+    test_context->total_case_number = total_case_num;
+    test_context->fail_case_number = fail_case_num;
+    test_context->tst_time_consume = ust_get_current_time() - start_test_time;
+    kal_mem_cpy(test_context->test_case_lst, test_case_list, sizeof(test_case_list));
+    
+    nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)data_buffer, ldi->size); //write context to record 1
+
+    nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size);
+    if(0 == kal_mem_cmp(data_buffer, cmp_buffer, sizeof(test_case_list)))
+    {
+        nvram_ut_trace("[NVRAM UT] Save test context success!\n\r");
+    }
+    
+    while(1)
+    {
+        nvram_ut_trace("[NVRAM UT] Please do SP \"Factory Reset Operation\" manually!\n\r");
+        kal_sleep_task(kal_milli_secs_to_ticks(5000));
+    }
+}
+
+void ota_save_context()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    factory_test_context_struct *test_context;
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    test_context = (factory_test_context_struct*)data_buffer;
+    test_context->context_is_valid = 0xCD; //a special value we appoint
+    test_context->break_test_case_num = test_number;
+    test_context->sub_test_case_num = sub_test_number;
+    test_context->valid_test_case_num_total = valid_test_case_num;
+    test_context->total_case_number = total_case_num;
+    test_context->fail_case_number = fail_case_num;
+    test_context->tst_time_consume = ust_get_current_time() - start_test_time;
+    kal_mem_cpy(test_context->test_case_lst, test_case_list, sizeof(test_case_list));
+    
+    nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)data_buffer, ldi->size); //write context to record 1
+
+    nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size);
+    if(0 == kal_mem_cmp(data_buffer, cmp_buffer, sizeof(test_case_list)))
+    {
+        nvram_ut_trace("[NVRAM UT] Save test context success!\n\r");
+    }
+}
+
+void ota_notify_tester(char *ptr)
+{
+    while(1)
+    {
+        nvram_ut_trace("[NVRAM UT] %s\n\r", ptr);
+        kal_sleep_task(kal_milli_secs_to_ticks(5000));
+    }
+}
+
+
+
+kal_bool factory_reset_user_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    if(!factory_test_reboot_finish)
+    {
+        save_context_notify_tester();
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    
+    //read, write and reset test
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))        
+    {
+        nvram_ut_trace("[NVUT] factory_reset_user_access(): access fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    return KAL_TRUE;
+}
+
+kal_bool factory_reset_internal_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    if(!factory_test_reboot_finish)
+    {
+        save_context_notify_tester();
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    
+    //read, write and reset test
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))        
+    {
+        nvram_ut_trace("[NVUT] factory_reset_internal_access(): access fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    return KAL_TRUE;
+}
+
+kal_bool factory_reset_calibrat_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i;
+    
+    if(!factory_test_reboot_finish)
+    {
+        save_context_notify_tester();
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+
+    //read test
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        kal_mem_set(data_buffer, 0, NVRAM_EF_TEST_LID_SIZE);
+        data_buffer[0] = 0x1; //modify data_buffer to special value write before binregion backup
+        kal_mem_set(cmp_buffer, 0, ldi->size);
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_calibrat_access(): read fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_calibrat_access(): read back value is not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    if(i <= ldi->total_records)
+    {   
+        nvram_ut_trace("[NVUT] factory_reset_calibrat_access(): read fail!\n\r");
+        return KAL_FALSE; //return error number
+    }
+    
+    //write and reset test
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_3_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] factory_reset_calibrat_access(): write/reset fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    return KAL_TRUE;
+}
+
+kal_bool factory_reset_important_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i;
+        
+    if(!factory_test_reboot_finish)
+    {
+        save_context_notify_tester();
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+
+    //read test
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        kal_mem_set(data_buffer, 0, NVRAM_EF_TEST_LID_SIZE);
+        data_buffer[0] = 0x1; //modify data_buffer to special value write before binregion backup
+        kal_mem_set(cmp_buffer, 0, ldi->size);
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_important_access(): read fail!\n\r");
+            return KAL_FALSE;
+        }
+        
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_important_access(): read back value is not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //write and reset test
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_4_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))        
+    {   
+        nvram_ut_trace("[NVUT] factory_reset_important_access(): write/reset fail!\n\r");
+        return KAL_FALSE;
+    }   
+    
+    return KAL_TRUE;
+}
+
+
+kal_bool factory_reset_importantl1_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i;
+        
+    if(!factory_test_reboot_finish)
+    {
+        save_context_notify_tester();
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+
+    //read test
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        kal_mem_set(data_buffer, 0, NVRAM_EF_TEST_LID_SIZE);
+        data_buffer[0] = 0x1; //modify data_buffer to special value write before binregion backup
+        kal_mem_set(cmp_buffer, 0, ldi->size);
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_importantl1_access(): read fail!\n\r");
+            return KAL_FALSE;
+        }
+        
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_importantl1_access(): read back value is not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //write test and reset test
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))         
+    {   
+        nvram_ut_trace("[NVUT] factory_reset_importantl1_access(): write/reset fail!\n\r");
+        return KAL_FALSE;
+    }   
+    
+    return KAL_TRUE;
+}
+
+kal_bool factory_reset_importantl4_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i;
+            
+    if(!factory_test_reboot_finish)
+    {
+        save_context_notify_tester();
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+
+    //read test, record 1 stores the factory reset context so read test start from record 2
+    for(i = 2; i <= ldi->total_records; i++)
+    {
+        kal_mem_set(data_buffer, 0, NVRAM_EF_TEST_LID_SIZE);
+        data_buffer[0] = 0x1; //modify data_buffer to special value write before binregion backup
+        kal_mem_set(cmp_buffer, 0, ldi->size);
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_importantl4_access(): read fail!\n\r");
+            return KAL_FALSE;
+        }
+        
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] factory_reset_importantl4_access(): read back value is not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write and reset test 
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))         
+    {   
+        nvram_ut_trace("[NVUT] factory_reset_importantl4_access(): write/reset fail!\n\r");
+        return KAL_FALSE;
+    }   
+    
+    return KAL_TRUE;
+}
+
+kal_bool ota_boot_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_basic_access(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_basic_access(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_basic_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_basic_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    
+    nvram_init();
+    
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_basic_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    { 
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i], 
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                         CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))            
+        {
+            nvram_ut_trace("[NVUT] ota_boot_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_lid_verno_change_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    #ifdef __NVRAM_LID_CACHE__    
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+         if(!reset_test_lid_default_setting(test_lid_enum[i]))
+         {
+            nvram_ut_trace("[NVUT] ota_boot_lid_verno_change_access(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+         }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_lid_verno_change_access(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_lid_verno_change_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_lid_verno_change_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //test LID1~LID6 verno +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!lid_verno_increase_one(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_lid_verno_change_access(): increase verno fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_lid_verno_change_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }    
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    { 
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i], 
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                         CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))            
+        {
+            nvram_ut_trace("NVUT] ota_boot_lid_verno_change_access(): nvram_lid_cmpt_operation() fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool ota_boot_add_record_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify LID's value
+    kal_mem_set(cmp_buffer, 0x0, ldi->size);
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!(nvram_external_write_data(test_lid_enum[i], ldi->total_records, (kal_uint8 *)cmp_buffer, ldi->size)))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): modify LID's value fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //test LID1~LID6 record number +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records += 1;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!(nvram_external_read_data(test_lid_enum[i], ldi->total_records - 1, (kal_uint8 *)data_buffer, ldi->size)))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): read old record fail!\n\r");
+            return KAL_FALSE;
+        }
+        //old record should keep value
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): old record value change!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(!(nvram_external_read_data(test_lid_enum[i], ldi->total_records, (kal_uint8 *)data_buffer, ldi->size)))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): read old record fail!\n\r");
+            return KAL_FALSE;
+        }
+        nvram_get_default_value_to_write(ldi, ldi->total_records, (kal_uint8 *)cmp_buffer, ldi->size);
+        //new record should be default value
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_read(): old record value change!\n\r");
+            return KAL_FALSE;
+        }   
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_add_record_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_write(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_write(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 record number +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records += 1;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i],
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                         CMPT_OP_WAY_API, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_write(): nvram_lid_cmpt_operation() fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_add_record_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_reset(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_reset(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 record number +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records += 1;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_add_record_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i<test_lid_number; i++)
+    {
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i],
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                         CMPT_OP_WAY_API, 1, ldi->total_records))           
+        {
+            nvram_ut_trace("[NVUT] ota_boot_add_record_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_delete_record_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify LID's value
+    kal_mem_set(cmp_buffer, 0x0, ldi->size);
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!(nvram_external_write_data(test_lid_enum[i], ldi->total_records - 1, (kal_uint8 *)cmp_buffer, ldi->size)))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): modify LID's value fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //test LID1~LID6 record number -1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records -= 1;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!(nvram_external_read_data(test_lid_enum[i], ldi->total_records, (kal_uint8 *)data_buffer, ldi->size)))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): read old record fail!\n\r");
+            return KAL_FALSE;
+        }
+        //old record should keep value
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_read(): old record value change!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_delete_record_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_write(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_write(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 record number -1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records -= 1;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i],
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                         CMPT_OP_WAY_API, 1, ldi->total_records))             
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_write(): nvram_lid_cmpt_operation() fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_delete_record_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_reset(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_reset(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 record number -1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records -= 1;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_delete_record_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i],
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                         CMPT_OP_WAY_API, 1, ldi->total_records))              
+        {
+            nvram_ut_trace("[NVUT] ota_boot_delete_record_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_verno_change_previous_lid_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //delete all files in Z:/BACKUP folder
+    FS_XDelete((const WCHAR*)L"Z:\\NVRAM\\BACKUP", (FS_FILE_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+
+    //this test will use LID verno "000"~"001" total 2 version
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 1))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+        //add NVRAM_ATTR_RESERVE_BACKWARD to test LID
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->attr |= NVRAM_ATTR_RESERVE_BACKWARD;
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write old LID with non-default value
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            if(!nvram_external_write_data(test_lid_enum[i], j, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                break;
+            }
+        }
+        
+        if(j <= NVRAM_EF_TEST_LID_RECORD_TOTAL)
+        {
+            nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 verno +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!lid_verno_increase_one(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): change LID verno fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    
+    nvram_init();
+    
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //old version lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_external_search_reserved_lid(ldi->LID, "000", NVRAM_EF_TEST_LID_RECORD_TOTAL, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): cannot find previous LID!\n\r");
+            return KAL_FALSE;
+        }
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            kal_mem_set(data_buffer, 0, ldi->size);
+            if(! nvram_external_read_data(NVRAM_EF_READ_RESERVED_LID, j, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): read reserve LID fail!\n\r");
+                return KAL_FALSE;
+            }
+
+            if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_verno_change_previous_lid_access(): read back reserve LID changed!\n\r");
+                return KAL_FALSE;
+            }
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_size_change_previous_lid_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i, j;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //delete all files in Z:/BACKUP folder
+    FS_XDelete((const WCHAR*)L"Z:\\NVRAM\\BACKUP", (FS_FILE_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+
+    //this test will use LID verno "000"~"001" total 2 version
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 1))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+        //add NVRAM_ATTR_RESERVE_BACKWARD to test LID
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        ldi->attr |= NVRAM_ATTR_RESERVE_BACKWARD;
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write old LID with non-default value
+    cmp_buffer[0] = 0x4; //modify some value
+    cmp_buffer[1] = 0x5;
+    cmp_buffer[2] = 0x6;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            if(!nvram_external_write_data(test_lid_enum[i], j, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                break;
+            }
+        }
+        
+        if(j <= NVRAM_EF_TEST_LID_RECORD_TOTAL)
+        {
+            nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 verno +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        ldi->size += RECORD_CHANGE_SIZE;
+    }
+    
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //old version lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        if(!nvram_external_search_reserved_lid(ldi->LID, "000", NVRAM_EF_TEST_LID_RECORD_TOTAL, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT]ldi->LID(0x%x) ota_boot_size_change_previous_lid_access(): cannot find previous LID!\n\r", ldi->LID);
+            return KAL_FALSE;
+        }
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            kal_mem_set(data_buffer, 0, ldi->size);
+            if(! nvram_external_read_data(NVRAM_EF_READ_RESERVED_LID, j, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): read reserve LID fail!\n\r");
+                return KAL_FALSE;
+            }
+
+            if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_size_change_previous_lid_access(): read back reserve LID changed!\n\r");
+                return KAL_FALSE;
+            }
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+
+kal_bool ota_boot_record_change_previous_lid_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i, j;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //delete all files in Z:/BACKUP folder
+    FS_XDelete((const WCHAR*)L"Z:\\NVRAM\\BACKUP", (FS_FILE_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+
+    //this test will use LID verno "000"~"001" total 2 version
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 1))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }   
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+        //add NVRAM_ATTR_RESERVE_BACKWARD to test LID
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        ldi->attr |= NVRAM_ATTR_RESERVE_BACKWARD;
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write old LID with non-default value
+    cmp_buffer[0] = 0x4; //modify some value
+    cmp_buffer[1] = 0x5;
+    cmp_buffer[2] = 0x6;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            if(!nvram_external_write_data(test_lid_enum[i], j, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                break;
+            }
+        }
+        
+        if(j <= NVRAM_EF_TEST_LID_RECORD_TOTAL)
+        {
+            nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //test LID1~LID6 verno +1
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        ldi->total_records += 1;
+    }
+    
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT]ldi->LID(0x%x) ota_boot_record_change_previous_lid_access(): enter version conflict fail!\n\r", ldi->LID);
+        return KAL_FALSE;
+    }
+
+    //old version lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        if(!nvram_external_search_reserved_lid(ldi->LID, "000", NVRAM_EF_TEST_LID_RECORD_TOTAL, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): cannot find previous LID!\n\r");
+            return KAL_FALSE;
+        }
+        for(j = 1; j <= NVRAM_EF_TEST_LID_RECORD_TOTAL; j++)
+        {
+            kal_mem_set(data_buffer, 0, ldi->size);
+            if(! nvram_external_read_data(NVRAM_EF_READ_RESERVED_LID, j, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): read reserve LID fail!\n\r");
+                return KAL_FALSE;
+            }
+
+            if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_record_change_previous_lid_access(): read back reserve LID changed!\n\r");
+                return KAL_FALSE;
+            }
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+
+kal_bool ota_boot_extend_record_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //set test LID1~LID6 record number to 1, reset LID, write LID, extend record size
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records = 1;
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): reset LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        ldi->size += RECORD_CHANGE_SIZE;
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE + RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): read fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): old data changed!\n\r");
+            return KAL_FALSE;
+        }
+
+        nvram_get_default_value_to_write(ldi, i, (kal_uint8 *)cmp_buffer, ldi->size);
+        if(0 != kal_mem_cmp((kal_char*)(&data_buffer[NVRAM_EF_TEST_LID_SIZE]), (kal_char*)(&cmp_buffer[NVRAM_EF_TEST_LID_SIZE]), RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_read(): extend data is not as expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_extend_record_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //extend record size
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records = 1;
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            
+            return KAL_FALSE;
+        }
+        ldi->size += RECORD_CHANGE_SIZE;
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    data_buffer[0] = 0x1;
+    data_buffer[1] = 0x2;
+    data_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE + RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): write extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE + RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): read extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE + RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_write(): read back value is not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_extend_record_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //set test LID1~LID6 record number to 1, reset LID, write LID, extend record size
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records = 1;
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): reset previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        ldi->size += RECORD_CHANGE_SIZE;
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): reset extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE + RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): read extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        nvram_get_default_value_to_write(ldi, i, (kal_uint8 *)cmp_buffer, ldi->size);
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE + RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_extend_record_reset(): read extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_minish_record_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //set test LID1~LID6 record number to 1, reset LID, write LID, minish record size
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records = 1;
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): reset previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        ldi->size -= RECORD_CHANGE_SIZE;
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE - RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): read extend record fail!\n\r");
+            return KAL_FALSE;
+        }
+        
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_read(): read back extend LID not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_minish_record_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //minish record size
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records = 1;
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): reset previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        ldi->size -= RECORD_CHANGE_SIZE;
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    data_buffer[0] = 0x1;
+    data_buffer[1] = 0x2;
+    data_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE - RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): write extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE - RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): read extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE - RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_write(): read back extend LID not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_minish_record_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //set test LID1~LID6 record number to 1, reset LID, write LID, minish record size
+    cmp_buffer[0] = 0x1; //modify some value
+    cmp_buffer[1] = 0x2;
+    cmp_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->total_records = 1;
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): reset previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): write previous LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        ldi->size -= RECORD_CHANGE_SIZE;
+    }
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): reset extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE - RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): read extend LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        nvram_get_default_value_to_write(ldi, i, (kal_uint8 *)cmp_buffer, ldi->size);
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE - RECORD_CHANGE_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_minish_record_reset(): read back extend LID not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_user_size_change_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))         
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): read LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+
+kal_bool ota_boot_user_size_change_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))         
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_write(): write LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_user_size_change_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))       
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_reset(): reset LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    
+    #ifdef __NVRAM_LID_CACHE__
+        mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_internal_size_change_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+        //internal LID size change expect read fail, internal will not run reset flow in nvram_read_data_item()
+    if(0 == nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))           
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): read fail do not happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_internal_size_change_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))           
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_write(): write LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_internal_size_change_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_internal_size_change_reset(): reset LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+//OTA file size change, CALIBRAT & IMPORTANT will assert(with FATAL_ASSERT)
+kal_bool ota_boot_calibrat_size_change(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    ldi->attr |= NVRAM_ATTR_FAULT_ASSERT;
+    
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_ut_assert_flag = 0;
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(0 == nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): calibration LID(with FAULT_ASSERT) size change OTA do not assert.\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+//OTA file size change, CALIBRAT & IMPORTANT will assert(with FATAL_ASSERT)
+kal_bool ota_boot_important_size_change(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    ldi->attr |= NVRAM_ATTR_FAULT_ASSERT;
+    
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_ut_assert_flag = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): enter version conflict fail!\n\r");
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(0 == nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_size_change_read(): important LID(with FAULT_ASSERT) size change OTA do not assert.\n\r");
+        return KAL_FALSE;
+    }
+
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    
+    return KAL_TRUE;
+    
+}
+
+//OTA boot file lost will try to restore from binregion(IMPORTANT & CALIBRAT)
+kal_bool ota_boot_calibrat_lost_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    kal_mem_set(data_buffer, 0, ldi->size);
+    data_buffer[0] = 0x1; //modify to the value before binregion backup
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_calibrat_lost_access(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }    
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+//OTA boot file lost will try to restore from binregion(IMPORTANT & CALIBRAT)
+kal_bool ota_boot_important_lost_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): delete test LID fail!\n\r");
+    }
+    
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    kal_mem_set(data_buffer, 0, ldi->size);
+    data_buffer[0] = 0x1; //modify to the value before binregion backup
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_important_lost_access(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }    
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    
+    return KAL_TRUE;
+    
+}
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+kal_bool ota_boot_importantl1_size_change_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_read(): read LID fail!\n\r");
+        return KAL_FALSE;       
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;       
+    }
+
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_importantl1_size_change_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_write(): write LID fail!\n\r");
+        return KAL_FALSE;       
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_importantl1_size_change_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl1_size_change_reset(): reset LID fail!\n\r");
+        return KAL_FALSE;       
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_importantl4_size_change_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): read fail happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_importantl4_size_change_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_write(): write LID fail!\n\r");
+        return KAL_FALSE;       
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_importantl4_size_change_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //delete old LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): delete test LID fail!\n\r");
+    }
+
+    //change test LID record size
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    ldi->size += RECORD_CHANGE_SIZE;
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //new LID access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_reset(): reset LID fail!\n\r");
+        return KAL_FALSE;       
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_ut_assert_flag: %d.\n\r", nvram_ut_assert_flag);
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_ota_reset_attr(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): reset LIDs to default seeting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write LID, add OTA_RESET attr
+    data_buffer[0] = 0x1; //modify some value
+    data_buffer[1] = 0x2;
+    data_buffer[2] = 0x3;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): reset LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        ldi->attr |= NVRAM_ATTR_OTA_RESET;
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): write LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)cmp_buffer, ldi->size);
+        if(!nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): read OTA LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_ota_reset_attr(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_reserve_backward_verno_change(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i, ota_time, j;
+    kal_uint8 lid_ver[4] = "000";
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //delete all files in Z:/BACKUP folder
+    FS_XDelete((const WCHAR*)L"Z:\\NVRAM\\BACKUP", (FS_FILE_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): reset to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //remove GEN_DEFAULT and add RESERVE_BACKWARD
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->attr &= (~NVRAM_ATTR_GEN_DEFAULT);
+        ldi->attr |= NVRAM_ATTR_RESERVE_BACKWARD;
+        if(0 == i)
+        {
+            ldi->attr |= NVRAM_ATTR_MULTIPLE; //add multiple for LID1
+        }
+    }
+
+    //this test will use LID verno "000"~"012" total 12 version
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 12))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //write LID
+    for(ota_time = 0; ota_time < 12; ota_time++)
+    {
+        if(0 == ota_time%2) //even loop time write LID of record 1 first
+        {
+            cmp_buffer[0] = ota_time + 0x30;
+            for(i = 0; i < test_lid_number; i++)
+            {
+                if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+                {
+                    nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): write previous LID fail!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+        }
+        //increase LID verno
+        for(i = 0; i < test_lid_number; i++)
+        {
+            if(!lid_verno_increase_one(test_lid_enum[i]))
+            {
+                nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): increase verno fail!\n\r");
+                return KAL_FALSE;
+            }
+        }
+        //modify MD SW version
+        if(!modify_md_sw_version())
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): modify MD SW version location1 fail!\n\r");
+        }
+        //call nvram_init()
+        nvram_boot_trace = 0;
+        nvram_init();
+        if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): enter version conflict fail!\n\r");
+            return KAL_FALSE;
+        }
+        
+    }
+
+    //test nvram_external_search_reserved_lid() API only give first two parameters
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        for(i = 0; i <= 10; i+=2) //version 2,4,6,8,10 should in backup folder, version 0 will be deleted
+        {
+            lid_ver[0] = i/100 + '0';
+            lid_ver[1] = i%100/10 + '0';
+            lid_ver[2] = i%10 + '0';
+
+            if(0 == i)
+            {
+                if(nvram_external_search_reserved_lid(ldi->LID, (kal_char *)lid_ver, 0, 0))
+                {
+                    nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): too old versions not deleted!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                if(! nvram_external_search_reserved_lid(ldi->LID, (kal_char *)lid_ver, 0, 0))
+                {
+                    nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): old versions not in backup folder!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+        }
+    }
+    
+    //check old versions delete or not(version 12 exist, version 0~14 not exist )
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->fileverno[0] = '0';
+        ldi->fileverno[1] = '0';
+        ldi->fileverno[2] = '0';
+    }
+    for(i = 0; i <= 12; i++)
+    {
+        for(j = 0; j < test_lid_number; j++)
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+            folder_index = nvram_query_folder_index(ldi->category);
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            nvram_query_file_name(folder_index, nvramname, filename);
+
+            if (FS_GetAttributes(filename) >= FS_NO_ERROR) //all files expect not exist
+            {
+                nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): old version LID not delete!\n\r");
+                return KAL_FALSE;
+            }
+
+            if(ldi->attr & NVRAM_ATTR_MULTIPLE)
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+                nvram_query_file_name(folder_index, nvramname, filename);
+
+                if (FS_GetAttributes(filename) >= FS_NO_ERROR)
+                {
+                    nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): old version LID not delete!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+            lid_verno_increase_one(test_lid_enum[j]);
+        }
+    }
+
+    //downgrade to MD SW version 3 -> related LID verno is "002"
+    for(i = 0; i < test_lid_number; i++) //set LID verno to "002"
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->fileverno[0] = '0';
+        ldi->fileverno[1] = '0';
+        ldi->fileverno[2] = '2';
+    }
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): modify MD SW version location2 fail!\n\r");
+    }
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): second enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    //check LID record 1 value
+    cmp_buffer[0] = 0x32; //expect value is 0x32
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): second read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): second read not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //downgrade to MD SW version 1 -> related LID verno is "000"
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->fileverno[0] = '0';
+        ldi->fileverno[1] = '0';
+        ldi->fileverno[2] = '0';
+    }
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): modify MD SW version location3 fail!\n\r");
+    }
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): third enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    //check LID record 1 value
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): third read fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)cmp_buffer, ldi->size);
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            cmp_buffer[0] += 1;
+            if (NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category) && 
+                !kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE) ) 
+            {
+                continue;
+            }
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_verno_change(): third read not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool ota_boot_reserve_backward_size_change(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i, ota_time;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //delete all files in Z:/BACKUP folder
+    FS_XDelete((const WCHAR*)L"Z:\\NVRAM\\BACKUP", (FS_FILE_TYPE|FS_RECURSIVE_TYPE), NULL, 0);
+
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): reset to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //remove GEN_DEFAULT and add RESERVE_BACKWARD
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->attr &= (~NVRAM_ATTR_GEN_DEFAULT);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        ldi->attr |= NVRAM_ATTR_RESERVE_BACKWARD;
+        if(0 == i)
+        {
+            ldi->attr |= NVRAM_ATTR_MULTIPLE; //add multiple for LID1
+        }
+    }
+
+    //this test will use LID verno "000" version
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 0))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //write LID
+    for(ota_time = 0; ota_time < 12; ota_time++)
+    {
+        if(0 == ota_time%2) //even loop time write LID of record 1 first
+        {
+            cmp_buffer[0] = ota_time + 0x30;
+            for(i = 0; i < test_lid_number; i++)
+            {
+                nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+                if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): write previous LID fail!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+        }
+        //change LID size
+        for(i = 0; i < test_lid_number; i++)
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+            if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+            {
+                continue;
+            }
+            ldi->size += 2; //add record size
+        }
+        //modify MD SW version
+        if(!modify_md_sw_version())
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): modify MD SW version location1 fail!\n\r");
+        }
+        //call nvram_init()
+        nvram_boot_trace = 0;
+        nvram_init();
+        if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): first enter version conflict fail!\n\r");
+            return KAL_FALSE;
+        }       
+        
+    }
+
+    //downgrade to MD SW version 2 -> related LID record size is (NVRAM_EF_TEST_LID_SIZE + 4)
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        ldi->size = NVRAM_EF_TEST_LID_SIZE + 4;
+    }
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): modify MD SW version location2 fail!\n\r");
+    }
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): second enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    //check LID record 1 value
+    cmp_buffer[0] = 0x32; //expect value is 0x32
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): second read fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): second read not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //downgrade to MD SW version 1 -> related LID record size is (NVRAM_EF_TEST_LID_SIZE)
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->size = NVRAM_EF_TEST_LID_SIZE;
+    }
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): modify MD SW version location3 fail!\n\r");
+    }
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): third enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    //check LID record 1 value
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if( NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) || NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            continue;
+        }
+        if(!nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): third read fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)cmp_buffer, ldi->size);
+        if(0 != kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ota_boot_reserve_backward_size_change(): third read not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_basic_access(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //this test will use LID verno "000" only
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 0))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_basic_access(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset(create) test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_basic_access(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_basic_access(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_basic_access(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(0 != nvram_lid_cmpt_operation(test_lid_enum[i], 
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                         CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))           
+        {   
+            nvram_ut_trace("[NVUT] normal_boot_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_user_lost_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_user_lost_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_user_lost_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_lost_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_internal_lost_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+        //internal LID size change expect read fail, internal will not run reset flow in nvram_read_data_item()
+    if(0 == nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): expect read fail not happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_internal_lost_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_internal_lost_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_lost_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_calibrat_lost_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    kal_mem_set(data_buffer, 0, ldi->size);
+    data_buffer[0] = 0x1; //modify to the value before binregion backup
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_read(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_calibrat_lost_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_3_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_calibrat_lost_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_3_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_lost_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_important_lost_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    kal_mem_set(data_buffer, 0, ldi->size);
+    data_buffer[0] = 0x1; //modify to the value before binregion backup
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_important_lost_read(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_important_lost_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_4_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): write fail do not happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_write(): expect assert not happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_important_lost_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_4_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_lost_reset(): unexpect asser happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl1_lost_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl1_lost_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl1_lost_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): delete test LID fail!\n\r");
+    }
+   
+   //reset LID and then delete it
+   nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+   if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+   {
+       nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): reset test LID fail!\n\r");
+       return KAL_FALSE;
+   }
+   folder_index = nvram_query_folder_index(ldi->category);
+   nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+   nvram_query_file_name(folder_index, nvramname, filename);
+   FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_lost_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl4_lost_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access, without FATAL_ASSET will run reset flow
+    nvram_ut_assert_flag = 0;
+    if(0 
+!= nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): read fail happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl4_lost_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): delete test LID fail!\n\r");
+    }
+
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access, without FATAL_ASSET will run reset flow
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): write fail happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl4_lost_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): delete test LID fail!\n\r");
+    }
+    
+    //reset LID and then delete it
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename);
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_lost_reset(): unexpect asser happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_user_altered_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): unexpect read fail happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_user_altered_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+    
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_user_altered_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }   
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_user_altered_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_internal_altered_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+        //internal LID size change expect read fail, internal will not run reset flow in nvram_read_data_item()
+    if(0 == nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): expect read fail not happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_internal_altered_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): write test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_internal_altered_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_2_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_2_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_2_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_2_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_internal_altered_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_calibrat_altered_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    kal_uint8 i;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    kal_mem_set(data_buffer, 0, ldi->size);
+    data_buffer[0] = 0x1; //modify to the value before binregion backup
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_read(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_calibrat_altered_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_3_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_calibrat_altered_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_3_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_3_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_3_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_3_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_calibrat_altered_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_important_altered_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    kal_uint8 i;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    kal_mem_set(data_buffer, 0, ldi->size);
+    data_buffer[0] = 0x1; //modify to the value before binregion backup
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): read LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_important_altered_read(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_important_altered_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_4_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_important_altered_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_4_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_4_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_4_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_4_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_important_altered_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl1_altered_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): unexpect read fail happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl1_altered_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl1_altered_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_5_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_5_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_5_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_5_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl1_altered_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl4_altered_read(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access, without FATAL_ASSET will run reset flow
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READ, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): read fail happen!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_read(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl4_altered_write(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_write(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_importantl4_altered_reset(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_6_LID) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): reset test LID settings fail!\n\r");
+    }
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_6_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): delete test LID fail!\n\r");
+    }
+
+    //reset(create) test LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //alter test LID
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): first FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Read(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] += 1;
+    data_buffer[1] += 1;
+    data_buffer[2] += 1;
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Write(hFile, data_buffer, ldi->size, &len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): write back test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+
+    //reset SYS LID to default value
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_COMPATIBLE))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_6_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_read_syslid_fail(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    kal_uint8 *default_value;
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i, temp_result;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //this test will use LID verno "000" only
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!delete_special_version_lid(test_lid_enum[i], 0, 0))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): delete old version LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset(create) test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): reset test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LID with non-default value
+    data_buffer[0] = 0x01;
+    data_buffer[1] = 0x02;
+    data_buffer[2] = 0x03;
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!nvram_external_write_data(test_lid_enum[i], 1, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_LID_SIZE))
+        {
+            nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): write test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //delete SYS LID
+    nvram_util_get_data_item(&ldi, NVRAM_EF_SW_VERNO_LID);
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    FS_Delete(filename); //here do not update bitmap
+    if(ldi->attr & NVRAM_ATTR_MULTIPLE)
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE); //B file
+        nvram_query_file_name(folder_index, nvramname, filename);
+        FS_Delete(filename);
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_READ_SYS_LID_FAIL))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): read SYS LID fail not happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    default_value = (kal_uint8*)get_ctrl_buffer(NVRAM_EF_TEST_LID_SIZE);
+    for(i = 0; i < test_lid_number; i++)
+    {
+        temp_result = nvram_external_read_data(test_lid_enum[i], 1, (kal_uint8 *)cmp_buffer, NVRAM_EF_TEST_LID_SIZE);
+        if(!temp_result)
+        {
+            nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): read test LID fail!\n\r");
+            break;
+        }
+        
+        if((NVRAM_EF_NVRAM_TEST_1_LID == test_lid_enum[i]) ||
+           (NVRAM_EF_NVRAM_TEST_2_LID == test_lid_enum[i]) )
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+            nvram_get_default_value_to_write(ldi, i, default_value, NVRAM_EF_TEST_LID_SIZE);
+            temp_result = !(kal_mem_cmp((kal_char*)default_value, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE));
+        }
+        else
+        {
+            temp_result = !(kal_mem_cmp((kal_char*)data_buffer, (kal_char*)cmp_buffer, NVRAM_EF_TEST_LID_SIZE));
+        }
+        
+        if(!temp_result)
+        {
+            nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): read back value is not expect!\n\r");
+            break;
+        }
+    }
+    free_ctrl_buffer(default_value);
+    
+    if(i < test_lid_number)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_read_syslid_fail(): read back value not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool normal_boot_file_corrupted_test(nvram_lid_enum LID)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 *p_buffer2 = NULL;
+    kal_uint8 i = 0;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0;
+    kal_uint32 temp_result = 0;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    
+    //reset test LIDs to default settings
+    if(!reset_test_lid_default_setting(LID))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_user_size_change_read(): reset LIDs to default setting fail!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_util_get_data_item(&ldi, LID);
+    //Get the LID file name
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    folder_index = nvram_query_folder_index_ex(ldi->category, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+    
+    if(ldi->category == NVRAM_CATEGORY_USER)
+    {
+        if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+        {
+            nvram_ut_trace("[NVUT] normal_boot_importantl4_altered_reset(): reset test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    else if((ldi->category & NVRAM_CATEGORY_CALIBRAT)|| (ldi->category & NVRAM_CATEGORY_IMPORTANT))
+    {
+        FS_Delete(filename);
+    }
+    
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    if(!nvram_external_read_data(LID,1,p_buffer,ldi->size))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: LID record[%d] cmpt operations fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    // Corrupt the LID file data extendly
+    
+    hFile = FS_Open(filename,FS_READ_WRITE | FS_CREATE_ALWAYS);    
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_file_corrupted_test(): can not find test LID file!\n\r");
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] normal_boot_file_corrupted_test(): open test LID file fail!\n\r");
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] normal_boot_file_corrupted_test(): FS_Seek test LID file fail!\n\r");
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    data_buffer[0]=0xAA;
+    data_buffer[1]=0xAA;
+    data_buffer[2]=0xAA;
+    if(FS_NO_ERROR >FS_Write(hFile,data_buffer,3,&len))
+    {
+        nvram_ut_trace("[NVUT] normal_boot_file_corrupted_test(): write test LID file fail!\n\r");
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+    //Readback the LID file
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    p_buffer2 = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    if(!nvram_external_read_data(LID,1,p_buffer2,ldi->size))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: LID record[1] read operations fail @line %d!\n\r",__FUNCTION__,__LINE__);
+        free_ctrl_buffer(p_buffer);
+        free_ctrl_buffer(p_buffer2);
+        return KAL_FALSE;
+    }
+    temp_result = kal_mem_cmp((kal_char*)p_buffer, (kal_char*)p_buffer2, ldi->size);
+    free_ctrl_buffer(p_buffer);
+    free_ctrl_buffer(p_buffer2);
+    if(temp_result!= 0)
+    {
+        nvram_ut_trace("[NVUT] %s() %d: LID record[1] compare data fail @line %d!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    return KAL_TRUE;
+}
+
+kal_bool normal_boot_user_corrupted_test(kal_uint32 flags, void *param)
+{    
+    return normal_boot_file_corrupted_test(NVRAM_EF_NVRAM_TEST_1_LID);
+}
+
+kal_bool normal_boot_calibrate_corrupted_test(kal_uint32 flags, void *param)
+{
+    return normal_boot_file_corrupted_test(NVRAM_EF_NVRAM_TEST_3_LID);
+}
+
+kal_bool normal_boot_important_corrupted_test(kal_uint32 flags, void *param)
+{
+    return normal_boot_file_corrupted_test(NVRAM_EF_NVRAM_TEST_4_LID);
+}
+
+kal_bool normal_boot_important_l4_corrupted_test(kal_uint32 flags, void *param)
+{
+    return normal_boot_file_corrupted_test(NVRAM_EF_NVRAM_TEST_6_LID);
+}
+
+kal_bool attr_average_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_average_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr = NVRAM_ATTR_AVERAGE;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_average_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_average_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] attr_average_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] attr_average_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool attr_multi_default_read_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer;
+    nvram_read_req_struct *read_req;
+    //nvram_read_cnf_struct *nvram_read_cnf;
+    ilm_struct current_ilm;
+    kal_uint8 i;
+    kal_uint8 temp_result;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_multi_default_read_basic_access(): reset test LID settings fail!\n\r");
+    }
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_multi_default_read_basic_access(): delete test LID fail!\n\r");
+    }
+    
+    for(i = 0; i < ldi->total_records; i++)
+    {
+        data_buffer[ldi->size * i] = i+1; //modify data_buffer to special value
+    }
+    ldi->default_value = (kal_uint8 const*)data_buffer;
+    ldi->attr = NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_MULTIREC_READ;
+    
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_multi_default_read_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+    read_req->ref_count = 1;
+    read_req->file_idx = ldi->LID;
+    read_req->para = 1;
+    read_req->rec_amount = ldi->total_records;
+    msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_READ_REQ, 
+            (local_para_struct*)read_req, NULL);    
+    msg_receive_extq(&current_ilm);
+    p_buffer = (kal_uint8 *)get_peer_buff_pdu(current_ilm.peer_buff_ptr, 0);
+    temp_result = kal_mem_cmp(data_buffer, p_buffer, ldi->size * ldi->total_records);
+    destroy_ilm(&current_ilm);
+    
+    if(0 != temp_result)
+    {
+        nvram_ut_trace("[NVUT] attr_multi_default_read_basic_access(): read back value not as expect!\n\r");
+        return KAL_FALSE;
+    }
+
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0, 0), 
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] attr_multi_default_read_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] attr_multi_default_read_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool attr_write_protect_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 lock_status;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): reset test LID settings fail!\n\r");
+    }
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)data_buffer, ldi->size);
+    
+    ldi->attr |= NVRAM_ATTR_WRITEPROTECT;
+    ldi->default_value = NVRAM_EF_FF_DEFAULT; //modify test LID's default value
+
+    //lid read
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): first read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): first read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    //lid write
+    lock_status = nvram_ptr->lock;
+    nvram_ptr->lock = KAL_TRUE;
+    cmp_buffer[0] = 0x30;
+    if( KAL_TRUE == nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): write fail not happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): second read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): second read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    //lid reset
+    nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records);
+    nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)data_buffer, ldi->size); //get new default value
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): third read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_write_protect_basic_access(): third read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+
+    nvram_ptr->lock = lock_status;
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool attr_multiple_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr = NVRAM_ATTR_MULTIPLE;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //lid read
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): nvram_lid_cmpt_operation() read fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): unexpect read assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid write
+    data_buffer[0] = 0x01;
+    data_buffer[1] = 0x02;
+    data_buffer[2] = 0x03;
+    if( !nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)data_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): write test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE); //A file
+    nvram_query_file_name(folder_index, nvramname, filename);
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_util_take_mutex(g_nvram_fs_mutex);    
+    #endif
+    FS_Delete(filename);
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+    #endif
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): read back value not as expect!\n\r");
+        return KAL_FALSE;
+    }
+
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE); //B file
+    nvram_query_file_name(folder_index, nvramname, filename);
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_util_take_mutex(g_nvram_fs_mutex);    
+    #endif
+    FS_Delete(filename);
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+    #endif
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): second read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): second read back value not as expect!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid reset
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_RESET, 0, 0, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): nvram_lid_cmpt_operation() reset fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] attr_multiple_basic_access(): unexpect reset assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool attr_confidential_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0, remainLen = 0;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache as change the LID file size as add the NVRAM_ATTR_CONFIDENTIAL
+    #endif
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr |= NVRAM_ATTR_CONFIDENTIAL;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] = 0x01;
+    data_buffer[1] = 0x02;
+    data_buffer[2] = 0x03;
+    if( !nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)data_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): first write test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): first read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): read back value not as expect!\n\r");
+        return KAL_FALSE;
+    }    
+    
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + NVRAM_CHKSUM_SIZE); //SW or HW encrpyt need align data
+    if(FS_NO_ERROR > FS_Read(hFile, cmp_buffer, ldi->size + NVRAM_CHKSUM_SIZE + remainLen, &len))
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+    //expect data is changed
+    if(0 == kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): after encrypt data not change!\n\r");
+        return KAL_FALSE;
+    }   
+
+    //decrypt
+    nvram_AES_decrypt((kal_uint8 *)cmp_buffer, ldi->size + NVRAM_CHKSUM_SIZE + remainLen);
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size)) //only check data part, ignore cheksum
+    {
+        nvram_ut_trace("[NVUT] attr_confidential_basic_access(): second read back value not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool attr_msp_basic_access(kal_uint32 flags, void *param)
+{
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    FS_HANDLE hFile = 0;
+    kal_uint32 len = 0, remainLen = 0, section_size = 0;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache as change the LID file size as add the NVRAM_ATTR_MSP
+    #endif
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr = NVRAM_ATTR_MSP;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    data_buffer[0] = 0x01;
+    data_buffer[1] = 0x02;
+    data_buffer[2] = 0x03;
+    if( !nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)data_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): write test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): first read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+
+    folder_index = nvram_query_folder_index(ldi->category);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_query_file_name(folder_index, nvramname, filename);
+
+    hFile = FS_Open((const kal_wchar*)filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_OPEN_SHARED);
+    if (hFile == FS_FILE_NOT_FOUND)
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): can not find test LID!\n\r");
+        return KAL_FALSE;
+    }
+    else if (hFile <= FS_NO_ERROR)
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): open test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(FS_NO_ERROR > FS_Seek(hFile, NVRAM_LDI_HEADER_SIZE, FS_FILE_BEGIN)) //skip LID header
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): FS_Seek test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + NVRAM_CHKSUM_SIZE); //SW or HW encrpyt need align data        
+    section_size = ldi->size + NVRAM_CHKSUM_SIZE + remainLen;
+    if(FS_NO_ERROR > FS_Read(hFile, cmp_buffer, section_size, &len))
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): FS_Read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    if(hFile > FS_NO_ERROR)
+    {
+        FS_Close(hFile);
+    }
+    //expect after HW encrypt data is changed
+    if(0 == kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): after encrypt data not change!\n\r");
+        return KAL_FALSE;
+    }
+
+    //decrypt
+    {
+        kal_uint8 *working_buffer2 = (kal_uint8*) get_ctrl_buffer(section_size);
+        kal_uint8 *working_buffer3 = (kal_uint8*) get_ctrl_buffer(section_size);
+        memcpy(working_buffer2, cmp_buffer, section_size);
+        do
+        {
+            //decrypt the cmp_buffer
+            SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32) (cmp_buffer), section_size, nvram_ptr->secret_key, (kal_uint8 *)cmp_buffer);
+            //copy decrypted data from working_buffer to working_buffer3
+            memcpy(working_buffer3, cmp_buffer, section_size);
+            //encrypt the working_buffer3
+            SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer3, section_size, nvram_ptr->secret_key, working_buffer3);
+
+            //compare the working_buffer2 & working_buffer3
+            if (memcmp(working_buffer2, working_buffer3, section_size) == 0)
+            {
+                //decrypt PASS
+                break;
+            }
+            else
+            {
+                //decrypt FAIL, try again
+                memcpy(cmp_buffer, working_buffer2, section_size);
+            }
+        }while(1);
+        free_ctrl_buffer(working_buffer2);
+        free_ctrl_buffer(working_buffer3);
+    }
+
+    //after decrypt expect data is same
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] attr_msp_basic_access(): second read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+#else
+
+    nvram_ut_trace("[NVUT] attr_msp_basic_access(): HW encrypt is not enable!\n\r");
+    return KAL_TRUE;
+    
+#endif
+    
+}
+
+kal_bool attr_committed_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_committed_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr = NVRAM_ATTR_COMMITTED;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_committed_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_committed_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] attr_committed_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] attr_committed_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool attr_ring_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_write_req_struct *write_req;
+    nvram_write_cnf_struct *nvram_write_cnf;
+    kal_uint8 *pdu_write_buffer;
+    ilm_struct current_ilm;
+    kal_uint8 i;
+    kal_uint8 temp_result;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attr_ring_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr = NVRAM_ATTR_RING;
+    ldi->total_records = 3;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] attr_ring_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] attr_ring_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //write LID
+    data_buffer[0] = 0x31;
+    data_buffer[1] = 0x32;
+    data_buffer[2] = 0x33;
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        write_req = (nvram_write_req_struct *)construct_local_para(sizeof(nvram_write_req_struct), TD_CTRL);
+        pdu_write_buffer = (kal_uint8 *)construct_peer_buff(ldi->size, 0, 0, TD_CTRL);
+        kal_mem_cpy(get_peer_buff_pdu((peer_buff_struct*)pdu_write_buffer, 0), data_buffer, ldi->size);
+        write_req->ref_count = 1;
+        write_req->file_idx = ldi->LID;
+        write_req->para = i;
+        msg_send6(kal_get_active_module_id(), MOD_NVRAM, PS_NVRAM_SAP, MSG_ID_NVRAM_WRITE_REQ, 
+                (local_para_struct*)write_req, (peer_buff_struct*)pdu_write_buffer);
+        msg_receive_extq(&current_ilm);
+        nvram_write_cnf = (nvram_write_cnf_struct*)current_ilm.local_para_ptr;
+        temp_result = nvram_write_cnf->result;
+        destroy_ilm(&current_ilm);
+        if(NVRAM_ERRNO_SUCCESS != temp_result)
+        {
+            break;
+        }
+    }
+
+    if(i <= ldi->total_records)
+    {
+        nvram_ut_trace("[NVUT] attr_ring_basic_access(): ring write test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check LID value
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if( !nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size) )
+        {
+            nvram_ut_trace("[NVUT] attr_ring_basic_access(): read test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+
+        if(1 == i)
+        {
+            if(cmp_buffer[0] != 0x2) //last write record is stored in cmp_buffer[0]
+            {
+                nvram_ut_trace("[NVUT] attr_ring_basic_access(): record 1 read back value is not expect!\n\r");
+                return KAL_FALSE;
+            }
+        }
+        else
+        {
+            if(0 != kal_mem_cmp(cmp_buffer, data_buffer, ldi->size)) //expect same
+            {
+                nvram_ut_trace("[NVUT] attr_ring_basic_access(): read back value is not expect!\n\r");
+                return KAL_FALSE;
+            }
+        }
+    }
+
+    return KAL_TRUE;
+    
+}
+
+/*
+Because IMPORTANT/IMPORTANT_L4 access error will cause assert defaultly, so NVRAM_ATTR_FAULT_ASSERT
+is mainly used for some LIDs without IMPORTANT/IMPORTANT_L4 category. So in this case we just test other
+categories with this attribute.
+*/
+kal_bool attr_fault_assert_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 category_list[] = {
+                                  NVRAM_CATEGORY_USER, NVRAM_CATEGORY_INTERNAL, 
+                                  NVRAM_CATEGORY_CALIBRAT,NVRAM_CATEGORY_IMPORTANT,
+                                  NVRAM_CATEGORY_IMPORTANT_L1,NVRAM_CATEGORY_IMPORTANT_L4,
+                                 };
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    NVRAM_FILE_NAME nvramname;
+    kal_uint8 i;
+    kal_bool multiple = KAL_FALSE;
+    kal_uint32 multiple_ID = 0;
+    
+    for(i = 0; i < sizeof(category_list)/sizeof(kal_uint32); i++)
+    {
+        //reset test LIDs to default settings
+        if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+        {
+            nvram_ut_trace("[NVUT] attr_fault_assert_test(): reset test LID settings fail!\n\r");
+        }
+        nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+        ldi->category = (nvram_category_enum)(category_list[i]);
+        ldi->attr |= NVRAM_ATTR_FAULT_ASSERT;
+        ldi->attr &= ~NVRAM_ATTR_MULTIPLE;
+
+        if(NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            ldi->fileverno[0]++; //change filename not same with binregion backup file
+        }
+        
+        if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+        {
+            multiple = KAL_TRUE;
+        }
+        //reset test LID to default value, LID default has GEN_DEFAULT attribute
+        if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+        {
+            nvram_ut_trace("[NVUT] attr_fault_assert_test(): reset test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        
+        #ifdef __NVRAM_LID_CACHE__
+        while((check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE));
+        #endif
+        
+        //delete LID
+        #ifdef __NVRAM_LID_CACHE__
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+        #endif
+        for (multiple_ID = 0; multiple_ID < 2; multiple_ID++)
+        {
+            folder_index = nvram_query_folder_index(ldi->category);
+            
+            #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+            if (multiple_ID == 1)
+            {            
+                folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+            }        
+            #endif
+
+            if (multiple_ID == 0)
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            }else
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+            }
+            nvram_query_file_name(folder_index, nvramname, filename);        
+            FS_Delete(filename);
+            if(!multiple)
+            {
+                break;
+            }
+        }
+		#ifdef __NVRAM_LID_CACHE__
+        nvram_util_give_mutex(g_nvram_fs_mutex);
+		#endif
+        #ifdef __NVRAM_LID_CACHE__
+        //clean the valid and dirty bit of LID
+        if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+        {
+            nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,ldi->LID,unmask_lid_all_record_valid_bit(ldi),unmask_lid_all_record_dirty_bit(ldi));
+            return KAL_FALSE;
+        }
+        #endif
+        
+        //read access
+        nvram_ut_assert_flag = 0;
+        if(KAL_TRUE == nvram_external_read_data(ldi->LID, 1, (kal_uint8*)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] attr_fault_assert_test(): read fail do not happen!\n\r");
+            return KAL_FALSE;
+        }
+        if((0 == nvram_ut_assert_flag) && (!NVRAM_IS_CATEGORY_INTERNAL(ldi->category))) //internal category read fail only return fail status
+        {
+            nvram_ut_trace("[NVUT] attr_fault_assert_test(): read assert do not happen!\n\r");
+            return KAL_FALSE;
+        }
+        #ifndef __NVRAM_LID_CACHE__
+        //delete LID
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+        for (multiple_ID = 0; multiple_ID < 2; multiple_ID++)
+        {
+            folder_index = nvram_query_folder_index(ldi->category);
+            
+            #if defined(__MTK_TARGET__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+            if (multiple_ID == 1)
+            {            
+                folder_index = nvram_query_folder_index_ex(ldi->category, KAL_FALSE);
+            }        
+            #endif
+
+            if (multiple_ID == 0)
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            }else
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+            }
+            nvram_query_file_name(folder_index, nvramname, filename);        
+            FS_Delete(filename);
+            if(!multiple)
+            {
+                break;
+            }
+        }
+        nvram_util_give_mutex(g_nvram_fs_mutex);
+        //write access
+        nvram_ut_assert_flag = 0;
+        if(KAL_TRUE == nvram_external_write_data(ldi->LID, 1, (kal_uint8*)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] attr_fault_assert_test(): write fail do not happen!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 == nvram_ut_assert_flag)
+        {
+            nvram_ut_trace("[NVUT] attr_fault_assert_test(): write assert do not happen!\n\r");
+            return KAL_FALSE;
+        }
+        #endif
+        
+    }
+
+    return KAL_TRUE;
+}
+
+
+kal_bool category_user_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] category_user_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_USER;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] category_user_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] category_user_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    #ifdef __NVRAM_LID_CACHE__
+    while((check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE));
+    #endif
+    
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] category_user_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] category_user_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool category_internal_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] category_internal_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_INTERNAL;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] category_internal_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] category_internal_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] category_internal_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] category_internal_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool category_calibrat_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] category_calibrat_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_CALIBRAT;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] category_calibrat_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] category_calibrat_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] category_calibrat_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] category_calibrat_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool category_important_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] category_important_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_IMPORTANT;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] category_important_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] category_important_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] category_important_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] category_important_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool category_importantl1_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] category_importantl1_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_IMPORTANT_L1;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] category_importantl1_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] category_importantl1_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] category_importantl1_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] category_importantl1_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool category_importantl4_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] category_importantl4_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category = NVRAM_CATEGORY_IMPORTANT_L4;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] category_importantl4_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] category_importantl4_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //lid access
+    nvram_ut_assert_flag = 0;
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] category_importantl4_basic_access(): nvram_lid_cmpt_operation() fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] category_importantl4_basic_access(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+    
+}
+
+kal_bool func_default_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] func_default_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->category |= NVRAM_CATEGORY_FUNC_DEFAULT;
+    ldi->default_value= (kal_uint8 const*)nvram_ut_get_default_value;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] func_default_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] func_default_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check LID value
+    nvram_ut_get_default_value(ldi->LID, (kal_uint8 *)data_buffer, ldi->size);
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] func_default_basic_access(): read test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] func_default_basic_access(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool zero_default_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] zero_default_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] zero_default_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] zero_default_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check LID value
+    kal_mem_set(data_buffer, 0x0, ldi->size);
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] zero_default_basic_access(): read test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] zero_default_basic_access(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool ff_default_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] ff_default_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->default_value = NVRAM_EF_FF_DEFAULT;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] ff_default_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] ff_default_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check LID value
+    kal_mem_set(data_buffer, 0xFF, ldi->size);
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ff_default_basic_access(): read test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] ff_default_basic_access(): read back value not expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool table_default_basic_access(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] table_default_basic_access(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    kal_mem_set(data_buffer, 0x01, ldi->size);
+    ldi->default_value = (kal_uint8 const*)data_buffer;
+
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] table_default_basic_access(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] table_default_basic_access(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check LID value
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] table_default_basic_access(): read test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] table_default_basic_access(): read back value not expcet!\n\r");
+            return KAL_FALSE;
+        }
+    }
+    
+    return KAL_TRUE;
+    
+}
+
+kal_bool attribute_category_defaultvalue_combine(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_attr_enum attr_bak;
+    kal_uint8 i, j, k;
+    kal_uint8 lock_status = KAL_FALSE;
+    kal_uint32 attribute_list[] = {
+                                    NVRAM_ATTR_AVERAGE, NVRAM_ATTR_COMMITTED, NVRAM_ATTR_CONFIDENTIAL,
+                                #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+                                    NVRAM_ATTR_MSP, 
+                                #endif
+                                    NVRAM_ATTR_MULTIPLE, NVRAM_ATTR_MULTIREC_READ,
+                                    NVRAM_ATTR_MULTI_DEFAULT, NVRAM_ATTR_OTA_RESET, NVRAM_ATTR_WRITEPROTECT,
+                                    NVRAM_ATTR_GEN_DEFAULT,
+                                  };
+    kal_uint32 category_list[] = {
+                                    NVRAM_CATEGORY_USER, NVRAM_CATEGORY_INTERNAL, NVRAM_CATEGORY_CALIBRAT,
+                                    NVRAM_CATEGORY_IMPORTANT, NVRAM_CATEGORY_IMPORTANT_L1, NVRAM_CATEGORY_IMPORTANT_L4,
+                                 };
+    
+    kal_uint8 const* default_value_list[] = {
+                                                (kal_uint8 const*)NVRAM_EF_ZERO_DEFAULT, (kal_uint8 const*)NVRAM_EF_FF_DEFAULT, (kal_uint8 const*)table_default, (kal_uint8 const*)nvram_ut_get_default_value,
+                                            };
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache as change the LID file size as add the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL
+    #endif    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] attribute_category_defaultvalue_combine(): reset test LID settings fail!\n\r");
+    }   
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr = 0;
+    ldi->category = 0;
+    ldi->default_value = 0;
+    for(i = 0; i < (sizeof(default_value_list)/sizeof(kal_uint8 const*)); i++) //default value loop
+    {
+        for(j = 0; j < (sizeof(category_list)/sizeof(kal_uint32)); j++) //category loop
+        {
+            for(k = 0; k < (sizeof(attribute_list)/sizeof(kal_uint32)); k++) //attribute loop
+            {
+                ldi->default_value = default_value_list[i];
+                ldi->category = category_list[j];
+                ldi->attr |= attribute_list[k];
+                if((kal_uint8 const*)nvram_ut_get_default_value == default_value_list[i])
+                {
+                    ldi->category |= NVRAM_CATEGORY_FUNC_DEFAULT;
+                }
+                else
+                {
+                    ldi->category &= ~NVRAM_CATEGORY_FUNC_DEFAULT;
+                }
+
+                if((kal_uint8 const*)table_default != default_value_list[i])
+                {
+                    ldi->attr &= ~NVRAM_ATTR_MULTI_DEFAULT;
+                }
+
+                if(ldi->attr & NVRAM_ATTR_WRITEPROTECT)
+                {
+                    lock_status = nvram_ptr->lock;
+                    nvram_ptr->lock = KAL_FALSE;
+                }
+                
+                //this test will use LID verno "000" only
+                if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+                {
+                    nvram_ut_trace("[NVUT] attribute_category_defaultvalue_combine(): delete test LID fail!\n\r");
+                    return KAL_FALSE;
+                }
+
+                attr_bak = ldi->attr;
+
+                //reset test LID to default value
+                if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+                {
+                    nvram_ut_trace("[NVUT] attribute_category_defaultvalue_combine(): reset test LID fail!\n\r");
+                    return KAL_FALSE;
+                }
+
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                                     CMPT_OP_WAY_API, 1, NVRAM_EF_TEST_LID_RECORD_TOTAL))
+                {
+                    nvram_ut_trace("[NVUT] attribute_category_defaultvalue_combine(): nvram_lid_cmpt_operation() fail!\n\r");
+                    return KAL_FALSE;
+                }
+
+                if(attr_bak != ldi->attr)
+                {
+                    nvram_ut_trace("[NVUT] attribute_category_defaultvalue_combine(): attr changed unexpect!\n\r");
+                }
+
+                if(ldi->attr & NVRAM_ATTR_WRITEPROTECT)
+                {
+                    nvram_ptr->lock = lock_status;
+                }
+            }
+            ldi->attr = 0; //attr is |= add, so need clear
+            kal_sleep_task(kal_milli_secs_to_ticks(10));
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool chksum_read_function_basic_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 remainLen = 0, file_size;
+    NVRAM_FILE_NAME nvramname;
+    FS_FileOpenHint Hint;
+    nvram_folder_enum folder_index;
+	kal_uint8 *chksum_buf = NULL;
+    kal_uint16 chksum_2b_buf = 0;
+	kal_uint8 chksum_size, chksum_2b_size;
+	kal_uint64 const EmptyChksum = 0xCDEF;
+    kal_uint8 i;
+	nvram_lid_chksum_info lid_chksum_info = {0};
+    kal_bool result = KAL_TRUE;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache as change the LID file size as add the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL
+    #endif
+
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): reset test LID settings fail!\n\r");
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->total_records = 1;
+    ldi->attr |= NVRAM_ATTR_CONFIDENTIAL;
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        ldi->attr |= NVRAM_ATTR_MSP;
+    #endif
+
+//check 2B checksum API
+    //zero default-with not NVRAM_ATTR_GEN_DEFAULT
+        //clear test environment
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): delete test LID fail!\n\r");
+    }
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+    ldi->attr &= (~NVRAM_ATTR_GEN_DEFAULT); //remove GEN_DEFAULT attr
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): reset test LID fail(ZERO default)!\n\r");
+        return KAL_FALSE;
+    }
+    kal_mem_set(data_buffer,0,NVRAM_UT_BUFFER_SIZE);
+    nvram_get_lid_chksum_algo_info(ldi,&lid_chksum_info,KAL_FALSE,KAL_FALSE);    
+    chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+    nvram_get_lid_chksum_algo_info(ldi,&lid_chksum_info,KAL_TRUE,KAL_TRUE);
+	chksum_2b_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    
+    nvram_external_read_chksum(ldi->LID, 1, 1, (kal_uint8 *)data_buffer, chksum_2b_size);
+	nvram_external_read_chksum_only(ldi->LID, 1, 1, (kal_uint8 *)cmp_buffer, chksum_2b_size);
+
+	if(0!=kal_mem_cmp(data_buffer, &EmptyChksum, sizeof(EmptyChksum)) || 0!=kal_mem_cmp(cmp_buffer, &EmptyChksum, sizeof(EmptyChksum)))
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): ZERO default without GEN_DEFAULT checksum mismatch!\n\r");
+        // nvram_ut_trace("[NVUT] chksum2: %x, chksum3: %x.\n\r", chksum2, chksum3);
+        return KAL_FALSE;
+    }
+
+    //zero default-with NVRAM_ATTR_GEN_DEFAULT
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): delete test LID fail!\n\r");
+    }
+    ldi->attr |= NVRAM_ATTR_GEN_DEFAULT; //add GEN_DEFAULT attr
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): reset test LID fail(ZERO default)!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_external_read_chksum(ldi->LID, 1, 1, (kal_uint8 *)data_buffer, chksum_2b_size);
+    nvram_external_read_chksum_only(ldi->LID, 1, 1, (kal_uint8 *)cmp_buffer, chksum_2b_size);
+
+	if(0!=kal_mem_cmp(data_buffer, &EmptyChksum, sizeof(EmptyChksum)) || 0!=kal_mem_cmp(cmp_buffer, &EmptyChksum, sizeof(EmptyChksum)))
+    {
+        nvram_ut_trace("[NVUT] chksum_read_function_test(): ZERO default without GEN_DEFAULT checksum mismatch!\n\r");
+        // nvram_ut_trace("[NVUT] chksum2: %x, chksum3: %x.\n\r", chksum2, chksum3);
+        return KAL_FALSE;
+    }
+    //non-zero default
+    kal_mem_set(data_buffer,0,NVRAM_UT_BUFFER_SIZE);
+    data_buffer[0] = 0x12; //modify one data
+    ldi->default_value = (const kal_uint8 *)data_buffer;
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+	chksum_buf = (kal_uint8 *)get_ctrl_buffer(chksum_size);
+    kal_mem_set(chksum_buf,0,chksum_size);
+    for(i = 0; i < 16; i++) //change LID to different size to test(SW/HW encrypt need 16B align)
+    {
+        if(i%2) //only 0dd time add SW/HW encrypt
+        {
+            ldi->attr |= NVRAM_ATTR_CONFIDENTIAL;
+            #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+                ldi->attr |= NVRAM_ATTR_MSP;
+            #endif
+        }
+        else
+        {
+            ldi->attr &= ~NVRAM_ATTR_CONFIDENTIAL;
+            #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+                ldi->attr &= ~NVRAM_ATTR_MSP;
+            #endif
+        }
+        kal_mem_set(data_buffer, i, ldi->size);
+        kal_mem_set(chksum_buf, 0, chksum_size);
+        chksum_2b_buf = nvram_util_caculate_checksum(ldi, (kal_uint8*)data_buffer, ldi->size, chksum_buf); //record size is about 1K, so can generate chksum at one time
+
+        //clear test environment
+        if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+        {
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): delete test LID fail!\n\r");
+        }
+
+        //reset test LID to default value
+        if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+        {
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): reset test LID fail!\n\r");
+            result = KAL_FALSE;
+            break;
+        }
+
+        //check LID file size
+        if((ldi->attr & NVRAM_ATTR_CONFIDENTIAL) || (ldi->attr & NVRAM_ATTR_MSP))
+            remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size+NVRAM_CHKSUM_SIZE); //SW or HW encrypt align after add checksum
+        else
+            remainLen = 0;
+        
+        folder_index = nvram_query_folder_index(ldi->category);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+        file_size = nvram_drv_fat_get_record_size(nvramname, &Hint, folder_index);
+        if(file_size != ((ldi->size+NVRAM_CHKSUM_SIZE+remainLen) * ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): file size not match!\n\r");
+            nvram_ut_trace("[NVUT] file size: %d, expect size: %d\n\r", file_size, (ldi->size+NVRAM_CHKSUM_SIZE+remainLen) * ldi->total_records);
+            result = KAL_FALSE;
+            break;
+        }
+
+        //check checksum value
+        if(!nvram_external_read_chksum(ldi->LID, 1, 1, (kal_uint8 *)cmp_buffer, chksum_2b_size))
+        {
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): nvram_external_read_chksum() fail!\n\r");
+            result = KAL_FALSE;
+            break;
+        }
+		if(0!=kal_mem_cmp(&chksum_2b_buf,cmp_buffer,chksum_2b_size))
+        {
+            nvram_ut_trace("[NVUT] i: %d.\n\r", i);
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): chksum compare fail!\n\r");
+            //nvram_ut_trace("[NVUT] chksum1: %x, chksum2: %x, chksum3: %x.\n\r", chksum1, chksum2, chksum3);
+            result = KAL_FALSE;
+            break;
+        }
+        if(!nvram_external_read_chksum_only(ldi->LID, 1, 1, (kal_uint8 *)cmp_buffer, chksum_2b_size))
+        {
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): nvram_external_read_chksum_only() fail!\n\r");
+            result = KAL_FALSE;
+            break;
+        }
+
+        if(0!=kal_mem_cmp(&chksum_2b_buf,cmp_buffer,chksum_2b_size))
+        {
+            nvram_ut_trace("[NVUT] i: %d.\n\r", i);
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): chksum compare fail!\n\r");
+            // nvram_ut_trace("[NVUT] chksum1: %x, chksum2: %x, chksum3: %x.\n\r", chksum1, chksum2, chksum3);
+            result = KAL_FALSE;
+            break;
+        }
+
+//chcek 8B checksum API
+        kal_mem_set(chksum_buf,0,chksum_size);
+        nvram_util_caculate_checksum(ldi, (kal_uint8 *)data_buffer, ldi->size, chksum_buf);
+        if(!nvram_external_read_chksum_8b(ldi->LID, 1, 1, (kal_uint8 *)cmp_buffer, chksum_size))
+        {
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): 8B checksum read fail!\n\r");
+            result = KAL_FALSE;
+            break;
+        }
+        if(0 != kal_mem_cmp(chksum_buf, cmp_buffer, chksum_size))
+        {
+            nvram_ut_trace("[NVUT] i: %d.\n\r", i);
+            nvram_ut_trace("[NVUT] chksum_read_function_test(): 8B checksum not match!\n\r");
+            result = KAL_FALSE;
+            break;
+        }
+        
+        ldi->size ++; //modify lid size
+    }
+
+    free_ctrl_buffer(chksum_buf);
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+
+    return result;
+    
+}
+
+kal_bool chksum_multi_read_function_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 md5_chksum_comput[NVRAM_CHKSUM_SIZE_2B* NVRAM_EF_TEST_LID_RECORD_TOTAL]; //chksum compute by API
+    kal_uint8 md5_chksum_read_2B[NVRAM_CHKSUM_SIZE_2B* NVRAM_EF_TEST_LID_RECORD_TOTAL]; //chksum read by nvram_external_chksum_read()
+    kal_uint8 md5_chksum_read_only_2B[NVRAM_CHKSUM_SIZE_2B* NVRAM_EF_TEST_LID_RECORD_TOTAL]; //chksum read by nvram_external_chksum_read_only()
+    // kal_uint8 md5_chksum_8B[NVRAM_CHKSUM_SIZE];
+
+	kal_uint8  *chksum_data_buffer=NULL;	//md5 chksum 8b
+	kal_uint16 *ptr = NULL;
+    kal_uint16 md5_chksum_2B = 0;
+    kal_uint8 i, chksum_size, chksum_2b_size;
+	nvram_lid_chksum_info lid_chksum_info = {0};
+    
+#define CHKSUM_TEST_RECORD_NUM  NVRAM_EF_TEST_LID_RECORD_TOTAL/2 //read start_record ~ total_record total CHKSUM_TEST_RECORD_NUM records
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache as change the LID file size as add the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL
+    #endif
+//NVRAM_EF_ZERO_DEFAULT check (chksum should be 0xCDEF)
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): reset test LID settings fail!\n\r");
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    ldi->attr &= ~NVRAM_ATTR_GEN_DEFAULT; //remove GEN_DEFAULT attribute
+    ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+	nvram_get_lid_chksum_algo_info(ldi,&lid_chksum_info,KAL_FALSE,KAL_FALSE);
+	chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+	// chksum 2b info
+	nvram_get_lid_chksum_algo_info(ldi,&lid_chksum_info,KAL_TRUE,KAL_TRUE);
+	chksum_2b_size = lid_chksum_info.algo_info.chksum_algo_length;
+	
+    //delete related version LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): delete test LID fail!\n\r");
+    }
+
+    ptr = (kal_uint16 *)md5_chksum_comput; //fill buffer with 0xCDEF
+    for(i = 0; i < CHKSUM_TEST_RECORD_NUM; i++)
+        ptr[i] = 0xCDEF;
+
+    kal_mem_set(md5_chksum_read_2B, 0, sizeof(md5_chksum_read_2B));
+    kal_mem_set(md5_chksum_read_only_2B, 0, sizeof(md5_chksum_read_only_2B));
+    nvram_external_read_chksum(ldi->LID, ldi->total_records-CHKSUM_TEST_RECORD_NUM+1, CHKSUM_TEST_RECORD_NUM, (kal_uint8 *)(md5_chksum_read_2B), sizeof(md5_chksum_read_2B));
+    nvram_external_read_chksum_only(ldi->LID, ldi->total_records-CHKSUM_TEST_RECORD_NUM+1, CHKSUM_TEST_RECORD_NUM, (kal_uint8 *)(md5_chksum_read_only_2B), sizeof(md5_chksum_read_only_2B));
+
+    if(0 != kal_mem_cmp(md5_chksum_comput, md5_chksum_read_2B, NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM) ||
+       0 != kal_mem_cmp(md5_chksum_comput, md5_chksum_read_only_2B, NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): zero default chksum check fail!\n\r");
+        for(i = 0; i < NVRAM_CHKSUM_SIZE_2B* CHKSUM_TEST_RECORD_NUM; i++)
+        {
+            nvram_ut_trace("[NVUT] cksum_compute[%d]: %x, chksum_read[%d]: %x, chksum_read_only[%d]: %x.\n\r", 
+                i, md5_chksum_comput[i], i, md5_chksum_read_2B[i], i, md5_chksum_read_only_2B[i]);
+        }
+        return KAL_FALSE;
+    }
+    
+//non-zero(with encrypt) chksum check
+    ldi->attr |= NVRAM_ATTR_CONFIDENTIAL;
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        ldi->attr |= NVRAM_ATTR_MSP;
+    #endif
+    //delete related version LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): delete test LID fail!\n\r");
+    }
+    ptr = (kal_uint16 *)md5_chksum_comput;
+    
+    chksum_data_buffer = (kal_uint8 *)get_ctrl_buffer(chksum_size);    
+    kal_mem_set(chksum_data_buffer, 0, sizeof(chksum_size));
+
+    for(i = NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1; i <= NVRAM_EF_TEST_LID_RECORD_TOTAL; i++)
+    {
+        data_buffer[i] = i;
+        kal_mem_set(chksum_data_buffer, 0, chksum_size);
+        md5_chksum_2B = nvram_util_caculate_checksum(ldi, (kal_uint8*)data_buffer, ldi->size, chksum_data_buffer);
+        ptr[i-(NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1)] = md5_chksum_2B;
+        if(!nvram_external_write_data(ldi->LID, i, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): write test LID fail!\n\r");
+            free_ctrl_buffer(chksum_data_buffer);
+            return KAL_FALSE;
+        }
+    }
+
+    kal_mem_set(md5_chksum_read_2B, 0, sizeof(md5_chksum_read_2B));
+    kal_mem_set(md5_chksum_read_only_2B, 0, sizeof(md5_chksum_read_only_2B));
+    nvram_external_read_chksum(ldi->LID, NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1, CHKSUM_TEST_RECORD_NUM, (kal_uint8 *)(md5_chksum_read_2B), sizeof(md5_chksum_read_2B));
+    nvram_external_read_chksum_only(ldi->LID, NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1, CHKSUM_TEST_RECORD_NUM, (kal_uint8 *)(md5_chksum_read_only_2B), sizeof(md5_chksum_read_only_2B));
+
+    if(0 != kal_mem_cmp(md5_chksum_comput, md5_chksum_read_2B, NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM) ||
+       0 != kal_mem_cmp(md5_chksum_comput, md5_chksum_read_only_2B, NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): non-zero with encrypt chksum check fail!\n\r");
+        for(i = 0; i < NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM; i++)
+        {
+            nvram_ut_trace("[NVUT] cksum_compute[%d]: %x, chksum_read[%d]: %x, chksum_read_only[%d]: %x.\n\r", 
+                i, md5_chksum_comput[i], i, md5_chksum_read_2B[i], i, md5_chksum_read_only_2B[i]);
+        }
+        free_ctrl_buffer(chksum_data_buffer);
+        return KAL_FALSE;
+    }
+
+//non-zero(without encrypt) chksum check
+    ldi->attr &= ~NVRAM_ATTR_CONFIDENTIAL;
+    #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        ldi->attr &= ~NVRAM_ATTR_MSP;
+    #endif
+    //delete related version LID
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): delete test LID fail!\n\r");
+    }
+    ptr = (kal_uint16 *)md5_chksum_comput;
+    for(i = NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1; i <= NVRAM_EF_TEST_LID_RECORD_TOTAL; i++)
+    {
+        data_buffer[i] = i;
+        kal_mem_set(chksum_data_buffer, 0, chksum_size);
+        md5_chksum_2B = nvram_util_caculate_checksum(ldi, (const kal_uint8*)data_buffer, ldi->size, chksum_data_buffer);
+        ptr[i-(NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1)] = md5_chksum_2B;
+        if(!nvram_external_write_data(ldi->LID, i, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): write test LID fail!\n\r");
+            free_ctrl_buffer(chksum_data_buffer);
+            return KAL_FALSE;
+        }
+    }
+
+    nvram_external_read_chksum(ldi->LID, NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1, CHKSUM_TEST_RECORD_NUM, (kal_uint8 *)(md5_chksum_read_2B), sizeof(md5_chksum_read_2B));
+    nvram_external_read_chksum_only(ldi->LID, NVRAM_EF_TEST_LID_RECORD_TOTAL-CHKSUM_TEST_RECORD_NUM+1, CHKSUM_TEST_RECORD_NUM, (kal_uint8 *)(md5_chksum_read_only_2B), sizeof(md5_chksum_read_only_2B));
+
+    if(0 != kal_mem_cmp(md5_chksum_comput, md5_chksum_read_2B, NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM) ||
+       0 != kal_mem_cmp(md5_chksum_comput, md5_chksum_read_only_2B, NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): non-zero chksum check fail!\n\r");
+        for(i = 0; i < NVRAM_CHKSUM_SIZE_2B*CHKSUM_TEST_RECORD_NUM; i++)
+        {
+            nvram_ut_trace("[NVUT] cksum_compute[%d]: %x, chksum_read[%d]: %x, chksum_read_only[%d]: %x.\n\r", 
+                i, md5_chksum_comput[i], i, md5_chksum_read_2B[i], i, md5_chksum_read_only_2B[i]);
+        }
+        free_ctrl_buffer(chksum_data_buffer);
+        return KAL_FALSE;
+    }
+
+    free_ctrl_buffer(chksum_data_buffer);
+    chksum_data_buffer = NULL;
+//integrated checksum check
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_8_LID) )
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): reset test 8_LID settings fail!\n\r");
+    }
+    nvram_external_reset_data(NVRAM_EF_NVRAM_TEST_8_LID, 1, NVRAM_EF_TEST_8_LID_RECORD_TOTAL);
+    //read checksum check
+    kal_mem_set(data_buffer, 0x55, NVRAM_EF_TEST_8_LID_SIZE);
+    nvram_external_write_data(NVRAM_EF_NVRAM_TEST_8_LID, 2, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_8_LID_SIZE);
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_8_LID);
+    nvram_external_read_chksum(ldi->LID, 1, NVRAM_EF_TEST_8_LID_RECORD_TOTAL, (kal_uint8 *)(md5_chksum_read_2B), sizeof(md5_chksum_read_2B));
+    nvram_external_read_chksum_only(ldi->LID, 1, NVRAM_EF_TEST_8_LID_RECORD_TOTAL, (kal_uint8 *)(md5_chksum_read_only_2B), sizeof(md5_chksum_read_only_2B));
+    if(0 != kal_mem_cmp(md5_chksum_read_2B, md5_chksum_read_only_2B, NVRAM_CHKSUM_SIZE_2B*NVRAM_EF_TEST_8_LID_RECORD_TOTAL))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): integrated chksum check fail!\n\r");
+        for(i = 0; i < NVRAM_CHKSUM_SIZE_2B*NVRAM_EF_TEST_8_LID_RECORD_TOTAL; i++)
+        {
+            nvram_ut_trace("[NVUT] cksum_compute[%d]: %x, chksum_read[%d]: %x, chksum_read_only[%d]: %x.\n\r", 
+                i, md5_chksum_comput[i], i, md5_chksum_read_2B[i], i, md5_chksum_read_only_2B[i]);
+        }
+        return KAL_FALSE;
+    }
+    //read checksum 8B check
+    do{
+
+	nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info,KAL_FALSE,KAL_FALSE);
+	chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+	chksum_data_buffer = (kal_uint8*)get_ctrl_buffer(chksum_size* NVRAM_EF_TEST_8_LID_RECORD_TOTAL);    
+    kal_mem_set(chksum_data_buffer, 0, chksum_size* NVRAM_EF_TEST_8_LID_RECORD_TOTAL);
+	kal_mem_set(cmp_buffer,0,chksum_size * NVRAM_EF_TEST_8_LID_RECORD_TOTAL);
+    // kal_uint8 md5_chksum_8b_read[chksum_size * NVRAM_EF_TEST_8_LID_RECORD_TOTAL];
+    kal_mem_set(data_buffer, 0xAA, NVRAM_EF_TEST_8_LID_SIZE);
+    nvram_external_write_data(NVRAM_EF_NVRAM_TEST_8_LID, 3, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_8_LID_SIZE);
+	
+	nvram_external_read_chksum_8b(ldi->LID, 1, NVRAM_EF_TEST_8_LID_RECORD_TOTAL, (kal_uint8 *)(chksum_data_buffer), chksum_size* NVRAM_EF_TEST_8_LID_RECORD_TOTAL);
+    nvram_external_read_chksum_only_8b(ldi->LID, 2, (NVRAM_EF_TEST_8_LID_RECORD_TOTAL - 1), (kal_uint8 *)(cmp_buffer), chksum_size*(NVRAM_EF_TEST_8_LID_RECORD_TOTAL-1));
+    if(0 != kal_mem_cmp((chksum_data_buffer+ chksum_size), cmp_buffer, chksum_size*(NVRAM_EF_TEST_8_LID_RECORD_TOTAL-1)))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): integrated 8b chksum check fail!\n\r");
+        for(i = 0; i < chksum_size*(NVRAM_EF_TEST_8_LID_RECORD_TOTAL - 1); i++)
+        {
+            nvram_ut_trace("[NVUT] chksum_read_8b[%d]: %x, chksum_read_only_8b[%d]: %x.\n\r", 
+                i, chksum_data_buffer[i+chksum_size], i, cmp_buffer[i+chksum_size]);
+        }
+        free_ctrl_buffer(chksum_data_buffer);
+        return KAL_FALSE;
+    }
+    }while(0);
+    //check appendix data
+    ldi->attr &= ~NVRAM_ATTR_CHKSUM_INTEGRATE;
+    kal_mem_set(data_buffer, 0xFF, NVRAM_EF_TEST_8_LID_SIZE);
+    kal_mem_set(chksum_data_buffer, 0, chksum_size* NVRAM_EF_TEST_8_LID_RECORD_TOTAL);
+    nvram_external_write_data(NVRAM_EF_NVRAM_TEST_8_LID, 3, (kal_uint8 *)data_buffer, NVRAM_EF_TEST_8_LID_SIZE);
+    ldi->attr |= NVRAM_ATTR_CHKSUM_INTEGRATE;
+    nvram_external_read_chksum_8b(ldi->LID, 2, (NVRAM_EF_TEST_8_LID_RECORD_TOTAL - 1), (kal_uint8 *)(chksum_data_buffer), chksum_size*(NVRAM_EF_TEST_8_LID_RECORD_TOTAL - 1));
+    nvram_external_read_chksum_only_8b(ldi->LID, 2, (NVRAM_EF_TEST_8_LID_RECORD_TOTAL - 1), (kal_uint8 *)(cmp_buffer), chksum_size*(NVRAM_EF_TEST_8_LID_RECORD_TOTAL - 1));
+    if(0 != kal_mem_cmp(chksum_data_buffer, cmp_buffer, chksum_size))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): integrated 8b appendix check fail!\n\r");
+        for(i = 0; i < chksum_size; i++)
+        {
+            nvram_ut_trace("[NVUT] chksum_read_8b[%d]: %x, chksum_read_only_8b[%d]: %x.\n\r", 
+                i, chksum_data_buffer[i], i, cmp_buffer[i]);
+        }
+        free_ctrl_buffer(chksum_data_buffer);
+        return KAL_FALSE;
+    }
+    if(0 == kal_mem_cmp((chksum_data_buffer+chksum_size), (cmp_buffer+chksum_size), chksum_size))
+    {
+        nvram_ut_trace("[NVUT] chksum_multi_read_function_test(): integrated 8b appendix check2 fail!\n\r");
+        for(i = 0; i < chksum_size; i++)
+        {
+            nvram_ut_trace("[NVUT] chksum_read_8b[%d]: %x, chksum_read_only_8b[%d]: %x.\n\r", 
+                i, chksum_data_buffer[i+chksum_size], i, cmp_buffer[i+chksum_size]);
+        }
+        free_ctrl_buffer(chksum_data_buffer);
+        return KAL_FALSE;
+    }
+    free_ctrl_buffer(chksum_data_buffer);
+
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+    #endif
+    return KAL_TRUE;
+    
+}
+
+
+kal_bool raw_data_access_function_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 *large_buffer_ptr = (kal_uint32*)large_buffer;
+    kal_uint32 i, j, addr;
+
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_7_LID) )
+    {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): reset test LID settings fail!\n\r");
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_7_LID);
+    if(!nvram_external_reset_data(ldi->LID, 1, ldi->total_records)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): LID reset fail!\n\r");
+    }
+    
+    //empty file read test
+    nvram_memset(large_buffer, 0xFF, NVRAM_UT_BUFFER_SIZE);
+    if(!nvram_external_read_raw_data(NVRAM_EF_NVRAM_TEST_7_LID, 0x100000, large_buffer, NVRAM_UT_BUFFER_SIZE)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): read empty file fail!\n\r");
+        return KAL_FALSE;
+    }
+    for(i = 0; i < (NVRAM_UT_BUFFER_SIZE / sizeof(kal_uint32)); i++) {
+        if(large_buffer_ptr[i] != 0) {
+            nvram_ut_trace("[NVUT] raw_data_access_function_test(): read empty file not as expect!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write extern
+    for(i = 0; i < (NVRAM_UT_BUFFER_SIZE / sizeof(kal_uint32)); i++) {
+        large_buffer_ptr[i] = ((i * sizeof(kal_uint32)) + 0xAA100000);
+    }
+    if(!nvram_external_write_raw_data(NVRAM_EF_NVRAM_TEST_7_LID, 0x100000, large_buffer, NVRAM_UT_BUFFER_SIZE)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): write extern file fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //write exist
+    for(i = 0; i < (NVRAM_UT_BUFFER_SIZE / sizeof(kal_uint32)); i++) {
+        large_buffer_ptr[i] = ((i * sizeof(kal_uint32)) + 0xBB0F0000);
+    }
+    if(!nvram_external_write_raw_data(NVRAM_EF_NVRAM_TEST_7_LID, 0xF0000, large_buffer, NVRAM_UT_BUFFER_SIZE)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): write exist file fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //read back check
+    for(i = 0; i < (0x100000 + 2*NVRAM_UT_BUFFER_SIZE); i+= NVRAM_UT_BUFFER_SIZE) {
+        nvram_memset(large_buffer, 0xFF, NVRAM_UT_BUFFER_SIZE);
+        if(!nvram_external_read_raw_data(NVRAM_EF_NVRAM_TEST_7_LID, i, large_buffer, NVRAM_UT_BUFFER_SIZE) &&
+            i < (0x100000 + NVRAM_UT_BUFFER_SIZE))
+        {
+            nvram_ut_trace("[NVUT] raw_data_access_function_test(): read back fail!\n\r");
+            return KAL_FALSE;
+        }
+        for(j = 0; j < (NVRAM_UT_BUFFER_SIZE / sizeof(kal_uint32)); j++) {
+            addr = (i + (j * sizeof(kal_uint32)));
+            if(addr < 0xF0000) {
+                if(large_buffer_ptr[j] != 0) {
+                    nvram_ut_trace("[NVUT] raw_data_access_function_test(): read back check_a fail!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+            else if(addr < (0x100000 + NVRAM_UT_BUFFER_SIZE - 0x10000)) {
+                if((large_buffer_ptr[j] >> 24) != 0xBB || (large_buffer_ptr[j] & 0x00FFFFFF) != addr) {
+                    nvram_ut_trace("[NVUT] raw_data_access_function_test(): read back check_b fail!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+            else if(addr < (0x100000 + NVRAM_UT_BUFFER_SIZE)) {
+                if((large_buffer_ptr[j] >> 24) != 0xAA || (large_buffer_ptr[j] & 0x00FFFFFF) != addr) {
+                    nvram_ut_trace("[NVUT] raw_data_access_function_test(): read back check_c fail!\n\r");
+                    return KAL_FALSE;
+                }
+            }
+            else {
+                if(large_buffer_ptr[j] != 0xFFFFFFFF) {
+                    nvram_ut_trace("[NVUT] raw_data_access_function_test(): read back check_d fail!\n\r");
+                    return KAL_FALSE;
+                }                
+            }
+        }
+    }
+
+    //check normal r/w API
+    if(nvram_external_read_data(NVRAM_EF_NVRAM_TEST_7_LID, 1, large_buffer, MAX_NVRAM_RECORD_SIZE)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): nvram_external_read_data() test fail.\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_external_secure_read_data(NVRAM_EF_NVRAM_TEST_7_LID, 1, large_buffer, MAX_NVRAM_RECORD_SIZE, NULL)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): nvram_external_secure_read_data() test fail.\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_external_write_data(NVRAM_EF_NVRAM_TEST_7_LID, 1, large_buffer, 2)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): nvram_external_write_data() test fail.\n\r");
+        return KAL_FALSE;
+    }
+    if(nvram_external_secure_write_data(NVRAM_EF_NVRAM_TEST_7_LID, 1, large_buffer, 2, NULL)) {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): nvram_external_secure_write_data() test fail.\n\r");
+        return KAL_FALSE;
+    } 
+        
+    return KAL_TRUE;
+    
+}
+
+kal_bool record_size_boundary_test(kal_uint32 flags, void *param)
+{
+    record_size_boundary_struct record_size_loop[] = {
+        {1, 32}, {1024-16, 1024+16}, {2*1024-16, 2*1024+16},
+        {4*1024-16, 4*1024+16}, {8*1024-16, 8*1024+16}, {16*1024-16, 16*1024+16},
+        {32*1024-16, 32*1024+16}, {NVRAM_MAX_OP_BUFFER_SIZE-32, NVRAM_MAX_OP_BUFFER_SIZE},
+    };
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i, j, result;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    for(i = 0; i < sizeof(record_size_loop)/sizeof(record_size_boundary_struct); i++)
+    {
+        for(j = record_size_loop[i].start_record_size ; j <= record_size_loop[i].end_record_size; j++)
+        {
+            //reset test LIDs to default settings
+            if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+            {
+                nvram_ut_trace("[NVUT] record_size_boundary_test(): reset test LID settings fail!\n\r");
+            }
+            nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+            ldi->total_records = 2; // to save time we just set record number to 2
+            ldi->size = j;
+
+            //this test will use LID verno "000" only
+            if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+            {
+                nvram_ut_trace("[NVUT] record_size_boundary_test(): delete test LID fail!\n\r");
+                return KAL_FALSE;
+            }
+
+            result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                         CMPT_OP_WAY_API,
+                                         1, ldi->total_records);
+            if(0 != result)
+            {
+                nvram_ut_trace("[NVUT] record_size_boundary_test(): lid API access fail! i=%d, j=%d.\n\r", i, j);
+                return KAL_FALSE;
+            }
+
+            result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                         CMPT_OP_WAY_MSG,
+                                         1, ldi->total_records);
+            if(0 != result)
+            {
+                nvram_ut_trace("[NVUT] record_size_boundary_test(): lid MSG access fail! i=%d, j=%d.\n\r", i, j);
+                return KAL_FALSE;
+            }
+
+            nvram_ut_trace("[NVUT] record_size_boundary_test(): loop i=%d j=%d\n\r", i, j);
+            kal_sleep_task(kal_milli_secs_to_ticks(10)); //do not always take CPU
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool record_number_boundary_test(kal_uint32 flags, void *param)
+{
+    record_number_boundary_struct record_number_loop[] = {
+        {1, 16}, {32-8, 32+8}, {64-8, 64+8},
+        {128-8, 128+8}, {256-8, 256+8}, {512-8, 512+8},
+        {1024-8, 1024+8}, {2048-8, 2048+8}, {4096-8, 2048+8}, 
+        {8192-8, 8192+8}, {16384-8, 16384+8}, {32768-8, 32768+8},
+        {65535-16, 65535},
+    };
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 i, j, result;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    for(i = 0; i < sizeof(record_number_loop)/sizeof(record_number_boundary_struct); i++)
+    {
+        for(j = record_number_loop[i].start_record_number ; j <= record_number_loop[i].end_record_number; j++)
+        {
+            //reset test LIDs to default settings
+            if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+            {
+                nvram_ut_trace("[NVUT] record_number_boundary_test(): reset test LID settings fail!\n\r");
+            }
+            nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+            ldi->total_records = j;
+            ldi->size = 20; //we just set record size to 10 for test
+
+            //this test will use LID verno "000" only
+            if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+            {
+                nvram_ut_trace("[NVUT] record_number_boundary_test(): delete test LID fail!\n\r");
+                return KAL_FALSE;
+            }
+
+            if(j > 30) //if record number large than 30, only access 30 records to test(begin, middle, end)
+            {
+                //through API
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                     CMPT_OP_WAY_API, 1, 10);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid API1 access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                     CMPT_OP_WAY_API, ldi->total_records/2 - 4, ldi->total_records/2 + 5);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid API2 access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                     CMPT_OP_WAY_API, ldi->total_records-9, ldi->total_records);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid API3 access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+                //through MSG
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                     CMPT_OP_WAY_MSG, 1, 10);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid MSG1 access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                     CMPT_OP_WAY_MSG, ldi->total_records/2 - 4, ldi->total_records/2 + 5);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid MSG2 access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                     CMPT_OP_WAY_MSG, ldi->total_records-9, ldi->total_records);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid MSG3 access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }                
+            }
+            else //full record cover
+            {
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                                 CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                 CMPT_OP_WAY_API, 1, ldi->total_records);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid API access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+
+                result = nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 
+                                             CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0), 
+                                             CMPT_OP_WAY_MSG, 1, ldi->total_records);
+                if(0 != result)
+                {
+                    nvram_ut_trace("[NVUT] record_number_boundary_test(): lid MSG access fail! i=%d, j=%d.\n\r", i, j);
+                    return KAL_FALSE;
+                }
+            }
+            nvram_ut_trace("[NVUT] record_number_boundary_test(): loop i=%d j=%d\n\r", i, j);
+            kal_sleep_task(kal_milli_secs_to_ticks(10)); //do not always take CPU
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_stress_test(kal_uint32 flags, void *param)
+{
+#define NVRAM_STRESS_TEST_LOOP  1000
+#define NVRAM_MAX_RAND_RECORD_NUM    512 //normally user's LID record number will not exceed 512
+#define NVRAM_MAX_FILE_SIZE 1024*1024 //there we assue max test LID file size is 1MB, if exceed, ajust record number
+    nvram_ltable_entry_struct *ldi = NULL;
+    nvram_attr_enum attr_bak;
+    nvram_write_req_struct *write_req;
+    nvram_write_cnf_struct *nvram_write_cnf;
+    kal_uint8 *pdu_write_buffer;
+    ilm_struct current_ilm;
+    kal_uint32 attribute_list[] = {
+                                    NVRAM_ATTR_AVERAGE, NVRAM_ATTR_COMMITTED, NVRAM_ATTR_CONFIDENTIAL,
+                                #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+                                    NVRAM_ATTR_MSP, 
+                                #endif
+                                    NVRAM_ATTR_MULTIPLE, NVRAM_ATTR_MULTIREC_READ,
+                                    NVRAM_ATTR_MULTI_DEFAULT, NVRAM_ATTR_OTA_RESET, NVRAM_ATTR_WRITEPROTECT,
+                                    NVRAM_ATTR_GEN_DEFAULT, NVRAM_ATTR_FAULT_ASSERT,
+                                    //because NVRAM_ATTR_RING is not often used, there do not test, if test ctrl buffer is not enough
+                                    //NVRAM_ATTR_RING,
+                                  };
+    kal_uint32 category_list[] = {
+                                    NVRAM_CATEGORY_USER, NVRAM_CATEGORY_INTERNAL, NVRAM_CATEGORY_CALIBRAT,
+                                    NVRAM_CATEGORY_IMPORTANT, NVRAM_CATEGORY_IMPORTANT_L1, NVRAM_CATEGORY_IMPORTANT_L4,
+                                 };
+    
+    kal_uint8 const* default_value_list[] = {
+                                                (kal_uint8 const*)NVRAM_EF_ZERO_DEFAULT, (kal_uint8 const*)NVRAM_EF_FF_DEFAULT, (kal_uint8 const*)table_default, (kal_uint8 const*)nvram_ut_get_default_value,
+                                            };
+    kal_uint32 attr_rand_range, category_rand_range, default_rand_range; //insteand random value range
+    kal_uint32 attr_rand_value, category_rand_value, default_rand_value;
+    kal_uint32 attr_number, category_number, default_number;
+    kal_uint32 i, j;
+    kal_uint16 ring_write_record;
+    kal_uint8 lock_status = KAL_FALSE;
+    kal_uint8 *d_buffer, *c_buffer, result;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache as change LID file size via adding the NVRAM_ATTR_CONFIDENTIAL or NVRAM_ATTR_MSP
+    #endif
+    attr_number = sizeof(attribute_list)/sizeof(kal_uint32);
+    category_number = sizeof(category_list)/sizeof(kal_uint32);
+    default_number = sizeof(default_value_list)/sizeof(kal_uint8 const *);
+
+    attr_rand_range = (kal_uint32)pow(2, attr_number); //each bit stands a attribute should have or not have
+    category_rand_range = category_number; //each LID only have one kind category
+    default_rand_range = default_number; //each LID only have one kind default value
+
+    //set random seed
+    srand(ust_get_current_time());
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    //reset test LID to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] nvram_stress_test(): reset test LID settings fail!\n\r");
+    }
+    
+    for(i = 0; i < NVRAM_STRESS_TEST_LOOP; i++)
+    {
+        attr_rand_value = rand()%attr_rand_range;
+        category_rand_value = rand()%category_rand_range;
+        default_rand_value = rand()%default_rand_range;
+        //set attr, category, default value, record_size, record_number
+        for(ldi->attr = 0, j = 0; j < attr_number; j++)
+        {
+            if((attr_rand_value>>j)&0x1) //shoud add this attribute
+            {
+                ldi->attr |= attribute_list[j];
+            }
+        }
+        
+        ldi->category = category_list[category_rand_value];
+        ldi->default_value = default_value_list[default_rand_value];
+        #ifndef __NVRAM_LID_CACHE__
+        ldi->total_records = rand()%NVRAM_MAX_RAND_RECORD_NUM + 1;
+        ldi->size = rand()%NVRAM_MAX_OP_BUFFER_SIZE + 1;
+        if((ldi->size+NVRAM_CHKSUM_SIZE)*ldi->total_records > NVRAM_MAX_FILE_SIZE) //do not allow LID size too large
+        {
+            ldi->total_records = NVRAM_MAX_FILE_SIZE / ldi->size;
+        }
+
+        if(ldi->attr & NVRAM_ATTR_RING)
+        {
+            if(ldi->size < 2)
+                ldi->size = 2;
+            if(ldi->total_records < 2)
+                ldi->total_records = 2;
+        }
+        #endif
+        nvram_ut_trace("[NVDBG] nvram_stress_test(): category= %8x,attr= %8x,ldi->size=%d,lid->total_records=%d!\n\r",
+            ldi->category,ldi->attr,ldi->size,ldi->total_records);
+
+        if((ldi->size+NVRAM_CHKSUM_SIZE)*ldi->total_records > NVRAM_MAX_OP_BUFFER_SIZE) //large LID can only set default value as 0x00 or 0xFF otherwise buffer is not enough
+        {
+            ldi->default_value = NVRAM_EF_ZERO_DEFAULT;
+            nvram_ut_trace("[NVDBG] nvram_stress_test(): default_value is NVRAM_EF_ZERO_DEFAULT!\n\r");
+        }
+
+        if((kal_uint8 const*)nvram_ut_get_default_value == ldi->default_value)
+        {
+            ldi->category |= NVRAM_CATEGORY_FUNC_DEFAULT;
+            nvram_ut_trace("[NVDBG] nvram_stress_test(): mask the NVRAM_CATEGORY_FUNC_DEFAULT!\n\r");
+        }
+        else
+        {
+            ldi->category &= ~NVRAM_CATEGORY_FUNC_DEFAULT;
+            nvram_ut_trace("[NVDBG] nvram_stress_test(): unmask the NVRAM_CATEGORY_FUNC_DEFAULT!\n\r");
+        }
+
+        if((kal_uint8 const*)table_default != ldi->default_value)
+        {
+            ldi->attr &= ~NVRAM_ATTR_MULTI_DEFAULT;
+            nvram_ut_trace("[NVDBG] nvram_stress_test(): unmask the NVRAM_ATTR_MULTI_DEFAULT!\n\r");
+        }
+        if(ldi->attr & NVRAM_ATTR_WRITEPROTECT) //temp close NVRAM system lock status
+        {
+            lock_status = nvram_ptr->lock;
+            nvram_ptr->lock = KAL_FALSE;
+        }
+        nvram_ut_trace("[NVDBG] nvram_stress_test() 2: category= %8x,attr= %8x,ldi->size=%d,lid->total_records=%d!\n\r",
+            ldi->category,ldi->attr,ldi->size,ldi->total_records);
+        //this test will use LID verno "000" only
+        if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+        {
+            nvram_ut_trace("[NVUT] nvram_stress_test(): delete test LID fail before test!\n\r");
+            //return KAL_FALSE;
+        }
+
+        attr_bak = ldi->attr;
+
+        //reset test LID to default value
+        if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+        {
+            nvram_ut_trace("[NVUT] nvram_stress_test(): reset test LID fail!\n\r");
+            return KAL_FALSE;
+        }
+        nvram_ut_trace("[NVDBG] nvram_stress_test(): reset test LID Success!\n\r");
+
+        if(ldi->attr & NVRAM_ATTR_RING) //ring attribute should use msg to test only
+        {
+            //write LID
+            d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+            d_buffer[0] = 0xEF;
+            write_req = (nvram_write_req_struct *)construct_local_para(sizeof(nvram_write_req_struct), TD_CTRL);
+            pdu_write_buffer = (kal_uint8 *)construct_peer_buff(ldi->size, 0, 0, TD_CTRL);
+            kal_mem_cpy(get_peer_buff_pdu((peer_buff_struct*)pdu_write_buffer, 0), d_buffer, ldi->size);
+            write_req->ref_count = 1;
+            write_req->file_idx = ldi->LID;
+            write_req->para = 1; //for ring, this para have no meaning
+            
+            msg_send6(kal_get_active_module_id(), MOD_NVRAM, 0, MSG_ID_NVRAM_WRITE_REQ, 
+                    (local_para_struct*)write_req, (peer_buff_struct*)pdu_write_buffer);
+            msg_receive_extq(&current_ilm);
+            nvram_write_cnf = (nvram_write_cnf_struct*)current_ilm.local_para_ptr;
+            result = nvram_write_cnf->result;
+            destroy_ilm(&current_ilm);
+            if(NVRAM_ERRNO_SUCCESS != result)
+            {
+                free_ctrl_buffer(d_buffer);
+                nvram_ut_trace("[NVUT] nvram_stress_test(): ring write fail!\n\r");
+                break;
+            }
+            c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+            //for ring LID, record 1's first two bytes stores the last written record
+            if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)c_buffer, ldi->size) )
+            {
+                free_ctrl_buffer(d_buffer);
+                free_ctrl_buffer(c_buffer);
+                nvram_ut_trace("[NVUT] nvram_stress_test(): ring read record 1 fail!\n\r");
+                return KAL_FALSE;
+            }
+            ring_write_record = (kal_uint16)c_buffer[0];
+            if( !nvram_external_read_data(ldi->LID, ring_write_record, (kal_uint8 *)c_buffer, ldi->size) )
+            {
+                free_ctrl_buffer(d_buffer);
+                free_ctrl_buffer(c_buffer);
+                nvram_ut_trace("[NVUT] nvram_stress_test(): ring read write record fail!\n\r");
+                return KAL_FALSE;
+            }      
+            if(0 != kal_mem_cmp(c_buffer, d_buffer, ldi->size))
+            {
+                free_ctrl_buffer(d_buffer);
+                free_ctrl_buffer(c_buffer);
+                nvram_ut_trace("[NVUT] nvram_stress_test(): ring read back value change.\n\r");
+                return KAL_FALSE;
+            }      
+            free_ctrl_buffer(d_buffer);
+            free_ctrl_buffer(c_buffer);
+        }
+        else
+        {
+            if(ldi->total_records <= 5) //full record cover
+            {
+                //API access
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                         CMPT_OP_WAY_API, 1, ldi->total_records))
+                {
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): nvram_lid_cmpt_operation() API fail!\n\r");
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_rand_value=%d, category_rand_value=%d, default_rand_value=%d.\n\r", attr_rand_value, category_rand_value, default_rand_value);
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_number=%d, category_number=%d, default_number=%d.\n\r", attr_number, category_number, default_number);
+                    return KAL_FALSE;
+                }
+                //MSG access
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                         CMPT_OP_WAY_MSG, 1, ldi->total_records))
+                {
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): nvram_lid_cmpt_operation() MSG fail!\n\r");
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_rand_value=%d, category_rand_value=%d, default_rand_value=%d.\n\r", attr_rand_value, category_rand_value, default_rand_value);
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_number=%d, category_number=%d, default_number=%d.\n\r", attr_number, category_number, default_number);
+                    return KAL_FALSE;
+                }
+            }
+            else //only access begin and end part ecah 2 records
+            {
+                //API access
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                         CMPT_OP_WAY_API, 1, 2))
+                {
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): nvram_lid_cmpt_operation() API fail!\n\r");
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_rand_value=%d, category_rand_value=%d, default_rand_value=%d.\n\r", attr_rand_value, category_rand_value, default_rand_value);
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_number=%d, category_number=%d, default_number=%d.\n\r", attr_number, category_number, default_number);
+                    return KAL_FALSE;
+                }
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                         CMPT_OP_WAY_API, ldi->total_records-1, ldi->total_records))
+                {
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): nvram_lid_cmpt_operation() API fail!\n\r");
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_rand_value=%d, category_rand_value=%d, default_rand_value=%d.\n\r", attr_rand_value, category_rand_value, default_rand_value);
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_number=%d, category_number=%d, default_number=%d.\n\r", attr_number, category_number, default_number);
+                    return KAL_FALSE;
+                }                
+                //MSG access
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                         CMPT_OP_WAY_MSG, 1, 2))
+                {
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): nvram_lid_cmpt_operation() MSG fail!\n\r");
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_rand_value=%d, category_rand_value=%d, default_rand_value=%d.\n\r", attr_rand_value, category_rand_value, default_rand_value);
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_number=%d, category_number=%d, default_number=%d.\n\r", attr_number, category_number, default_number);
+                    return KAL_FALSE;
+                }
+                if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                         CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK, CMPT_OP_FLAG_WRITE, CMPT_OP_FLAG_RESET, 0),
+                         CMPT_OP_WAY_MSG, ldi->total_records-1, ldi->total_records))
+                {
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): nvram_lid_cmpt_operation() MSG fail!\n\r");
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_rand_value=%d, category_rand_value=%d, default_rand_value=%d.\n\r", attr_rand_value, category_rand_value, default_rand_value);
+                    nvram_ut_trace("[NVUT] nvram_stress_test(): attr_number=%d, category_number=%d, default_number=%d.\n\r", attr_number, category_number, default_number);
+                    return KAL_FALSE;
+                }
+            }
+        }
+        
+        if(attr_bak != ldi->attr)
+        {
+            nvram_ut_trace("[NVUT] nvram_stress_test(): attr changed unexpect!\n\r");
+        }
+        if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+        {
+            nvram_ut_trace("[NVUT] nvram_stress_test(): delete test LID fail after test!\n\r");
+        }
+        if(ldi->attr & NVRAM_ATTR_WRITEPROTECT)
+        {
+            nvram_ptr->lock = lock_status;
+        }
+
+        if(0 == i%10) //suspend a while
+        {
+            kal_sleep_task(kal_milli_secs_to_ticks(10));
+        }
+        nvram_ut_trace("[NVUT] nvram_stress_test(): loop i=%d\n\r", i);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool nvram_exception_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint32 exception_test_lid[]=
+    {
+        NVRAM_EF_SYS_EXCEPTION_LID_DUMMY, NVRAM_EF_SYS_STATISTICS_LID
+    }; //nvram_write_exception_data_item and nvram_read_exception_data_item only allow this two LID's operation
+    kal_uint32 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    for(i = 0; i < sizeof(exception_test_lid)/sizeof(kal_uint32); i++)
+    {
+        nvram_util_get_data_item(&ldi, exception_test_lid[i]);
+
+        data_buffer[0] = i;
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+            //nvram_write_exception_data_item() test
+            if(NVRAM_DRV_OK != nvram_write_exception_data_item(ldi, j, (kal_uint8 *)data_buffer))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): nvram_write_exception_data_item() fail.\n\r");
+                return KAL_FALSE;
+            }
+            if(NVRAM_DRV_OK != nvram_read_exception_data_item(ldi, j, (kal_uint8 *)cmp_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): 1st nvram_read_exception_data_item() fail.\n\r");
+                return KAL_FALSE;
+            }
+            if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): nvram_read_exception_data_item() 1st readback not as except.\n\r");
+                return KAL_FALSE;
+            }
+            if(! nvram_external_read_data(ldi->LID, j, (kal_uint8 *)cmp_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): 1st nvram_external_read_data() fail.\n\r");
+                return KAL_FALSE;
+            }
+            if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): 1st nvram_external_read_data() readback not as except.\n\r");
+                return KAL_FALSE;
+            }
+
+            //nvram_read_exception_data_item() test
+            if(! nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): nvram_external_write_data() fail.\n\r");
+                return KAL_FALSE;
+            }
+            if(NVRAM_DRV_OK != nvram_read_exception_data_item(ldi, j, (kal_uint8 *)cmp_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): 2nd nvram_read_exception_data_item() fail.\n\r");
+                return KAL_FALSE;
+            }
+            if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_exception_test(): nvram_read_exception_data_item() 2nd readback not as except.\n\r");
+                return KAL_FALSE;
+            }
+            
+        }
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+    
+}
+
+kal_bool nvram_security_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): reset test LID settings fail!\n\r");
+    }
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    //this test will use LID verno "000" only
+    if( !delete_special_version_lid(NVRAM_EF_NVRAM_TEST_1_LID, 0, 0) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): delete test LID fail!\n\r");
+    }
+
+    //reset test LID to default value
+    if( !nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): reset test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): reset test LID Success!\n\r");
+    
+    nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)data_buffer, ldi->size);
+
+    ldi->attr |= NVRAM_ATTR_WRITEPROTECT;
+    ldi->default_value = NVRAM_EF_FF_DEFAULT; //modify test LID's default value
+    //lid read
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): first read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): first read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): first read  as expect!\n\r");
+    
+   //lid access
+    nvram_ut_assert_flag = 0;
+    
+    if(0 != nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_SET_LOCK, 0, 0, 0),
+                                     CMPT_OP_WAY_MSG, 1, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): nvram_lid_cmpt_operation()Lock fail!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): nvram_lid_cmpt_operation()Lock Success!\n\r");
+    
+    cmp_buffer[0] = 0x30;
+    if( KAL_TRUE == nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): write fail not happen!\n\r");
+        return KAL_FALSE;
+    }
+    else
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): can't write when locked!\n\r");
+    }
+    
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): second read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): second read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): second read  as expect!\n\r");
+    
+    if(0 == nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID,
+                                     CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_SET_UNLOCK, 0, 0, 0),
+                                     CMPT_OP_WAY_MSG, 1, 1))
+    {
+        #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+        nvram_ut_trace("[NVUT] nvram_security_test(): nvram_lid_cmpt_operation() UNLOCK fail not happen!\n\r");
+        return KAL_FALSE;
+        #else
+        nvram_ut_trace("[NVUT] nvram_security_test(): nvram_lid_cmpt_operation() UNLOCK Success !\n\r");
+        #endif
+        
+    }
+    #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+    nvram_ut_trace("[NVUT] nvram_security_test(): nvram_lid_cmpt_operation() UNLOCK fail happen!\n\r");
+    #endif
+    
+    if(nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): unexpect assert happen!\n\r");
+        return KAL_FALSE;
+    }
+    
+    cmp_buffer[0] = 0x32;
+    if( KAL_TRUE == nvram_external_write_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+        nvram_ut_trace("[NVUT] nvram_security_test(): write fail not happen!\n\r");
+        return KAL_FALSE;
+        #else
+        nvram_ut_trace("[NVUT] nvram_security_test(): write success after unlock!\n\r");
+        #endif
+    }
+    #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+    nvram_ut_trace("[NVUT] nvram_security_test(): write fail happen when unlock fail!\n\r");
+    #endif
+    
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): third read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__
+        nvram_ut_trace("[NVUT] nvram_security_test(): third read not as expect!\n\r");
+        return KAL_FALSE;
+        #endif
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): third read as expect!\n\r");
+    
+    //lid reset
+    nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records);
+    nvram_get_default_value_to_write(ldi, 1, (kal_uint8 *)data_buffer, ldi->size); //get new default value
+    if( !nvram_external_read_data(ldi->LID, 1, (kal_uint8 *)cmp_buffer, ldi->size) )
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): third read test LID fail!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): third read test LID Success!\n\r");
+    if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    {
+        nvram_ut_trace("[NVUT] nvram_security_test(): third read not as expect!\n\r");
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] nvram_security_test(): third read as expect!\n\r");
+    return KAL_TRUE; 
+}
+
+
+#if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+extern const checksum_reset_struct lid_structure_chksum[];
+extern const checksum_reset_struct lid_default_value_chksum[];
+
+
+extern kal_uint32 lid_structure_chksum_num;
+extern kal_uint32 lid_default_value_chksum_num;
+
+kal_bool nvram_modify_structure_checksum(nvram_lid_enum LID)
+{
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    nvram_ldi_header nv_header;
+    nvram_ltable_entry_struct *ldi;
+    kal_bool mulpiple = KAL_FALSE, ret_val = KAL_TRUE;
+    kal_int32 backup_file_num = 1, result;
+    kal_uint32 len;
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header, NVRAM_LDI_HEADER_SIZE);
+    nv_header.nv_dbg_header.struct_chkrst[0]++;
+
+    //write header nvram_write_data_header()
+    if(NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+    {
+        mulpiple = KAL_TRUE;
+        backup_file_num = 2;
+    }
+    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    do {
+        file_handle = FS_Open(filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE);
+        if (file_handle < FS_NO_ERROR) {
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_4, ldi->LID);
+            }
+            ret_val = KAL_FALSE;
+        }
+        if ((result = FS_Write(file_handle, (void *)(&nv_header), sizeof(nv_header), &len)) < FS_NO_ERROR) {
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_5, ldi->LID);
+            }
+            ret_val = KAL_FALSE;
+        }
+        if(file_handle > FS_NO_ERROR) {
+            FS_Close(file_handle);
+        }
+        if(!mulpiple)
+        {
+          break;  
+        }
+        nvram_folder = nvram_query_folder_index_ex(ldi->category,KAL_FALSE);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+    }while(backup_file_num > 0);
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+    return ret_val;
+}
+
+kal_bool nvram_modify_default_value_checksum(nvram_lid_enum LID)
+{
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    nvram_ldi_header nv_header;
+    nvram_ltable_entry_struct *ldi;
+    kal_bool mulpiple = KAL_FALSE, ret_val = KAL_TRUE;
+    kal_int32 backup_file_num = 1, result;
+    kal_uint32 len;
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header, NVRAM_LDI_HEADER_SIZE);
+    nv_header.nv_dbg_header.defval_chkrst_l[0]++;
+
+    //write header nvram_write_data_header()
+    if(NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+    {
+        mulpiple = KAL_TRUE;
+        backup_file_num = 2;
+    }
+    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+    do {
+        file_handle = FS_Open(filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE);
+        if (file_handle < FS_NO_ERROR) {
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_4, ldi->LID);
+            }
+            ret_val = KAL_FALSE;
+        }
+        if ((result = FS_Write(file_handle, (void *)(&nv_header), sizeof(nv_header), &len)) < FS_NO_ERROR) {
+            if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_5, ldi->LID);
+            }
+            ret_val = KAL_FALSE;
+        }
+        if(file_handle > FS_NO_ERROR) {
+            FS_Close(file_handle);
+        }
+        if(!mulpiple)
+        {
+          break;  
+        }
+        nvram_folder = nvram_query_folder_index_ex(ldi->category,KAL_FALSE);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+    }while(backup_file_num > 0);
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+
+    return ret_val;
+}
+
+kal_bool nvram_verify_checksum(nvram_lid_enum LID)
+{
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    nvram_ldi_header nv_header;
+    nvram_ltable_entry_struct *ldi;
+    kal_int32 index = 0;
+
+    nvram_util_get_data_item(&ldi, LID);
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header, NVRAM_LDI_HEADER_SIZE);
+
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
+    for(index = 0; index < lid_structure_chksum_num && LID != lid_structure_chksum[index].LID; index ++)
+    {}
+    if(index >= lid_structure_chksum_num)
+    {
+        nvram_ut_trace("[NVUT] nvram_verify_checksum(): LID not in structure checksum table!\n\r");
+        nvram_ut_trace("[NVUT] LID: %d!\n\r", LID);
+        return KAL_FALSE;
+    }
+    if(strncmp((const char *)(lid_structure_chksum[index].chksum), (const char *)(nv_header.nv_dbg_header.struct_chkrst), RST_CHKSUM_SIZE))
+    {
+        nvram_ut_trace("[NVUT] nvram_verify_checksum(): structure checksum not match LID header!\n\r");
+        nvram_ut_trace("[NVUT] LID: %d!\n\r", LID);
+        return KAL_FALSE;
+    }
+    #endif
+
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    for(index = 0; index < lid_default_value_chksum_num && LID != lid_default_value_chksum[index].LID; index ++)
+    {}
+    if(index >= lid_default_value_chksum_num)
+    {
+        nvram_ut_trace("[NVUT] nvram_verify_checksum(): LID not in default value checksum table!\n\r");
+        nvram_ut_trace("[NVUT] LID: %d!\n\r", LID);
+        return KAL_FALSE;
+    }
+    if(strncmp((const char *)(nv_header.nv_ota_header.defval_chkrst_h), (const char *)(lid_default_value_chksum[index].chksum), RST_CHKSUM_SIZE-6) ||
+        strncmp((const char *)(nv_header.nv_dbg_header.defval_chkrst_l), (const char*)(&(lid_default_value_chksum[index].chksum[RST_CHKSUM_SIZE-6])), 6))
+    {
+        nvram_ut_trace("[NVUT] nvram_verify_checksum(): default value checksum not match LID header!\n\r");
+        nvram_ut_trace("[NVUT] LID: %d!\n\r", LID);
+        return KAL_FALSE;
+    }
+    #endif
+
+    return KAL_TRUE;
+}
+    
+
+
+kal_bool nvram_smart_reset_entry_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    kal_int32 index = 0;
+    kal_bool case_fail = KAL_FALSE;
+
+    //first round check: every reset LID should in checksum table
+    do
+    {
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
+        if(NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi))
+        {
+            for(index = 0; index < lid_structure_chksum_num && lid_structure_chksum[index].LID != ldi->LID; index ++)
+            {}
+            if(index >= lid_structure_chksum_num)
+            {
+                nvram_ut_trace("[NVUT] nvram_smart_reset_entry_test(): LID not in structure checksum table!\n\r");
+                nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                case_fail = KAL_TRUE;
+            }
+        }
+    #endif
+
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+        if(NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi))
+        {
+            for(index = 0; index < lid_default_value_chksum_num && lid_default_value_chksum[index].LID != ldi->LID; index ++)
+            {}
+            if(index >= lid_default_value_chksum_num)
+            {
+                nvram_ut_trace("[NVUT] nvram_smart_reset_entry_test(): LID not in default value checksum table!\n\r");
+                nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                case_fail = KAL_TRUE;
+            }            
+        }
+    #endif
+    }while(nvram_util_next_data_item(&ldi));
+
+    //second round check: every LID in checksum table should be reset LID
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
+    for(index = 0; index < lid_structure_chksum_num; index++)
+    {
+        ldi = NULL;
+        nvram_util_get_data_item(&ldi, lid_structure_chksum[index].LID);
+        if(! ldi)
+        {
+            nvram_ut_trace("[NVUT] nvram_smart_reset_entry_test(): structure checksum LID not in LID table!\n\r");
+            nvram_ut_trace("[NVUT] LID: %d!\n\r", lid_structure_chksum[index].LID);
+            case_fail = KAL_TRUE;
+        }
+        if(! NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi))
+        {
+            nvram_ut_trace("[NVUT] nvram_smart_reset_entry_test(): structure checksum LID can not be reset!\n\r");
+            nvram_ut_trace("[NVUT] LID: %d!\n\r", lid_structure_chksum[index].LID);
+            case_fail = KAL_TRUE;          
+        }
+        
+    }
+    #endif
+
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    for(index = 0; index < lid_default_value_chksum_num; index++)
+    {
+        ldi = NULL;
+        nvram_util_get_data_item(&ldi, lid_default_value_chksum[index].LID);
+        if(! ldi)
+        {
+            nvram_ut_trace("[NVUT] nvram_smart_reset_entry_test(): structure checksum LID not in LID table!\n\r");
+            nvram_ut_trace("[NVUT] LID: %d!\n\r", lid_default_value_chksum[index].LID);
+            case_fail = KAL_TRUE;
+        }
+        if(! NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi))
+        {
+            nvram_ut_trace("[NVUT] nvram_smart_reset_entry_test(): default value checksum LID can not be reset!\n\r");
+            nvram_ut_trace("[NVUT] LID: %d!\n\r", lid_default_value_chksum[index].LID);
+            case_fail = KAL_TRUE;            
+        }
+    }
+    #endif
+
+    if(case_fail)
+        return KAL_FALSE;
+    else
+        return KAL_TRUE; 
+}
+
+kal_bool nvram_structure_change_reset_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+
+    //modify structure checksum
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_modify_structure_checksum(test_lid_enum[i]);
+    }    
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check new checksum is right
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_1_LID)) //USER category
+    {
+        return KAL_FALSE;
+    }
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_5_LID)) //L1 category
+    {
+        return KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(ldi->LID == NVRAM_EF_NVRAM_TEST_1_LID || ldi->LID == NVRAM_EF_NVRAM_TEST_5_LID)
+            {
+                if(kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): LID do not reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): un-expect LID reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_default_value_change_reset_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+
+    //modify structure checksum
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_modify_default_value_checksum(test_lid_enum[i]);
+    }    
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check new checksum is right
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_1_LID)) //USER category
+    {
+        return KAL_FALSE;
+    }
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_5_LID)) //L1 category
+    {
+        return KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(ldi->LID == NVRAM_EF_NVRAM_TEST_1_LID || ldi->LID == NVRAM_EF_NVRAM_TEST_5_LID)
+            {
+                if(kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): LID do not reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): un-expect LID reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_func_default_checksum_change_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+        if(test_lid_enum[i] == NVRAM_EF_NVRAM_TEST_1_LID || test_lid_enum[i] == NVRAM_EF_NVRAM_TEST_5_LID)
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+            ldi->category |= NVRAM_CATEGORY_FUNC_DEFAULT;
+            ldi->default_value= (kal_uint8 const*)nvram_ut_get_default_value;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+
+    //modify structure checksum
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_modify_default_value_checksum(test_lid_enum[i]);
+    }    
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): un-expect LID reset!\n\r");
+                nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                free_ctrl_buffer(d_buffer);
+                free_ctrl_buffer(c_buffer);
+                return KAL_FALSE;
+            }
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_smart_reset_checksum_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 i;
+    
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //check new checksum is right
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_1_LID)) //USER category
+    {
+        return KAL_FALSE;
+    }
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_5_LID)) //L1 category
+    {
+        return KAL_FALSE;
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+
+    //check new checksum is right
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_1_LID)) //USER category
+    {
+        return KAL_FALSE;
+    }
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_5_LID)) //L1 category
+    {
+        return KAL_FALSE;
+    }
+
+    return KAL_TRUE;
+}
+
+kal_bool nvram_no_checksum_change_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //check new checksum is right
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_1_LID)) //USER category
+    {
+        return KAL_FALSE;
+    }
+    if(! nvram_verify_checksum(NVRAM_EF_NVRAM_TEST_5_LID)) //L1 category
+    {
+        return KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_structure_change_reset_test(): un-expect LID reset!\n\r");
+                nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                free_ctrl_buffer(d_buffer);
+                free_ctrl_buffer(c_buffer);
+                return KAL_FALSE;
+            }
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_write_header_test(kal_uint32 flags, void *param)
+{
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    nvram_ldi_header nv_header, nv_header_cmp;
+    nvram_ltable_entry_struct *ldi;
+    kal_uint8 i;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_write_header_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_write_header_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID); //only use NVRAM_EF_NVRAM_TEST_1_LID to test
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header, NVRAM_LDI_HEADER_SIZE);
+
+    //write ota header by API
+    nvram_write_data_header(ldi, LDI_HEADER_OTA_SECTION);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header_cmp, NVRAM_LDI_HEADER_SIZE);
+    if(strncmp((const char *)(nv_header.nv_dbg_header.defval_chkrst_l), (const char *)(nv_header_cmp.nv_dbg_header.defval_chkrst_l), 6) ||
+       strncmp((const char *)(nv_header.nv_dbg_header.struct_chkrst), (const char *)(nv_header_cmp.nv_dbg_header.struct_chkrst), RST_CHKSUM_SIZE) ||
+       strncmp((const char *)(nv_header.nv_ota_header.defval_chkrst_h), (const char *)(nv_header_cmp.nv_ota_header.defval_chkrst_h), RST_CHKSUM_SIZE-6))
+    {
+        nvram_ut_trace("[NVUT] nvram_write_header_test(): write ota header checksum change!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //write dbg header by API
+    nvram_write_data_header(ldi, LDI_HEADER_DBG_SECTION);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header_cmp, NVRAM_LDI_HEADER_SIZE);
+    if(strncmp((const char *)(nv_header.nv_dbg_header.defval_chkrst_l), (const char *)(nv_header_cmp.nv_dbg_header.defval_chkrst_l), 6) ||
+       strncmp((const char *)(nv_header.nv_dbg_header.struct_chkrst), (const char *)(nv_header_cmp.nv_dbg_header.struct_chkrst), RST_CHKSUM_SIZE) ||
+       strncmp((const char *)(nv_header.nv_ota_header.defval_chkrst_h), (const char *)(nv_header_cmp.nv_ota_header.defval_chkrst_h), RST_CHKSUM_SIZE-6))
+    {
+        nvram_ut_trace("[NVUT] nvram_write_header_test(): write dbg header checksum change!\n\r");
+        return KAL_FALSE;
+    }
+
+    //write all header by API
+    nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION);
+    nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, &nv_header_cmp, NVRAM_LDI_HEADER_SIZE);
+    if(strncmp((const char *)(nv_header.nv_dbg_header.defval_chkrst_l), (const char *)(nv_header_cmp.nv_dbg_header.defval_chkrst_l), 6) ||
+       strncmp((const char *)(nv_header.nv_dbg_header.struct_chkrst), (const char *)(nv_header_cmp.nv_dbg_header.struct_chkrst), RST_CHKSUM_SIZE) ||
+       strncmp((const char *)(nv_header.nv_ota_header.defval_chkrst_h), (const char *)(nv_header_cmp.nv_ota_header.defval_chkrst_h), RST_CHKSUM_SIZE-6))
+    {
+        nvram_ut_trace("[NVUT] nvram_write_header_test(): write all header checksum change!\n\r");
+        return KAL_FALSE;
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_attribute_change_reset_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+
+    //modify attribute
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->attr &= (~NVRAM_ATTR_GEN_DEFAULT); //remove GEN_DEFAULT
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(ldi->LID == NVRAM_EF_NVRAM_TEST_1_LID || ldi->LID == NVRAM_EF_NVRAM_TEST_5_LID)
+            {
+                if(kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): LID do not reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_attribute_change_reset_test(): un-expect LID reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_attribute_no_change_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    //reset test LIDs to default settings
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(!reset_test_lid_default_setting(test_lid_enum[i]))
+        {
+            nvram_ut_trace("[NVUT] nvram_attribute_no_change_test(): reset LIDs to default setting fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //reset test LIDs
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] nvram_attribute_no_change_test(): reset test LIDs fail!\n\r");
+            return KAL_FALSE;
+        }
+    }
+
+    //write test LIDs to non-default
+    nvram_write_test_lids();
+
+    //modify attribute
+    for(i = 0; i < test_lid_number; i++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+        ldi->attr |= NVRAM_ATTR_WRITEPROTECT; //add a now reset attribute to test
+    }
+    
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] nvram_attribute_no_change_test(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //modify MD SW version
+    if(!modify_md_sw_version())
+    {
+        nvram_ut_trace("[NVUT] nvram_attribute_no_change_test(): modify MD SW version fail!\n\r");
+        return KAL_FALSE;
+    }
+
+    //call nvram_init()
+    nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] nvram_attribute_no_change_test(): enter version conflict fail!\n\r");
+        return KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] nvram_attribute_no_change_test(): un-expect LID reset!\n\r");
+                nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                free_ctrl_buffer(d_buffer);
+                free_ctrl_buffer(c_buffer);
+                return KAL_FALSE;
+            }
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+#endif
+
+kal_bool nvram_smart_reset_new_ota_old_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    if(!manual_ota_reboot_finish)
+    {
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    #else
+        nvram_ut_trace("[NVUT] nvram_smart_reset_new_ota_old_test(): First version is not smart reset enable!\n\r");
+        return KAL_FALSE;
+    #endif
+        //reset test LIDs to default settings
+        for(i = 0; i < test_lid_number; i++)
+        {
+            if(!reset_test_lid_default_setting(test_lid_enum[i]))
+            {
+                nvram_ut_trace("[NVUT] nvram_smart_reset_new_ota_old_test(): reset LIDs to default setting fail!\n\r");
+                return KAL_FALSE;
+            }
+        }
+
+        //reset test LIDs
+        for(i = 0; i < test_lid_number; i++)
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+            if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+            {
+                nvram_ut_trace("[NVUT] nvram_smart_reset_new_ota_old_test(): reset test LIDs fail!\n\r");
+                return KAL_FALSE;
+            }
+        }
+
+        //write test LIDs to non-default
+        nvram_write_test_lids();
+        ota_save_context();
+        ota_notify_tester("Please mannual do OTA: NEW(smart reset) -> OLD(no smart reset)");
+    }
+    else
+    {
+        manual_ota_reboot_finish = KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(ldi->LID == NVRAM_EF_NVRAM_TEST_1_LID || ldi->LID == NVRAM_EF_NVRAM_TEST_5_LID)
+            {
+                if(kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_smart_reset_new_ota_old_test(): LID do not reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_smart_reset_new_ota_old_test(): un-expect LID reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_smart_reset_old_ota_new_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *d_buffer, *c_buffer;
+    kal_uint8 i, j;
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_cache_reset();//Disable NVRAM Cache
+    #endif
+    if(!manual_ota_reboot_finish)
+    {
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+        nvram_ut_trace("[NVUT] nvram_smart_reset_old_ota_new_test(): Second version is not no smart reset!\n\r");
+        return KAL_FALSE;
+    #else
+    #endif
+        //reset test LIDs to default settings
+        for(i = 0; i < test_lid_number; i++)
+        {
+            if(!reset_test_lid_default_setting(test_lid_enum[i]))
+            {
+                nvram_ut_trace("[NVUT] nvram_smart_reset_old_ota_new_test(): reset LIDs to default setting fail!\n\r");
+                return KAL_FALSE;
+            }
+        }
+
+        //reset test LIDs
+        for(i = 0; i < test_lid_number; i++)
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+            if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+            {
+                nvram_ut_trace("[NVUT] nvram_smart_reset_old_ota_new_test(): reset test LIDs fail!\n\r");
+                return KAL_FALSE;
+            }
+        }
+
+        //write test LIDs to non-default
+        nvram_write_test_lids();
+        ota_save_context();
+        ota_notify_tester("Please mannual do OTA: OLD(no smart reset) -> NEW(smart reset)");
+    }
+    else
+    {
+        manual_ota_reboot_finish = KAL_FALSE;
+    }
+    
+    //check LID is reset
+    for(j = 0; j < test_lid_number; j++)
+    {
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+        d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        c_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        kal_mem_set(c_buffer, 0x33, ldi->size);
+        kal_mem_set(d_buffer, 0x66, ldi->size);
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            nvram_get_default_value_to_write(ldi, i, c_buffer, ldi->size);
+            nvram_external_read_data(ldi->LID, i, d_buffer, ldi->size);
+            if(ldi->LID == NVRAM_EF_NVRAM_TEST_1_LID || ldi->LID == NVRAM_EF_NVRAM_TEST_5_LID)
+            {
+                if(kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_smart_reset_old_ota_new_test(): LID do not reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                if(! kal_mem_cmp((kal_char*)d_buffer, (kal_char*)c_buffer, ldi->size))
+                {
+                    nvram_ut_trace("[NVUT] nvram_smart_reset_old_ota_new_test(): un-expect LID reset!\n\r");
+                    nvram_ut_trace("[NVUT] LID: %d!\n\r", ldi->LID);
+                    free_ctrl_buffer(d_buffer);
+                    free_ctrl_buffer(c_buffer);
+                    return KAL_FALSE;
+                }
+            }
+
+        }
+        free_ctrl_buffer(d_buffer);
+        free_ctrl_buffer(c_buffer);
+    }
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();//Enable NVRAM Cache
+    #endif
+    return KAL_TRUE;
+}
+
+kal_bool nvram_external_get_lid_info_test(kal_uint32 flags, void *param)
+{
+    nvram_ltable_entry_struct ltable_entry={0};
+    kal_uint8 i;
+
+    
+    for(i = 0; i < test_lid_number; i++)
+    {
+        if(NVRAM_ERRNO_SUCCESS != nvram_external_get_lid_info(test_lid_enum[i],&ltable_entry))
+        {
+            nvram_ut_trace("[NVUT] nvram_external_get_lid_info():get LID info fail!\n\r");
+            return KAL_FALSE;
+        }
+        nvram_ut_trace("LID info:\r\n");
+        nvram_ut_trace("attr:0x%x,category:0x%x\r\n",ltable_entry.attr,ltable_entry.category);
+        nvram_ut_trace("filname:%s,verno:%s\r\n",ltable_entry.fileprefix,ltable_entry.fileverno);
+    }
+     return KAL_TRUE;
+}
+
+
+kal_bool nvram_ut_test1(kal_uint32 flags, void *param)
+{   
+    nvram_ut_trace("[NVUT] This is in nvram_ut_test1().\n\r");
+    return KAL_FALSE;
+}
+kal_bool nvram_ut_test2(kal_uint32 flags, void *param)
+{
+    nvram_ut_trace("[NVUT] This is in nvram_ut_test2().\n\r");
+    return KAL_FALSE;
+}
+kal_bool nvram_ut_test3(kal_uint32 flags, void *param)
+{
+    nvram_ut_trace("[NVUT] This is in nvram_ut_test3().\n\r");
+    return KAL_TRUE;
+}
+kal_bool nvram_ut_test4(kal_uint32 flags, void *param)
+{
+    nvram_ut_trace("[NVUT] This is in nvram_ut_test4().\n\r");
+    return KAL_TRUE;
+}
+
+#ifdef __NVRAM_LID_CACHE__
+
+kal_bool unmask_lid_all_record_valid_bit(nvram_ltable_entry_struct* ldi)
+{
+   return unmask_valid_bit_by_ltable_entry(ldi,1,ldi->total_records);
+}
+
+kal_bool unmask_lid_all_record_dirty_bit(nvram_ltable_entry_struct* ldi)
+{
+   return unmask_dirty_bit_by_ltable_entry(ldi,1,ldi->total_records);
+}
+
+kal_bool check_lid_all_record_is_valid_bit(nvram_ltable_entry_struct* ldi)
+{
+   kal_uint8 i;
+   for(i = 1; i <= ldi->total_records; i++)
+   {
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            return KAL_FALSE;
+        }
+   }
+   return KAL_TRUE;
+}
+
+kal_bool check_lid_all_record_is_dirty_bit(nvram_ltable_entry_struct* ldi)
+{
+   kal_uint8 i;
+   for(i = 1; i <= ldi->total_records; i++)
+   {
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            return KAL_FALSE;
+        }
+   }
+   return KAL_TRUE;
+}
+
+kal_bool check_lid_all_record_is_invalid_bit(nvram_ltable_entry_struct* ldi)
+{
+   kal_uint8 i;
+   for(i = 1; i <= ldi->total_records; i++)
+   {
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            return KAL_FALSE;
+        }
+   }
+   return KAL_TRUE;
+}
+
+kal_bool check_lid_all_record_is_undirty_bit(nvram_ltable_entry_struct* ldi)
+{
+   kal_uint8 i;
+   for(i = 1; i <= ldi->total_records; i++)
+   {
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            return KAL_FALSE;
+        }
+   }
+   return KAL_TRUE;
+}
+
+
+kal_bool first_boot_cache_access()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i = 0,j = 0,count = 0;
+
+    for(j = 0; j < test_lid_number; j++)
+    {
+        if(!NVRAM_IS_LID_VALID(test_lid_enum[j]))
+        {
+            return KAL_FALSE;
+        }
+        //reset test LIDs to default settings
+        if( !reset_test_lid_default_setting(test_lid_enum[j]) )
+        {
+            nvram_ut_trace("[NVUT] %s(): reset test LID settings fail!\n\r",__FUNCTION__);
+        }
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+    
+        //clean the valid and dirty bit of LID
+        if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+        {
+            nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,unmask_lid_all_record_valid_bit(ldi),unmask_lid_all_record_dirty_bit(ldi));
+            return KAL_FALSE;
+        }
+        //check the defalut value of valid bit and dirty bit of the LID
+        if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+        {
+            nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,check_lid_all_record_is_invalid_bit(ldi),check_lid_all_record_is_undirty_bit(ldi));
+            return KAL_FALSE;
+        }
+        p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            memset(p_buffer,0,ldi->size);
+            if(!nvram_external_read_data(test_lid_enum[j],i,p_buffer,ldi->size))
+            {
+                nvram_ut_trace("[NVUT] %s(): nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            //check the defalut value of valid bit and dirty bit of the LID
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] check valid bit fail!\n\r",__FUNCTION__,__LINE__,i);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] check dirty bit fail!\n\r",__FUNCTION__,__LINE__,i);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            memset(p_buffer,0,ldi->size);
+            p_buffer[0] = 0x1; //modify some data
+            if(ldi->size >= 3)
+            {
+                p_buffer[1] = 0x2;
+                p_buffer[2] = 0x3;
+            }
+            if(!nvram_external_write_data(test_lid_enum[j],i,p_buffer,ldi->size))
+            {
+                nvram_ut_trace("[NVUT] %s(): nvram_external_write_data fail @%d!\n\r",__FUNCTION__,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            count = 0;
+            //check the defalut value of valid bit and dirty bit of the LID
+            while(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE) //may be optional
+            {
+                count ++;
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] wait(%d) data to be flushed!\n\r",__FUNCTION__,__LINE__,i,count);
+            }
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] valid bit check error!\n\r",__FUNCTION__,__LINE__,i);
+                free_ctrl_buffer(p_buffer); 
+                return KAL_FALSE;
+            } 
+                  
+        }
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            memset(p_buffer,0,ldi->size);
+            
+            if(!nvram_external_read_data(test_lid_enum[j],i,p_buffer,ldi->size))
+            {
+                nvram_ut_trace("[NVUT] %s(): record[%d] nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] valid bit check error!\n\r",__FUNCTION__,__LINE__,i);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            
+            //check the defalut value of valid bit and dirty bit of the LID
+            if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE) //may be optional
+            {            
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] dirty bit check error!\n\r",__FUNCTION__,__LINE__,i);
+            }
+            
+            if(p_buffer[0] != 0x1)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] data[0]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[0]);
+                free_ctrl_buffer(p_buffer);            
+                return KAL_FALSE;
+            }
+            if(ldi->size >= 3)
+            {
+                if((p_buffer[1] != 0x2) ||(p_buffer[2] != 0x3))
+                {
+                    nvram_ut_trace("[NVUT] %s() %d: record[%d] data[1]:%d data[2]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[1],p_buffer[2]);
+                    free_ctrl_buffer(p_buffer);
+                    return KAL_FALSE;
+                }
+            }
+                      
+        }
+        free_ctrl_buffer(p_buffer);
+    }
+    return KAL_TRUE;
+}
+
+kal_bool normal_boot_cache_access()
+{
+    return first_boot_cache_access();
+}
+
+kal_bool ota_boot_cache_access()
+{
+    return first_boot_cache_access();
+}
+
+kal_bool normal_boot_file_lost_cache_read(nvram_lid_enum LID)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    kal_uint32 idx;
+    
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(LID) )
+    {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): reset test LID settings fail!\n\r");
+    }
+    nvram_util_get_data_item(&ldi, LID);
+
+    //clean the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: unmask valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: check valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+
+    //read all the record data of a LID
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        if(!nvram_external_read_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s() %d: LID record[%d] cmpt operations fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: check record[%d] valid bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: check record[%d] dirty bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    
+    for (idx = 0; idx < 2; idx++) 
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, (idx==0));
+        folder_index = nvram_query_folder_index_ex(ldi->category, (idx==0));
+        nvram_query_file_name(folder_index, nvramname, filename);
+        FS_Delete(filename);
+    }
+    
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        if(!nvram_external_read_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID cmpt operations fail!\n\r",__FUNCTION__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s(): check record[%d] valid bit fail@line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s(): check record[%d]dirty bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    
+    //re-create file 
+    if(nvram_cache_reset_one_data_item(ldi,1,ldi->total_records) == NVRAM_IO_ERRNO_OK)
+    {
+        //check the defalut value of valid bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s(): check record[%d] valid bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    
+    free_ctrl_buffer(p_buffer);
+    return KAL_TRUE;
+}
+
+kal_bool normal_boot_file_lost_cache_read_with_recover(nvram_lid_enum LID)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    kal_uint32 idx = 0,count = 0;
+    
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(LID) )
+    {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): reset test LID settings fail!\n\r");
+    }
+    nvram_util_get_data_item(&ldi, LID);
+
+    //clean the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+         nvram_ut_trace("[NVUT] %s() %d: unmask valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+         nvram_ut_trace("[NVUT] %s() %d: check valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+
+    //read all the record data of a LID
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        if(!nvram_external_read_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID record[%d] cmpt operations fail @line%d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s(): check record[%d] valid bit fail @line%d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s(): check record[%d] dirty bit fail @line%d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    
+    for (idx = 0; idx < 2; idx++) 
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, (idx==0));
+        folder_index = nvram_query_folder_index_ex(ldi->category, (idx==0));
+        nvram_query_file_name(folder_index, nvramname, filename);
+        FS_Delete(filename);
+    }
+
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+         nvram_ut_trace("[NVUT] %s() %d: unmask valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+         free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        if(!nvram_external_read_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID record[%d] cmpt operations fail@ line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        count = 0;
+        //check the defalut value of valid bit and dirty bit of the LID
+        while(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s():record[%d] wait(%d) valid bit become true@line %d !\n\r",__FUNCTION__,i,count,__LINE__);            
+            count++;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+             nvram_ut_trace("[NVUT] %s():check record[%d] dirty bit fail at line %d!\n\r",__FUNCTION__,i,__LINE__);
+             free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }    
+    free_ctrl_buffer(p_buffer);
+    return KAL_TRUE;
+}
+
+
+kal_bool normal_boot_user_lost_cache_read()
+{
+    return normal_boot_file_lost_cache_read(NVRAM_EF_NVRAM_TEST_1_LID);
+}
+
+kal_bool nvram_boot_calibrate_lost_cache_read()
+{
+    return normal_boot_file_lost_cache_read(NVRAM_EF_NVRAM_TEST_3_LID);
+}
+
+kal_bool nvram_boot_important_lost_cache_read()
+{ 
+   return normal_boot_file_lost_cache_read(NVRAM_EF_NVRAM_TEST_4_LID); 
+}
+
+kal_bool nvram_boot_important_l4_lost_cache_read()
+{ 
+   return normal_boot_file_lost_cache_read(NVRAM_EF_NVRAM_TEST_6_LID); 
+}
+
+kal_bool normal_boot_user_lost_cache_read_with_recover()
+{
+    return normal_boot_file_lost_cache_read_with_recover(NVRAM_EF_NVRAM_TEST_1_LID);
+}
+
+kal_bool nvram_boot_calibrate_lost_cache_read_with_recover()
+{
+    return normal_boot_file_lost_cache_read_with_recover(NVRAM_EF_NVRAM_TEST_3_LID);
+}
+
+kal_bool nvram_boot_important_lost_cache_read_with_recover()
+{ 
+   return normal_boot_file_lost_cache_read_with_recover(NVRAM_EF_NVRAM_TEST_4_LID); 
+}
+
+kal_bool nvram_boot_important_l4_lost_cache_read_with_recover()
+{ 
+   return normal_boot_file_lost_cache_read_with_recover(NVRAM_EF_NVRAM_TEST_6_LID); 
+}
+
+
+extern kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi);
+
+kal_bool nvram_cache_valid_bit_after_recover()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i,j;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    kal_uint32 idx;
+    for(j = 0; j < test_lid_number; j++)
+    {
+        if(!NVRAM_IS_LID_VALID(test_lid_enum[j]))
+        {
+            return KAL_FALSE;
+        }
+    
+        //read all the record data of a LID
+        nvram_util_get_data_item(&ldi, test_lid_enum[j]);
+
+        //clean the valid and dirty bit of LID
+        if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+        {
+            nvram_ut_trace("[NVUT] %s() %d: unmask valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+            return KAL_FALSE;
+        }
+        
+        //check the defalut value of valid bit and dirty bit of the LID
+        if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+        {
+            nvram_ut_trace("[NVUT] %s() %d: check invalid/undirty bit fail!\n\r",__FUNCTION__,__LINE__);
+            return KAL_FALSE;
+        }
+        p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+        
+        for(i = 1; i <= ldi->total_records; i++)
+        {
+            memset(p_buffer,0,ldi->size);
+            if(!nvram_external_read_data(test_lid_enum[j],i,p_buffer,ldi->size))
+            {
+                nvram_ut_trace("[NVUT] %s() : nvram_external_read_data record[%d] fail at line%d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            //check the defalut value of valid bit and dirty bit of the LID
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+            {
+                nvram_ut_trace("[NVUT] %s(): check record[%d] dirty bit fail@line %d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+            if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+            {
+                nvram_ut_trace("[NVUT] %s(): check record[%d] dirty bit fail@line %d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+        
+        for (idx = 0; idx < 2; idx++) 
+        {
+            nvram_util_make_lid_filename(ldi, nvramname, (idx==0));
+            folder_index = nvram_query_folder_index_ex(ldi->category, (idx==0));
+            nvram_query_file_name(folder_index, nvramname, filename);
+
+            FS_Delete(filename);
+        }
+        if(NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+        {
+            if(nvram_recover_data_item(ldi) == NVRAM_IO_ERRNO_OK)
+            {
+                //check the defalut value of valid bit of the LID
+                if(check_lid_all_record_is_valid_bit(ldi)!= KAL_FALSE)
+                {
+                    nvram_ut_trace("[NVUT] %s() %d: check all valid bit fail!\n\r",__FUNCTION__,__LINE__);
+                    free_ctrl_buffer(p_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                nvram_ut_trace("[NVUT] %s() %d: recover data fail!\n\r",__FUNCTION__,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+        else
+        {           
+            //reset LID to default
+            if(nvram_cache_reset_one_data_item(ldi,1,ldi->total_records) == NVRAM_IO_ERRNO_OK)
+            {
+                //check the defalut value of valid bit of the LID
+                if(check_lid_all_record_is_valid_bit(ldi)!= KAL_FALSE)
+                {
+                    nvram_ut_trace("[NVUT] %s(): check valid bit fail@line %d!\n\r",__FUNCTION__,__LINE__);
+                    free_ctrl_buffer(p_buffer);
+                    return KAL_FALSE;
+                }
+            }
+            else
+            {
+                nvram_ut_trace("[NVUT] %s(): cache reset LID (%d)fail @line %d!\n\r",__FUNCTION__,ldi->LID,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+        
+        free_ctrl_buffer(p_buffer);
+    }
+    return KAL_TRUE;
+}
+
+
+kal_bool normal_boot_file_lost_cache_write(nvram_lid_enum LID)
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i;
+    NVRAM_FILE_NAME nvramname;
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    kal_uint32 idx =0,count=0;
+    
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(LID) )
+    {
+        nvram_ut_trace("[NVUT] raw_data_access_function_test(): reset test LID settings fail!\n\r");
+    }
+    
+    nvram_util_get_data_item(&ldi, LID);
+    //clean the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: unmask all record valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: check all record invalid/undirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        if(!nvram_external_read_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID cmpt operations fail!\n\r",__FUNCTION__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        count = 0;
+        while(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            count ++;
+            nvram_ut_trace("[NVUT] %s() %d: wait(%d) data to be flushed!\n\r",__FUNCTION__,__LINE__,count);
+        }
+    }
+    
+    for (idx = 0; idx < 2; idx++) 
+    {
+        nvram_util_make_lid_filename(ldi, nvramname, (idx==0));
+        folder_index = nvram_query_folder_index_ex(ldi->category, (idx==0));
+        nvram_query_file_name(folder_index, nvramname, filename);
+
+        FS_Delete(filename);
+    }
+
+    //set flag to disable cache flush
+
+    
+    for(i = 1; i <= ldi->total_records; )
+    {
+        memset(p_buffer,0,ldi->size);
+        p_buffer[0] = 0x1; //modify some data
+        if(ldi->size >= 3)
+        {
+            p_buffer[1] = 0x2;
+            p_buffer[2] = 0x3;
+        }
+        
+        unmask_valid_bit_by_ltable_entry(ldi,i,1);
+        if(!nvram_external_write_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID cmpt operations fail!\n\r",__FUNCTION__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+		count = 0;
+        //check the defalut value of valid bit and dirty bit of the LID        
+        while(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+			count++;
+			nvram_ut_trace("[NVUT] %s(): wait(%d) the data has to be flushed!\n\r",__FUNCTION__,count);	
+        }
+        while(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+           nvram_ut_trace("[NVUT] %s(): check_dirty_bit_by_ltable_entry fail at line %d!\n\r",__FUNCTION__,__LINE__); 
+        }      
+        i = i +2;
+    }
+    
+    for(i = 1; i <= ldi->total_records; i+=2)
+    {
+        memset(p_buffer,0,ldi->size);
+        if(!nvram_external_read_data(LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): nvram_external_read_data fail at line %d!\n\r",__FUNCTION__,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(p_buffer[0] != 0x1)
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(ldi->size >= 3)
+        {
+            if((p_buffer[1] != 0x2) ||(p_buffer[2] != 0x3))
+            {
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        //Maybe optional
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    free_ctrl_buffer(p_buffer);
+    return KAL_TRUE;
+}
+
+kal_bool normal_boot_user_lost_cache_write()
+{
+  return normal_boot_file_lost_cache_write(NVRAM_EF_NVRAM_TEST_1_LID);
+}
+
+kal_bool normal_boot_calibrate_lost_cache_write()
+{
+  return normal_boot_file_lost_cache_write(NVRAM_EF_NVRAM_TEST_3_LID);
+}
+
+kal_bool normal_boot_important_lost_cache_write()
+{
+   return normal_boot_file_lost_cache_write(NVRAM_EF_NVRAM_TEST_4_LID);
+}
+
+kal_bool normal_boot_important_l4_lost_cache_write()
+{
+    return normal_boot_file_lost_cache_write(NVRAM_EF_NVRAM_TEST_6_LID);
+}
+
+#define CACHE_READ_COUNT (100)
+kal_bool nvram_cache_read_performance_chek()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i;
+    kal_uint32 start_time;
+    kal_uint32 end_time;
+    kal_uint32 during_time;
+    kal_uint32 consum_time[2]={0,0};
+    
+    // reset and backup data into data_buffer
+	if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID))
+	{
+		nvram_ut_trace("[NVUT] %s():rest test lid fail!\n\r", __FUNCTION__);
+		return KAL_FALSE;
+	}
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+	{
+		nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+		return KAL_FALSE;
+	}
+    
+    //clean and check the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: unmask valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size*ldi->total_records);
+
+    //read all the record data of a LID
+    start_time = ust_get_current_time();
+    if(!nvram_external_read_multi_record(NVRAM_EF_NVRAM_TEST_1_LID,1,ldi->total_records,p_buffer,ldi->size*ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] %s(): LID cmpt operations fail!\n\r",__FUNCTION__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    end_time = ust_get_current_time();
+    consum_time[0] = end_time - start_time;
+    
+    for(i = 0; i < CACHE_READ_COUNT ; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        start_time = ust_get_current_time();    
+        if(!nvram_external_read_multi_record(NVRAM_EF_NVRAM_TEST_1_LID,1,ldi->total_records,p_buffer,ldi->size*ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID cmpt operations fail!\n\r",__FUNCTION__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        end_time = ust_get_current_time();
+        during_time = end_time - start_time;
+        if(consum_time[0] <= during_time )
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        consum_time[1] += during_time;
+    }
+    nvram_ut_trace("[NVUT] %s(): LID non-cache read average time:%u \n\r", __FUNCTION__, consum_time[0]);
+    nvram_ut_trace("[NVUT] %s(): LID cache read total time:%u \n\r",__FUNCTION__, consum_time[1]);
+    //compare the read time
+    consum_time[1] = consum_time[1]/CACHE_READ_COUNT;
+    nvram_ut_trace("[NVUT] %s(): LID cache read average time:%u \n\r",__FUNCTION__, consum_time[1]);
+    if(consum_time[0] < consum_time[1])
+    {
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    free_ctrl_buffer(p_buffer);
+    return KAL_TRUE;
+}
+
+kal_bool nvram_cache_write_performance_chek()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i;
+    kal_uint32 start_time;
+    kal_uint32 end_time;
+    kal_uint32 during_time;
+    kal_uint32 consum_time[2]={0,0};
+
+    // reset and backup data into data_buffer
+	if(!reset_test_lid_default_setting(NVRAM_EF_NVRAM_TEST_1_LID))
+	{
+		nvram_ut_trace("[NVUT] %s():rest test lid fail!\n\r", __FUNCTION__);
+		return KAL_FALSE;
+	}
+    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_1_LID);
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+	{
+		nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+		return KAL_FALSE;
+	}
+    
+    //clean and check the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: unmask valid/dirty bit fail!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    //disable the cache funtion
+    unmark_nvram_cache_ready();        
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size*ldi->total_records);
+
+    //write all the record data of a LID
+    for(i= 1; i <= ldi->total_records; i++)
+    {
+        start_time = ust_get_current_time();
+        if(!nvram_external_write_data(NVRAM_EF_NVRAM_TEST_1_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): LID cmpt operations fail!\n\r",__FUNCTION__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        end_time = ust_get_current_time();
+        nvram_ut_trace("[NVUT] %s(): LID non-cache write time:%u \n\r", __FUNCTION__, (end_time - start_time));
+        consum_time[0] += (end_time - start_time);
+    }
+    nvram_ut_trace("[NVUT] %s(): LID non-cache write total time:%u \n\r",__FUNCTION__, consum_time[0]);
+
+    consum_time[0] = consum_time[0]/ldi->total_records;
+    nvram_ut_trace("[NVUT] %s(): LID non-cache write average time:%u \n\r", __FUNCTION__, consum_time[0]);
+    //Enable the cache funtion
+    mark_nvram_cache_ready();
+    for(i= 0; i < ldi->total_records; i++)
+    {
+        start_time = ust_get_current_time();
+        nvram_external_write_data(NVRAM_EF_NVRAM_TEST_1_LID,i+1,p_buffer,ldi->size);
+        end_time = ust_get_current_time();
+        during_time = end_time - start_time;
+        if(consum_time[0] <= during_time)
+        {
+            //free_ctrl_buffer(p_buffer);
+            //return KAL_FALSE;            
+            nvram_ut_trace("[NVUT] %s(): LID cache write During time:%u \n\r", __FUNCTION__, during_time);
+        }
+        consum_time[1] += during_time;
+    }
+    nvram_ut_trace("[NVUT] %s(): LID cache write total time:%u \n\r",__FUNCTION__, consum_time[1]);
+
+    consum_time[1] = consum_time[1]/ldi->total_records;    
+    nvram_ut_trace("[NVUT] %s(): LID cache write average time:%u \n\r", __FUNCTION__, consum_time[1]);
+
+    if(consum_time[0] < consum_time[1])
+    {
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    
+    free_ctrl_buffer(p_buffer);
+    return KAL_TRUE;
+}
+
+kal_bool  nvram_cache_read_data_less_than_16K()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint32 i = 0,j = 0,count = 0;
+
+    if(!NVRAM_IS_LID_VALID(NVRAM_EF_INTERNAL_TEST_14_LID))
+    {
+        return KAL_FALSE;
+    }
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_INTERNAL_TEST_14_LID) )
+    {
+        nvram_ut_trace("[NVUT] %s(): reset test LID settings fail!\n\r",__FUNCTION__);
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_INTERNAL_TEST_14_LID);
+    nvram_ut_trace("[NVUT] %s(): LID->attr=(%x) \n\r", __FUNCTION__, ldi->attr);
+
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+	{
+		nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+		return KAL_FALSE;
+	}
+
+    //clean the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,unmask_lid_all_record_valid_bit(ldi),unmask_lid_all_record_dirty_bit(ldi));
+        return KAL_FALSE;
+    }
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,check_lid_all_record_is_invalid_bit(ldi),check_lid_all_record_is_undirty_bit(ldi));
+        return KAL_FALSE;
+    }
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+
+    memset(p_buffer,0,ldi->size);
+    if(!nvram_external_read_data(NVRAM_EF_INTERNAL_TEST_14_LID,1,p_buffer,ldi->size))
+    {
+        nvram_ut_trace("[NVUT] %s(): nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,__LINE__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    
+    if(p_buffer[0] != 1)
+    {
+        nvram_ut_trace("[NVUT] %s() %d: record[1] check data fail(data[0]!=1) p_buffer=%d !\n\r",__FUNCTION__,__LINE__, *((kal_uint32 *)p_buffer));           
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE; 
+    }
+    
+    for(j = 1; j < ldi->size; j++)
+    {
+        if(p_buffer[j] != 0)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[1] check data fail(data[%d]!=0)!\n\r",__FUNCTION__,__LINE__,j);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE; 
+        }
+    }
+    
+    for(i = 1; i <= ldi->total_records; i++)
+    {        
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check valid bit fail!\n\r",__FUNCTION__,__LINE__,i);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check dirty bit fail!\n\r",__FUNCTION__,__LINE__,i);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }        
+    }
+
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        p_buffer[0] = 0x1; //modify some data
+        if(ldi->size >= 3)
+        {
+            p_buffer[1] = 0x2;
+            p_buffer[2] = 0x3;
+        }
+        if(!nvram_external_write_data(NVRAM_EF_INTERNAL_TEST_14_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): nvram_external_write_data fail @%d!\n\r",__FUNCTION__,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        count = 0;
+        //check the defalut value of valid bit and dirty bit of the LID
+        while(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE) //may be optional
+        {
+            count ++;
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] wait(%d) data to be flushed!\n\r",__FUNCTION__,__LINE__,i,count);
+        }
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] valid bit check error!\n\r",__FUNCTION__,__LINE__,i);
+            free_ctrl_buffer(p_buffer); 
+            return KAL_FALSE;
+        } 
+              
+    }
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        
+        if(!nvram_external_read_data(NVRAM_EF_INTERNAL_TEST_14_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): record[%d] nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if( i == 1 ){
+            for(j = 1; j <= ldi->total_records; j++){
+                if(check_valid_bit_by_ltable_entry(ldi,j)!= KAL_TRUE)
+                {
+                    nvram_ut_trace("[NVUT] %s() %d: record[%d] valid bit check error!\n\r",__FUNCTION__,__LINE__,j);
+                    free_ctrl_buffer(p_buffer);
+                    return KAL_FALSE;
+                }
+                
+                //check the defalut value of valid bit and dirty bit of the LID
+                if(check_dirty_bit_by_ltable_entry(ldi,j)!= KAL_FALSE) //may be optional
+                {            
+                    nvram_ut_trace("[NVUT] %s() %d: record[%d] dirty bit check error!\n\r",__FUNCTION__,__LINE__,j);
+                }
+            }
+        }
+        if(p_buffer[0] != 0x1)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] data[0]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[0]);
+            free_ctrl_buffer(p_buffer);            
+            return KAL_FALSE;
+        }
+        if(ldi->size >= 3)
+        {
+            if((p_buffer[1] != 0x2) ||(p_buffer[2] != 0x3))
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] data[1]:%d data[2]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[1],p_buffer[2]);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+                  
+    }
+    //re-create file 
+    if(nvram_cache_reset_one_data_item(ldi,1,ldi->total_records) == NVRAM_IO_ERRNO_OK)
+    {
+        for(i = 1; i <= ldi->total_records; i++){
+            //check the defalut value of valid bit of the LID
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+            {
+                nvram_ut_trace("[NVUT] %s(): check record[%d] valid bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+    }    
+    nvram_util_get_data_item(&ldi, NVRAM_EF_INTERNAL_TEST_14_LID);
+    for(j = 1; j <= ldi->total_records; j++)
+    {
+        kal_mem_set(data_buffer, 0, ldi->size);
+        data_buffer[0] = j;
+        if(!nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    
+    free_ctrl_buffer(p_buffer);
+
+    return KAL_TRUE;    
+}
+
+kal_uint8 temp_cache_buffer[65*1024];
+#define RECORD_CNT_FOR_16K_MORE_CACHE_READ (2)
+#define RECORD_CNT_FOR_64K_MORE_CACHE_READ (59)
+
+kal_bool  nvram_cache_read_data_more_than_16K()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint32 i = 0,j = 0,count = 0;
+
+    if(!NVRAM_IS_LID_VALID(NVRAM_EF_INTERNAL_13_LID))
+    {
+        return KAL_FALSE;
+    }
+    //reset test LIDs to default settings
+    if( !reset_test_lid_default_setting(NVRAM_EF_INTERNAL_13_LID) )
+    {
+        nvram_ut_trace("[NVUT] %s(): reset test LID settings fail!\n\r",__FUNCTION__);
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_INTERNAL_13_LID);
+
+    if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+	{
+		nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+		return KAL_FALSE;
+	}
+
+    for(j = 1; j <= ldi->total_records; j++)
+    {
+        kal_mem_set(data_buffer, 0, ldi->size);
+        data_buffer[0] = j;
+        if(!nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            return KAL_FALSE;
+        }
+    }
+    //clean the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,unmask_lid_all_record_valid_bit(ldi),unmask_lid_all_record_dirty_bit(ldi));
+        return KAL_FALSE;
+    }
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,check_lid_all_record_is_invalid_bit(ldi),check_lid_all_record_is_undirty_bit(ldi));
+        return KAL_FALSE;
+    }
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    memset(temp_cache_buffer,0,ldi->size * RECORD_CNT_FOR_16K_MORE_CACHE_READ);
+    if(!nvram_external_read_multi_record(NVRAM_EF_INTERNAL_13_LID,1,RECORD_CNT_FOR_16K_MORE_CACHE_READ,temp_cache_buffer,ldi->size * RECORD_CNT_FOR_16K_MORE_CACHE_READ))
+    {
+        nvram_ut_trace("[NVUT] %s(): nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,__LINE__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    
+    for(i = 1; i <= (RECORD_CNT_FOR_16K_MORE_CACHE_READ); i++)
+    {        
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check valid bit fail!\n\r",__FUNCTION__,__LINE__,i);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check dirty bit fail!\n\r",__FUNCTION__,__LINE__,i);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        if(temp_cache_buffer[((i-1)*ldi->size)] != i)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check data fail(data[%d]!=%d)!\n\r",__FUNCTION__,__LINE__,i,((i-1)*ldi->size),i);           
+            return KAL_FALSE; 
+        }
+        
+        for(j = 1; j < ldi->size; j++)
+        {
+            if(temp_cache_buffer[((i-1)*ldi->size + j)] != 0)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] check data fail(data[%d]!=0)!\n\r",__FUNCTION__,__LINE__,i,j);
+                return KAL_FALSE; 
+            }
+        }
+    }
+
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        p_buffer[0] = 0x1; //modify some data
+        if(ldi->size >= 3)
+        {
+            p_buffer[1] = 0x2;
+            p_buffer[2] = 0x3;
+        }
+        if(!nvram_external_write_data(NVRAM_EF_INTERNAL_13_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): nvram_external_write_data fail @%d!\n\r",__FUNCTION__,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        count = 0;
+        //check the defalut value of valid bit and dirty bit of the LID
+        while(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE) //may be optional
+        {
+            count ++;
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] wait(%d) data to be flushed!\n\r",__FUNCTION__,__LINE__,i,count);
+        }        
+              
+    }
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        
+        if(!nvram_external_read_data(NVRAM_EF_INTERNAL_13_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): record[%d] nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }        
+        if(p_buffer[0] != 0x1)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] data[0]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[0]);
+            free_ctrl_buffer(p_buffer);            
+            return KAL_FALSE;
+        }
+        if(ldi->size >= 3)
+        {
+            if((p_buffer[1] != 0x2) ||(p_buffer[2] != 0x3))
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] data[1]:%d data[2]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[1],p_buffer[2]);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+                  
+    }
+    
+    //re-create file 
+    if(nvram_cache_reset_one_data_item(ldi,1,ldi->total_records) == NVRAM_IO_ERRNO_OK)
+    {
+        for(i = 1; i <= ldi->total_records; i++){
+            //check the defalut value of valid bit of the LID
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+            {
+                nvram_ut_trace("[NVUT] %s(): check record[%d] valid bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+    }
+    
+    for(j = 1; j <= ldi->total_records; j++)
+    {
+        kal_mem_set(data_buffer, 0, ldi->size);
+        data_buffer[0] = j;
+        if(!nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }   
+    free_ctrl_buffer(p_buffer);
+
+    return KAL_TRUE;    
+}
+
+kal_bool  nvram_cache_read_data_more_than_64K()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint32 i = 0,j = 0,count = 0;
+    
+    if(!NVRAM_IS_LID_VALID(NVRAM_EF_INTERNAL_TEST_16_LID))
+    {
+        return KAL_FALSE;
+    }
+    nvram_util_get_data_item(&ldi, NVRAM_EF_INTERNAL_TEST_16_LID);
+
+    //clean the valid and dirty bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) || (unmask_lid_all_record_dirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,unmask_lid_all_record_valid_bit(ldi),unmask_lid_all_record_dirty_bit(ldi));
+        return KAL_FALSE;
+    }
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,j,check_lid_all_record_is_invalid_bit(ldi),check_lid_all_record_is_undirty_bit(ldi));
+        return KAL_FALSE;
+    }
+    memset(temp_cache_buffer,0,ldi->size * RECORD_CNT_FOR_64K_MORE_CACHE_READ);
+    if(!nvram_external_read_multi_record(NVRAM_EF_INTERNAL_TEST_16_LID,1,RECORD_CNT_FOR_64K_MORE_CACHE_READ,temp_cache_buffer,ldi->size * RECORD_CNT_FOR_64K_MORE_CACHE_READ))
+    {
+        nvram_ut_trace("[NVUT] %s(): nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,__LINE__);
+        return KAL_FALSE;
+    }
+    
+    //read more than 64KB per one time
+    for(i = 1; i <= RECORD_CNT_FOR_64K_MORE_CACHE_READ; i++)
+    {        
+        //check the defalut value of valid bit and dirty bit of the LID
+        if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_TRUE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check valid bit fail!\n\r",__FUNCTION__,__LINE__,i);
+            return KAL_FALSE;
+        }
+        if(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check dirty bit fail!\n\r",__FUNCTION__,__LINE__,i);            
+            return KAL_FALSE;
+        }
+
+        if(temp_cache_buffer[((i-1)*ldi->size)] != i)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] check data fail(data[%d]!=%d)!\n\r",__FUNCTION__,__LINE__,i,((i-1)*ldi->size),i);           
+            return KAL_FALSE; 
+        }
+        
+        for(j = 1; j < ldi->size;j++)
+        {
+            if(temp_cache_buffer[((i-1)*ldi->size) + j] != 0)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] check data fail(data[%d]!=0)!\n\r",__FUNCTION__,__LINE__,i,j);
+                return KAL_FALSE; 
+            }
+        }
+    }
+    
+    p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    memset(p_buffer,0,ldi->size);
+    
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        p_buffer[0] = 0x1; //modify some data
+        if(ldi->size >= 3)
+        {
+            p_buffer[1] = 0x2;
+            p_buffer[2] = 0x3;
+        }
+        if(!nvram_external_write_data(NVRAM_EF_INTERNAL_TEST_16_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): nvram_external_write_data fail @%d!\n\r",__FUNCTION__,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+        count = 0;
+        //check the defalut value of valid bit and dirty bit of the LID
+        while(check_dirty_bit_by_ltable_entry(ldi,i)!= KAL_FALSE) //may be optional
+        {
+            count ++;
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] wait(%d) data to be flushed!\n\r",__FUNCTION__,__LINE__,i,count);
+        }        
+              
+    }
+    for(i = 1; i <= ldi->total_records; i++)
+    {
+        memset(p_buffer,0,ldi->size);
+        
+        if(!nvram_external_read_data(NVRAM_EF_INTERNAL_TEST_16_LID,i,p_buffer,ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s(): record[%d] nvram_external_read_data fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }        
+        if(p_buffer[0] != 0x1)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: record[%d] data[0]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[0]);
+            free_ctrl_buffer(p_buffer);            
+            return KAL_FALSE;
+        }
+        if(ldi->size >= 3)
+        {
+            if((p_buffer[1] != 0x2) ||(p_buffer[2] != 0x3))
+            {
+                nvram_ut_trace("[NVUT] %s() %d: record[%d] data[1]:%d data[2]:%d error!\n\r",__FUNCTION__,__LINE__,i,p_buffer[1],p_buffer[2]);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+                  
+    }
+    
+    //re-create file 
+    if(nvram_cache_reset_one_data_item(ldi,1,ldi->total_records) == NVRAM_IO_ERRNO_OK)
+    {
+        for(i = 1; i <= ldi->total_records; i++){
+            //check the defalut value of valid bit of the LID
+            if(check_valid_bit_by_ltable_entry(ldi,i)!= KAL_FALSE)
+            {
+                nvram_ut_trace("[NVUT] %s(): check record[%d] valid bit fail @line %d!\n\r",__FUNCTION__,i,__LINE__);
+                free_ctrl_buffer(p_buffer);
+                return KAL_FALSE;
+            }
+        }
+    }
+    
+    for(j = 1; j <= ldi->total_records; j++)
+    {
+        kal_mem_set(data_buffer, 0, ldi->size);
+        data_buffer[0] = j;
+        if(!nvram_external_write_data(NVRAM_EF_INTERNAL_TEST_16_LID, j, (kal_uint8 *)data_buffer, ldi->size))
+        {
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+    free_ctrl_buffer(p_buffer);
+
+    return KAL_TRUE;    
+}
+
+
+#ifdef __NVRAM_LID_PREREAD__
+kal_bool nvram_cache_preread_chk()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 idx;
+
+    for(idx = 0; idx < preread_white_list_amount; idx++)
+    {
+        nvram_util_get_data_item(&ldi, pre_read_white_list[idx]);
+        //check the valid and dirty bit of LID
+        if(ldi->attr & NVRAM_ATTR_GEN_DEFAULT)
+        {
+            if(check_lid_all_record_is_valid_bit(ldi)!= KAL_TRUE)
+            {
+                nvram_ut_trace("[NVUT] %s() %d: the valid bit !\n\r",__FUNCTION__,__LINE__);
+                return KAL_FALSE;
+            }else
+            {
+                nvram_ut_trace("[NVUT] %s() %d: have pre-read !\n\r",__FUNCTION__, ldi->LID);
+            }
+        }
+    }
+
+    return KAL_TRUE;
+}
+#endif
+
+kal_bool nvram_cache_bypass_white_list_test()
+{
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_uint8 *p_buffer = NULL;
+    kal_uint8 i;
+
+    nvram_util_get_data_item(&ldi, NVRAM_EF_INTERNAL_TEST_17_LID);
+
+    //check the defalut value of valid bit and dirty bit of the LID
+    if((check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid or dirty bit check fail.\n\r", __FUNCTION__, __LINE__, NVRAM_EF_INTERNAL_TEST_17_LID);
+        return KAL_FALSE;
+    }
+
+     p_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size*ldi->total_records);
+     memset(p_buffer,0,ldi->size*ldi->total_records);
+
+    //write all the record data of a LID
+    for(i= 1; i <= ldi->total_records; i++)
+    {
+        p_buffer[0] = i;
+        if(!nvram_external_write_data(NVRAM_EF_INTERNAL_TEST_17_LID, i, p_buffer, ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s() %d: LID write operations fail!\n\r",__FUNCTION__, __LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+
+    //check the defalut value of valid bit and dirty bit of the LID
+    if(check_lid_all_record_is_valid_bit(ldi)!= KAL_TRUE)
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid bit check fail.\n\r",__FUNCTION__, __LINE__, NVRAM_EF_INTERNAL_TEST_17_LID);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+
+    nvram_ut_trace("[NVUT] %s(): LID write done.\n\r",__FUNCTION__);
+
+    //clean and check the valid bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) && (check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: unmask valid bit fail!\n\r",__FUNCTION__,__LINE__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+
+    //read all the record data of a LID
+    memset(p_buffer,0,ldi->size*ldi->total_records);
+
+    if(!nvram_external_read_multi_record(NVRAM_EF_INTERNAL_TEST_17_LID,1,ldi->total_records,p_buffer,ldi->size*ldi->total_records))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: LID cmpt operations fail!\n\r",__FUNCTION__, __LINE__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+
+    //check the record data of a LID
+    for(i= 0; i < ldi->total_records; i++)
+    {
+        if(p_buffer[i*1024] != (i+1))
+        {
+            nvram_ut_trace("[NVUT] %s() %d: check the LID data fail!\n\r",__FUNCTION__, __LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+
+    //check the value of valid bit of the LID
+    if(check_lid_all_record_is_valid_bit(ldi)!= KAL_TRUE)
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid bit check fail.\n\r",__FUNCTION__, __LINE__, NVRAM_EF_INTERNAL_TEST_17_LID);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    nvram_ut_trace("[NVUT] %s(): LID read multi record done.\n\r",__FUNCTION__);
+
+    //clean and check the valid bit of LID
+    if((unmask_lid_all_record_valid_bit(ldi)!= KAL_TRUE) && (check_lid_all_record_is_invalid_bit(ldi)!= KAL_TRUE))
+    {
+        nvram_ut_trace("[NVUT] %s() %d: unmask valid bit fail!\n\r",__FUNCTION__,__LINE__);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+
+    //read all the record data of a LID
+    memset(p_buffer,0,ldi->size*ldi->total_records);
+    for(i= 1; i <= ldi->total_records; i++)
+    {
+        if(!nvram_external_read_data(NVRAM_EF_INTERNAL_TEST_17_LID, i,(p_buffer + ((i-1)*1024)),ldi->size))
+        {
+            nvram_ut_trace("[NVUT] %s() %d: LID cmpt operations fail!\n\r",__FUNCTION__, __LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+
+        //check the record data of a LID
+        if(p_buffer[(i-1)*1024] != i)
+        {
+            nvram_ut_trace("[NVUT] %s() %d: check the LID data fail!\n\r",__FUNCTION__, __LINE__);
+            free_ctrl_buffer(p_buffer);
+            return KAL_FALSE;
+        }
+    }
+
+    //check the value of valid bit of the LID
+    if(check_lid_all_record_is_valid_bit(ldi)!= KAL_TRUE)
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid bit check fail.\n\r",__FUNCTION__, __LINE__, NVRAM_EF_INTERNAL_TEST_17_LID);
+        free_ctrl_buffer(p_buffer);
+        return KAL_FALSE;
+    }
+    free_ctrl_buffer(p_buffer);
+    return KAL_TRUE;
+}
+
+#endif
+
+//  __NVRAM_ENHANCE_CHKSUM_ALGORITHM__
+#ifdef __NV_CHKSUM_ENHANCE__
+kal_bool reset_test_lids(kal_uint32 *lid_list, kal_uint8 length)
+{
+	kal_uint8 i=0;
+	nvram_ltable_entry_struct *ldi = NULL;
+
+	for(i=0; i< length; i++)
+	{
+		//reset test LID to default settings
+		nvram_util_get_data_item(&ldi,lid_list[i]);
+	    if( !reset_test_lid_default_setting(lid_list[i]) )
+	    {
+	        nvram_ut_trace("[NVUT] %s(): reset test LID to default settings fail!\n\r",__FUNCTION__);
+			return KAL_FALSE;
+	    }
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+        {
+            nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+            return KAL_FALSE;
+        }	
+	}	
+	return KAL_TRUE;
+
+}
+
+kal_bool access_chksum_test_lid()
+{
+	kal_uint8 i;
+	nvram_ltable_entry_struct *ldi=NULL;
+
+	for(i=0; i<chksum_algo_test_lid_number; i++)
+	{
+		nvram_util_get_data_item(&ldi,chksum_algo_test_lid_list[i]);
+		if(0!= nvram_lid_cmpt_operation(ldi->LID,\
+			CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK,CMPT_OP_FLAG_WRITE,CMPT_OP_FLAG_RESET,0),CMPT_OP_WAY_API,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): CMPT access lid(%x) fail access way CMPT_OP_WAY_API\n\r", __FUNCTION__, ldi->LID);
+			return KAL_FALSE;
+		}
+		if(0!= nvram_lid_cmpt_operation(ldi->LID,CMPT_OP_FLAG_GEN(CMPT_OP_FLAG_READBACK,CMPT_OP_FLAG_WRITE,CMPT_OP_FLAG_RESET,0),
+			CMPT_OP_WAY_MSG,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): CMPT access lid(%x) fail access way CMPT_OP_WAY_MSG\n\r", __FUNCTION__, ldi->LID);
+			return KAL_FALSE;
+		}
+	}
+
+	return KAL_TRUE;			
+}
+
+kal_bool reset_chksum_info_lid()
+{
+	nvram_ltable_entry_struct *ldi=NULL;
+	kal_bool result = KAL_TRUE;
+	
+	nvram_cfg_crrnt_chksum_algo();
+	nvram_util_get_data_item(&ldi,NVRAM_EF_CORE_CHKSUM_INFO_LID);
+	if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+	{
+		result = KAL_FALSE;
+	}
+	nvram_ut_trace("[NVUT]%s():CHK_1_CONFIG def_size(%d),def_type(%d)\n\r", __FUNCTION__, NVRAM_CHK_CONFIG.default_algo_size, NVRAM_CHK_CONFIG.default_algo_type);
+	nvram_ut_trace("[NVUT]%s():CHK_1_CONFIG enh_size(%d),enh_type(%d)\n\r", __FUNCTION__, NVRAM_CHK_CONFIG.enhance_algo_size, NVRAM_CHK_CONFIG.enhance_algo_type);
+	return result;
+}
+
+/*
+This function is used to change LID chksum algo type,  verno .
+Input:
+    chksum_chg_type: the type chksum alog change
+    inc_verno: true, verno+1 else keep verno
+Output:
+    KAL_TRUE: success
+    KAL_FALSE: fail
+*/
+
+kal_bool nvram_chg_chksum_test_lid_info(nvram_chksum_change_enum chksum_chg_type, kal_bool inc_verno, kal_uint32 *lid_list, kal_uint8 length)
+{
+	kal_uint8 i;
+	nvram_ltable_entry_struct *ldi= NULL;
+	nvram_checksum_config *nv_chk_cf_bk = NULL;
+
+	if(chksum_chg_type == FROM_ENHANCE_A_TO_B)
+	{
+		// backup NVRAM_CHK_CONFIG
+        nvram_ut_trace("[NVUT]%s(): def_size(%d),def_type(%d)\n\r", __FUNCTION__, chksum_config_backup.default_algo_size, chksum_config_backup.default_algo_type);
+        nvram_ut_trace("[NVUT]%s(): enh_size(%d),enh_type(%d)\n\r", __FUNCTION__, chksum_config_backup.enhance_algo_size, chksum_config_backup.enhance_algo_type);
+		nv_chk_cf_bk = (nvram_checksum_config *)(&NVRAM_CHK_CONFIG);
+		nv_chk_cf_bk->enhance_algo_size = nv_chk_cf_bk->default_algo_size;
+		nv_chk_cf_bk->enhance_algo_type = nv_chk_cf_bk->default_algo_type;
+		if(inc_verno)
+		{
+			for(i=0; i<length; i++)
+			{
+				if(!lid_verno_increase_one(lid_list[i]))
+				{
+					nvram_ut_trace("[NVUT]%s(): lid verno increase fail\n\r", __FUNCTION__);
+					return KAL_FALSE;
+				}
+			}
+		}
+	}
+	else
+	{
+		for(i=0; i<length; i++)
+		{
+			nvram_util_get_data_item(&ldi,lid_list[i]);
+			switch(chksum_chg_type)
+			{
+				case FROM_DEF_TO_ENHANCE:
+				{
+					ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+					break;
+				}
+				case FROM_ENHANCE_TO_DEF:
+                {
+					ldi->attr &= (~NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM);
+					break;
+				}
+				default:
+				{
+					nvram_ut_trace("[NVUT] %s(): Error chksum change type %d\r\n", __FUNCTION__, chksum_chg_type);
+					return KAL_FALSE;
+				}
+			}
+
+			if(inc_verno)
+			{
+				if(!lid_verno_increase_one(ldi->LID))
+				{
+					nvram_ut_trace("[NVUT]%s(): lid verno increase fail\n\r", __FUNCTION__);
+					return KAL_FALSE;
+				}
+			}
+		}
+	}
+	return KAL_TRUE;
+}
+
+
+kal_bool test_chksum_algo_ota_boot_init(kal_uint32 *lid_list, const kal_uint8 count)
+{
+	kal_bool result=KAL_TRUE;
+	
+	// reset chksum algo test lid
+	// result = reset_test_lids(chksum_algo_test_lid_list,chksum_algo_test_lid_number);
+	result = reset_test_lids(lid_list,count);
+
+    //reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_calibrat_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+		nvram_ut_trace("[NVUT] %s(): modify MD SW version fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+	}
+	return result;
+}
+
+kal_bool ota_boot_change_chksum_default_algorithm_config()
+{
+	kal_bool result = KAL_TRUE;
+	
+	#ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+	if(KAL_TRUE != test_chksum_algo_ota_boot_init(chksum_algo_test_lid_list, chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s(): ota boot init fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto final;
+	}
+	// Modify default chksum algo
+	kal_mem_cpy(&chksum_config_backup,&NVRAM_CHK_CONFIG,sizeof(NVRAM_CHK_CONFIG));
+    nvram_ut_trace("[NVUT]%s():CHK_0_CONFIG def_size(%d),def_type(%d)\n\r", __FUNCTION__, NVRAM_CHK_CONFIG.default_algo_size, NVRAM_CHK_CONFIG.default_algo_type);
+    nvram_ut_trace("[NVUT]%s():CHK_0_CONFIG enh_size(%d),enh_type(%d)\n\r", __FUNCTION__, NVRAM_CHK_CONFIG.enhance_algo_size, NVRAM_CHK_CONFIG.enhance_algo_type);
+    nvram_ut_trace("[NVUT]%s():back def_size(%d),def_type(%d)\n\r", __FUNCTION__, chksum_config_backup.default_algo_size, chksum_config_backup.default_algo_type);
+    nvram_ut_trace("[NVUT]%s():back enh_size(%d),enh_type(%d)\n\r", __FUNCTION__, chksum_config_backup.enhance_algo_size, chksum_config_backup.enhance_algo_type);
+	NVRAM_CHK_CONFIG.default_algo_size = NVRAM_CHK_CONFIG.enhance_algo_size;
+	NVRAM_CHK_CONFIG.default_algo_type = NVRAM_CHK_CONFIG.enhance_algo_type;
+	
+    //call nvram_init()
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+    nvram_init();
+    if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+    {
+        nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+    }
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(0 == nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] %s(): Default chksum algo change ota not assert.\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+    }
+
+	// recover customer chksum setting
+	kal_mem_cpy(&NVRAM_CHK_CONFIG,&chksum_config_backup, sizeof(NVRAM_CHK_CONFIG));
+	if(KAL_TRUE != reset_chksum_info_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): reset chksum info lid error!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+
+final:
+
+    #ifdef __NVRAM_LID_CACHE__
+    mark_nvram_cache_ready();
+	#endif
+	
+    return result;
+
+}
+
+kal_bool ota_boot_lid_algo_def_to_en_incr_verno()
+{
+	kal_bool result=KAL_TRUE;
+	
+	#ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+	if(KAL_TRUE != test_chksum_algo_ota_boot_init(chksum_algo_test_lid_list, chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s(): ota boot init fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto final;
+	}
+	
+	if(KAL_TRUE != nvram_chg_chksum_test_lid_info(FROM_DEF_TO_ENHANCE,KAL_TRUE, chksum_algo_test_lid_list, chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(KAL_TRUE != access_chksum_test_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): access chksum test lid fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+
+reset_default:
+
+	// reset chksum algo test lid to default 
+	if(KAL_TRUE != reset_test_lids(chksum_algo_test_lid_list,chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+
+final:
+
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+	
+}
+
+/*
+LID chksum algo from def to enhance with out verno+1
+Normal LIDs: except calibrate & important
+*/
+kal_bool ota_boot_lid_algo_def_to_en_normal()
+{
+	kal_bool result = KAL_TRUE;
+	kal_uint8 i,j;
+    nvram_ltable_entry_struct *ldi = NULL;;
+
+    #ifdef __NVRAM_LID_CACHE__
+        nvram_cache_reset();
+	#endif
+
+	if(KAL_TRUE != test_chksum_algo_ota_boot_init(chksum_algo_normal_list, chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): modify MD SW version fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto final;
+	}
+
+	// write LID record(1) and backup data for data check after OTA 
+
+	for(i=0; i< chksum_algo_normal_len; i++)
+	{
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+        kal_mem_set(data_buffer, 0, ldi->size);
+	    data_buffer[0] = 0x1;
+	    data_buffer[1] = 0x2;
+	    data_buffer[2] = 0x3;
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+            if(!nvram_external_write_data(ldi->LID, j, (kal_uint8 *)data_buffer, ldi->size))
+            {
+                nvram_ut_trace("[NVUT] %s():%d write test LIDs(0x%x) fail!\n\r", __FUNCTION__, __LINE__, ldi->LID);
+                result = KAL_FALSE;
+                goto reset_default;
+            }
+        }
+	}
+
+    if(KAL_TRUE != nvram_chg_chksum_test_lid_info(FROM_DEF_TO_ENHANCE,KAL_FALSE, chksum_algo_normal_list, chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto reset_default;
+	}
+
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+
+	//Read and check record data
+	for(i=0; i<chksum_algo_normal_len; i++)
+	{
+	    nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+        kal_mem_set(cmp_buffer, 0, ldi->size);
+        kal_mem_set(data_buffer, 0, ldi->size);
+	    data_buffer[0] = 0x1;
+	    data_buffer[1] = 0x2;
+	    data_buffer[2] = 0x3;
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+    		if(!nvram_external_read_data(ldi->LID,j,(kal_uint8 *)cmp_buffer, ldi->size))
+    		{
+    			nvram_ut_trace("[NVUT] %s():read lid(%x) fail!\n\r", __FUNCTION__, chksum_algo_normal_list[i]);
+            	result = KAL_FALSE;
+    			goto reset_default;
+    		}
+    		if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    		{	
+    			nvram_ut_trace("[NVUT] %s():lid(%x) data check error after OTA.\n\r", __FUNCTION__, chksum_algo_normal_list[i]);
+    			result = KAL_FALSE;
+                goto reset_default;
+    		}
+        }
+	}
+
+reset_default:
+
+	// reset chksum algo test lid to default 
+	if(KAL_TRUE != reset_test_lids(chksum_algo_normal_list,chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset test lid to default setting fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+
+final:
+
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+	
+}
+
+kal_bool ota_boot_lid_algo_def_to_en_special()
+{
+	kal_bool result = KAL_TRUE;
+
+    #ifdef __NVRAM_LID_CACHE__
+        nvram_cache_reset();
+	#endif
+
+	if(KAL_TRUE != test_chksum_algo_ota_boot_init(chksum_algo_special_list, chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): modify MD SW version fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto final;
+	}
+	
+	if(KAL_TRUE != nvram_chg_chksum_test_lid_info(FROM_DEF_TO_ENHANCE,KAL_FALSE, chksum_algo_special_list, chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+	}
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(0 == nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] %s(): line: %d nvram ota not assert.\n\r", __FUNCTION__, __LINE__);
+        result = KAL_FALSE;
+    }
+
+reset_default:
+
+	// reset chksum algo test lid to default 
+	if(KAL_TRUE != reset_test_lids(chksum_algo_special_list,chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset test lid to default setting fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+
+final:
+
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+	
+}
+
+/**/
+kal_bool ota_boot_lid_algo_en_A_to_B_inc_verno()
+{
+	kal_uint8 i;
+	nvram_ltable_entry_struct * ldi=NULL;
+	kal_bool result = KAL_TRUE;
+	
+	
+	#ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+    kal_mem_cpy(&chksum_config_backup,&NVRAM_CHK_CONFIG,sizeof(NVRAM_CHK_CONFIG));
+	for(i=0; i< chksum_algo_test_lid_number; i++)
+	{
+		// Add ATTR_ENHANCE for test lid
+		reset_test_lid_default_setting(chksum_algo_test_lid_list[i]);
+		nvram_util_get_data_item(&ldi,chksum_algo_test_lid_list[i]);
+		ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): nvram reset lid fail!\n\r", __FUNCTION__);
+            result = KAL_FALSE;
+			goto reset_default;
+		}
+	}
+	//  CHKSUM A_TO_B
+	if(KAL_TRUE != nvram_chg_chksum_test_lid_info(FROM_ENHANCE_A_TO_B,KAL_TRUE, chksum_algo_test_lid_list, chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto reset_default;
+	}
+	//reset SYS LID
+    if(KAL_TRUE != nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        result = KAL_FALSE;
+        goto reset_default;
+    }
+	// Modify sw version
+	if(KAL_TRUE != modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+	    result = KAL_FALSE;
+        goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(!access_chksum_test_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): access chksum test lid fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+
+reset_default:
+
+	// Recover customer config chksum algo
+	kal_mem_cpy(&NVRAM_CHK_CONFIG,&chksum_config_backup, sizeof(NVRAM_CHK_CONFIG));
+	if(!reset_chksum_info_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): reset chksum info lid error!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+	// reset chksum algo test lid to default 
+	if(!reset_test_lids(chksum_algo_test_lid_list,chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default setting fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+	
+}
+
+
+kal_bool ota_boot_lid_algo_en_A_to_B_normal()
+{	
+	kal_uint8 i, j;
+	nvram_ltable_entry_struct * ldi=NULL;
+	kal_bool result = KAL_TRUE;
+	
+	
+	#ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+    kal_mem_cpy(&chksum_config_backup,&NVRAM_CHK_CONFIG,sizeof(NVRAM_CHK_CONFIG));
+
+	for(i=0; i< chksum_algo_normal_len; i++)
+	{
+		// Add ATTR_ENHANCE for test lid
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+		reset_test_lid_default_setting(ldi->LID);
+
+		ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): nvram reset lid fail!\n\r", __FUNCTION__);
+            result = KAL_FALSE;
+			goto reset_default;
+		}
+
+        kal_mem_set(data_buffer, 0, ldi->size);
+	    data_buffer[0] = 0x1;
+	    data_buffer[1] = 0x2;
+	    data_buffer[2] = 0x3;
+
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+            if(NVRAM_IO_ERRNO_OK != nvram_write_data_item(ldi,j,(kal_uint8 *)data_buffer,KAL_FALSE))
+		    {	
+    			nvram_ut_trace("[NVUT] %s(): write test LIDs fail!\n\r", __FUNCTION__);
+                result = KAL_FALSE;
+    			goto reset_default;
+		    }
+        }
+	}
+	// CHKSUM A_TO_B
+	if(!nvram_chg_chksum_test_lid_info(FROM_ENHANCE_A_TO_B,KAL_FALSE, chksum_algo_normal_list, chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto reset_default;
+	}
+	//reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        result = KAL_FALSE;
+        goto reset_default;
+    }
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+	    result = KAL_FALSE;
+        goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+
+    nvram_ut_trace("[NVUT] %s():nvram_ut_assert_flag(0x%x) enter version conflict fail!\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+
+	nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	for(i=0; i<chksum_algo_normal_len; i++)
+	{
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+        kal_mem_set(data_buffer, 0, ldi->size);
+	    data_buffer[0] = 0x1;
+	    data_buffer[1] = 0x2;
+	    data_buffer[2] = 0x3;
+        for(j = 1; j <= ldi->total_records; j++)
+        {            
+            kal_mem_set(cmp_buffer, 0, ldi->size);
+    		if(!nvram_external_read_data(ldi->LID,j,(kal_uint8 *)cmp_buffer, ldi->size))
+    		{
+    			nvram_ut_trace("[NVUT] %s():read lid(%x) fail!\n\r", __FUNCTION__, chksum_algo_normal_list[i]);
+            	result = KAL_FALSE;
+    			goto reset_default;
+    		}
+    		if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    		{	
+    			nvram_ut_trace("[NVUT] %s():lid(%x) data check error after OTA.\n\r", __FUNCTION__, chksum_algo_normal_list[i]);
+    			result = KAL_FALSE;
+                goto reset_default;
+    		}
+        }
+	}
+
+reset_default:
+	// Recover customer config chksum algo
+	kal_mem_cpy(&NVRAM_CHK_CONFIG,&chksum_config_backup, sizeof(NVRAM_CHK_CONFIG));
+	if(!reset_chksum_info_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): reset chksum info lid error!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+	// reset chksum algo test lid to default 
+	if(!reset_test_lids(chksum_algo_normal_list,chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+
+final:
+
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+	
+}
+
+
+kal_bool ota_boot_lid_algo_en_A_to_B_special()
+{	
+	kal_uint8 i;
+	nvram_ltable_entry_struct * ldi=NULL;
+	kal_bool result = KAL_TRUE;
+	
+	
+	#ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+    kal_mem_cpy(&chksum_config_backup,&NVRAM_CHK_CONFIG,sizeof(NVRAM_CHK_CONFIG));
+	for(i=0; i< chksum_algo_special_len; i++)
+	{
+		// Add ATTR_ENHANCE for test lid
+		reset_test_lid_default_setting(chksum_algo_special_list[i]);
+		nvram_util_get_data_item(&ldi,chksum_algo_special_list[i]);
+		ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): nvram reset lid fail!\n\r", __FUNCTION__);
+            result = KAL_FALSE;
+            goto reset_default;
+		}
+	}
+	// CHKSUM A_TO_B
+	if(!nvram_chg_chksum_test_lid_info(FROM_ENHANCE_A_TO_B,KAL_FALSE, chksum_algo_special_list, chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+		goto reset_default;
+	}
+	//reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        result = KAL_FALSE;
+        goto reset_default;
+    }
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+	    result = KAL_FALSE;
+        goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+
+    nvram_ut_trace("[NVUT] %s():nvram_ut_assert_flag(0x%x) enter version conflict fail!\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+	}
+	
+	nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(0 == nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] %s(): ota not assert.\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+    }
+
+reset_default:
+
+	// Recover customer config chksum algo
+	kal_mem_cpy(&NVRAM_CHK_CONFIG,&chksum_config_backup, sizeof(NVRAM_CHK_CONFIG));
+	if(!reset_chksum_info_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): reset chksum info lid error!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+	// reset chksum algo test lid to default 
+	if(!reset_test_lids(chksum_algo_special_list,chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+	
+}
+
+kal_bool ota_boot_lid_algo_en_to_def_incr_verno()
+{
+	kal_bool result=KAL_TRUE;
+	kal_uint8 i;
+	nvram_ltable_entry_struct *ldi=NULL;
+
+    #ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+	for(i=0; i< chksum_algo_test_lid_number; i++)
+	{
+		// Add ATTR_ENHANCE for test lid
+		reset_test_lid_default_setting(chksum_algo_test_lid_list[i]);
+		nvram_util_get_data_item(&ldi,chksum_algo_test_lid_list[i]);
+		ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): nvram reset lid fail!\n\r", __FUNCTION__);
+			result = KAL_FALSE;
+            goto reset_default;
+		}
+	}
+	if(!nvram_chg_chksum_test_lid_info(FROM_ENHANCE_TO_DEF,KAL_TRUE, chksum_algo_test_lid_list, chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+        goto reset_default;
+	}
+	//reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        result = KAL_FALSE;
+        goto reset_default;
+    }
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}	
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(!access_chksum_test_lid())
+	{
+		nvram_ut_trace("[NVUT] %s(): access chksum test lid fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+	}
+
+reset_default:
+
+	// reset chksum algo test lid to default 
+	if(!reset_test_lids(chksum_algo_test_lid_list,chksum_algo_test_lid_number))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	
+	return result;	
+}
+
+kal_bool ota_boot_lid_algo_en_to_def_normal()
+{
+	kal_bool result = KAL_TRUE;
+	kal_uint8 i, j;
+	nvram_ltable_entry_struct *ldi=NULL;
+	
+    #ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+	for(i=0; i< chksum_algo_normal_len; i++)
+	{
+		// Add ATTR_ENHANCE for test lid
+		nvram_util_get_data_item(&ldi,chksum_algo_normal_list[i]);
+		reset_test_lid_default_setting(ldi->LID);
+
+		ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): nvram reset lid fail!\n\r", __FUNCTION__);
+			result = KAL_FALSE;
+            goto reset_default;
+		}
+
+        kal_mem_set(data_buffer, 0, ldi->size);
+	    data_buffer[0] = 0x1;
+	    data_buffer[1] = 0x2;
+	    data_buffer[2] = 0x3;
+
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+            if(NVRAM_IO_ERRNO_OK != nvram_write_data_item(ldi,j,(kal_uint8 *)data_buffer,KAL_FALSE))
+		    {	
+    			nvram_ut_trace("[NVUT] %s(): write test LIDs fail!\n\r", __FUNCTION__);
+    			result = KAL_FALSE;
+                goto reset_default;
+		    }
+        }
+	}
+	// CHKSUM A_TO_B
+	if(!nvram_chg_chksum_test_lid_info(FROM_ENHANCE_TO_DEF,KAL_FALSE, chksum_algo_normal_list, chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+        goto reset_default;
+	}
+	//reset SYS LID
+	if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+	{
+		nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+		result = KAL_FALSE;
+        goto reset_default;
+	}
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+        goto reset_default;
+	}
+	
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	//Read and check record data
+	for(i=0; i<chksum_algo_normal_len; i++)
+	{
+	    nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+        kal_mem_set(cmp_buffer, 0, ldi->size);
+        kal_mem_set(data_buffer, 0, ldi->size);
+	    data_buffer[0] = 0x1;
+	    data_buffer[1] = 0x2;
+	    data_buffer[2] = 0x3;
+        for(j = 1; j <= ldi->total_records; j++)
+        {
+    		if(!nvram_external_read_data(ldi->LID,j,(kal_uint8 *)cmp_buffer, ldi->size))
+    		{
+    			nvram_ut_trace("[NVUT] %s():read lid(%x) fail!\n\r", __FUNCTION__, chksum_algo_normal_list[i]);
+            	result = KAL_FALSE;
+    			goto reset_default;
+    		}
+    		if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+    		{	
+    			nvram_ut_trace("[NVUT] %s():lid(%x) data check error after OTA.\n\r", __FUNCTION__, chksum_algo_normal_list[i]);
+    			result = KAL_FALSE;
+                goto reset_default;
+    		}
+        }
+	}
+
+reset_default:
+
+	// reset chksum algo test lid to default 
+	if(!reset_test_lids(chksum_algo_normal_list,chksum_algo_normal_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	return result;	
+}
+
+kal_bool ota_boot_lid_algo_en_to_def_special()
+{
+	kal_bool result = KAL_TRUE;
+	kal_uint8 i;
+	nvram_ltable_entry_struct *ldi=NULL;
+	
+    #ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+	for(i=0; i< chksum_algo_special_len; i++)
+	{
+		// Add ATTR_ENHANCE for test lid
+		reset_test_lid_default_setting(chksum_algo_special_list[i]);
+		nvram_util_get_data_item(&ldi,chksum_algo_special_list[i]);
+		ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+		if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN,NVRAM_APP_RESERVED,ldi,1,ldi->total_records))
+		{
+			nvram_ut_trace("[NVUT] %s(): nvram reset lid fail!\n\r", __FUNCTION__);
+            result = KAL_FALSE;
+            goto reset_default;
+		}
+	}
+
+	if(!nvram_chg_chksum_test_lid_info(FROM_ENHANCE_TO_DEF,KAL_FALSE, chksum_algo_special_list, chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s():chksum change fail!\n\r", __FUNCTION__);
+		result = KAL_FALSE;
+        goto reset_default;
+	}
+	//reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        result = KAL_FALSE;
+        goto reset_default;
+    }
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+        goto reset_default;
+	}
+	// Call nvram_init
+	nvram_ut_assert_flag = 0;
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+	}
+
+    nvram_ut_trace("[NVUT] %s(): nvram_ut_assert_flag(%d) nvram ota state.\n\r", __FUNCTION__, nvram_ut_assert_flag);
+	if(0 == nvram_ut_assert_flag)
+    {
+        nvram_ut_trace("[NVUT] %s(): ota not assert.\n\r", __FUNCTION__);
+        result = KAL_FALSE;
+    }
+
+reset_default:
+
+	// reset chksum algo test lid to default 
+	if(!reset_test_lids(chksum_algo_special_list,chksum_algo_special_len))
+	{
+		nvram_ut_trace("[NVUT] %s(): %d reset to default fail!\n\r", __FUNCTION__, __LINE__);
+		result = KAL_FALSE;
+	}
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+	return result;	
+}
+
+
+kal_bool data_double_check(nvram_chksum_change_enum chksum_chg_type)
+{
+	kal_uint32 buffer_size;
+	kal_uint8 i, j, chksum_size;
+	kal_uint8 *chksum_buf = NULL;
+    kal_uint16 chksum_buf_2b = 0;
+	kal_bool result=KAL_TRUE;
+	nvram_lid_chksum_info lid_algo_info = {0};
+    nvram_errno_enum state = NVRAM_IO_ERRNO_OK;
+    kal_bool algo_chksum_only[2]= {KAL_TRUE, KAL_FALSE};
+	kal_bool algo_read_2b[2] = {KAL_FALSE, KAL_FALSE};    
+    kal_int32 algo_chksum_only_length = sizeof(algo_chksum_only)/sizeof(kal_bool);
+    kal_int32 algo_read_2b_length = sizeof(algo_read_2b)/sizeof(kal_bool);
+    kal_int32 chk_indx =0;
+    kal_int32 rd2b_indx =0;
+    kal_uint32 tmp_indx =0;
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    for(j=0; j< chksum_algo_normal_len; j++)
+	{
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[j]);
+    	if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    	{
+    		nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+    		return KAL_FALSE;
+    	}
+
+        kal_mem_set(data_buffer, 0, ldi->size);
+
+    	data_buffer[0] = 0x1;
+    	data_buffer[1] = 0x2;
+    	data_buffer[2] = 0x3;
+    	buffer_size = ldi->size;
+    	for(i=1; i<=ldi->total_records; i++)
+    	{
+    		if(!nvram_external_write_data(ldi->LID , i, (kal_uint8 *)data_buffer, ldi->size))
+    		{
+    		    nvram_ut_trace("[NVUT] %s():%d write lid fail!\n\r", __FUNCTION__, __LINE__);
+    			return KAL_FALSE;
+    		}
+    	}
+
+        for(i = 1; i <= ldi->total_records; i++)
+        {            
+            kal_mem_set(cmp_buffer, 0, ldi->size);
+            if(!nvram_external_read_data(ldi->LID,i,(kal_uint8 *)cmp_buffer, ldi->size))
+            {
+        	    nvram_ut_trace("[NVUT] %s():%d read lid(%x) fail!\n\r", __FUNCTION__, __LINE__, ldi->LID);
+        		return KAL_FALSE;
+        	}
+        }
+
+    	// lid chksum algo from def to enhance
+    	switch(chksum_chg_type)
+    	{
+    		case FROM_DEF_TO_ENHANCE:
+    		{
+    			ldi->attr |= NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM;
+    			break;
+    		}
+    		case FROM_ENHANCE_TO_DEF:
+    		{
+    			ldi->attr &= (~NVRAM_ATTR_CHKSUM_ENHNC_ALGRTHM);
+    			break;
+    		}
+    		default:
+    		{
+    			nvram_ut_trace("[NVUT] %s(): Error chksum change type %d\r\n", __FUNCTION__, chksum_chg_type);
+    			return KAL_FALSE;
+    		}
+    	}
+    }
+	//reset SYS LID
+    if(!nvram_external_reset_data(NVRAM_EF_SW_VERNO_LID, SW_VERNO_RECORD_NUMBER, 1))
+    {
+        nvram_ut_trace("[NVUT] ota_boot_importantl4_size_change_read(): reset SYS LID fail!\n\r");
+        return KAL_FALSE;
+    }
+	// Modify sw version
+	if(!modify_md_sw_version())
+	{
+	    nvram_ut_trace("[NVUT]%s(): modify_md_sw_version(): fail!\n\r", __FUNCTION__);
+        return KAL_FALSE;
+	}
+
+	// Call nvram_init
+	nvram_boot_trace = 0;
+	nvram_init();
+	if(!(nvram_boot_trace & BOOT_TRACE_SW_VERNO_CONFLICT))
+	{
+		nvram_ut_trace("[NVUT] %s(): enter version conflict fail!\n\r", __FUNCTION__);
+        return KAL_FALSE;
+	}
+
+    for(j=0; j< chksum_algo_normal_len; j++)
+	{
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[j]);
+    	// read lid data info cmp_buffer
+    	kal_mem_set(data_buffer, 0, ldi->size);
+    	data_buffer[0] = 0x1;
+    	data_buffer[1] = 0x2;
+    	data_buffer[2] = 0x3;
+        for(i = 1; i <= ldi->total_records; i++)
+        {            
+            kal_mem_set(cmp_buffer, 0, ldi->size);
+            if(!nvram_external_read_data(ldi->LID, i, (kal_uint8 *)cmp_buffer, ldi->size))
+        	{
+        		nvram_ut_trace("[NVUT] %s():%d read lid(%x) fail!\n\r", __FUNCTION__, __LINE__, ldi->LID);
+                return KAL_FALSE;
+        	}
+        	if(0 != kal_mem_cmp(data_buffer, cmp_buffer, ldi->size))
+        	{	
+        		nvram_ut_trace("[NVUT] %s():%d lid(%x) data check error after OTA.\n\r", __FUNCTION__, __LINE__, ldi->LID);
+        		return KAL_FALSE;
+        	}
+        }
+
+	    // CHKSUM cmp
+	    for(chk_indx = 0 ; chk_indx < algo_chksum_only_length; chk_indx++)
+        {
+            nvram_get_lid_chksum_algo_info(ldi,&lid_algo_info, algo_chksum_only[chk_indx], KAL_FALSE);
+            chksum_size = lid_algo_info.algo_info.chksum_algo_length;
+            nvram_ut_trace("[NVUT] %s(): chksum_size(%d).\n\r", __FUNCTION__, chksum_size);
+
+            for(rd2b_indx = 0 ; rd2b_indx < algo_read_2b_length; rd2b_indx++)
+            {
+                nvram_get_lid_chksum_algo_info(ldi,&lid_algo_info, algo_chksum_only[chk_indx], algo_read_2b[rd2b_indx]);
+                buffer_size = lid_algo_info.algo_info.chksum_algo_length * ldi->total_records;
+
+                nvram_ut_trace("[NVUT] %s():buffer_size(%d), chksum_algo_length(%d).\n\r", __FUNCTION__, buffer_size, lid_algo_info.algo_info.chksum_algo_length);
+                nvram_ut_trace("[NVUT] %s():algo_chksum_only[%d](%d), algo_read_2b[%d](%d).\n\r", __FUNCTION__, chk_indx, algo_chksum_only[chk_indx], rd2b_indx, algo_read_2b[rd2b_indx]);
+            	// Reuse for checksum compare
+            	kal_mem_set(cmp_buffer,0,buffer_size);
+            	chksum_buf = (kal_uint8*)get_ctrl_buffer(chksum_size);
+
+            	for(i=1; i<=ldi->total_records; i++)
+            	{
+            	    kal_mem_set(chksum_buf, 0, chksum_size);
+                    if((lid_algo_info.algo_info.chksum_algo_type == NVRAM_MD5) && (algo_read_2b[rd2b_indx] == KAL_TRUE))
+                    {
+                        chksum_buf_2b = nvram_util_caculate_checksum(ldi, (kal_uint8*)data_buffer, ldi->size, chksum_buf);
+                        nvram_ut_trace("[NVUT] %s(): chksum_buf_2b = %hd.\n\r", __FUNCTION__, chksum_buf_2b);
+                    }
+                    else
+                    {
+                        nvram_util_caculate_checksum(ldi, (kal_uint8*)data_buffer, ldi->size, chksum_buf);
+                    }
+
+                    nvram_ut_trace("[NVUT_cmp] %s(): caculate chksum show start.\n\r", __FUNCTION__);
+                    for(tmp_indx = 0; tmp_indx < chksum_size; tmp_indx += 4)
+                    {
+                        nvram_ut_trace("[NVUT] (0x%x)\n\r", *((kal_uint32 *)(chksum_buf + tmp_indx)));
+                    }
+                    nvram_ut_trace("[NVUT] %s(): caculate chksum show done(%d).\n\r", __FUNCTION__, i);
+
+            		state = nvram_external_read_chksum_value(ldi->LID,i,1,(kal_uint8 *)cmp_buffer,lid_algo_info.algo_info.chksum_algo_length, lid_algo_info.read_chksum_type);
+                    if(state != NVRAM_IO_ERRNO_OK)
+                    {
+                        nvram_ut_trace("[NVUT_cmp] %s(): read chksum value fail.\n\r", __FUNCTION__);
+                        result = KAL_FALSE;
+                        free_ctrl_buffer(chksum_buf);
+            			goto TEST_END;
+                    }
+                    nvram_ut_trace("[NVUT_cmp] %s(): read chksum show start.\n\r", __FUNCTION__);
+                    for(tmp_indx = 0; tmp_indx < lid_algo_info.algo_info.chksum_algo_length; tmp_indx += 4)
+                    {
+                        nvram_ut_trace("[NVUT_cmp] (0x%x)\n\r", *((kal_uint32 *)(((kal_uint8 *)cmp_buffer) + tmp_indx)));
+                    }
+                    nvram_ut_trace("[NVUT_cmp] %s(): read chksum show done(%d).\n\r", __FUNCTION__, i);
+
+                    if((lid_algo_info.algo_info.chksum_algo_type == NVRAM_MD5) && (algo_read_2b[rd2b_indx] == KAL_TRUE))
+                    {
+                        result = kal_mem_cmp(&chksum_buf_2b, cmp_buffer, lid_algo_info.algo_info.chksum_algo_length);
+                    }
+                    else
+                    {
+                        result = kal_mem_cmp(chksum_buf, cmp_buffer, lid_algo_info.algo_info.chksum_algo_length);
+                    }
+
+            		if(0 != result)
+            		{
+            			nvram_ut_trace("[NVUT] %s(): chksum double check fail!\n\r", __FUNCTION__);
+            			result = KAL_FALSE;
+                        free_ctrl_buffer(chksum_buf);
+            			goto TEST_END;
+            		}
+                    else
+                    {
+                        result = KAL_TRUE;
+                    }
+            	}
+
+                free_ctrl_buffer(chksum_buf);
+            }
+        }
+    }   
+	
+
+TEST_END:
+
+	return result;	
+}
+
+/*
+double check data & chksum after algo change ota boot
+*/
+kal_bool ota_boot_lid_algo_change_with_double_chkdata()
+{
+	kal_uint8 i, j, length;
+	nvram_chksum_change_enum chksum_chg_lists[] = {FROM_DEF_TO_ENHANCE, FROM_ENHANCE_TO_DEF};
+	kal_bool result = KAL_TRUE;
+    nvram_ltable_entry_struct *ldi = NULL;
+
+	length = sizeof(chksum_chg_lists)/sizeof(nvram_chksum_change_enum);
+	#ifdef __NVRAM_LID_CACHE__
+	nvram_cache_reset();
+	#endif
+
+    for(i=0; i< chksum_algo_normal_len; i++)
+	{
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+
+        // reset and backup data into data_buffer
+    	if(!reset_test_lid_default_setting(ldi->LID))
+    	{
+    		nvram_ut_trace("[NVUT] %s():rest test lid fail!\n\r", __FUNCTION__);
+    		result = KAL_FALSE;
+            goto reset_default;
+    	}
+    }
+
+    for(j=0; j<length; j++)
+    {
+    	if(!data_double_check(chksum_chg_lists[j]))
+    	{
+    		nvram_ut_trace("[NVUT] %s():double check error! chksum change type: %d!\n\r", __FUNCTION__, chksum_chg_lists[j]);
+    		result = KAL_FALSE;
+    		break;
+    	}
+    }
+
+reset_default:
+
+    for(i=0; i< chksum_algo_normal_len; i++)
+    {
+        nvram_util_get_data_item(&ldi, chksum_algo_normal_list[i]);
+
+        // reset and backup data into data_buffer
+    	if(!reset_test_lid_default_setting(ldi->LID))
+    	{
+    		nvram_ut_trace("[NVUT] %s():rest test lid fail!\n\r", __FUNCTION__);
+    		result = KAL_FALSE;
+    	}
+
+        if(!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records))
+    	{
+    		nvram_ut_trace("[NVUT] %s(): reset test LIDs fail!\n\r", __FUNCTION__);
+    		result = KAL_FALSE;
+    	}
+
+        if(result == KAL_FALSE)
+        {
+            break;
+        }
+    }
+
+
+	#ifdef __NVRAM_LID_CACHE__
+	mark_nvram_cache_ready();
+	#endif
+
+	return result;
+}
+
+#endif
+
+/*__NVRAM_ENHANCE_CHKSUM_ALGORITHM__*/
+
+
+/*
+Test case return value: 0: success, others: fail
+*/
+ut_testcase_struct ut_nvram_full_test[] = 
+{
+  //factory test cases
+    {factory_reset_user_access, 0, NULL, "Factory Reset USER LID Access Test", "2.1.1.1"},
+    {factory_reset_internal_access, 0, NULL, "Factory Reset INTERNAL LID Access Test", "2.1.1.2"},
+    {factory_reset_calibrat_access, 0, NULL, "Factory Reset CALIBRAT LID Access Test", "2.1.1.3"},
+    {factory_reset_important_access, 0, NULL, "Factory Reset IMPORTANT LID Access Test", "2.1.1.4"},
+    {factory_reset_importantl1_access, 0, NULL, "Factory Reset IMPORTANT_L1 LID Access Test", "2.1.1.5"},
+    {factory_reset_importantl4_access, 0, NULL, "Factory Reset IMPORTANT_L4 LID Access Test", "2.1.1.6"},
+  //first boot test cases
+    {first_boot_basic_access, 0, NULL, "First Boot Basic Access Test", "2.1.2.1"},
+  //OTA boot test cases
+    {ota_boot_basic_access, 0, NULL, "OTA Boot Basic Access Test", "2.1.3.1"},
+    {ota_boot_lid_verno_change_access, 0, NULL, "OTA Boot LID Verno Change Access", "2.1.3.2"},
+        //{ota_boot_add_lid_access, 0, NULL, "OTA Boot Basic Add LID Access Test", "2.1.3.3"},//cancel, this is the same with 2.1.3.1
+    /* bellow 6 cases feature currently not support
+    {ota_boot_add_record_read, 0, NULL, "OTA Boot Add Record Read Test", "2.1.3.4"},
+    {ota_boot_add_record_write, 0, NULL, "OTA Boot Add Record Write Test", "2.1.3.5"},
+    {ota_boot_add_record_reset, 0, NULL, "OTA Boot Add Record Reset Test", "2.1.3.6"},
+    {ota_boot_delete_record_read, 0, NULL, "OTA Boot Delete Record Read Test", "2.1.3.7"},
+    {ota_boot_delete_record_write, 0, NULL, "OTA Boot Delete Record Write Test", "2.1.3.8"},
+    {ota_boot_delete_record_reset, 0, NULL, "OTA Boot Delete Record Reset Test", "2.1.3.9"},
+    */
+    {ota_boot_verno_change_previous_lid_access, 0, NULL, "OTA Boot Verno Change Previous Version LID Access Test", "2.1.3.10"},
+    {ota_boot_size_change_previous_lid_access, 0, NULL, "OTA Boot Record Size Change Previous Version LID Access Test", "2.1.3.11"},
+    {ota_boot_record_change_previous_lid_access, 0, NULL, "OTA Boot Record Number Change Previous Version LID Access Test", "2.1.3.12"},
+    /* bellow 6 cases feature currently not support
+    {ota_boot_extend_record_read, 0, NULL, "OTA Boot Extend Record Read Test", "2.1.3.13"},
+    {ota_boot_extend_record_write, 0, NULL, "OTA Boot Extend Record Write Test", "2.1.3.14"},
+    {ota_boot_extend_record_reset, 0, NULL, "OTA Boot Extend Record Reset Test", "2.1.3.15"},
+    {ota_boot_minish_record_read, 0, NULL, "OTA Boot Minish Record Read Test", "2.1.3.16"},
+    {ota_boot_minish_record_write, 0, NULL, "OTA Boot Minish Record Write Test", "2.1.3.17"},
+    {ota_boot_minish_record_reset, 0, NULL, "OTA Boot Minish Record Reset Test", "2.1.3.18"},
+    */
+    {ota_boot_user_size_change_read, 0, NULL, "OTA Boot USER LID Size Change Read Test", "2.1.3.19"},
+    {ota_boot_user_size_change_write, 0, NULL, "OTA Boot USER LID Size Change Write Test", "2.1.3.20"},
+    {ota_boot_user_size_change_reset, 0, NULL, "OTA Boot USER LID Size Change Reset Test", "2.1.3.21"},
+    {ota_boot_internal_size_change_read, 0, NULL, "OTA Boot INTERNAL LID Size Change Read Test", "2.1.3.22"},
+    {ota_boot_internal_size_change_write, 0, NULL, "OTA Boot INTERNAL LID Size Change Write Test", "2.1.3.23"},
+    {ota_boot_internal_size_change_reset, 0, NULL, "OTA Boot INTERNAL LID Size Change Reset Test", "2.1.3.24"},
+    {ota_boot_calibrat_size_change, 0, NULL, "OTA Boot CALIBRAT LID Size Change Test", "2.1.3.25"},
+    {ota_boot_important_size_change, 0, NULL, "OTA Boot IMPORTANT LID Size Change Test", "2.1.3.26"},
+    {ota_boot_calibrat_lost_access, 0, NULL, "OTA Boot CALIBRAT LID Lost Test", "2.1.3.27"},
+    {ota_boot_important_lost_access, 0, NULL, "OTA Boot IMPORTANT LID Lost Test", "2.1.3.28"},
+    #if 0 //change test cases, because NVRAM design flow change
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #endif
+    {ota_boot_importantl1_size_change_read, 0, NULL, "OTA Boot IMPORTANT_L1 LID Size Change Read Test", "2.1.3.31"},
+    {ota_boot_importantl1_size_change_write, 0, NULL, "OTA Boot IMPORTANT_L1 LID Size Change Write Test", "2.1.3.32"},
+    {ota_boot_importantl1_size_change_reset, 0, NULL, "OTA Boot IMPORTANT_L1 LID Size Change Reset Test", "2.1.3.33"},
+    {ota_boot_importantl4_size_change_read, 0, NULL, "OTA Boot IMPORTANT_L4 LID Size Change Read Test", "2.1.3.34"},
+    {ota_boot_importantl4_size_change_write, 0, NULL, "OTA Boot IMPORTANT_L4 LID Size Change Write Test", "2.1.3.35"},
+    {ota_boot_importantl4_size_change_reset, 0, NULL, "OTA Boot IMPORTANT_L4 LID Size Change Reset Test", "2.1.3.36"},
+    {ota_boot_ota_reset_attr, 0, NULL, "OTA Boot OTA_RESET Attribute Test", "2.1.3.37"},
+    {ota_boot_reserve_backward_verno_change, 0, NULL, "OTA Boot RESERVE_BACKWARD VERNO Change Test", "2.1.3.38"},
+    {ota_boot_reserve_backward_size_change, 0, NULL, "OTA Boot RESERVE_BACKWARD Size Change Test", "2.1.3.39"},
+  //normal boot test
+    {normal_boot_basic_access, 0, NULL, "Normal Boot Basic Access Test", "2.1.4.1"},
+    {normal_boot_user_lost_read, 0, NULL, "Normal Boot USER LID Lost Read Test", "2.1.4.2"},
+    {normal_boot_user_lost_write, 0, NULL, "Normal Boot USER LID Lost Write Test", "2.1.4.3"},
+    {normal_boot_user_lost_reset, 0, NULL, "Normal Boot USER LID Lost Reset Test", "2.1.4.4"},
+    {normal_boot_internal_lost_read, 0, NULL, "Normal Boot INTERNAL LID Lost Read Test", "2.1.4.5"},
+    {normal_boot_internal_lost_write, 0, NULL, "Normal Boot INTERNAL LID Lost Write Test", "2.1.4.6"},
+    {normal_boot_internal_lost_reset, 0, NULL, "Normal Boot INTERNAL LID Lost Reset Test", "2.1.4.7"},
+    {normal_boot_calibrat_lost_read, 0, NULL, "Normal Boot CALIBRAT LID Lost Read Test", "2.1.4.8"},
+    {normal_boot_calibrat_lost_write, 0, NULL, "Normal Boot CALIBRAT LID Lost Write Test", "2.1.4.9"},
+    {normal_boot_calibrat_lost_reset, 0, NULL, "Normal Boot CALIBRAT LID Lost Reset Test", "2.1.4.10"},
+    {normal_boot_important_lost_read, 0, NULL, "Normal Boot IMPORTANT LID Lost Read Test", "2.1.4.11"},
+    {normal_boot_important_lost_write, 0, NULL, "Normal Boot IMPORTANT LID Lost Write Test", "2.1.4.12"},
+    {normal_boot_important_lost_reset, 0, NULL, "Normal Boot IMPORTANT LID Lost Reset Test", "2.1.4.13"},
+    {normal_boot_importantl1_lost_read, 0, NULL, "Normal Boot IMPORTANT_L1 LID Lost Read Test", "2.1.4.14"},
+    {normal_boot_importantl1_lost_write, 0, NULL, "Normal Boot IMPORTANT_L1 LID Lost Write Test", "2.1.4.15"},
+    {normal_boot_importantl1_lost_reset, 0, NULL, "Normal Boot IMPORTANT_L1 LID Lost Reset Test", "2.1.4.16"},
+    {normal_boot_importantl4_lost_read, 0, NULL, "Normal Boot IMPORTANT_L4 LID Lost Read Test", "2.1.4.17"},
+    {normal_boot_importantl4_lost_write, 0, NULL, "Normal Boot IMPORTANT_L4 LID Lost Write Test", "2.1.4.18"},
+    {normal_boot_importantl4_lost_reset, 0, NULL, "Normal Boot IMPORTANT_L4 LID Lost Reset Test", "2.1.4.19"},
+    {normal_boot_user_altered_read, 0, NULL, "Normal Boot USER LID Altered Read Test", "2.1.4.20"},
+    {normal_boot_user_altered_write, 0, NULL, "Normal Boot USER LID Altered Write Test", "2.1.4.21"},
+    {normal_boot_user_altered_reset, 0, NULL, "Normal Boot USER LID Altered Reset Test", "2.1.4.22"},
+    {normal_boot_internal_altered_read, 0, NULL, "Normal Boot INTERNAL LID Altered Read Test", "2.1.4.23"},
+    {normal_boot_internal_altered_write, 0, NULL, "Normal Boot INTERNAL LID Altered Write Test", "2.1.4.24"},
+    {normal_boot_internal_altered_reset, 0, NULL, "Normal Boot INTERNAL LID Altered Reset Test", "2.1.4.25"},
+    {normal_boot_calibrat_altered_read, 0, NULL, "Normal Boot CALIBRAT LID Altered Read Test", "2.1.4.26"},
+    {normal_boot_calibrat_altered_write, 0, NULL, "Normal Boot CALIBRAT LID Altered Write Test", "2.1.4.27"},
+    {normal_boot_calibrat_altered_reset, 0, NULL, "Normal Boot CALIBRAT LID Altered Reset Test", "2.1.4.28"},
+    {normal_boot_important_altered_read, 0, NULL, "Normal Boot IMPORTANT LID Altered Read Test", "2.1.4.29"},
+    {normal_boot_important_altered_write, 0, NULL, "Normal Boot IMPORTANT Altered Write Test", "2.1.4.30"},
+    {normal_boot_important_altered_reset, 0, NULL, "Normal Boot IMPORTANT Altered Reset Test", "2.1.4.31"},
+    {normal_boot_importantl1_altered_read, 0, NULL, "Normal Boot IMPORTANT_L1 LID Altered Read Test", "2.1.4.32"},
+    {normal_boot_importantl1_altered_write, 0, NULL, "Normal Boot IMPORTANT_L1 LID Altered Write Test", "2.1.4.33"},
+    {normal_boot_importantl1_altered_reset, 0, NULL, "Normal Boot IMPORTANT_L1 LID Altered Reset Test", "2.1.4.34"},
+    {normal_boot_importantl4_altered_read, 0, NULL, "Normal Boot IMPORTANT_L4 LID Altered Read Test", "2.1.4.35"},
+    {normal_boot_importantl4_altered_write, 0, NULL, "Normal Boot IMPORTANT_L4 LID Altered Write Test", "2.1.4.36"},
+    {normal_boot_importantl4_altered_reset, 0, NULL, "Normal Boot IMPORTANT_L4 LID Altered Reset Test", "2.1.4.37"},
+    {normal_boot_read_syslid_fail, 0, NULL, "Normal Boot Read SYS LID Fail Test", "2.1.4.38"},
+
+    {normal_boot_user_corrupted_test, 0, NULL, "Normal Boot User Category LID Corrupted Data Test", "2.1.5.1"},
+    {normal_boot_calibrate_corrupted_test, 0, NULL, "Normal Boot Calibrate Category LID Corrupted Data Test", "2.1.5.2"},
+    {normal_boot_important_corrupted_test, 0, NULL, "Normal Boot Important Category LID Corrupted Data Test", "2.1.5.3"},
+    {normal_boot_important_l4_corrupted_test, 0, NULL, "Normal Boot Important_L4 Category LID Corrupted Data Test", "2.1.5.4"},
+  //attribute & category test
+    {attr_average_basic_access, 0, NULL, "NVRAM_ATTR_AVERAGE Attribute Basic Test", "2.2.1.1"},
+    {attr_multi_default_read_basic_access, 0, NULL, "MULTI_DEFAULT and MULTI_READ Attribute Basic Test", "2.2.1.2"},
+    {attr_write_protect_basic_access, 0, NULL, "NVRAM_ATTR_WRITE_PROTECT Attribute Basic Test", "2.2.1.3"},
+    {attr_multiple_basic_access, 0, NULL, "NVRAM_ATTR_MULTIPLE Attribute Basic Test", "2.2.1.4"},
+    {attr_confidential_basic_access, 0, NULL, "NVRAM_ATTR_CONFIDENTIAL Attribute Basic Test", "2.2.1.5"},
+    {attr_msp_basic_access, 0, NULL, "NVRAM_ATTR_MSP Attribute Basic Test", "2.2.1.6"},
+    {attr_committed_basic_access, 0, NULL, "NVRAM_ATTR_COMMITTED Attribute Basic Test", "2.2.1.7"},
+    {attr_ring_basic_access, 0, NULL, "NVRAM_ATTR_RING Attribute Basic Test", "2.2.1.8"},
+    {attr_fault_assert_test, 0, NULL, "NVRAM_ATTR_FAULT_ASSERT Attribute Test", "2.2.1.9"},
+    {category_user_basic_access, 0, NULL, "NVRAM_CATEGORY_USER Basic Test", "2.2.2.1"},
+    {category_internal_basic_access, 0, NULL, "NVRAM_CATEGORY_INTERNAL Basic Test", "2.2.2.2"},
+    {category_calibrat_basic_access, 0, NULL, "NVRAM_CATEGORY_CALIBRAT Basic Test", "2.2.2.3"},
+    {category_important_basic_access, 0, NULL, "NVRAM_CATEGORY_IMPORTANT Basic Test", "2.2.2.4"},
+    {category_importantl1_basic_access, 0, NULL, "NVRAM_CATEGORY_IMPORTANT_L1 Basic Test", "2.2.2.5"},
+    {category_importantl4_basic_access, 0, NULL, "NVRAM_CATEGORY_IMPORTANT_L4 Basic Test", "2.2.2.6"},
+    {func_default_basic_access, 0, NULL, "NVRAM_CATEGORY_FUNC_DEFAULT Basic Test", "2.2.2.7"},
+    {zero_default_basic_access, 0, NULL, "NVRAM_EF_ZERO_DEFAULT Basic Test", "2.2.2.8"},
+    {ff_default_basic_access, 0, NULL, "NVRAM_EF_FF_DEFAULT Basic Test", "2.2.2.9"},
+    {table_default_basic_access, 0, NULL, "TABLE_DEFAULT Basic Test", "2.2.2.10"},
+    {attribute_category_defaultvalue_combine, 0, NULL, "Attribute/Category/Default Value Combine Basic Test", "2.2.2.11"},
+    {chksum_read_function_basic_test, 0, NULL, "NVRAM Checksum Read Function Basic Test", "2.2.2.12"},
+    {chksum_multi_read_function_test, 0, NULL, "NVRAM Checksum Multi Read Function Test", "2.2.2.13"},
+    {raw_data_access_function_test, 0, NULL, "NVRAM RAW_DATA Access Function Test", "2.2.2.14"},
+  //boundary & stress test
+    {record_size_boundary_test, 0, NULL, "NVRAM Record Size Boundary Test", "2.3.1.1"},
+    {record_number_boundary_test, 0, NULL, "NVRAM Record Number Boundary Test", "2.3.2.1"},
+    {nvram_stress_test, 0, NULL, "NVRAM Stress Test", "2.3.3.1"},
+
+  //nvram special feature test
+    //{nvram_write_exception_test, 0, NULL, "NVRAM Write Exception Test", "2.4.4.1"}, //cancel, this API is exception owner own
+    {nvram_exception_test, 0, NULL, "NVRAM Exception Test", "2.4.4.2"},
+    {nvram_security_test, 0, NULL, "NVRAM Security Test", "2.4.1.3"},
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    {nvram_smart_reset_entry_test, 0, NULL, "NVRAM Smart Reset Entry Number Test", "2.4.1.4"}, //build checksum enties need match code
+    {nvram_structure_change_reset_test, 0, NULL, "NVRAM Structure Change Reset Test", "2.4.1.5"},
+    {nvram_default_value_change_reset_test, 0, NULL, "NVRAM Default Value Change Reset Test", "2.4.1.6"},
+    {nvram_func_default_checksum_change_test, 0, NULL, "NVRAM FUN_DEF Checksum Change Test", "2.4.1.7"},
+    {nvram_smart_reset_checksum_test, 0, NULL, "NVRAM Smart Reset Checksum Test", "2.4.1.8"},
+    {nvram_no_checksum_change_test, 0, NULL, "NVRAM No Checksum Change Test", "2.4.1.9"},
+    {nvram_write_header_test, 0, NULL, "NVRAM Write Header Test", "2.4.1.10"},
+    {nvram_attribute_change_reset_test, 0, NULL, "NVRAM Attribute Change Reset Test", "2.4.1.11"},
+    {nvram_attribute_no_change_test, 0, NULL, "NVRAM Attribute No Change Test", "2.4.1.12"},
+    #endif
+    /*Bellow two cases should not be put into __NVRAM_STRUCTURE_CHANGE_RESET__ and __NVRAM_DEFVAL_CHANGE_RESET__ option
+          these two test need prepare two versions modem load
+          1st version: NVRAM_UT enable, NVRAM_OTA_SMART_RESET enable
+          2nd version: NVRAM_UT enable, NVRAM_OTA_SMART_RESET disable
+    these two cases need manual build load to test
+    Tips:
+        disable dbg header write then build load.
+        old OTA to new or new OTA to old, CALIBRAT/IMPORTANT/IMPORTANT_L4 category LID should not change.
+        LIDs in USER and IMPORTANT_1 should all reset.
+      */
+    {nvram_smart_reset_new_ota_old_test, 0, NULL, "NVRAM Smart Reset OTA to No Smart Reset Test", "2.4.1.20"},
+    {nvram_smart_reset_old_ota_new_test, 0, NULL, "NVRAM No Smart Reset OTA to Smart Reset Test", "2.4.1.21"},
+    {nvram_external_get_lid_info_test, 0, NULL, "NVRAM Get LID Info Test", "2.5.1.1"},
+    //These case is used for LID cache feature
+    #ifdef __NVRAM_LID_CACHE__
+    {first_boot_cache_access, 0, NULL, "First Boot Cache Access Test", "2.6.1"},    
+    {normal_boot_cache_access, 0, NULL, "Normal Boot Cache Access Test", "2.6.2"},
+    {ota_boot_cache_access, 0, NULL, "OTA Boot Cache Access Test", "2.6.3"},
+    {normal_boot_user_lost_cache_read, 0, NULL, "Normal Boot User File Lost Cache Read Test", "2.6.4"},    
+    {nvram_boot_calibrate_lost_cache_read, 0, NULL, "Normal Boot Calibrate File Lost Cache Read Test", "2.6.5"},    
+    {nvram_boot_important_lost_cache_read, 0, NULL, "Normal Boot Important File Lost Cache Read Test", "2.6.6"},
+    {nvram_boot_important_l4_lost_cache_read, 0, NULL, "Normal Boot Important L4 File Lost Cache  Read Test", "2.6.7"},
+    {nvram_cache_valid_bit_after_recover, 0, NULL, "Nvram Cache Valid Bit After Recover Test", "2.6.8"},
+    {normal_boot_user_lost_cache_read_with_recover, 0, NULL, "Normal Boot User File Lost Cache Read With Recover Test", "2.6.9"},    
+    {nvram_boot_calibrate_lost_cache_read_with_recover, 0, NULL, "Normal Boot Calibrate File Lost Cache Read With Recover Test", "2.6.10"},    
+    {nvram_boot_important_lost_cache_read_with_recover, 0, NULL, "Normal Boot Important File Lost Cache Read With Recover Test", "2.6.11"},
+    {nvram_boot_important_l4_lost_cache_read_with_recover, 0, NULL, "Normal Boot Important L4 File Lost Cache With Recover Read Test", "2.6.12"},    
+    {normal_boot_user_lost_cache_write, 0, NULL, "Normal Boot User File Lost Cache  Write Test", "2.6.13"},
+    {normal_boot_calibrate_lost_cache_write, 0, NULL, "Normal Boot Calibrate File Lost Cache  Write Test", "2.6.14"},
+    {normal_boot_important_lost_cache_write, 0, NULL, "Normal Boot Important File Lost Cache  Write Test", "2.6.15"},
+    {normal_boot_important_l4_lost_cache_write, 0, NULL, "Normal Boot Important_L4 File Lost Cache  Write Test", "2.6.16"},
+    {nvram_cache_read_performance_chek, 0, NULL, "Normal Boot Cache Read Performance Test", "2.6.17"},
+    {nvram_cache_write_performance_chek, 0, NULL, "Normal Boot Cache Write Performance Test", "2.6.18"},
+    {nvram_cache_read_data_less_than_16K, 0, NULL, "Normal Boot Cache Read Less Than 16K Data Test", "2.6.19"},
+    {nvram_cache_read_data_more_than_16K, 0, NULL, "Normal Boot Cache Read More Than 16K Data Test", "2.6.20"},
+    {nvram_cache_read_data_more_than_64K, 0, NULL, "Normal Boot Cache Read More Than 64K Data Test", "2.6.21"},
+    {nvram_cache_bypass_white_list_test, 0, NULL, "Normal Boot Cache Bypass White List Test", "2.6.22"},
+    #ifdef __NVRAM_LID_PREREAD__
+    {nvram_cache_preread_chk, 0, NULL, "Normal Boot Cache pre-read Test", "2.8.1"},
+    #endif
+    #endif
+
+    #ifdef __NV_CHKSUM_ENHANCE__
+	{ota_boot_change_chksum_default_algorithm_config, 0, NULL, "OTA Boot Default chksum algo change Test", "2.9.1"},
+	{ota_boot_lid_algo_def_to_en_incr_verno, 0, NULL, "OTA Boot Chksum algo add enhance ATTR Test", "2.9.2"},
+	{ota_boot_lid_algo_def_to_en_normal, 0, NULL, "OTA Boot Chksum algo add enhance ATTR (normal lids)without verno+1 Test", "2.9.3"},
+	{ota_boot_lid_algo_def_to_en_special, 0, NULL, "OTA Boot Chksum algo add enhance ATTR(CALI&IMEI) without verno+1 Test", "2.9.4"},
+	{ota_boot_lid_algo_en_A_to_B_inc_verno, 0, NULL, "OTA Boot Chksum algo from Enhance A TO B Test", "2.9.5"},
+	{ota_boot_lid_algo_en_A_to_B_normal, 0, NULL, "OTA Boot Chksum algo from Enhance A TO B(normal lids) without verno+1 Test", "2.9.6"},
+	{ota_boot_lid_algo_en_A_to_B_special, 0, NULL, "OTA Boot Chksum algo from Enhance A TO B (CALI&IMEI)without verno+1 Test", "2.9.7"},
+	{ota_boot_lid_algo_en_to_def_incr_verno, 0, NULL, "OTA Boot Chksum algo remove ATTR enhance Test", "2.9.8"},
+	{ota_boot_lid_algo_en_to_def_normal, 0, NULL, "OTA Boot Chksum algo remove ATTR enhance (normal lids) without verno+1 Test", "2.9.9"},
+	{ota_boot_lid_algo_en_to_def_special, 0, NULL, "OTA Boot Chksum algo remove ATTR enhance (CALI&IMEI) without verno+1 Test", "2.9.10"},
+	{ota_boot_lid_algo_change_with_double_chkdata, 0, NULL, "OTA Boot Chksum algo cahnge data check Test", "2.9.11"},
+	#endif
+	
+	//pleaes add test case before these cases
+    /* These 4 cases just use for test structure
+    {nvram_ut_test1, 0, NULL, "NVRAM UT Test Case 1", "9.1"},
+    {nvram_ut_test2, 0, NULL, "NVRAM UT Test Case 2", "9.11"},
+    {nvram_ut_test3, 0, NULL, "NVRAM UT Test Case 3", "9.1.1"},
+    {nvram_ut_test4, 0, NULL, "NVRAM UT Test Case 4", "9.1.2"},
+    */
+};
+kal_uint16 full_test_num = sizeof(ut_nvram_full_test)/sizeof(ut_testcase_struct);
+
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+
+kal_uint32 nvram_ut_test() //return value insted fail case num, 0 stands all pass
+{
+    kal_uint32 result;
+    kal_uint8 next_char;
+
+    start_test_time = ust_get_current_time();
+    for(; test_number < valid_test_case_num; test_number++)
+    {
+        for(; sub_test_number < full_test_num; sub_test_number++)
+        {
+            //if(case_is_need_run(test_case_list[test_number], (kal_uint8*)ut_nvram_full_test[sub_test_number].testplan_section))
+            if(strlen((char *)test_case_list[test_number]) > strlen((char *)ut_nvram_full_test[sub_test_number].testplan_section))
+            {
+                continue;
+            }
+
+            //test case is "2.1", case "2.11" should not run. next_char is used to this case
+            next_char = ut_nvram_full_test[sub_test_number].testplan_section[strlen((char *)test_case_list[test_number])];
+            if(0 == kal_mem_cmp(test_case_list[test_number], ut_nvram_full_test[sub_test_number].testplan_section, strlen((char *)test_case_list[test_number]))
+                && ('\0' == next_char || '.' == next_char))
+            {
+                result = ut_nvram_full_test[sub_test_number]._main_fn(ut_nvram_full_test[sub_test_number].flags, ut_nvram_full_test[sub_test_number].para);
+                total_case_num++;
+                if(KAL_TRUE == result) //success
+                {
+                    nvram_ut_trace("[NVRAM UT] %s : %s -- test result: PASS!\n\r", 
+                                    ut_nvram_full_test[sub_test_number].testplan_section, ut_nvram_full_test[sub_test_number].description);
+                }
+                else
+                {
+                    nvram_ut_trace("[NVRAM UT] %s : %s -- test result: FAIL!\n\r",
+                                    ut_nvram_full_test[sub_test_number].testplan_section, ut_nvram_full_test[sub_test_number].description);
+                    fail_case_num++;
+                }
+            }
+            kal_sleep_task(kal_milli_secs_to_ticks(10));
+        }
+
+        sub_test_number = 0;
+    }
+    end_test_time = ust_get_current_time();
+    test_time_consume += end_test_time - start_test_time;
+
+    return fail_case_num;
+}
+
+//kal_uint32 read_write_buffer[NVRAM_EF_TEST_LID_SIZE/4]; //1K glbal buffer
+void nvram_Ttask1_main(task_entry_struct *task_entry_ptr)
+{
+    /*local parameters*/
+    ilm_struct current_ilm;
+    tst_module_string_inject_struct *nvram_tst_req;
+    //nvram_stress_test1_req_struct *stress_test1_req1,*stress_test1_req2,*stress_test1_req3;
+    //nvram_stress_test1_cnf_struct *stress_test1_cnf;
+    nvram_ltable_entry_struct *ldi = NULL;
+    factory_test_context_struct *test_context;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN] = L"Z:\\W_TST_LID.log";
+    kal_uint8 *d_buffer;
+    kal_uint32 i;
+    kal_uint8 test_result;
+    kal_uint8 begin_test = 0;
+    
+    #ifdef __NVRAM_LID_CACHE__
+    if(check_nvram_cache_ready())
+    {
+        for(i = 0; i < test_lid_number; i++)
+        {
+            nvram_util_get_data_item(&ldi, test_lid_enum[i]);
+            if((check_lid_all_record_is_invalid_bit(ldi) != KAL_TRUE) || (check_lid_all_record_is_undirty_bit(ldi)!= KAL_TRUE))
+            {
+                nvram_ut_trace("[NVRAM UT] %s() %d: test_lid_enum[%d] valid(%d) and dirty(%d) bit check fail.\n\r",__FUNCTION__,__LINE__,i,check_lid_all_record_is_invalid_bit(ldi),check_lid_all_record_is_undirty_bit(ldi));
+                return;
+            }
+        }
+    }else
+    {
+        nvram_ut_trace("[NVRAM UT] %s() %d: NVRAM cache not ready!!!\n\r", __FUNCTION__, __LINE__);
+        return;
+    }
+    #endif
+    nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_TEST_6_LID);
+    d_buffer = (kal_uint8*)get_ctrl_buffer(ldi->size);
+    nvram_external_read_data(ldi->LID, 1, d_buffer, ldi->size);
+    test_context = (factory_test_context_struct*)d_buffer;
+    if(0xAB == test_context->context_is_valid) //0xAB is a special value we write
+    {
+        factory_test_reboot_finish = KAL_TRUE;
+        test_number = test_context->break_test_case_num;
+        sub_test_number = test_context->sub_test_case_num;
+        valid_test_case_num = test_context->valid_test_case_num_total;
+        total_case_num = test_context->total_case_number;
+        fail_case_num = test_context->fail_case_number;
+        test_time_consume = test_context->tst_time_consume;
+        kal_mem_cpy(test_case_list, test_context->test_case_lst, sizeof(test_case_list));
+        nvram_external_reset_data(NVRAM_EF_NVRAM_TEST_6_LID, 1, 1);
+
+        msg_receive_extq(&current_ilm); //wait start msg
+        destroy_ilm(&current_ilm);
+    }
+    else if(0xCD == test_context->context_is_valid)
+    {
+        manual_ota_reboot_finish = KAL_TRUE;
+        test_number = test_context->break_test_case_num;
+        sub_test_number = test_context->sub_test_case_num;
+        valid_test_case_num = test_context->valid_test_case_num_total;
+        total_case_num = test_context->total_case_number;
+        fail_case_num = test_context->fail_case_number;
+        test_time_consume = test_context->tst_time_consume;
+        kal_mem_cpy(test_case_list, test_context->test_case_lst, sizeof(test_case_list));
+        nvram_external_reset_data(NVRAM_EF_NVRAM_TEST_6_LID, 1, 1);
+
+        msg_receive_extq(&current_ilm); //wait start msg
+        destroy_ilm(&current_ilm);
+
+    }
+    else
+    {
+		#ifdef __NVRAM_LID_CACHE__
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+		#endif
+        if(FS_GetAttributes(filename) < FS_NO_ERROR) //before binregion backup write TEST LIDs to special value
+        {
+			#ifdef __NVRAM_LID_CACHE__
+            nvram_util_give_mutex(g_nvram_fs_mutex);
+			#endif
+            nvram_write_test_lids();            
+            #ifdef __NVRAM_LID_CACHE__
+			nvram_util_take_mutex(g_nvram_fs_mutex);
+			#endif
+            FS_Close(FS_Open(filename, FS_READ_WRITE | FS_CREATE_ALWAYS));
+            nvram_ap_bin_region_backup();
+            #ifdef __NVRAM_LID_CACHE__
+			nvram_util_give_mutex(g_nvram_fs_mutex);
+			#endif
+        }else
+        {
+			#ifdef __NVRAM_LID_CACHE__
+            nvram_util_give_mutex(g_nvram_fs_mutex);
+			#endif
+        }
+    }
+    free_ctrl_buffer(d_buffer);
+
+    nvram_test_task1_id = kal_get_current_task();
+    
+    while(1)
+    {
+        if(!factory_test_reboot_finish && !manual_ota_reboot_finish)
+        {
+            msg_receive_extq(&current_ilm);
+            kal_set_active_module_id(current_ilm.dest_mod_id);  
+            
+            if(current_ilm.msg_id == MSG_ID_TST_INJECT_STRING)
+            {
+                nvram_tst_req = (tst_module_string_inject_struct*) current_ilm.local_para_ptr;
+                nvram_ut_trace("[NVRAM UT] test_case_num:%s\n\r", nvram_tst_req->string);
+                nvram_ut_trace("[NVRAM UT] test_start:%d\n\r", nvram_tst_req->index);
+
+                if(0 == kal_mem_cmp("p", nvram_tst_req->string, 1)) //print all test_case_list
+                {
+                    if(0 == valid_test_case_num)
+                    {
+                        nvram_ut_trace("[NVRAM UT] test_case_list is NULL.\n\r");
+                    }
+
+                    for(i = 0; i < valid_test_case_num; i++)
+                    {
+                        nvram_ut_trace("[NVRAM UT] test_case_list[%d]: %s.\n\r", i, test_case_list[i]);
+                    }
+
+                    if((valid_test_case_num > 0) && (0 != nvram_tst_req->index))
+                    {
+                        begin_test = 1;
+                    }
+                }
+                else if(0 == kal_mem_cmp("c", nvram_tst_req->string, 1)) //clear all test_case_list
+                {
+                    kal_mem_set(test_case_list, 0 , sizeof(test_case_list));
+                    valid_test_case_num = 0;
+                    nvram_ut_trace("[NVRAM UT] test_case_list has been cleared.\n\r");
+                    
+                }
+                else //normal test case parse
+                {
+                    for(i = 0; i < full_test_num && 
+                        0 != (kal_mem_cmp(nvram_tst_req->string, (kal_uint8*)ut_nvram_full_test[i].testplan_section, strlen((char *)nvram_tst_req->string)))
+                        ; i++)
+                    {} //to find whether there is one test case need to run
+                    
+                    if(i >= full_test_num)
+                    {
+                        nvram_ut_trace("[NVRAM UT] Invalid test_case_num, please try again!\n\r");
+                    }
+                    else
+                    {
+                        if(valid_test_case_num < 10)
+                        {
+                            kal_mem_cpy(test_case_list[valid_test_case_num++], nvram_tst_req->string, strlen((char *)nvram_tst_req->string));
+                        }
+                        else
+                        {
+                            nvram_ut_trace("[NVRAM UT] test_case_num list is full, max is 10!\n\r");
+                        }
+
+                        if(nvram_tst_req->index)
+                        {
+                            begin_test = 1;
+                        }
+                    }
+                }
+            }
+            destroy_ilm(&current_ilm);
+        }
+        else //go on factory test
+        {
+            kal_set_active_module_id(MOD_NV_TEST1);
+            begin_test = 1;
+        }
+        
+        if(begin_test)
+        {
+            nvram_ut_trace("[NVRAM UT] Start: nvram_ut_test()!\n\r");
+            test_result = nvram_ut_test();
+            nvram_ut_trace("[NVRAM UT] End: nvram_ut_test()!\n\r");
+
+            //print test results
+            nvram_ut_trace("[NVRAM UT] Total Test Cases: %d.\n\r", total_case_num);
+            if(!test_result)
+            {
+                nvram_ut_trace("[NVRAM UT] NVRAM UT Test Result: PASS!\n\r");
+            }
+            else
+            {
+                nvram_ut_trace("[NVRAM UT] NVRAM UT Test Result: FAIL!\n\r");
+                nvram_ut_trace("[NVRAM UT] Total Fail Cases: %d!\n\r", fail_case_num);
+            }
+            nvram_ut_trace("[NVRAM UT] Test Time Consume: %d ticks.\n\r", test_time_consume);
+
+            //clear environment, you can do another test again(except factory reset test)
+            kal_mem_set(test_case_list, 0 , sizeof(test_case_list));
+            begin_test = 0;
+            valid_test_case_num = 0;
+            factory_test_reboot_finish = KAL_FALSE;
+            manual_ota_reboot_finish = KAL_FALSE;
+            test_number = 0;
+            sub_test_number = 0;
+            total_case_num = 0;
+            fail_case_num = 0;
+            test_time_consume = 0;
+        }
+
+        /*send msg to Ttask2~Ttask4*/
+        /*
+        stress_test1_req1 = (nvram_stress_test1_req_struct*) construct_local_para(sizeof(nvram_stress_test1_req_struct), TD_CTRL);
+        stress_test1_req1->access_id = 0x0;
+        stress_test1_req1->ref_count = 1;
+        stress_test1_req1->start_stress_test1 = 1;
+        msg_send6(MOD_NV_TEST1, MOD_NV_TEST2, 0x0, MSG_ID_NVRAM_STRESS_TEST1_REQ, 
+            (local_para_struct*)stress_test1_req1, NULL);
+        
+        stress_test1_req2 = (nvram_stress_test1_req_struct*) construct_local_para(sizeof(nvram_stress_test1_req_struct), TD_CTRL);
+        stress_test1_req2->access_id = 0x0;
+        stress_test1_req2->ref_count = 1;
+        stress_test1_req2->start_stress_test1 = 1;
+        msg_send6(MOD_NV_TEST1, MOD_NV_TEST3, 0x0, MSG_ID_NVRAM_STRESS_TEST1_REQ, 
+            (local_para_struct*)stress_test1_req2, NULL);
+        
+        stress_test1_req3 = (nvram_stress_test1_req_struct*) construct_local_para(sizeof(nvram_stress_test1_req_struct), TD_CTRL);
+        stress_test1_req3->access_id = 0x0;
+        stress_test1_req3->ref_count = 1;
+        stress_test1_req3->start_stress_test1 = 1;
+        msg_send6(MOD_NV_TEST1, MOD_NV_TEST4, 0x0, MSG_ID_NVRAM_STRESS_TEST1_REQ, 
+            (local_para_struct*)stress_test1_req3, NULL);
+        
+        kal_prompt_trace(MOD_NVRAM, "Ttask1 send msg to Ttask2~Ttask4 done!\n\r");
+        */
+        /*else if(current_ilm.msg_id == MSG_ID_NVRAM_STRESS_TEST1_CNF)
+        {
+            stress_test1_cnf = (nvram_stress_test1_cnf_struct*) current_ilm.local_para_ptr;
+            kal_prompt_trace(MOD_NVRAM, "current_ilm.src_mod_id = %d!\n\r", current_ilm.src_mod_id);
+            kal_prompt_trace(MOD_NVRAM, "test result = %d!\n\r", stress_test1_cnf.stress_test1_result);
+        }*/
+        
+        //nvram_ut_trace("cmpt_op_result:%d\n\r", nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 0x01020300, 0x1));
+        //nvram_ut_trace("cmpt_op_result:%d\n\r", nvram_lid_cmpt_operation(NVRAM_EF_NVRAM_TEST_1_LID, 0x00020301, 0x2));
+    }
+
+}
+
+kal_bool nvram_Ttask1_init(void)
+{
+
+    return KAL_TRUE;
+
+}
+
+kal_bool nvram_Ttask1_reset(void)
+{
+
+    return KAL_TRUE;
+
+}
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+kal_bool nvram_Ttask1_create(comptask_handler_struct **handle)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    static const comptask_handler_struct nvram_ttask1_handler_info =
+    {
+        nvram_Ttask1_main,    /* task entry function */
+        nvram_Ttask1_init,         /* task initialization function */
+        nvram_Ttask1_reset        /* task reset handler */
+    };
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    *handle = (comptask_handler_struct*) & nvram_ttask1_handler_info;
+    return KAL_TRUE;
+}
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+#endif
diff --git a/mcu/service/nvram/src/nvram_util.c b/mcu/service/nvram/src/nvram_util.c
new file mode 100644
index 0000000..f54a24b
--- /dev/null
+++ b/mcu/service/nvram/src/nvram_util.c
@@ -0,0 +1,2912 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ * nvram_util.c
+ *
+ * Project:
+ * --------
+ *   MAUI
+ *
+ * Description:
+ * ------------
+ *   This is utility for NVRAM
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include "stdio.h"
+#include "string.h"
+#include "stdarg.h"
+#include "kal_general_types.h"
+#include "kal_internal_api.h"  /* basename */
+#include "kal_public_api.h"
+#include "kal_trace.h"
+#include "kal_public_defs.h" //MSBB change #include "stack_config.h"
+#include "nvram_main.h"
+#include "che_api.h"
+#include "dcl.h"
+#include "che_api.h" // to calculate checksum
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+#include "dcl_gpt.h"
+#endif
+#include <ex_public.h>
+
+#ifdef __NVRAM_LID_CACHE__
+#include "nvram_cache_interface.h"
+#endif
+#include "us_timer.h"
+#include "stdlib.h"
+#include "ex_public.h"
+
+#if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+#if defined(__MTK_TARGET__)  //target load
+#include "nvram_checksum_reset.h"
+#else //modis load define a dummy table to avoid build error
+const checksum_reset_struct lid_default_value_chksum[] ={	
+    {NVRAM_EF_CHKSUM_RESET_REC_LID, {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}},
+};
+
+const checksum_reset_struct lid_structure_chksum[] ={	
+    {NVRAM_EF_CHKSUM_RESET_REC_LID, {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}},
+};
+
+kal_uint32 lid_structure_chksum_num = sizeof(lid_structure_chksum)/sizeof(checksum_reset_struct);
+kal_uint32 lid_default_value_chksum_num = sizeof(lid_default_value_chksum)/sizeof(checksum_reset_struct);
+#endif
+#endif
+
+
+#ifdef __NVRAM_INIT_TIME_UT__
+kal_uint16 init_time_tick[10] = {0};
+nvram_init_flow_trace init_trace = 0;
+#endif	
+#ifdef __NVRAM_INIT_LID_BUFFER__
+typedef enum
+{
+    NVRAM_INIT_LID_BUF_INVALID = 0,
+    NVRAM_INIT_LID_BUF_ENPTY,
+    NVRAM_INIT_LID_BUF_READ,
+    NVRAM_INIT_LID_BUF_VALID,
+    NVRAM_INIT_LID_BUF_DIRTY,
+} nvram_init_lid_buffer_status;
+
+typedef struct
+{
+    nvram_lid_enum  LID;
+    nvram_ltable_entry_struct *ldi_ptr;
+    kal_uint8 *buffer;
+    nvram_init_lid_buffer_status status;
+} nvram_init_lid_buffer_struct;
+
+nvram_init_lid_buffer_struct lid_buffer_list[] = {
+    {NVRAM_EF_LTECSR_PROFILE_LID, NULL, NULL, 0},
+    {NVRAM_EF_IMS_PROFILE_LID, NULL, NULL, 0},
+    {NVRAM_EF_VDM_ADS_PROFILE_LID, NULL, NULL, 0},
+    {NVRAM_EF_SDM_ADS_PROFILE_LID, NULL, NULL, 0},
+    {NVRAM_EF_SBP_MODEM_DATA_CONFIG_LID, NULL, NULL, 0},
+    {NVRAM_EF_SBP_MODEM_CONFIG_LID, NULL, NULL, 0},
+    {NVRAM_EF_UMTS_USIME_RRC_DYNAMIC_CAP_FDD_LID, NULL, NULL, 0},
+    {NVRAM_EF_UMTS_USIME_RRC_DYNAMIC_CAP_TDD_LID, NULL, NULL, 0},
+    {NVRAM_EF_LTE_PREFERENCE_LID, NULL, NULL, 0},
+    {NVRAM_EF_REGIONAL_PHONE_MODE_LID, NULL, NULL, 0},
+    {NVRAM_EF_MSCAP_LID, NULL, NULL, 0},
+    {NVRAM_EF_ERRC_PERFORMANCE_PARA_LID, NULL, NULL, 0},
+    {NVRAM_EF_UE_EUTRA_CAP_CSFB_LID, NULL, NULL, 0},
+    {NVRAM_EF_NVRAM_SEC_CHECK_LID, NULL, NULL, 0},
+};
+kal_uint16 lid_buffer_list_num = sizeof(lid_buffer_list)/sizeof(nvram_init_lid_buffer_struct);
+kal_uint8 *nvram_init_lid_buffer = NULL;
+kal_bool nvram_init_lid_buffer_en = KAL_FALSE;
+#endif
+
+kal_int8  g_access_trace_setting_file_result = 0;
+kal_uint32  g_nvram_trace_setting= 0;
+#ifdef __NV_CHKSUM_ENHANCE__
+extern nvram_algo_info *chksum_algo_ptr;
+#endif
+
+extern void InitDebugPrint(void);
+extern void DebugPrint(kal_uint8, kal_uint8, kal_uint8*);
+
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+extern void nvram_gpt_timeout_callback(void *data);
+#endif
+
+
+#define NVRAM_TRC_SIZE 256
+
+/*
+ * External variables
+ */
+extern kal_mutexid g_nvram_impt_mutex;
+extern kal_mutexid g_nvram_fs_mutex;
+extern ilm_struct *g_ilm_ptr;
+extern kal_uint32 g_nvram_task_idx;
+extern kal_bool is_nvram_in_ota_flow;
+#if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+extern DCL_HANDLE nvram_gpt_handle;
+#endif
+extern kal_bool is_nvram_factory_reset;
+
+
+extern nvram_ee_info_type* nvram_ee_info;
+extern kal_char nvram_trace_dump_temp_buffer[];
+extern kal_char nvram_trace_dump_buffer[];
+extern kal_mutexid g_nvram_dump_trace_mutex;
+extern kal_wchar nvram_trace_filename[];
+extern FS_HANDLE nvram_trace_file_hdl;
+extern kal_uint32 nvram_trace_dump_buffer_offset;
+
+extern module_type stack_get_active_module_id( void );
+
+static kal_uint8 g_util_chksum[128] = {0};
+
+
+#if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+kal_int32 nvram_get_structure_chksum_index(nvram_lid_enum LID)
+{
+    kal_int32 index = 0;
+
+    for(; index < lid_structure_chksum_num && LID != lid_structure_chksum[index].LID; index++)
+    {}
+
+    if(index >= lid_structure_chksum_num)
+    {
+        index = -1;
+    }
+        
+    return index;
+}
+
+kal_int32 nvram_get_defval_chksum_index(nvram_lid_enum LID)
+{
+    kal_int32 index = 0;
+
+    for(; index < lid_default_value_chksum_num && LID != lid_default_value_chksum[index].LID; index++)
+    {}
+
+    if(index >= lid_default_value_chksum_num)
+    {
+        index = -1;
+    }
+        
+    return index;
+}
+#endif
+
+
+kal_bool nvram_util_next_data_item(nvram_ltable_entry_struct **entry)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    nvram_ltable_entry_struct *ldi = *entry;
+    kal_uint32 end = (kal_uint32)logical_data_item_table + nvram_ptr->ltable.area_size;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+        if (ldi == NULL)
+        {
+            ldi = &logical_data_item_table[0];
+        if (ldi->fileprefix[0])
+        {
+            *entry = ldi;
+            return KAL_TRUE;
+        }
+        }
+
+    while((kal_uint32)++ldi < end)
+    {
+        if (ldi->fileprefix[0])
+        {
+            *entry = ldi;
+            return KAL_TRUE;
+        }
+    }
+
+    *entry = NULL;
+    return KAL_FALSE;
+}
+
+
+kal_bool nvram_util_get_data_item(nvram_ltable_entry_struct **ldi, nvram_lid_enum LID)    
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i = 0, count = 0;
+    kal_uint32 end = (kal_uint32)logical_data_item_table + nvram_ptr->ltable.area_size;
+
+    do 
+    {
+        if (logical_data_item_table[i].fileprefix[0])
+        {
+            count++;
+
+            if (logical_data_item_table[i].LID == LID)
+            {
+                if (ldi) {
+                    *ldi = &logical_data_item_table[i];
+                }
+                return KAL_TRUE;
+            }
+        }
+        i++;
+    }while(count < nvram_ptr->ltable.total_LID && ((kal_uint32)&logical_data_item_table[i] < end));
+
+    if (ldi)
+        *ldi = NULL;
+
+    return KAL_FALSE;
+}
+
+kal_bool nvram_util_get_data_item_by_fileprefix(nvram_ltable_entry_struct **ldi, kal_char *fileprefix)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i = 0, count = 0;
+    kal_uint32 end = (kal_uint32)logical_data_item_table + nvram_ptr->ltable.area_size;
+
+    do
+    {
+        if (logical_data_item_table[i].fileprefix[0])
+        {
+            count++;
+            //if (!memcmp(logical_data_item_table[i].fileprefix, fileprefix, FILE_PREFIX_LEN))
+            //speed up search
+            if((kal_mem_cmp(fileprefix,logical_data_item_table[i].fileprefix,FILE_PREFIX_LEN) == 0) && (logical_data_item_table[i].LID != NVRAM_EF_READ_RESERVED_LID))
+            {
+                if (ldi) {
+                    *ldi = &logical_data_item_table[i];
+                    return KAL_TRUE;
+                }
+            }
+        }
+        i++;
+    }while(count < nvram_ptr->ltable.total_LID && ((kal_uint32)&logical_data_item_table[i] < end));
+
+    if (ldi)
+        *ldi = NULL;
+
+    return KAL_FALSE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_drval_caculate_checksum
+ * DESCRIPTION
+ *  produce the check sum of the given record.
+ * PARAMETERS
+ *  checksum        [?]
+ *  buf             [?]
+ *  size            [IN]
+ * RETURNS
+ *  checksum(?)
+ *****************************************************************************/
+kal_uint16 nvram_util_cal_checksum_simple(const kal_uint8 *buf, kal_uint32 size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i;
+    kal_uint16 chksum = 0;
+    kal_uint8 *byte_chksum = (kal_uint8*) &chksum;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (buf == NVRAM_EF_ZERO_DEFAULT)
+    {
+        return 0xCDEF;
+    }
+    else if (buf == NVRAM_EF_FF_DEFAULT)
+    {
+        for (i = 0 ;i < size; i++)
+        {
+            if (i & 0x1)
+            {
+                *(byte_chksum + 1) += 0xFF;
+            }
+            else
+            {
+                *byte_chksum += 0xFF;
+            }
+        }
+        return chksum;
+     }
+
+    for (i = 0; i < size; i++)
+    {
+        if (i & 0x1)
+        {
+            *(byte_chksum + 1) += *(buf + i);
+        }
+        else
+        {
+            *byte_chksum += *(buf + i);
+        }
+    }
+
+    //Replace conflict chksum
+    if (chksum == 0)
+        return 0xCDEF;
+    else if(chksum == 0xCDEF)
+        return 0xCEDF;
+    else
+        return chksum;
+}
+
+kal_bool nvram_util_zero_data_check(const kal_uint8 *buf, kal_uint32 size)
+{
+    while(size > 0) {
+        if((size < 7) || ((kal_uint32)buf & 0x3)) {
+            if(*buf != 0) {
+                return KAL_FALSE;
+            }
+            buf += 1;
+            size -= 1;            
+        }
+        else {
+            if(*(kal_uint64*)buf != 0) {
+                return KAL_FALSE;
+            }
+            buf += 8;
+            size -= 8;
+        }
+    }
+    return KAL_TRUE;
+}
+
+kal_uint16 nvram_util_md5_checksum_convert(const kal_uint8 *checksum_buf_8B, kal_uint8 *checksum_buf_2B, kal_bool Check_CDEF)
+{
+    kal_uint8 i;
+    kal_uint64 const EmptyChksum = 0xCDEF;
+    kal_uint16 val = 0;
+    kal_uint16 *chk_ptr = (kal_uint16*)checksum_buf_8B;
+    kal_uint32 nvram_chksum_size = 0;
+    #ifdef __NV_CHKSUM_ENHANCE__
+    nvram_chksum_size = MD5_CHKSUM_LENGTH_8;
+    #else
+    nvram_chksum_size = NVRAM_CHKSUM_SIZE;
+    #endif
+
+    //Check Empty
+    if(Check_CDEF && !kal_mem_cmp(checksum_buf_8B, (kal_uint8*)&EmptyChksum, nvram_chksum_size)) {
+        if(checksum_buf_2B != NULL) {
+            checksum_buf_2B[0] = 0xEF;
+            checksum_buf_2B[1] = 0xCD;
+        }
+        return 0xCDEF;
+    }
+    
+    //Merge 8B MD5 to 2B
+    for(i = 0; i < (nvram_chksum_size / 2); i++){
+        val += chk_ptr[i];
+    }
+
+    //Replace conflict chksum
+    if(val == 0xCDEF) {
+        val = 0xCEDF;
+    }
+
+    //Return
+    if(checksum_buf_2B != NULL) {
+        kal_mem_cpy(checksum_buf_2B, (kal_uint8*)&val, 2);
+    }
+    return val;
+}
+
+kal_uint16 nvram_util_caculate_checksum(nvram_ltable_entry_struct *ldi, const kal_uint8 *buf, kal_uint32 size, kal_uint8* checksum_buf)
+{
+     kal_uint8 i=0;
+     kal_uint16 chksum_2B = 0;
+     nvram_lid_chksum_info lid_chksum_info = {0};
+     kal_uint64 const EmptyChksum = 0xCDEF;
+     kal_uint8 *byte_chksum = (kal_uint8*) &chksum_2B;
+     kal_uint8 *temp_chksum_buf = NULL;
+     kal_uint32 temp_chksum_buf_size = 0;
+     NVRAM_ALGO_TYPE chksum_algo_type = NVRAM_MD5;
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    
+    #ifdef __NV_CHKSUM_ENHANCE__
+    if(lid_chksum_info.algo_info.chksum_algo_type == chksum_algo_ptr->cur_algo.def_algo_type)
+    {
+        temp_chksum_buf_size = chksum_algo_ptr->cur_algo.def_algo_length;
+    }
+    else if(lid_chksum_info.algo_info.chksum_algo_type == chksum_algo_ptr->cur_algo.en_algo_type)
+    {
+        temp_chksum_buf_size = chksum_algo_ptr->cur_algo.en_algo_length;
+    }
+    chksum_algo_type = lid_chksum_info.algo_info.chksum_algo_type;
+    #else
+    temp_chksum_buf_size = NVRAM_CHKSUM_SIZE * 2;
+    chksum_algo_type = NVRAM_MD5;
+    #endif
+
+    if (buf == NVRAM_EF_ZERO_DEFAULT || nvram_util_zero_data_check(buf, size))
+    {
+        if(temp_chksum_buf_size < sizeof(EmptyChksum))
+        {
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[NVUT_UTIL_CAL]%s(): LDI<0x%x> chksize(%d) too small\n\r", __FUNCTION__, ldi->LID, temp_chksum_buf_size);
+            kal_prompt_trace(MOD_NVRAM,"[NVUT_UTIL_CAL] %s(): LDI<0x%x> chksize(%d) too small.\n\r", __FUNCTION__, ldi->LID, temp_chksum_buf_size);
+            NVRAM_EXT_ASSERT(KAL_FALSE, ldi->LID, NVRAM_LOC_CHKSUM_ALGO_MISSMATCH_FAIL, chksum_algo_type, temp_chksum_buf_size);
+        }
+        kal_mem_cpy(checksum_buf, (kal_uint8*)&EmptyChksum, sizeof(EmptyChksum));
+        return 0xCDEF;
+    }
+
+    if(INT_QueryExceptionStatus()== KAL_TRUE)
+    {
+        temp_chksum_buf = (kal_uint8 *)g_util_chksum;
+    }
+    else
+    {
+        temp_chksum_buf = (kal_uint8*) get_ctrl_buffer(temp_chksum_buf_size);
+    }
+    kal_mem_set(temp_chksum_buf, 0, temp_chksum_buf_size);
+    nvram_calculate_checksum(chksum_algo_type, (kal_uint8 *)buf, size, temp_chksum_buf);
+
+    //Merge 16B MD5 to 8B
+    if(chksum_algo_type == NVRAM_MD5)
+    {
+        for(i = 0; i< NVRAM_CHKSUM_SIZE; i++)
+        {
+            checksum_buf[i] = temp_chksum_buf[i]^temp_chksum_buf[i+8];
+        }
+
+        //Merge 8B MD5 to 2B
+        nvram_util_md5_checksum_convert(checksum_buf, byte_chksum, KAL_FALSE);
+    }
+    else
+    {
+            kal_mem_cpy(checksum_buf, temp_chksum_buf, temp_chksum_buf_size);
+    }
+
+    if(INT_QueryExceptionStatus() != KAL_TRUE)
+    {
+        free_ctrl_buffer(temp_chksum_buf);
+    }
+
+    return chksum_2B;
+}
+
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_lid_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_util_make_lid_filename(nvram_ltable_entry_struct *ldi, NVRAM_FILE_NAME nvramname, kal_bool first_copy)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    if (ldi == NULL)
+    {
+        EXT_ASSERT(KAL_FALSE,(kal_uint32)ldi,NVRAM_LOC_LID_PTR_IS_NULL_2, 0);
+        return;
+    }
+
+#ifdef __NVRAM_PSEUDO_MERGE__
+    if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+    {
+        nvram_make_package_filename(nvramname, 'A');
+        return;
+    }
+#endif
+
+    if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+    {
+        if (first_copy)
+        {
+            nvram_util_make_filename(nvramname, ldi->fileprefix, 'A', ldi->fileverno);
+        }
+        else
+        {
+            #if defined(__NVRAM_WRITE_PROTECT_ENABLE__)	&& defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__)
+            nvram_util_make_filename(nvramname, ldi->fileprefix, 'A', ldi->fileverno);
+		    #else
+			nvram_util_make_filename(nvramname, ldi->fileprefix, 'B', ldi->fileverno);
+		    #endif
+        }
+    }
+    else
+    {
+        nvram_util_make_filename(nvramname, ldi->fileprefix, '_', ldi->fileverno);
+    }
+
+    return;
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_make_lid_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_util_make_filename(NVRAM_FILE_NAME buf, kal_char* prefix, kal_char M, kal_char* verno) 
+{
+   buf[0] = prefix[0];  
+   buf[1] = prefix[1];  
+   buf[2] = prefix[2];  
+   buf[3] = prefix[3];  
+   buf[4] = M;             
+   buf[5] = verno[0];   
+   buf[6] = verno[1];   
+   buf[7] = verno[2];   
+   buf[8] = '\0';    
+};
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_util_is_usbboot
+ * DESCRIPTION
+ *  old function name: INT_USBBoot
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_bool nvram_util_is_usbboot(void) 
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    PW_CTRL_IS_USB_BOOT CtrlVal;
+    DCL_HANDLE handle;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    handle=DclPW_Open(DCL_PW, FLAGS_NONE);
+    DclPW_Control(handle, PW_CMD_IS_USB_BOOT,(DCL_CTRL_DATA_T *)&CtrlVal);
+    DclPW_Close(handle);
+    return ((kal_bool)CtrlVal.val);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_util_poweron
+ * DESCRIPTION
+ *  old function name: DRV_POWERON
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+kal_bool nvram_util_poweron(void) 
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    DCL_HANDLE handle;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    handle=DclPW_Open(DCL_PW, FLAGS_NONE);
+    DclPW_Control(handle,PW_CMD_POWERON,NULL);
+    DclPW_Close(handle);
+    return KAL_TRUE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_util_poweron
+ * DESCRIPTION
+ *  old function name: DRV_POWERON
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+void nvram_util_poweroff(void) 
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    DCL_HANDLE handle;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    handle=DclPW_Open(DCL_PW, FLAGS_NONE);
+    DclPW_Control(handle,PW_CMD_POWEROFF,NULL);
+    DclPW_Close(handle);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_total_num_lid
+ * DESCRIPTION
+ *  Get the total LID number
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  nvram_lid_enum
+ *****************************************************************************/
+nvram_lid_enum nvram_get_total_num_lid(void)
+{
+    return nvram_ptr->ltable.total_LID;
+}
+
+nvram_lid_enum nvram_util_get_IMEISV_LID(void)
+{
+    return NVRAM_EF_IMEI_IMEISV_LID;
+}
+
+kal_uint32 nvram_util_get_IMEISV_size(void)
+{
+    return NVRAM_EF_IMEI_IMEISV_SIZE;
+}
+
+kal_uint32 nvram_util_get_IMEI_size(void)
+{
+    return NVRAM_EF_IMEI_IMEI_SIZE;
+}
+
+void nvram_util_take_mutex(kal_mutexid ext_mutex_id_ptr)
+{
+    if (!INT_QueryExceptionStatus() && !kal_query_systemInit() && ext_mutex_id_ptr)
+    {
+        kal_take_mutex(ext_mutex_id_ptr);
+    }
+}
+
+void nvram_util_give_mutex(kal_mutexid ext_mutex_id_ptr)
+{
+    if (!INT_QueryExceptionStatus() && !kal_query_systemInit() && ext_mutex_id_ptr)
+    {
+        kal_give_mutex(ext_mutex_id_ptr);
+    }
+}
+
+#ifdef __NVRAM_INIT_TIME_UT__
+void nvram_init_time_ut_save(void)
+{
+    kal_uint8 i;
+
+    for(i = 1; i < 9; i++) {
+        if(init_time_tick[i]) {
+            init_time_tick[i] -= init_time_tick[0];
+        }
+    }
+    //init_time_tick[1] = ((init_time_tick[1] & 0x0FFF) | (init_trace << 12));
+	init_time_tick[9] = init_trace;
+    nvram_external_write_data(NVRAM_EF_SYS_CACHE_OCTET_LID,
+                             NVRAM_SYS_NVRAM_INIT_TIME_UT,
+                             (kal_uint8*)&init_time_tick[1],
+                             NVRAM_EF_SYS_CACHE_OCTET_SIZE);
+    nvram_external_write_data(NVRAM_EF_SYS_CACHE_OCTET_LID,
+                             NVRAM_SYS_NVRAM_INIT_TIME_UT2,
+                             (kal_uint8*)&init_time_tick[5],
+                             NVRAM_EF_SYS_CACHE_OCTET_SIZE);
+}
+#endif /* __NVRAM_INIT_TIME_UT__ */
+
+void * nvram_memset(void* dest, kal_int32 value, kal_uint32 size)
+{
+    kal_uint8 *dest_ptr = (kal_uint8*)dest;
+    
+    while(size)
+    {
+        if(size > (64*1024)) {
+            kal_mem_set(dest_ptr, value, (64*1024));
+            size -= (64*1024);
+            dest_ptr += (64*1024);
+        }
+        else {
+            return kal_mem_set(dest_ptr, value, size);
+        }
+    }
+    return NULL;
+}
+
+#if defined(__NVRAM_CREATE_FILE_ON_WRITE__)
+#define NVRAM_INFO_FILE_MAGIC_START     0x4F464E49     // "INFO"
+#define NVRAM_INFO_FILE_STAT_READY      0xFDFDFBFB
+#define MD5_CHECKSUM_LEN                16
+#define NVRAM_LID_BITMAP_SIZE ((NVRAM_LID_GRP_MAX-(NVRAM_LID_2ND_GRP_START-NVRAM_LID_1ST_GRP_END)+7)>>3)
+
+typedef struct {
+    kal_uint32 magic_start;
+    kal_uint32 file_stat;
+    kal_uint8 check_sum[MD5_CHECKSUM_LEN];
+} nvram_info_file_hdr_struct;
+
+typedef struct {
+    nvram_info_file_hdr_struct hdr;
+    kal_uint8 bitmap[NVRAM_LID_BITMAP_SIZE];
+    kal_bool changed;
+}  nvram_created_file_info_struct;
+
+kal_mutexid nvram_bitmap_mutex = NULL;
+kal_mutexid nvram_pre_write_check_mutex = NULL;
+nvram_created_file_info_struct nvram_created_file_info;
+kal_uint8 *nvram_bitmap_ptr = nvram_created_file_info.bitmap;
+    
+static WCHAR *nvram_util_get_info_file_path()
+{
+    static WCHAR fileName[NVRAM_MAX_PATH_LEN];
+
+    NVRAM_FS_MAKE_ROOT_PATH(fileName);
+
+    kal_wstrcat(fileName, L"\\INFO_FILE");
+
+    return fileName;
+}
+
+void nvram_util_lid_bimtap_set(kal_uint8 *bitmap, kal_uint32 lid)
+{
+    kal_uint32 offset;
+    kal_uint32 bit = lid&0x7;
+
+    if(!bitmap) {
+        EXT_ASSERT(KAL_FALSE, (kal_uint32)bitmap, NVRAM_LOC_BITMAP_INVALID, lid);
+    }    
+    if (lid < NVRAM_LID_1ST_GRP_END) {
+        offset = lid>>3;
+    } else if (lid >= NVRAM_LID_2ND_GRP_START){
+        offset = (NVRAM_LID_1ST_GRP_END>>3) + ((lid-NVRAM_LID_2ND_GRP_START)>>3);
+    } else {
+        EXT_ASSERT(KAL_FALSE, (kal_uint32)bitmap, NVRAM_LOC_BITMAP_ACCESS_OOR, lid);
+    }
+
+    bitmap[offset] |= (0x1<<bit);
+    nvram_created_file_info.changed = KAL_TRUE;
+}
+
+void nvram_util_lid_bitmap_clr(kal_uint8 *bitmap, kal_uint32 lid)
+{
+    kal_uint32 offset;
+    kal_uint32 bit = lid&0x7;
+
+    if(!bitmap) {
+        EXT_ASSERT(KAL_FALSE, (kal_uint32)bitmap, NVRAM_LOC_BITMAP_INVALID, lid);
+    }
+    if (lid < NVRAM_LID_1ST_GRP_END) {
+        offset = lid>>3;
+    } else if (lid >= NVRAM_LID_2ND_GRP_START){
+        offset = (NVRAM_LID_1ST_GRP_END>>3) + ((lid-NVRAM_LID_2ND_GRP_START)>>3);
+    } else {
+        EXT_ASSERT(KAL_FALSE, (kal_uint32)bitmap, NVRAM_LOC_BITMAP_ACCESS_OOR, lid);
+    }
+
+    bitmap[offset] &= ~(0x1<<bit);
+    nvram_created_file_info.changed = KAL_TRUE;
+}
+
+kal_bool nvram_util_lid_bitmap_check(kal_uint8 *bitmap, kal_uint32 lid)
+{
+    kal_uint32 offset;
+    kal_uint32 bit = lid&0x7;
+
+    if(!bitmap) {
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)bitmap, NVRAM_LOC_BITMAP_INVALID, lid);
+    }    
+    if (lid < NVRAM_LID_1ST_GRP_END) {
+        offset = lid>>3;
+    } else if (lid >= NVRAM_LID_2ND_GRP_START){
+        offset = (NVRAM_LID_1ST_GRP_END>>3) + ((lid-NVRAM_LID_2ND_GRP_START)>>3);
+    } else {
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)bitmap, NVRAM_LOC_BITMAP_ACCESS_OOR, lid);
+    }
+
+    return ((bitmap[offset] & (0x1<<bit)) != 0)?KAL_TRUE:KAL_FALSE;
+}
+
+void nvram_utile_reset_lid_bitmap()
+{
+    nvram_created_file_info.hdr.magic_start = NVRAM_INFO_FILE_MAGIC_START;
+    nvram_created_file_info.hdr.file_stat = NVRAM_INFO_FILE_STAT_READY;
+    nvram_created_file_info.changed = KAL_FALSE;
+    kal_mem_set(nvram_created_file_info.bitmap, 0, sizeof(nvram_created_file_info.bitmap));
+}
+
+static void nvram_util_calc_md5_checksum(kal_uint8 *data_buf, kal_uint32 data_buf_len, kal_uint8 *chksum_buf)
+{
+    
+    // MD5 of bit map
+    nvram_calculate_checksum(NVRAM_MD5, data_buf, data_buf_len, chksum_buf);
+
+    return;
+}
+
+
+kal_bool nvram_write_bitmap_into_file()
+{
+    kal_uint32 buf_len = 0;
+    kal_uint8 *write_buf = NULL;
+    WCHAR *file_path = NULL;
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    kal_int32 result = FS_NO_ERROR;
+    kal_uint32 write_len;
+
+    //Reduce the time of nvram init at first bootup by void writing bitmap file many times
+    if (nvram_ptr->state != NVRAM_STATE_READY) //before nvram init done, cann't write bitmap
+    {
+        return KAL_TRUE;
+    }
+    if(!nvram_created_file_info.changed) //Must After nvram init,can write bitmap when first boot or version change 
+    {
+       return KAL_TRUE;
+    }
+    file_path = nvram_util_get_info_file_path();
+    NVRAM_FS_START_EX(FS_OP_OPEN,file_path);
+    file_handle = FS_Open(file_path, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE_ALWAYS);
+    NVRAM_FS_END(FS_OP_OPEN,file_handle);
+    if (file_handle < FS_NO_ERROR) {        
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Open bitmap fail at %d,file_handle=%d\r\n",__FUNCTION__,__LINE__,file_handle);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_BITMAP_OPEN_FAIL, buf_len);
+    }
+
+    nvram_created_file_info.hdr.file_stat = NVRAM_INFO_FILE_STAT_READY;
+    nvram_util_calc_md5_checksum(nvram_created_file_info.bitmap, sizeof(nvram_created_file_info.bitmap), nvram_created_file_info.hdr.check_sum);
+    
+    write_buf = (kal_uint8 *)&nvram_created_file_info;
+    buf_len = sizeof(nvram_created_file_info);
+    NVRAM_FS_START(FS_OP_WRITE);
+    result = FS_Write(file_handle, write_buf, buf_len, &write_len);
+    NVRAM_FS_END(FS_OP_WRITE,result);
+    if (result < FS_NO_ERROR) {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->FS_Write fail at %d,result=%d\r\n",__FUNCTION__,__LINE__,result);
+        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_LOC_BITMAP_WRITE_FAIL, buf_len, FS_Close(file_handle));
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(file_handle);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+    nvram_created_file_info.changed = KAL_FALSE;
+    return KAL_TRUE;
+}
+
+kal_bool nvram_delete_bitmap_file()
+{
+    WCHAR *file_path = NULL;
+    kal_int32 result = FS_NO_ERROR;
+    file_path = nvram_util_get_info_file_path();    
+    NVRAM_FS_START_EX(FS_OP_DELETE,file_path);
+    result = FS_Delete(file_path);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s result=%d\r\n",__FUNCTION__,result);
+    return KAL_TRUE;
+}
+kal_taskid pre_write_check_mutex_owner = (kal_taskid)-1;  /* to avoid recursive lock */
+void nvram_util_pre_write_lid(nvram_ltable_entry_struct *ldi)
+{
+    if (pre_write_check_mutex_owner != kal_get_current_task()) {
+        nvram_util_take_mutex(nvram_pre_write_check_mutex);
+        pre_write_check_mutex_owner = kal_get_current_task();
+
+        if (!nvram_util_has_file_created(ldi) && !nvram_util_always_gen_default(ldi)) 
+        {
+            if(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))
+            {
+                // no need reset RAW data file
+                nvram_util_post_reset_gen_default_lid(ldi);
+            }
+            else
+            {
+                // mark always create, then reset the lid
+                ldi->attr |= NVRAM_ATTR_GEN_DEFAULT;
+                 
+                // reset the LID, bitmap will be set after reset ok
+                nvram_reset_data_items(NVRAM_RESET_CERTAIN, 0, ldi, 1, ldi->total_records);
+                // clear the mark
+                ldi->attr &= ~NVRAM_ATTR_GEN_DEFAULT;
+            }
+        }
+
+        pre_write_check_mutex_owner = (kal_taskid)-1;
+        nvram_util_give_mutex(nvram_pre_write_check_mutex);
+    }
+}
+
+void nvram_util_post_write_lid(nvram_ltable_entry_struct *ldi)
+{
+
+}
+
+void nvram_util_pre_reset_gen_default_lid(nvram_ltable_entry_struct *ldi)
+{
+    if (nvram_util_has_file_created(ldi)) {
+        // do nothing
+        return;
+    }
+
+    // prepare reset
+}
+
+void nvram_util_post_reset_gen_default_lid(nvram_ltable_entry_struct *ldi)
+{
+    nvram_lid_enum lid = ldi->LID;
+    
+    if (nvram_util_has_file_created(ldi)) {
+        // do nothing
+        return;
+    }
+
+    // reset lid finish, file generated success fully
+	#ifdef __NVRAM_LID_CACHE__
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+	#endif
+    nvram_util_take_mutex(nvram_bitmap_mutex);
+    nvram_util_lid_bimtap_set(nvram_created_file_info.bitmap, lid);
+    nvram_write_bitmap_into_file();
+    nvram_util_give_mutex(nvram_bitmap_mutex);
+	#ifdef __NVRAM_LID_CACHE__
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+	#endif
+}
+
+kal_bool nvram_util_has_file_created(nvram_ltable_entry_struct *ldi)
+{
+    nvram_lid_enum lid = ldi->LID;
+    
+    if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category) ||
+        NVRAM_IS_CATEGORY_OTP(ldi->category)) {
+        return KAL_TRUE;
+    }
+#ifdef __NVRAM_READ_RESERVED_FILE__
+    if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) {
+        return KAL_TRUE;
+    }
+#endif
+
+    // read only
+    return nvram_util_lid_bitmap_check(nvram_created_file_info.bitmap, lid);
+}
+
+kal_bool nvram_util_always_gen_default(nvram_ltable_entry_struct *ldi)
+{
+    if ((ldi->attr & (NVRAM_ATTR_GEN_DEFAULT)) != 0) {
+        return KAL_TRUE;
+    }
+
+    return KAL_FALSE;
+}
+
+void nvram_util_mark_file_uncreated(nvram_ltable_entry_struct *ldi)
+{
+    nvram_lid_enum lid = ldi->LID;
+    kal_uint32 idx;
+    kal_int32 result = FS_NO_ERROR;
+    // remove record
+    nvram_util_take_mutex(nvram_bitmap_mutex);
+    if (nvram_util_lid_bitmap_check(nvram_created_file_info.bitmap, lid)) {
+        nvram_util_lid_bitmap_clr(nvram_created_file_info.bitmap, lid);
+
+        // delete the LID's NVRAM File
+        for (idx = 0; idx < 2; idx++) {
+            NVRAM_FILE_NAME nvramname;
+            WCHAR filename[NVRAM_MAX_PATH_LEN];
+            nvram_folder_enum folder_index;
+
+            nvram_util_make_lid_filename(ldi, nvramname, (idx==0));
+            folder_index = nvram_query_folder_index_ex(ldi->category, (idx==0));
+            nvram_query_file_name(folder_index, nvramname, filename);
+            NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+            result = FS_Delete(filename);
+            NVRAM_FS_END(FS_OP_DELETE,result);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Delete %s result=%d\r\n",__FUNCTION__,nvramname,result);
+            if (!(ldi->attr & NVRAM_ATTR_MULTIPLE)) {
+                break;
+            }
+        }
+
+        // update info file
+        nvram_write_bitmap_into_file();
+    }
+    nvram_util_give_mutex(nvram_bitmap_mutex);
+}
+
+static kal_bool nvram_util_reconstruct_info_file()
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    FS_FileOpenHint Hint;
+    NVRAM_FILE_NAME nvramname;
+    kal_int32 file_size = 0;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum folder_index;
+    kal_uint32 i;
+    nvram_ltable_entry_struct *ldi = &logical_data_item_table[0];
+    kal_bool file_exist;
+    nvram_lid_enum lid;
+    kal_int32 result = FS_NO_ERROR;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    /* Must clear up Hint beforehand */
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s ====>\r\n",__FUNCTION__);
+    kal_mem_set(&Hint, 0, sizeof(Hint));
+    nvram_util_take_mutex(nvram_bitmap_mutex);
+    nvram_utile_reset_lid_bitmap();
+
+    do
+    {
+        file_exist = KAL_FALSE;
+        lid = ldi->LID;
+        
+        for (i = 0 ; i < 2; i++)
+        {
+            folder_index = nvram_query_folder_index(ldi->category);
+
+            if (i == 0)  // first copy
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+            }
+            else // second copy
+            {
+                nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+
+            #ifdef __NVRAM_BACKUP_DISK_FAT__
+                if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr))
+                {
+                    folder_index = NVRAM_NVD_BAK;
+                }
+            #endif
+            }
+
+            file_size = nvram_drv_fat_get_record_size(nvramname, &Hint, folder_index);
+
+            if (file_size == 0)
+            {
+                // delete empty file
+                nvram_query_file_name(folder_index, nvramname, filename);
+                NVRAM_FS_START_EX(FS_OP_DELETE,filename);
+                result = FS_Delete(filename);
+                NVRAM_FS_END(FS_OP_DELETE,result);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Delete %s result=%d\r\n",__FUNCTION__,nvramname,result);
+            }
+
+            if (file_size > 0) {
+                file_exist = KAL_TRUE;
+                break;
+            }
+            
+            if (!NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+            {
+                break;
+            }
+        }
+
+        if (file_exist == KAL_TRUE) {
+            nvram_util_lid_bimtap_set(nvram_created_file_info.bitmap, lid);
+        }
+    }while(nvram_util_next_data_item(&ldi));
+    nvram_created_file_info.changed = KAL_TRUE;
+    nvram_write_bitmap_into_file();
+    nvram_util_give_mutex(nvram_bitmap_mutex);
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_CONSTRUCT_BITMAP_DONE;
+    }
+    NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"%s <====\r\n",__FUNCTION__);
+    return KAL_TRUE;
+}
+
+
+kal_bool nvram_get_created_file_info()
+{
+    WCHAR *file_path = NULL;
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    kal_uint32 read_len;
+    kal_int32 result = FS_NO_ERROR;
+    nvram_info_file_hdr_struct *hdr = &nvram_created_file_info.hdr;
+    kal_uint8 temp_checksum[MD5_CHECKSUM_LEN];
+    
+
+    file_path = nvram_util_get_info_file_path();
+    NVRAM_FS_START_EX(FS_OP_OPEN,file_path);
+    file_handle = FS_Open(file_path, FS_READ_ONLY|FS_OPEN_NO_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,file_handle);
+    if (file_handle < FS_NO_ERROR) {
+        // file not exist, maybe deleted
+        is_nvram_factory_reset = KAL_TRUE;
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s bitmap file is not exist\r\n",__FUNCTION__);
+        return nvram_util_reconstruct_info_file();
+    }
+    NVRAM_FS_START(FS_OP_READ);
+    result = FS_Read(file_handle, hdr, sizeof(*hdr), &read_len);
+    NVRAM_FS_END(FS_OP_READ,result);
+
+    if (result < FS_NO_ERROR || read_len != sizeof(*hdr)) {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Read result=%d,read_len=%d \r\n",__FUNCTION__,result,read_len);
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(file_handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        return nvram_util_reconstruct_info_file();
+    }
+
+    if (hdr->magic_start != NVRAM_INFO_FILE_MAGIC_START) {
+        // Invalid header
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s bitmap file:Invalid header\r\n",__FUNCTION__);
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(file_handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        return nvram_util_reconstruct_info_file();
+    }
+
+    if (hdr->file_stat != NVRAM_INFO_FILE_STAT_READY) {
+        // File is updating but power lost
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s bitmap file:data is corruption\r\n",__FUNCTION__);
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(file_handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        return nvram_util_reconstruct_info_file();
+    }
+
+    NVRAM_FS_START(FS_OP_READ);
+    result = FS_Read(file_handle, nvram_created_file_info.bitmap, sizeof(nvram_created_file_info.bitmap), &read_len);
+    NVRAM_FS_END(FS_OP_READ,result);
+    if (result < FS_NO_ERROR || read_len != sizeof(nvram_created_file_info.bitmap)) {
+        // Read Error
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s->FS_Read fail,result=%d\r\n",__FUNCTION__,result);
+        NVRAM_FS_START(FS_OP_CLOSE);
+        result = FS_Close(file_handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+        return nvram_util_reconstruct_info_file();
+    }
+    NVRAM_FS_START(FS_OP_CLOSE);
+    result = FS_Close(file_handle);
+    NVRAM_FS_END(FS_OP_CLOSE,result);
+
+    nvram_util_calc_md5_checksum(nvram_created_file_info.bitmap, sizeof(nvram_created_file_info.bitmap), temp_checksum);
+    if (memcmp(nvram_created_file_info.hdr.check_sum, temp_checksum, MD5_CHECKSUM_LEN) != 0) {
+        // checksum check fail
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s bitmap file:checksum error\r\n",__FUNCTION__);
+        return nvram_util_reconstruct_info_file();
+    }
+
+    return KAL_TRUE;
+}
+    
+kal_bool nvram_util_init_info_file()
+{
+    // MUST call once @ nvram_init
+    static kal_bool inited = KAL_FALSE;
+
+    if (!inited) {
+        inited = KAL_TRUE;
+        
+        nvram_bitmap_mutex = kal_create_mutex("NV_INFO");
+        nvram_pre_write_check_mutex = kal_create_mutex("NV_PREW");
+
+        if (nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT) {
+            nvram_utile_reset_lid_bitmap();
+            nvram_write_bitmap_into_file();
+        } else {
+            nvram_get_created_file_info();
+        }
+    }
+    
+    return KAL_TRUE;
+}
+
+#endif
+
+DECLARE_MIPS32 
+static kal_uint16 nvram_data_header_checksum(kal_uint8 *buf, kal_uint32 size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    kal_uint32 i;
+    kal_uint16 chksum = *(kal_uint16*)buf;
+    kal_uint8 *byte_chksum = (kal_uint8*)&chksum;
+    kal_uint8 value;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+    for (i = 0; i < size; i++)
+    {
+        value = *(buf + i);
+        while(value) {
+            if(value & 0x1) {
+            #if defined(__MTK_TARGET__)
+                __asm__ __volatile__
+                (
+                "rol %0, %0, 1\r\n"
+                ::"r"(chksum)
+                );              
+            #else
+                __asm {ROL [chksum],1};
+            #endif
+            }
+            value >>= 1;
+        }
+    #if defined(__MTK_TARGET__)
+        __asm__ __volatile__
+        (
+        "rol %0, %0, 4\r\n"
+        ::"r"(chksum)
+        );              
+    #else
+        __asm {ROL [chksum],4};
+    #endif
+
+        *byte_chksum += *(buf + i);
+    }
+    
+    return chksum;
+}
+
+kal_uint32 nvram_appendix_header_offset(nvram_ltable_entry_struct *ldi)
+{
+    kal_uint32 size = 0;
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    if ((ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+        #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+        || (ldi->attr & NVRAM_ATTR_MSP)
+        #endif
+    )
+    {
+        /* 16 byte alignment */ 
+        size = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_chksum_size) + ldi->size + nvram_chksum_size;
+    }
+    else 
+    {
+        size = (ldi->size + nvram_chksum_size);
+    }
+    size = size * ldi->total_records;
+    return (NVRAM_LDI_HEADER_SIZE + size);
+}
+
+static __inline kal_bool nvram_prepare_ota_header(nvram_ldi_ota_header *ldi_ota_header, nvram_ltable_entry_struct *ldi)
+{
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    kal_int32 chksum_index;
+    #endif
+
+    memcpy(ldi_ota_header->header, "LDI", 4);
+    ldi_ota_header->LID = ldi->LID;
+    ldi_ota_header->ldi_attr = ldi->attr;
+    ldi_ota_header->ldi_category= ldi->category;
+    ldi_ota_header->record_size = ldi->size;
+    ldi_ota_header->total_records = ldi->total_records;
+    //check appendix header offset
+    if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE) {
+        ldi->append_offset = nvram_appendix_header_offset(ldi);
+    }
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    chksum_index = nvram_get_defval_chksum_index(ldi->LID);
+    if(-1 != chksum_index)
+    {
+        kal_mem_cpy((char *)(ldi_ota_header->defval_chkrst_h), (const char*)(lid_default_value_chksum[chksum_index].chksum), RST_CHKSUM_SIZE-6);
+    }    
+    #endif
+    ldi_ota_header->checksum = nvram_data_header_checksum((kal_uint8*)ldi_ota_header, (NVRAM_LDI_OTA_HEADER_SIZE - sizeof(ldi_ota_header->checksum)));
+    return KAL_TRUE;
+}
+
+static __inline kal_bool nvram_prepare_debug_header(nvram_ldi_debug_header *ldi_debug_header, nvram_ltable_entry_struct *ldi)
+{
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    kal_int32 chksum_index;
+    #endif
+
+    ldi_debug_header->last_write_taskID = kal_get_current_task_index();
+    ldi_debug_header->last_write_time = kal_get_systicks();
+    ldi_debug_header->write_times += 1;
+    
+    #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__)
+    chksum_index = nvram_get_structure_chksum_index(ldi->LID);
+    if(-1 != chksum_index)
+    {
+        kal_mem_cpy((char *)(ldi_debug_header->struct_chkrst), (const char*)(lid_structure_chksum[chksum_index].chksum), RST_CHKSUM_SIZE);
+    }
+    #endif
+
+    #if defined(__NVRAM_DEFVAL_CHANGE_RESET__)
+    chksum_index = nvram_get_defval_chksum_index(ldi->LID);
+    if(-1 != chksum_index)
+    {
+        kal_mem_cpy((char *)(ldi_debug_header->defval_chkrst_l),(const char*)(&(lid_default_value_chksum[chksum_index].chksum[RST_CHKSUM_SIZE-6])), 6);
+    }    
+    #endif
+
+    return KAL_TRUE;
+}
+
+kal_bool nvram_prepare_data_header(nvram_ltable_entry_struct *ldi,kal_uint8 *ldi_hd_buffer)
+{
+    nvram_ldi_ota_header *ldi_ota_header = (nvram_ldi_ota_header*)ldi_hd_buffer;
+    nvram_ldi_debug_header *ldi_debug_header = (nvram_ldi_debug_header*)(ldi_hd_buffer + NVRAM_LDI_OTA_HEADER_SIZE);
+
+    nvram_prepare_ota_header(ldi_ota_header,ldi);
+    nvram_prepare_debug_header(ldi_debug_header, ldi);
+
+    return KAL_TRUE;
+}
+
+/* =====================================================================
+APDX_hdr1  chksum   type   data_offset1
+APDX_hdr2  chksum   type   data_offset2
+data1 ......
+data2 ......
+
+ * FUNCTION
+ *  nvram_prepare_appendix_header
+ * DESCRIPTION
+ *  This function is used to read the checksum of data item for external module.
+ *  Please must check with NVRAM owner before you use this API.
+ * PARAMETERS
+ *  type:            [IN]   header type
+ *  ldi_append_header: [IN]  header buffer
+ *  ldi:             [IN]   NVRAM LID
+ *  data_offset:     [IN]   current APDX data offset
+ * RETURNS
+ *  the next APDX data start offset
+=======================================================================*/
+kal_uint32 nvram_prepare_appendix_header(nvram_appendix_type_enum type, nvram_ldi_appendix_header *ldi_append_header, nvram_ltable_entry_struct *ldi, kal_uint32 data_offset)
+{
+    kal_uint32 nvram_chksum_size = 0;
+    nvram_lid_chksum_info lid_chksum_info = {0};
+
+    nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE);
+    nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length;
+
+    memset(ldi_append_header, 0, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+    memcpy(ldi_append_header->header, "APDX", 4);
+    
+    if(type == NVRAM_APPEND_TYPE_CHKSUM) {
+        ldi_append_header->type = NVRAM_APPEND_TYPE_CHKSUM;
+        ldi_append_header->data_offset = data_offset;
+        //caculate next data start
+        data_offset = (data_offset + (ldi->total_records * nvram_chksum_size));
+        data_offset = NVRAM_MSP_ALIGNMENT_CEILING(data_offset);
+    }
+    else {
+        ldi_append_header->type = NVRAM_APPEND_TYPE_END;
+        data_offset = 0;
+    }
+    ldi_append_header->checksum = nvram_data_header_checksum((kal_uint8*)ldi_append_header, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+    return data_offset;
+}
+
+kal_bool nvram_write_data_header(nvram_ltable_entry_struct *ldi, nvram_header_section_enum section)
+{
+
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    kal_int32 result = FS_NO_ERROR;
+    kal_int32 backup_file_num = 1;
+    kal_bool mulpiple = KAL_FALSE;
+    kal_bool ret_val = KAL_TRUE;
+    nvram_ldi_header nv_header;
+    nvram_ldi_appendix_header nv_appendix_header;
+    nvram_ldi_ota_header *ldi_ota_header = &(nv_header.nv_ota_header);
+    nvram_ldi_debug_header *ldi_debug_header = &(nv_header.nv_dbg_header);
+    nvram_ldi_appendix_header *ldi_append_header = &nv_appendix_header;
+    kal_uint32 ldi_hd_buffer_size = 0;
+    kal_uint32 ldi_hd_offset = 0;
+    kal_uint32 ldi_checksum_hd_offset = 0;
+    #ifdef __NVRAM_LID_CACHE__
+    kal_uint32 cache_offset = 0;
+    kal_uint32 openOption = FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE;
+    #endif
+
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_WRITE_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+
+    kal_mem_set(&nv_header, 0x0, sizeof(nv_header));
+    kal_mem_set(&nv_appendix_header, 0x0, sizeof(nv_appendix_header));
+    
+    if(NVRAM_IS_ATTR_MULTIPLE(ldi->attr) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+    {
+        mulpiple = KAL_TRUE;
+        backup_file_num = 2;
+    }
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, filename);
+    
+    if(section == LDI_HEADER_ALL_SECTION) {
+        nvram_prepare_ota_header(ldi_ota_header,ldi);
+        nvram_prepare_debug_header(ldi_debug_header,ldi);
+        if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE){
+            nvram_prepare_appendix_header(NVRAM_APPEND_TYPE_CHKSUM, ldi_append_header, ldi, NVRAM_LDI_APPENDIX_HEADER_SIZE);
+        }
+        ldi_hd_buffer_size = NVRAM_LDI_OTA_HEADER_SIZE + NVRAM_LDI_DEBUG_HEADER_SIZE;
+    }
+    else
+    {
+        if(NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) {
+            //CALIBRATION and IMPT_L4 need update debug section
+        }
+        else {
+            return KAL_FALSE;
+        }
+        nvram_util_take_mutex(g_nvram_fs_mutex);
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start); //start timer
+        #endif
+        nvram_read_data_header(filename, LDI_HEADER_ALL_SECTION, (void*)&nv_header, NVRAM_LDI_HEADER_SIZE);
+        #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+        #endif
+        nvram_util_give_mutex(g_nvram_fs_mutex);        
+    }
+    if(section == LDI_HEADER_DBG_SECTION)
+    {
+        if(NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) {
+            //CALIBRATION and IMPT_L4 need update debug section
+        }
+        else {
+            return KAL_FALSE;
+        }
+        nvram_prepare_debug_header(ldi_debug_header,ldi);
+        ldi_hd_offset = NVRAM_LDI_OTA_HEADER_SIZE;
+        ldi_hd_buffer_size = NVRAM_LDI_DEBUG_HEADER_SIZE;        
+    }
+    else if(section == LDI_HEADER_OTA_SECTION)
+    {
+        nvram_prepare_ota_header(ldi_ota_header,ldi);
+        ldi_hd_offset = 0;
+        ldi_hd_buffer_size = NVRAM_LDI_OTA_HEADER_SIZE;
+    }
+    
+    nvram_util_take_mutex(g_nvram_fs_mutex);
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start); //start timer
+    #endif
+    
+    do{
+        #ifdef __NVRAM_LID_CACHE__
+        if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_WITH_CACHE(ldi->LID))
+        {
+            if(NVRAM_IO_ERRNO_OK != (result = get_lid_cache_base_address(ldi, &cache_offset))) {                
+                ret_val = KAL_FALSE;
+                break;
+            }
+            if(NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, (void *)(&nv_header), NVRAM_LDI_HEADER_SIZE, cache_offset))){
+                kal_prompt_trace(MOD_NVRAM, "NVRAM write header write fail:0x%x\n\r", result);
+                kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                kal_prompt_trace(MOD_NVRAM, "section:%d,cache_offset:%d\n\r", section,cache_offset);
+                
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM write header at %d write fail:%d\n\r", __LINE__,result);
+                if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "section:%d,cache_offset:%d\r\n", section,cache_offset);
+                    NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_WRITE_HEADER_FAIL, ldi->LID);
+                }
+                ret_val = KAL_FALSE;
+                break;
+            }
+            if(section == LDI_HEADER_ALL_SECTION)
+            {
+                set_reset_flag_by_ltable_entry(ldi);
+            }
+             mask_dirty_bit_by_ltable_entry(ldi, 0, 1);   
+             mask_valid_bit_by_ltable_entry(ldi, 0, 1);
+             
+            //write appendix header
+            ldi_checksum_hd_offset = nvram_appendix_header_offset(ldi);
+            if((section == LDI_HEADER_ALL_SECTION) && (ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)) {                
+                cache_offset = cache_offset + ldi_checksum_hd_offset;
+                if (NVRAM_IO_ERRNO_OK != (result = nvram_write_data_to_cache(ldi, (void *)ldi_append_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, cache_offset))) {
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM appendix header write fail:0x%x\n\r", result);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);                
+                    kal_prompt_trace(MOD_NVRAM, "cache_offset:%d\r\n",cache_offset);
+
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM appendix header at %d write fail :%d\n\r", __LINE__,result);
+                    if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {                        
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "cache_offset:%d\r\n",cache_offset);
+                        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_WRITE_HEADER_FAIL, ldi->LID);
+                    }
+                    ret_val = KAL_FALSE;
+                    break;
+                }
+        
+            }
+            nvram_cache_enqueue(ldi, 0, 1, openOption);
+            send_event_to_nvram_cache();
+        }
+        else
+        #endif
+        {
+            NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+            file_handle = FS_Open(filename, FS_READ_WRITE | FS_OPEN_NO_DIR | FS_CREATE);
+            NVRAM_FS_END(FS_OP_OPEN,file_handle);
+            if (file_handle < FS_NO_ERROR) {
+                kal_prompt_trace(MOD_NVRAM, "NVRAM write header open fail:0x%x\n\r", file_handle);
+                kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+                
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM write header at %d open fail:%d\n\r", __LINE__,result);
+                if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "section:%d\r\n",section);
+                    NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_4, ldi->LID);
+                }
+                ret_val = KAL_FALSE;
+            }
+            if(ldi_hd_offset && (file_handle > FS_NO_ERROR)) {
+                NVRAM_FS_START(FS_OP_SEEK);
+                result = FS_Seek(file_handle, ldi_hd_offset, FS_FILE_BEGIN);
+                NVRAM_FS_END(FS_OP_SEEK,result);
+            }
+
+            if (file_handle > FS_NO_ERROR){
+                NVRAM_FS_START(FS_OP_WRITE);
+                result = FS_Write(file_handle, (void *)(((kal_uint32)(&nv_header)) + ldi_hd_offset), ldi_hd_buffer_size, &ldi_hd_buffer_size);
+                NVRAM_FS_END(FS_OP_WRITE,result);
+                if (result < FS_NO_ERROR){
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM write header write fail:0x%x\n\r", result);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                    kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM write header at %d write fail:%d\n\r", __LINE__,result);
+                    if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                        NVRAM_FS_START(FS_OP_CLOSE);
+                        result = FS_Close(file_handle);
+                        NVRAM_FS_END(FS_OP_CLOSE,result);                        
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "section:%d\r\n",section);
+                        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_OPEN_NV_FOLDER_FAIL_5, ldi->LID, result);
+                    }
+                    ret_val = KAL_FALSE;
+                }
+                #ifdef __NVRAM_LID_CACHE__
+                else
+                {
+                    if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                    {
+                        get_lid_cache_base_address(ldi, &cache_offset);
+                        nvram_write_data_to_cache(ldi, (void *)(&nv_header), NVRAM_LDI_HEADER_SIZE, cache_offset);
+                        mask_valid_bit_by_ltable_entry(ldi, 0, 1);
+                    }
+                }
+                #endif
+            }
+            
+            //write appendix header
+            ldi_checksum_hd_offset = nvram_appendix_header_offset(ldi);
+            if((section == LDI_HEADER_ALL_SECTION) && (ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)) {
+                if(file_handle > FS_NO_ERROR){
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Seek(file_handle, ldi_checksum_hd_offset, FS_FILE_BEGIN);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                    NVRAM_FS_START(FS_OP_WRITE);
+                    result = FS_Write(file_handle, ldi_append_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, &ldi_hd_buffer_size);
+                    NVRAM_FS_END(FS_OP_WRITE,result);
+                }
+                if ((file_handle > FS_NO_ERROR) &&(result < FS_NO_ERROR)) {
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM appendix header write fail:0x%x\n\r", result);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "[Error]NVRAM appendix header at %d write fail:%d\n\r", __LINE__,result);
+                    if(NVRAM_IS_ATTR_FAULT_ASSERT(ldi->attr)) {
+                        NVRAM_FS_START(FS_OP_CLOSE);
+                        result = FS_Close(file_handle);
+                        NVRAM_FS_END(FS_OP_CLOSE,result);                        
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "LID:0x%04X, total_records:%d, record_size:%d\r\n", ldi->LID, ldi->total_records, ldi->size);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP, "fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                        NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)file_handle, NVRAM_LOC_WRITE_FILE_FAIL_4, ldi->LID, result);
+                    }
+                    ret_val = KAL_FALSE;
+                }
+                #ifdef __NVRAM_LID_CACHE__
+                else
+                {
+                    if((!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_WR_2_FILE_WITH_2_CACHE(ldi->LID))
+                    {
+                        get_lid_cache_base_address(ldi, &cache_offset);
+                        cache_offset = cache_offset + ldi_checksum_hd_offset;
+                        nvram_write_data_to_cache(ldi, ldi_append_header, NVRAM_LDI_APPENDIX_HEADER_SIZE, cache_offset);
+                        
+                    }
+                }
+                #endif
+                
+            }            
+            if(file_handle > FS_NO_ERROR) {
+                NVRAM_FS_START(FS_OP_CLOSE);
+                result = FS_Close(file_handle);
+                NVRAM_FS_END(FS_OP_CLOSE,result);
+            }
+        }  
+        backup_file_num --;
+        #if defined(__NVRAM_WRITE_PROTECT_ENABLE__)
+        if (NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) {
+            // Don't write protect2
+            break;
+        }
+        #endif
+        if(!mulpiple)
+        {
+          break;
+        }
+        nvram_folder = nvram_query_folder_index_ex(ldi->category,KAL_FALSE);
+        nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+        nvram_query_file_name(nvram_folder, nvramname, filename);
+                
+    }while(backup_file_num > 0);
+    
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+        
+    nvram_util_give_mutex(g_nvram_fs_mutex);
+    return ret_val;
+}   
+
+kal_bool nvram_read_data_header(const kal_wchar *filename, nvram_header_section_enum section, void* buffer, kal_uint32 buffer_size)
+{
+    kal_char s_filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    kal_int32 result = FS_NO_ERROR;
+    kal_bool ret_val = KAL_TRUE;
+
+    kal_uint32 ldi_hd_buffer_size = 0;
+    kal_uint32 ldi_hd_buffer_data_size = 0;
+    kal_uint32 ldi_hd_offset = 0;
+    nvram_ldi_ota_header *ldi_ota_header;
+
+    #ifdef __NVRAM_LID_CACHE__
+    nvram_ldi_appendix_header nv_appendix_header;
+    nvram_ldi_appendix_header *ldi_append_header = &nv_appendix_header;
+    kal_uint32 ldi_checksum_hd_offset = 0;
+    kal_uint32 ldi_checksum_hd_buffer_size = NVRAM_LDI_APPENDIX_HEADER_SIZE;
+    kal_uint32 ldi_checksum_hd_data_size = 0;
+    kal_uint32 cache_offset = 0;
+    kal_wchar wcfilename[NVRAM_FILE_LEN + 1];
+    kal_char cfilename[NVRAM_FILE_LEN + 1];
+    
+    nvram_ltable_entry_struct *ldi = NULL;
+    #endif
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    SGPT_CTRL_START_T start;
+    #endif
+
+    if(section == LDI_HEADER_OTA_SECTION) {
+        //ldi_hd_offset = 0;
+        ldi_hd_buffer_size += NVRAM_LDI_OTA_HEADER_SIZE;
+    }
+    else if(section == LDI_HEADER_DBG_SECTION) {
+        ldi_hd_offset = NVRAM_LDI_OTA_HEADER_SIZE;
+        ldi_hd_buffer_size += NVRAM_LDI_DEBUG_HEADER_SIZE;
+    }
+    else if(section == LDI_HEADER_ALL_SECTION) {
+        //ldi_hd_offset = 0;
+        ldi_hd_buffer_size += (NVRAM_LDI_OTA_HEADER_SIZE + NVRAM_LDI_DEBUG_HEADER_SIZE);
+    }
+    else {
+        kal_prompt_trace(MOD_NVRAM, "nvram_read_data_header:section 0x%x is wrong\n\r", section);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s section 0x%x is wrong\r\n",__FUNCTION__,section);
+        return KAL_FALSE;
+    }
+
+
+    if(!buffer || (buffer_size < ldi_hd_buffer_size)) {
+        return KAL_FALSE;
+    }
+    
+    /* NVRAM GPT timeout assert start timer */
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    start.u2Tick= NVRAM_READ_GPT_TIMEOUT;
+    start.pfCallback=nvram_gpt_timeout_callback;
+    start.vPara=NULL;
+    #endif
+    
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+    DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_START, (DCL_CTRL_DATA_T*)&start); //start timer
+    #endif
+
+    #ifdef __NVRAM_LID_CACHE__    
+    kal_mem_set(cfilename,0,NVRAM_FILE_LEN + 1);
+    kal_mem_set(wcfilename,0,(NVRAM_FILE_LEN + 1)*sizeof(kal_wchar));
+    nvram_query_file_name_by_path((kal_wchar *)filename, wcfilename);
+    kal_dchar2char((WCHAR *)wcfilename, cfilename);
+   
+    nvram_util_get_data_item_by_fileprefix(&ldi, cfilename);
+    
+    if(ldi == NULL)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s Can't find the LID entry at %d,cfilename:%s\r\n",__FUNCTION__,__LINE__,cfilename);
+        if(nvram_ptr->state == NVRAM_STATE_READY)
+        {
+            kal_prompt_trace(MOD_NVRAM, "cfilename:%s\n\r", cfilename);
+            kal_prompt_trace(MOD_NVRAM, "Can not find the LID entry in the LID table:\n\r");            
+            NVRAM_EXT_ASSERT(KAL_FALSE,0 , NVRAM_LOC_LID_PTR_IS_NULL_4, ldi);
+        }else
+        {
+            kal_prompt_trace(MOD_NVRAM, "cfilename:%s\n\r", cfilename);
+            goto non_cache_read;
+        }
+    }
+    if(NVRAM_RD_WITH_CACHE(ldi->LID))
+    {
+        if((!(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))) && (check_valid_bit_by_ltable_entry(ldi, 0) || check_dirty_bit_by_ltable_entry(ldi, 0)))
+        {
+            do{
+                get_lid_cache_base_address(ldi, &cache_offset);
+                cache_offset = cache_offset + ldi_hd_offset;
+                if ((result = nvram_read_header_from_cache(ldi, buffer, ldi_hd_buffer_size, cache_offset)) != KAL_TRUE) {
+                    kal_dchar2char((WCHAR *)filename, s_filename);
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM read header read fail: 0x%x\n\r", result);
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                    kal_prompt_trace(MOD_NVRAM, "filename:%s\n\r", s_filename);
+                    kal_prompt_trace(MOD_NVRAM, "section:%d,cache_offset:%d\n\r", section,cache_offset);
+
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM read header at %d read fail:%d\r\n", __LINE__,result);
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"filename:%s\r\n", s_filename);
+                    NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"section:%d,cache_offset:%d\r\n", section,cache_offset);
+                    ret_val = KAL_FALSE;
+                    break;
+                }
+            }while(0);
+        }else
+        {
+            goto non_cache_read;
+        }
+    }else
+    #endif
+    {
+    #ifdef __NVRAM_LID_CACHE__
+    non_cache_read:
+    #endif
+        #if 0// (defined(__NVRAM_FS_OPERATION_COMPACT__) && defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_FS_CMPT_SIMULATION__)
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+        #else
+        NVRAM_FS_START_EX(FS_OP_OPEN,filename);
+        file_handle = FS_Open(filename, FS_READ_ONLY | FS_OPEN_SHARED |FS_OPEN_NO_DIR);
+        NVRAM_FS_END(FS_OP_OPEN,file_handle);
+        if (file_handle < FS_NO_ERROR) {
+            kal_dchar2char((WCHAR *)filename, s_filename);
+            kal_prompt_trace(MOD_NVRAM, "NVRAM read header open fail:0x%x\n\r", file_handle);
+            kal_prompt_trace(MOD_NVRAM, "filename:%s\n\r", s_filename);
+            kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM read header at %d open fail:%d\r\n", __LINE__,file_handle);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"filename:%s\r\n", s_filename);
+            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"section:%d\r\n", section);
+            ret_val = KAL_FALSE;
+        }
+        if(ldi_hd_offset && (file_handle > FS_NO_ERROR)) {
+            NVRAM_FS_START(FS_OP_SEEK);
+            result = FS_Seek(file_handle, ldi_hd_offset, FS_FILE_BEGIN);
+            NVRAM_FS_END(FS_OP_SEEK,result);
+        }           
+
+        if (file_handle > FS_NO_ERROR) {
+            NVRAM_FS_START(FS_OP_READ);
+            result = FS_Read(file_handle, buffer, ldi_hd_buffer_size, &ldi_hd_buffer_data_size);
+            NVRAM_FS_END(FS_OP_READ,result);
+            if((result < FS_NO_ERROR) || (ldi_hd_buffer_size != ldi_hd_buffer_data_size)){    
+                kal_dchar2char((WCHAR *)filename, s_filename);
+                kal_prompt_trace(MOD_NVRAM, "NVRAM read header read fail:0x%x, 0x%x\n\r", file_handle, result);
+                kal_prompt_trace(MOD_NVRAM, "filename:%s\n\r", s_filename);
+                kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM read header at %d read fail:%d\r\n", __LINE__,result);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"filename:%s\r\n", s_filename);
+                NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"section:%d\r\n", section);
+                ret_val = KAL_FALSE;
+            }
+        }
+        if(file_handle > FS_NO_ERROR) {
+            NVRAM_FS_START(FS_OP_CLOSE);
+            result = FS_Close(file_handle);
+            NVRAM_FS_END(FS_OP_CLOSE,result);
+        }
+        #endif
+
+        #ifdef __NVRAM_LID_CACHE__
+        if((ldi != NULL) && (!NVRAM_IS_ATTR_RAW_DATA(ldi->attr)) && NVRAM_RD_WITH_CACHE(ldi->LID))
+        {
+            if(ret_val == KAL_TRUE)
+            {
+                update_cache_header(ldi, buffer, ldi_hd_offset, ldi_hd_buffer_size);
+                mask_valid_bit_by_ltable_entry(ldi, 0, 1);
+
+                //read appendix header
+                if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+                {
+                    ldi_checksum_hd_offset = nvram_appendix_header_offset(ldi);
+                    NVRAM_FS_START_EX(FS_OP_OPEN, filename);
+                    file_handle = FS_Open(filename, FS_READ_ONLY | FS_OPEN_SHARED |FS_OPEN_NO_DIR);
+                    NVRAM_FS_END(FS_OP_OPEN,file_handle);
+
+                    if (file_handle < FS_NO_ERROR) {
+                        kal_dchar2char((WCHAR *)filename, s_filename);
+                        kal_prompt_trace(MOD_NVRAM, "NVRAM read header open fail:0x%x\n\r", file_handle);
+                        kal_prompt_trace(MOD_NVRAM, "filename:%s\n\r", s_filename);
+                        kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM read header at %d open fail:%d\r\n", __LINE__,file_handle);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"filename:%s\r\n", s_filename);
+                        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"section:%d\r\n", section);
+                        ret_val = KAL_FALSE;
+                    }
+
+                    if(file_handle > FS_NO_ERROR)
+                    {
+                        NVRAM_FS_START(FS_OP_SEEK);
+                        result = FS_Seek(file_handle, ldi_checksum_hd_offset, FS_FILE_BEGIN);
+                        NVRAM_FS_END(FS_OP_SEEK,result);
+                    }
+
+                    if (file_handle > FS_NO_ERROR) {
+                        NVRAM_FS_START(FS_OP_READ);
+                        result = FS_Read(file_handle, ldi_append_header, ldi_checksum_hd_buffer_size, &ldi_checksum_hd_data_size);
+                        NVRAM_FS_END(FS_OP_READ,result);
+                        if( (result < FS_NO_ERROR) || (ldi_checksum_hd_buffer_size != ldi_checksum_hd_data_size)){
+                            kal_dchar2char((WCHAR *)filename, s_filename);
+                            kal_prompt_trace(MOD_NVRAM, "NVRAM read header read fail:0x%x, 0x%x\n\r", file_handle, result);
+                            kal_prompt_trace(MOD_NVRAM, "filename:%s\n\r", s_filename);
+                            kal_prompt_trace(MOD_NVRAM, "section:%d\n\r", section);
+
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM read header at %d read fail:%d\r\n", __LINE__,result);
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"filename:%s\r\n", s_filename);
+                            NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"section:%d\r\n", section);
+                            ret_val = KAL_FALSE;
+                        }
+                    }
+
+                    if(file_handle > FS_NO_ERROR)
+                    {
+                        NVRAM_FS_START(FS_OP_CLOSE);
+                        kal_int32 fs_result = FS_Close(file_handle);
+                        NVRAM_FS_END(FS_OP_CLOSE,fs_result);
+                    }
+                    if(ret_val)
+                    {
+                        update_cache_header(ldi, ldi_append_header, ldi_checksum_hd_offset, ldi_checksum_hd_buffer_size);
+                    }
+                }
+            }
+        }
+        #endif
+    }
+
+    #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__)
+        DclSGPT_Control(nvram_gpt_handle, SGPT_CMD_STOP, (DCL_CTRL_DATA_T*)NULL);   //stop timer
+    #endif
+
+    if((is_nvram_in_ota_flow != KAL_TRUE) && (ret_val != KAL_FALSE) && (section & LDI_HEADER_OTA_SECTION)) {
+        ldi_ota_header = (nvram_ldi_ota_header*)buffer;
+        ldi_hd_offset = nvram_data_header_checksum((kal_uint8*)ldi_ota_header, (NVRAM_LDI_OTA_HEADER_SIZE - sizeof(ldi_ota_header->checksum)));
+        if((ldi_ota_header->checksum != ldi_hd_offset) ||
+           memcmp(ldi_ota_header->header, "LDI", 4)) {
+            ret_val = KAL_FALSE;
+        }
+    }
+
+    return ret_val;
+}
+
+#ifdef __NVRAM_LID_CACHE__
+kal_bool nvram_cache_read_ota_header(const kal_wchar *filename, FS_HANDLE hFile, void* buffer, kal_uint32 buffer_size)
+{
+    kal_uint32 len;
+    nvram_ldi_ota_header *ldi_ota_header;
+    nvram_ldi_header nv_header;
+    kal_uint16 checksum;
+    kal_uint32 cache_offset;    
+    kal_wchar wcfilename[NVRAM_FILE_LEN + 1];
+    kal_char cfilename[NVRAM_FILE_LEN + 1];
+    nvram_ltable_entry_struct *ldi = NULL;
+    kal_int32 result = FS_NO_ERROR;
+    kal_bool ret_val = KAL_TRUE;
+	kal_int32 ret = FS_NO_ERROR;
+
+    kal_mem_set(cfilename,0,NVRAM_FILE_LEN + 1);
+    kal_mem_set(wcfilename,0,(NVRAM_FILE_LEN + 1)*sizeof(kal_wchar));
+        
+    nvram_query_file_name_by_path((kal_wchar *)filename, wcfilename);
+    kal_dchar2char((WCHAR *)wcfilename, cfilename);
+    nvram_util_get_data_item_by_fileprefix(&ldi, cfilename);
+    if(ldi == NULL)
+    {
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s Can not find the LID entry at %d,cfilename:%s\r\n",__FUNCTION__,__LINE__,cfilename);
+        if(nvram_ptr->state == NVRAM_STATE_READY)
+        {
+            kal_prompt_trace(MOD_NVRAM, "cfilename:%s\n\r", cfilename);
+            kal_prompt_trace(MOD_NVRAM, "Can not find the LID entry in the LID table:\n\r");
+            NVRAM_EXT_ASSERT(KAL_FALSE,0 , NVRAM_LOC_LID_PTR_IS_NULL_5, ldi);
+        }
+        else
+        {
+            kal_prompt_trace(MOD_NVRAM, "cfilename:%s\n\r", cfilename);
+            goto ota_non_cache;
+        }
+    }
+    if(NVRAM_RD_WITH_CACHE(ldi->LID))
+    {
+        if((!(NVRAM_IS_ATTR_RAW_DATA(ldi->attr))) && (check_valid_bit_by_ltable_entry(ldi, 0) || check_dirty_bit_by_ltable_entry(ldi, 0)))
+        {
+            do{
+                if(NVRAM_IO_ERRNO_OK != (result = get_lid_cache_base_address(ldi, &cache_offset))) {                
+                    ret_val = KAL_FALSE;
+                    break;
+                }
+
+                if ((result = nvram_read_header_from_cache(ldi, buffer, buffer_size, cache_offset)) != KAL_TRUE) {
+                    kal_prompt_trace(MOD_NVRAM, "NVRAM read header read fail:0x%x\n\r", result);            
+                    kal_prompt_trace(MOD_NVRAM, "category:0x%x, attr:0x%x\n\r", ldi->category, ldi->attr);
+                    kal_prompt_trace(MOD_NVRAM, "fileprefix:%s, fileverno:%s\n\r", ldi->fileprefix, ldi->fileverno);
+                    kal_prompt_trace(MOD_NVRAM, "filename:%s\n\r", cfilename);
+                    
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]NVRAM read header at %d read fail:%d\r\n", __LINE__,result);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"category:0x%08X, attr:0x%08X\r\n", ldi->category, ldi->attr);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"fileprefix:%s, fileverno:%s\r\n", ldi->fileprefix, ldi->fileverno);
+                    NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"filename:%s\r\n", cfilename);
+                    ret_val = KAL_FALSE;
+                    break;
+                }
+            }while(0);
+        }else
+        {
+            goto ota_non_cache;
+        }
+    }else
+    {
+        ota_non_cache:
+        kal_mem_set(&nv_header, 0x0, sizeof(nv_header));
+        NVRAM_FS_START(FS_OP_SEEK);
+        ret = FS_Seek(hFile, 0x0, FS_FILE_BEGIN);
+        NVRAM_FS_END(FS_OP_SEEK,ret);
+        NVRAM_FS_START(FS_OP_READ); 
+        result = FS_Read(hFile, (void *)(&nv_header), NVRAM_LDI_HEADER_SIZE, &len);
+        NVRAM_FS_END(FS_OP_READ,result);
+        if((result >= FS_NO_ERROR) && (len == NVRAM_LDI_HEADER_SIZE))
+        {
+            kal_mem_cpy((char *)buffer, (char *)(&nv_header), buffer_size);
+            ret_val = KAL_TRUE;
+        }
+
+        if((ldi != NULL) && NVRAM_RD_WITH_CACHE(ldi->LID))
+      {
+        if(ret_val == KAL_TRUE)
+        {
+            update_cache_header(ldi, (void *)(&nv_header), 0, NVRAM_LDI_HEADER_SIZE);
+            mask_valid_bit_by_ltable_entry(ldi, 0, 1);
+        }
+      }
+
+    }
+
+    ldi_ota_header = (nvram_ldi_ota_header*)buffer;
+    checksum = nvram_data_header_checksum((kal_uint8*)ldi_ota_header, (NVRAM_LDI_OTA_HEADER_SIZE - sizeof(ldi_ota_header->checksum)));
+    if((ldi_ota_header->checksum != checksum) ||
+       memcmp(ldi_ota_header->header, "LDI", 4)) {
+        return KAL_FALSE;
+    }
+
+    return ret_val;
+}
+#endif
+
+kal_bool nvram_read_ota_header(FS_HANDLE hFile, void* buffer, kal_uint32 buffer_size)
+{
+    kal_uint32 len;
+    nvram_ldi_ota_header *ldi_ota_header;
+    kal_uint16 checksum;
+    kal_int32 fs_result = FS_NO_ERROR;
+    
+    NVRAM_FS_START(FS_OP_SEEK);
+    fs_result = FS_Seek(hFile, 0x0, FS_FILE_BEGIN);
+    NVRAM_FS_END(FS_OP_SEEK,fs_result);
+    NVRAM_FS_START(FS_OP_READ);
+    fs_result = FS_Read(hFile, buffer, buffer_size, &len);
+    NVRAM_FS_END(FS_OP_READ,fs_result);
+    ldi_ota_header = (nvram_ldi_ota_header*)buffer;
+    checksum = nvram_data_header_checksum((kal_uint8*)ldi_ota_header, (NVRAM_LDI_OTA_HEADER_SIZE - sizeof(ldi_ota_header->checksum)));
+    if((ldi_ota_header->checksum != checksum) ||
+       memcmp(ldi_ota_header->header, "LDI", 4)) {
+        return KAL_FALSE;
+    }
+    return KAL_TRUE;
+}
+
+
+static kal_uint32 nvram_ota_wstrtol(kal_wchar *wstr, kal_uint8 length)
+{
+    kal_uint32 ret = 0;
+    kal_char c;
+
+    for(;length > 0; length--, wstr++) {
+        ret <<= 4;
+        c = (kal_char)*wstr;
+        if(c >= '0' && c <= '9') {
+            c -= '0';
+        }
+        else if(c >= 'a' && c <= 'f') {
+            c -= 'a';
+            c += 10;
+        }
+        else if(c >= 'A' && c <= 'F') {
+            c -= 'A';
+            c += 10;
+        }
+        else {
+            return 0;
+        }
+        ret += (kal_uint8)c;
+    }
+    return ret;
+}
+
+static void nvram_ota_convert_filename(kal_wchar *filename, kal_uint16 *verno, kal_uint32 *size)
+{
+    NVRAM_OTA_FILE_NAME *ota_file = (NVRAM_OTA_FILE_NAME*)filename;
+
+    *verno = nvram_ota_wstrtol(ota_file->fileverno, FILE_VERNO_LEN);
+    *size = nvram_ota_wstrtol(ota_file->record, 8);
+}
+static kal_uint8 nvram_ota_search_overdue_file(NVRAM_FULL_PATH *filenameArry, kal_wchar *filename)
+{
+    kal_uint8 i, ret = 0;
+    kal_uint16 verno[NVRAM_OTA_RESERVE_CNT];
+    kal_uint32 size[NVRAM_OTA_RESERVE_CNT];
+    kal_wchar *s_filename = filename;
+    kal_uint16 val_v;
+    kal_uint32 val_s;
+
+    // remove path
+    filename = kal_wstrrchr(s_filename, '\\');
+    if(filename)
+        filename++;
+
+    // find same filename
+    for(i=0; i<NVRAM_OTA_RESERVE_CNT; i++) {
+        if(!kal_wstrcmp(filenameArry[i], filename)) {
+            return i;
+        }
+        nvram_ota_convert_filename(filenameArry[i], &verno[i], &size[i]);
+    }
+
+    // find the oldest verno
+    val_v = 0xFFFF;
+    for(i=0; i<NVRAM_OTA_RESERVE_CNT; i++) {
+        if(verno[i] < val_v) {
+            val_v = verno[i];
+            ret = i;
+        }
+    }
+
+    // find the smallest record & size
+    val_s = 0xFFFFFFFF;
+    for(i=0; i<NVRAM_OTA_RESERVE_CNT; i++) {
+        if((verno[i] == val_v) && (size[i] < val_s)) {
+            val_s = size[i];
+            ret = i;
+        }
+    }
+
+    return ret;
+}
+
+kal_bool nvram_ota_backup_file(const kal_wchar *s_filename, nvram_ldi_ota_header *ldi_ota_header)
+{
+    NVRAM_FULL_PATH d_filename;
+    NVRAM_FULL_PATH f_filename;
+    kal_wchar *filename;
+    NVRAM_FULL_PATH filenameArry[NVRAM_OTA_RESERVE_CNT];
+    FS_HANDLE handle;
+    FS_DOSDirEntry fileinfo;
+    kal_uint8 cnt = 0;
+    kal_int32 result = FS_NO_ERROR;
+    // create destination filename
+    filename = kal_wstrrchr(s_filename, '\\');
+    if(filename++) {
+        // skip B file
+        if(filename[FILE_PREFIX_LEN] == 'B') {
+            NVRAM_FS_START_EX(FS_OP_DELETE,s_filename);
+            result = FS_Delete(s_filename);
+            NVRAM_FS_END(FS_OP_DELETE,result);
+            return KAL_TRUE;
+        }
+        kal_wsprintf(d_filename, "%s\\%w_%04X%04X", NVRAM_FS_OTA_DATAITEM_PATH, filename, ldi_ota_header->total_records, ldi_ota_header->record_size);
+    }
+    else {
+        return KAL_FALSE;
+    }
+
+    // scan backup file
+    kal_wsprintf(f_filename, "%s\\%w", NVRAM_FS_OTA_DATAITEM_PATH, filename);
+    filename = kal_wstrrchr(f_filename, '\\');
+    kal_wstrcpy((filename + (FILE_PREFIX_LEN + 1)), L"*");
+    filename = filenameArry[0];
+    handle = FS_FindFirst(f_filename, 0, FS_ATTR_DIR, &fileinfo, filename, NVRAM_MAX_PATH_LEN);
+    if(handle > FS_NO_ERROR) {
+        for(cnt = 1; cnt < NVRAM_OTA_RESERVE_CNT; cnt++) {
+            filename = filenameArry[cnt];
+            NVRAM_FS_START(FS_OP_FINDNEXT);
+            result = FS_FindNext(handle, &fileinfo, filename, NVRAM_MAX_PATH_LEN);
+            NVRAM_FS_END(FS_OP_FINDNEXT,result);
+            if(result != FS_NO_ERROR) {
+                break;
+            }
+        }
+        NVRAM_FS_START(FS_OP_FINDCLOSE);
+        result = FS_FindClose(handle);
+        NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+    }
+
+    // delete overdue file
+    if(cnt >= NVRAM_OTA_RESERVE_CNT) {
+        cnt = nvram_ota_search_overdue_file(filenameArry,(kal_wchar *)d_filename);
+        kal_wsprintf(f_filename, "%s\\%w", NVRAM_FS_OTA_DATAITEM_PATH, filenameArry[cnt]);
+        NVRAM_FS_START_EX(FS_OP_DELETE,f_filename);
+        result = FS_Delete(f_filename);
+        NVRAM_FS_END(FS_OP_DELETE,result);
+    }
+
+    // backup file
+    NVRAM_FS_START_EX(FS_OP_MOVE,d_filename);
+    result = FS_Move(s_filename, d_filename, FS_MOVE_COPY, NULL, NULL, 0);
+    NVRAM_FS_END(FS_OP_MOVE,result);
+    if(result != FS_NO_ERROR) {
+        return KAL_FALSE;
+    }
+    NVRAM_FS_START_EX(FS_OP_DELETE,s_filename);
+    result = FS_Delete(s_filename);
+    NVRAM_FS_END(FS_OP_DELETE,result);
+    return KAL_TRUE;
+}
+
+kal_bool nvram_ota_search_backup_file(const kal_char *s_filename, NVRAM_FULL_PATH *r_filename)
+{
+    FS_HANDLE handle;
+    FS_DOSDirEntry fileinfo;
+    kal_wchar *filename_start;
+    kal_int32 result = FS_NO_ERROR;
+    nvram_query_file_name(NVRAM_NVD_BACKUP, (kal_char *)s_filename, (kal_wchar*)r_filename);
+    filename_start = kal_wstrrchr((const WCHAR*)r_filename, '\\');
+    NVRAM_FS_START_EX(FS_OP_FINDFIRST,r_filename);
+    handle = FS_FindFirst((const WCHAR*)r_filename, 0, FS_ATTR_DIR, &fileinfo, (filename_start + 1), NVRAM_MAX_PATH_LEN);
+    NVRAM_FS_END(FS_OP_FINDFIRST,handle);
+    if(handle > FS_NO_ERROR) {
+        NVRAM_FS_START(FS_OP_FINDCLOSE);
+        result = FS_FindClose(handle);
+        NVRAM_FS_END(FS_OP_FINDCLOSE,result);
+        return KAL_TRUE;
+    }
+    return KAL_FALSE;
+}
+kal_bool nvram_ota_restore_file(nvram_ltable_entry_struct *ldi)
+{
+    NVRAM_FILE_NAME nvramname;
+    kal_wchar s_filename[NVRAM_MAX_PATH_LEN];
+    kal_wchar d_filename[NVRAM_MAX_PATH_LEN];
+    nvram_folder_enum nvram_folder;
+    nvram_ldi_ota_header ota_hdr;
+    kal_bool hdr_ret;
+    kal_int32 result = FS_NO_ERROR;
+    nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+    nvram_folder = nvram_query_folder_index(ldi->category);
+    nvram_query_file_name(nvram_folder, nvramname, d_filename);
+    
+    kal_wsprintf(s_filename, "%s\\%s_%04X%04X", NVRAM_FS_OTA_DATAITEM_PATH, nvramname, ldi->total_records, ldi->size);
+    hdr_ret = nvram_read_data_header(s_filename, LDI_HEADER_OTA_SECTION, (void*)&ota_hdr, NVRAM_LDI_OTA_HEADER_SIZE);
+    if( (hdr_ret == KAL_TRUE) && 
+        (ota_hdr.LID == ldi->LID) &&
+        (ota_hdr.total_records == ldi->total_records) && 
+        (ota_hdr.record_size == ldi->size) &&
+        (ota_hdr.ldi_category == ldi->category) ) 
+    {
+        //LDI recover hit
+        NVRAM_FS_START_EX(FS_OP_MOVE,d_filename);
+        result = FS_Move(s_filename, d_filename, FS_MOVE_COPY, NULL, NULL, 0);
+        NVRAM_FS_END(FS_OP_MOVE,result);
+        if(result != FS_NO_ERROR) {
+            return KAL_FALSE;
+        }
+
+        if(NVRAM_IS_ATTR_MULTIPLE(ldi->attr)) {
+            nvram_util_make_lid_filename(ldi, nvramname, KAL_FALSE);
+            nvram_query_file_name(nvram_folder, nvramname, d_filename);
+            NVRAM_FS_START_EX(FS_OP_MOVE,d_filename);
+            result = FS_Move(s_filename, d_filename, FS_MOVE_COPY, NULL, NULL, 0);
+            NVRAM_FS_END(FS_OP_MOVE,result);
+        }
+        return KAL_TRUE;
+    }
+    
+    return KAL_FALSE;
+}
+
+kal_uint32 nvram_ota_buffer_size()
+{
+    return NVRAM_LID_BITMAP_SIZE;
+}
+
+#ifdef __NVRAM_INIT_LID_BUFFER__
+void nvram_init_lid_buffer_prepare(void)
+{
+    kal_uint32 size = 0;
+    kal_uint16 i;
+    nvram_ltable_entry_struct *ldi = NULL;
+
+    for(i = 0; i < lid_buffer_list_num; i++) {        
+        if(!nvram_util_get_data_item(&ldi, lid_buffer_list[i].LID)) {
+            continue;
+        }
+        lid_buffer_list[i].ldi_ptr = ldi;
+        size += (ldi->size * ldi->total_records);
+    }
+    NVRAM_EXT_ASSERT((size < MAX_NVRAM_RECORD_SIZE), size, NVRAM_LOC_INIT_BUFFER_OVERFLOW, MAX_NVRAM_RECORD_SIZE);
+    nvram_init_lid_buffer = (kal_uint8 *)get_ctrl_buffer(size);
+    for(size = 0, i = 0; i < lid_buffer_list_num; i++) {        
+        if(lid_buffer_list[i].ldi_ptr == NULL) {
+            continue;
+        }
+        lid_buffer_list[i].buffer = (nvram_init_lid_buffer + size);
+        size += (lid_buffer_list[i].ldi_ptr->size * lid_buffer_list[i].ldi_ptr->total_records);
+        lid_buffer_list[i].status = NVRAM_INIT_LID_BUF_ENPTY;
+    }
+    nvram_init_lid_buffer_en = KAL_TRUE;
+}
+
+nvram_errno_enum nvram_init_lid_buffer_read(nvram_lid_enum LID, kal_uint32 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    kal_uint16 i;
+    kal_uint32 size, offset;
+
+    if(!nvram_init_lid_buffer_en) {
+        return NVRAM_ERRNO_NOT_READY;
+    }
+    for(i = 0; i < lid_buffer_list_num; i++) {
+        if(LID == lid_buffer_list[i].LID) {
+            if(lid_buffer_list[i].ldi_ptr == NULL ||
+                lid_buffer_list[i].status == NVRAM_INIT_LID_BUF_INVALID ||
+                lid_buffer_list[i].status == NVRAM_INIT_LID_BUF_READ ) {
+                return NVRAM_ERRNO_FAIL;
+            }
+            if(lid_buffer_list[i].status == NVRAM_INIT_LID_BUF_ENPTY) {
+                lid_buffer_list[i].status = NVRAM_INIT_LID_BUF_READ;
+                if(NVRAM_ERRNO_SUCCESS != nvram_read_data_item(lid_buffer_list[i].ldi_ptr,
+                                                               1,
+                                                               lid_buffer_list[i].ldi_ptr->total_records,
+                                                               lid_buffer_list[i].buffer,
+                                                               (lid_buffer_list[i].ldi_ptr->size * lid_buffer_list[i].ldi_ptr->total_records) )) 
+                {
+                    lid_buffer_list[i].status = NVRAM_INIT_LID_BUF_INVALID;
+                    return NVRAM_ERRNO_FAIL;
+                }
+                lid_buffer_list[i].status = NVRAM_INIT_LID_BUF_VALID;
+            }
+            size = (lid_buffer_list[i].ldi_ptr->size * rec_amount);
+            offset = ((rec_index - 1) * lid_buffer_list[i].ldi_ptr->size);
+            if((size > buffer_size) || 
+               ((rec_amount + rec_index - 1) > lid_buffer_list[i].ldi_ptr->total_records) )
+            {
+                return NVRAM_ERRNO_FAIL;
+            }
+            nvram_util_take_mutex(g_nvram_fs_mutex);
+            kal_mem_cpy(buffer, (lid_buffer_list[i].buffer + offset), size);
+            nvram_util_give_mutex(g_nvram_fs_mutex);
+            return NVRAM_ERRNO_SUCCESS;
+        }
+    }
+    return NVRAM_IO_ERRNO_INVALID_LID;
+}
+
+nvram_errno_enum nvram_init_lid_buffer_write(nvram_lid_enum LID, kal_uint32 rec_index, kal_uint16 rec_amount, kal_uint8 *buffer, kal_uint32 buffer_size)
+{
+    kal_uint16 i;
+    kal_uint32 size, offset;
+
+    if(!nvram_init_lid_buffer_en) {
+        return NVRAM_ERRNO_NOT_READY;
+    }
+    for(i = 0; i < lid_buffer_list_num; i++) {
+        if(LID == lid_buffer_list[i].LID) {
+            if(lid_buffer_list[i].ldi_ptr == NULL || 
+               lid_buffer_list[i].status == NVRAM_INIT_LID_BUF_INVALID ||
+               lid_buffer_list[i].status == NVRAM_INIT_LID_BUF_ENPTY)
+            {
+                return NVRAM_ERRNO_FAIL;
+            }
+            size = (lid_buffer_list[i].ldi_ptr->size * rec_amount);
+            offset = ((rec_index - 1) * lid_buffer_list[i].ldi_ptr->size);
+            if((buffer_size > size) || 
+               ((rec_amount + rec_index - 1) > lid_buffer_list[i].ldi_ptr->total_records) )
+            {
+                return NVRAM_ERRNO_FAIL;
+            }
+            nvram_util_take_mutex(g_nvram_fs_mutex);
+            kal_mem_cpy((lid_buffer_list[i].buffer + offset), buffer, size);
+            lid_buffer_list[i].status = NVRAM_INIT_LID_BUF_DIRTY;
+            nvram_util_give_mutex(g_nvram_fs_mutex);
+            return NVRAM_ERRNO_SUCCESS;
+        }
+    }
+    return NVRAM_IO_ERRNO_INVALID_LID;
+}
+
+void nvram_init_lid_buffer_writeback(void)
+{
+    kal_uint16 i,idx;
+    kal_uint32 offset;
+    
+    if(!nvram_init_lid_buffer_en) {
+        return;
+    }
+    nvram_init_lid_buffer_en = KAL_FALSE;
+    for(i = 0; i < lid_buffer_list_num; i++) {
+        if((lid_buffer_list[i].ldi_ptr == NULL) || (lid_buffer_list[i].status != NVRAM_INIT_LID_BUF_DIRTY)) {
+            continue;
+        }
+        for(idx = 0; idx < lid_buffer_list[i].ldi_ptr->total_records; idx++) {
+            offset = (idx * lid_buffer_list[i].ldi_ptr->size);
+            nvram_write_data_item(lid_buffer_list[i].ldi_ptr, (idx + 1), (lid_buffer_list[i].buffer + offset), KAL_FALSE);
+        }
+    }
+    free_ctrl_buffer(nvram_init_lid_buffer);
+}
+#endif
+
+void nvram_get_trace_configuration()
+{
+    WCHAR filename[NVRAM_MAX_PATH_LEN];
+    FS_HANDLE file_handle = FS_INVALID_FILE_HANDLE;
+    kal_int32 result = FS_NO_ERROR;
+    kal_char  trace_config[4]= {0};
+    kal_uint32 len = 0;
+
+    kal_mem_set(filename,0,NVRAM_MAX_PATH_LEN * sizeof(WCHAR));    
+    kal_wsprintf(filename, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH,"md_nv_config.txt");   
+
+    kal_mem_set(nvram_trace_filename,0,NVRAM_MAX_PATH_LEN * sizeof(kal_wchar));
+    kal_wsprintf(nvram_trace_filename, "Z:\\%s","nvram_trace_log.log");
+    
+    NVRAM_FS_START(FS_OP_OPEN); 
+    file_handle = FS_Open(filename, FS_READ_ONLY | FS_OPEN_SHARED |FS_OPEN_NO_DIR);
+    NVRAM_FS_END(FS_OP_OPEN,file_handle);
+    if (file_handle < FS_NO_ERROR) {
+        if(nvram_ee_info != NULL){
+            nvram_ee_info->nvram_trace_setting = 0;
+            nvram_ee_info->nvram_access_trace_setting_file_val = NVRAM_OPEN_TRACE_SETTING_FILE_FAIL;
+            g_access_trace_setting_file_result = NVRAM_OPEN_TRACE_SETTING_FILE_FAIL;
+            g_nvram_trace_setting = 0;
+        }
+        return;
+    }
+    if (file_handle > FS_NO_ERROR ) {
+        
+        NVRAM_FS_START(FS_OP_GETFILESIZE); 
+        result = FS_GetFileSize(file_handle, &len);
+        NVRAM_FS_END(FS_OP_GETFILESIZE,file_handle);
+
+        kal_mem_set(trace_config,0,4);
+        
+        NVRAM_FS_START(FS_OP_READ); 
+        result = FS_Read(file_handle, trace_config, len, &len);
+        NVRAM_FS_END(FS_OP_READ,result);
+        if(result < FS_NO_ERROR )
+        {
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_access_trace_setting_file_val = NVRAM_READ_TRACE_SETTING_FILE_FAIL;
+                g_access_trace_setting_file_result = NVRAM_READ_TRACE_SETTING_FILE_FAIL;
+                g_nvram_trace_setting = 0;
+            }
+        }
+        else
+        {            
+            if(nvram_ee_info != NULL){
+                nvram_ee_info->nvram_trace_setting = atoi(trace_config);
+                nvram_ee_info->nvram_access_trace_setting_file_val = NVRAM_READ_TRACE_SETTING_FILE_SUCCESS;
+                g_access_trace_setting_file_result = NVRAM_READ_TRACE_SETTING_FILE_SUCCESS;
+                g_nvram_trace_setting = nvram_ee_info->nvram_trace_setting;
+            }
+        }
+    }
+    if(file_handle > FS_NO_ERROR) {
+        NVRAM_FS_START(FS_OP_CLOSE); 
+        result =  FS_Close(file_handle);
+        NVRAM_FS_END(FS_OP_CLOSE,result);
+    }
+    if(nvram_ee_info != NULL){
+        nvram_ee_info->nvram_init_step = NVRAM_PRE_INIT_GET_TRACE_SETTING_DONE;
+    }
+    return;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  nvram_get_lid_chksum_algo_info
+ * DESCRIPTION
+ *  get cache LID from cache table 
+ * PARAMETERS
+ *  ldi             [IN]
+ * RETURNS
+ *  success or fail
+ *****************************************************************************/
+nvram_errno_enum nvram_get_lid_chksum_algo_info(nvram_ltable_entry_struct *ldi, nvram_lid_chksum_info * lid_chksum_info, kal_bool chksum_only, kal_bool read_2B)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if((NULL == ldi) || (NULL == lid_chksum_info))
+    {
+        kal_prompt_trace(MOD_NVRAM,"%s->(%d)NVRAM_LOC_BUFFER_PTR_IS_NULL_42 NULL \r\n",__FUNCTION__, __LINE__);
+        NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s()[Error]:NVRAM_LOC_BUFFER_PTR_IS_NULL_42 NULL %d.\r\n", __FUNCTION__,__LINE__);
+        NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_LOC_BUFFER_PTR_IS_NULL_42, 0, __LINE__);
+        return NVRAM_ERRNO_FAIL;
+    }
+
+    #ifdef __NV_CHKSUM_ENHANCE__
+        if(NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(ldi->attr))
+        {
+            lid_chksum_info->algo_info.chksum_algo_type = chksum_algo_ptr->cur_algo.en_algo_type;
+            if(NVRAM_MD5 == lid_chksum_info->algo_info.chksum_algo_type)
+            {
+                lid_chksum_info->algo_info.chksum_algo_length = read_2B? MD5_CHKSUM_LENGTH_2: MD5_CHKSUM_LENGTH_8;
+            }else
+            {
+                 lid_chksum_info->algo_info.chksum_algo_length = chksum_algo_ptr->cur_algo.en_algo_length;   
+            }
+        }else
+        {
+            lid_chksum_info->algo_info.chksum_algo_type = chksum_algo_ptr->cur_algo.def_algo_type;
+            if(NVRAM_MD5 == lid_chksum_info->algo_info.chksum_algo_type)
+            {
+                lid_chksum_info->algo_info.chksum_algo_length = read_2B? MD5_CHKSUM_LENGTH_2: MD5_CHKSUM_LENGTH_8;
+            }else
+            {
+                 lid_chksum_info->algo_info.chksum_algo_length = chksum_algo_ptr->cur_algo.def_algo_length;   
+            }
+        }
+    #else
+        lid_chksum_info->algo_info.chksum_algo_type = NVRAM_MD5;
+        lid_chksum_info->algo_info.chksum_algo_length = read_2B? MD5_CHKSUM_LENGTH_2: MD5_CHKSUM_LENGTH_8;
+    #endif
+
+    if((lid_chksum_info->algo_info.chksum_algo_type == NVRAM_MD5) && (read_2B == KAL_TRUE))
+    {
+        lid_chksum_info->read_chksum_type = (chksum_only? NVRAM_DRV_READ_TYPE_CHKSUM_ONLY_2B: NVRAM_DRV_READ_TYPE_CHKSUM_2B);
+    }
+    else
+    {
+        lid_chksum_info->read_chksum_type = chksum_only? NVRAM_DRV_READ_TYPE_CHKSUM_ONLY: NVRAM_DRV_READ_TYPE_CHKSUM;
+    }
+
+    return NVRAM_IO_ERRNO_OK;
+}
+
diff --git a/mcu/service/nvram/src/nvtest_main.c b/mcu/service/nvram/src/nvtest_main.c
new file mode 100644
index 0000000..14149bd
--- /dev/null
+++ b/mcu/service/nvram/src/nvtest_main.c
@@ -0,0 +1,110 @@
+#include <string.h>
+#include "nvram_msgid.h"
+
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+#include "syscomp_config.h"
+#include "task_config.h"
+#include "sysconf_statistics.h"     /* stack_statistics_struct */
+
+#include "nvram_enums.h"
+#include "nvram_struct.h"
+#include "nvram_data_items.h"
+#include "drv_sap.h"
+
+#include "tst_msgid.h"
+#include "tst_sap.h"
+
+void nvtest_main(ilm_struct *ilm_ptr)
+{
+    NVRAM_EXT_ASSERT(ilm_ptr != NULL,(kal_uint32)ilm_ptr,NVRAM_LOC_ILM_PTR_IS_NULL_2, 0);
+
+    if (ilm_ptr != NULL)
+    {
+        if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_CNF) {
+            nvram_read_cnf_struct *read_cnf;
+            kal_uint8 *data_ptr;
+            kal_uint16 data_len;
+            
+            read_cnf = (nvram_read_cnf_struct *)ilm_ptr->local_para_ptr;
+            data_ptr = get_peer_buff_pdu(ilm_ptr->peer_buff_ptr, &data_len);
+            kal_prompt_trace(MOD_NVTEST, "Got Read CNF from NVRAM, [LID=%d, Index=%d, Len=%d]", 
+                read_cnf->file_idx, read_cnf->para, read_cnf->length);
+        } else if (ilm_ptr->msg_id == MSG_ID_TST_INJECT_STRING) {
+            tst_module_string_inject_struct *tst_inject = (tst_module_string_inject_struct*) ilm_ptr->local_para_ptr;
+            if (strncmp((kal_char*) tst_inject->string, "reg", 3) == 0 || strncmp((kal_char*) tst_inject->string, "REG", 3) == 0 )
+            {
+                kal_prompt_trace(MOD_NVTEST, "Test Reg NVRAM Monitor, index=%d, inject string=%s", tst_inject->index , tst_inject->string);
+                nvram_mon_reg_notify(tst_inject->index, 1, 1);
+            }
+            else if (strncmp((kal_char*) tst_inject->string, "dereg", 5) == 0 || strncmp((kal_char*) tst_inject->string, "DEREG", 5) == 0 )
+            {
+                kal_prompt_trace(MOD_NVTEST, "Test Dereg NVRAM Monitor, index=%d, inject string=%s", tst_inject->index , tst_inject->string);
+                nvram_mon_dereg_notify(tst_inject->index, 1, 1);
+            }
+        }
+    }
+}
+
+void nvtest_task_main(task_entry_struct *task_entry_ptr)
+{
+    ilm_struct current_ilm;
+    kal_set_active_module_id(MOD_NVTEST);
+
+    while(1) {
+        msg_receive_extq(&current_ilm);
+        nvtest_main(&current_ilm);
+        destroy_ilm(&current_ilm);
+    }
+}
+
+void nvram_mon_reg_notify(nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
+{
+    nvram_read_req_struct *read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+
+    read_req->file_idx = lid;
+    read_req->para = rec_idx;
+    read_req->rec_amount = rec_amt;
+
+    msg_send5(MOD_NVTEST, MOD_NVRAM, NVTEST_SAP, MSG_ID_NVRAM_REG_NOTIFY_REQ,  (local_para_struct *)read_req);
+}
+
+void nvram_mon_dereg_notify(nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
+{
+    nvram_read_req_struct *read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+
+    read_req->file_idx = lid;
+    read_req->para = rec_idx;
+    read_req->rec_amount = rec_amt;
+
+    msg_send5(MOD_NVTEST, MOD_NVRAM, NVTEST_SAP, MSG_ID_NVRAM_DEREG_NOTIFY_REQ,  (local_para_struct *)read_req);
+}
+
+
+kal_bool nvtest_init(void)
+{
+    nvram_mon_reg_notify(NVRAM_EF_CB_CH_INFO_LID, 1, 1);
+    return KAL_TRUE;
+}
+
+kal_bool nvtest_reset(void)
+{
+    return KAL_TRUE;
+}
+
+kal_bool nvtest_create(comptask_handler_struct **handle)
+{
+    static const comptask_handler_struct nvram_handler_info =
+    {
+        nvtest_task_main,   /* task entry function */
+        nvtest_init,                /* task initialization function */
+        nvtest_reset            /* task reset handler */
+    };
+
+    *handle = (comptask_handler_struct*) & nvram_handler_info;
+    return KAL_TRUE;
+}
+