[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/tools/NVRAMStatistic/src/Makefile b/mcu/tools/NVRAMStatistic/src/Makefile
new file mode 100644
index 0000000..b4d204f
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/Makefile
@@ -0,0 +1,266 @@
+
+.PHONY: nvram_auto_gen
+
+modem_dir := ../../../custom/modem/common/ps
+nvram_dir := ../../../custom/service/nvram
+bsp_dir := ../../../custom/driver/common
+#mmi_dir := ../../../custom/common
+
+bsp_src := $(basename $(notdir $(wildcard $(bsp_dir)/*_nvram_def.c)))
+modem_src := $(basename $(notdir $(wildcard $(modem_dir)/*_nvram_def.c)))
+#mmi_src := $(basename $(notdir $(wildcard $(mmi_dir)/*_nvram_def.c)))
+#nvram_src := $(basename $(notdir $(wildcard $(nvram_dir)/*.c)))
+
+debug_path := $(subst \,/, $(NVRAM_DEBUG_PATH))
+
+include $(debug_path)/../include/custom_include.txt
+include $(debug_path)/../include/custom_option.txt
+
+bsp_obj := $(patsubst %, $(debug_path)/%.o, $(bsp_src))
+modem_obj := $(patsubst %, $(debug_path)/%.o, $(modem_src))
+mmi_obj := $(patsubst %, $(debug_path)/%.o, $(mmi_src))
+
+NVM_CUST_SRC = \
+BSP_LIST \
+MODEM_LIST \
+nvram_data_items.o \
+nvram_cust_pack.o \
+custom_nvram_sec.o \
+nvram_gen_util.o
+
+ifneq ($(filter "__MMI_FMI__", $(strip $(CUSTOM_OPTION))),)
+
+ NVM_CUST_SRC += nvram_common_config.o \
+ nvram_user_config.o
+endif
+
+ifneq ($(words $(mmi_src)), 0)
+ NVM_CUST_SRC += MMI_LIST
+endif
+
+
+#Vendor only can compile these files
+NVM_VENDOR_SRC = nvram_gen_util.o
+
+ifneq ($(filter "__MMI_FMI__", $(strip $(CUSTOM_OPTION))),)
+ NVM_VENDOR_SRC += nvram_user_config.o
+endif
+
+
+
+NVM_CORE_SRC = \
+nvram_factory_config.o
+
+NVM_GEN_SRC = \
+nvram_auto_gen.o
+
+NVM_LNK_CMD = \
+-Xlinker --script=nvram_auto_gen.txt -Xlinker --Map -Xlinker $(debug_path)/nvram_auto_gen.map
+
+NVM_GEN_OBJS = \
+$(debug_path)/nvram_auto_gen.o \
+$(debug_path)/nvram_gen_util.o \
+$(debug_path)/nvram_factory_config.o \
+$(debug_path)/nvram_data_items.o \
+$(debug_path)/nvram_cust_pack.o \
+$(debug_path)/custom_nvram_sec.o \
+$(debug_path)/fs_quota_entry_dump.o \
+$(modem_obj) \
+$(bsp_obj)
+
+ifneq ($(filter "__MMI_FMI__", $(strip $(CUSTOM_OPTION))),)
+ NVM_GEN_OBJS += $(debug_path)/nvram_user_config.o \
+ $(debug_path)/nvram_common_config.o \
+ $(mmi_obj)
+endif
+
+ifneq ($(filter "__FS_QM_SUPPORT__", $(strip $(CUSTOM_OPTION))),)
+ NVM_GEN_OBJS += $(debug_path)/fs_quota.o
+endif
+
+QUOTA_SRC = fs_quota_entry_dump.o
+
+ifneq ($(filter "__FS_QM_SUPPORT__", $(strip $(CUSTOM_OPTION))),)
+ QUOTA_SRC += fs_quota.o
+endif
+
+ifeq ($(strip $(LEVEL)), VENDOR) # vendor release
+ NVM_OPTION = -fshort-enums -D "NVRAM_AUTO_GEN" -D "__VENDOR_RELEASE__"
+else
+ NVM_OPTION = -fshort-enums -D "NVRAM_AUTO_GEN"
+endif
+
+NVM_INC = -I "../include"
+
+QUOTA_OPTION = -D "BUILD_TIME_CHECK_GEN" -D "GEN_FOR_PC"
+QUOTA_INC = -I "../../../custom/common/"
+
+
+#Using the folder from resource generator
+MTK_DEFS = \
+ -D "__MULTI_BIN_LOAD__" \
+ -D "__EXE_DLL__"
+
+
+
+############ MMI CACHE Makefile ####################################
+
+ifeq ($(strip $(MMI_FOLDER)), NEPTUNE_MMI)
+ MMI_CACHE_GEN_CMD = \
+ $(debug_path)/nvram_gen_mmi_cache.o \
+ $(debug_path)/common_mmi_cache_config.o \
+ $(debug_path)/custom_mmi_cache_config.o
+else
+ MMI_CACHE_GEN_CMD = \
+ $(debug_path)/nvram_gen_mmi_cache.o
+endif
+
+ifeq ($(strip $(MMI_FOLDER)), NEPTUNE_MMI)
+ NVM_CACHE_OBJS = \
+ nvram_gen_mmi_cache.o \
+ common_mmi_cache_config.o \
+ custom_mmi_cache_config.o
+else
+ NVM_CACHE_OBJS = \
+ nvram_gen_mmi_cache.o
+endif
+
+.SUFFIXES: .o .cpp .c .txt
+
+############### mmi cache compiling ####################
+
+common_mmi_cache_config.o: ../../../custom/common/${MMI_FOLDER}/common_mmi_cache_config.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "common_mmi_cache_config.o done"
+
+custom_mmi_cache_config.o: ../../../custom/app/$(strip $(CUSTOM_FOLDER))/custom_mmi_cache_config.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "custom_mmi_cache_config.o done"
+
+nvram_gen_mmi_cache.o: nvram_gen_mmi_cache.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "nvram_gen_mmi_cache.o done"
+
+ifeq ($(strip $(LEVEL)), LEVEL2_OBJ)
+ mmi_cache_gen: $(NVM_CACHE_OBJS)
+ gcc -o $(debug_path)/mmi_cache_gen $(MMI_CACHE_GEN_CMD)
+ echo "build level2_obj nvram_auto_gen done"
+else
+ ifeq ($(strip $(LEVEL)), VENDOR) # vendor release
+ mmi_cache_gen:
+ gcc -o $(debug_path)/mmi_cache_gen $(MMI_CACHE_GEN_CMD)
+ echo "build vendor mmi_cache_gen done"
+ else
+ mmi_cache_gen: $(NVM_CACHE_OBJS)
+ gcc -o $(debug_path)/mmi_cache_gen $(MMI_CACHE_GEN_CMD)
+ echo "build mmi_cache_gen done"
+ endif
+endif
+
+
+############ nvram_auto_gen compiling ####################################
+
+MMI_LIST:
+# echo "Building MMI: $(notdir $(mmi_src))"
+# for f in $(mmi_src) ; do \
+# echo Compile $(mmi_dir)/$$f.c; \
+# gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $(mmi_dir)/$$f.c -MMD -MF $(debug_path)/$$f.d -o $(debug_path)/$$f.o; \
+# done
+
+BSP_LIST:
+ echo "Building BSP: $(notdir $(bsp_src))"
+ for f in $(bsp_src) ; do \
+ echo Compile $(bsp_dir)/$$f.c; \
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $(bsp_dir)/$$f.c -MMD -MF $(debug_path)/$$f.d -o $(debug_path)/$$f.o; \
+ done
+
+
+
+MODEM_LIST:
+ echo "Building MODEM: $(notdir $(modem_src))"
+ for f in $(modem_src) ; do \
+ echo Compile $(modem_dir)/$$f.c; \
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $(modem_dir)/$$f.c -MMD -MF $(debug_path)/$$f.d -o $(debug_path)/$$f.o; \
+ done
+
+#NVRAM_LIST:
+# echo "Building NVRAM: $(notdir $(nvram_src))"
+# for f in $(nvram_src) ; do \
+# echo Compile $(nvram_dir)/$$f.c; \
+# gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $(nvram_dir)/$$f.c -MMD -MF $(debug_path)/$$f.d -o $(debug_path)/$$f.o; \
+# done
+
+
+nvram_data_items.o: ../../../custom/service/nvram/nvram_data_items.c
+ echo "Compile ../../../custom/service/nvram/nvram_data_items.c"
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+
+nvram_cust_pack.o: ../../../custom/service/nvram/nvram_cust_pack.c
+ echo "Compile ../../../custom/service/nvram/nvram_cust_pack.c"
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+
+custom_nvram_sec.o: ../../../custom/service/nvram/custom_nvram_sec.c
+ echo "Compile ../../../custom/service/nvram/custom_nvram_sec.c"
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+
+
+nvram_factory_config.o: ../../../service/nvram/src/nvram_factory_config.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "nvram_factory_config.o done"
+
+ifneq ($(filter "__MMI_FMI__", $(strip $(CUSTOM_OPTION))),)
+nvram_user_config.o: ../../../custom/app/$(strip $(CUSTOM_FOLDER))/nvram_user_config.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "nvram_user_config.o done"
+
+nvram_common_config.o: ../../../custom/common/${MMI_FOLDER}/nvram_common_config.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "nvram_common_config.o done"
+endif
+
+fs_quota_entry_dump.o: fs_quota_entry_dump.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+
+
+fs_quota.o: ../../../custom/common/fs_quota.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+
+nvram_auto_gen.o: nvram_auto_gen.c
+ echo "Compile nvram_auto_gen.c"
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "nvram_auto_gen.o done"
+
+nvram_gen_util.o: nvram_gen_util.c
+ gcc ${CUSTOM_OPTION} $(NVM_OPTION) ${CUSTOM_INC} $(NVM_INC) -w -c $< -MMD -MF $(debug_path)/$(basename $(@F)).d -o $(debug_path)/$@
+ echo "nvram_gen_util.o done"
+
+ifneq ($(filter "NVRAM_NOT_PRESENT", $(strip $(CUSTOM_OPTION))),)
+ nvram_auto_gen: nvram_auto_gen.o $(QUOTA_SRC)
+ gcc -o $(debug_path)/nvram_auto_gen $(debug_path)/nvram_auto_gen.o
+ echo "build nvram_auto_gen done"
+else
+ifeq ($(strip $(LEVEL)), LEVEL2_OBJ)
+ ifneq ($(strip $(CUSTOM_RELEASE)), FALSE)
+ nvram_auto_gen: $(NVM_GEN_SRC) $(NVM_CUST_SRC) $(QUOTA_SRC)
+ else
+ nvram_auto_gen: $(NVM_GEN_SRC) $(NVM_CUST_SRC) $(NVM_CORE_SRC) $(QUOTA_SRC)
+ endif
+ gcc -o $(debug_path)/nvram_auto_gen $(debug_path)/$(NVM_GEN_OBJS)
+ echo "build level2_obj nvram_auto_gen done"
+else
+ ifeq ($(strip $(LEVEL)), VENDOR) # vendor release
+ nvram_auto_gen: $(NVM_GEN_SRC) $(NVM_VENDOR_SRC) $(QUOTA_SRC)
+ gcc $(NVM_LNK_CMD) -o $(debug_path)/nvram_auto_gen $(NVM_GEN_OBJS)
+ echo "build vendor nvram_auto_gen done"
+ else
+ nvram_auto_gen: $(NVM_GEN_SRC) $(NVM_CUST_SRC) $(NVM_CORE_SRC) $(QUOTA_SRC)
+# nvram_auto_gen: nvram_auto_gen.o nvram_gen_util.o
+ gcc $(NVM_LNK_CMD) -o $(debug_path)/nvram_auto_gen $(NVM_GEN_OBJS)
+# ld nvram_auto_gen.txt -o $(debug_path)/nvram_auto_gen $(NVM_GEN_OBJS) -Map $(debug_path)/nvram_auto_gen.map
+# gcc -o $(debug_path)/nvram_auto_gen $(NVM_GEN_OBJS)
+ echo "build nvram_auto_gen done"
+ endif
+endif
+endif
+############### fs quota compiling ####################
+
diff --git a/mcu/tools/NVRAMStatistic/src/ckSySDrv_flash_cfg_preproc.c b/mcu/tools/NVRAMStatistic/src/ckSySDrv_flash_cfg_preproc.c
new file mode 100644
index 0000000..3d3d740
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/ckSySDrv_flash_cfg_preproc.c
@@ -0,0 +1,301 @@
+/*****************************************************************************
+* 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) 2008
+*
+* 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:
+ * ---------
+ * ckSysDrv_flash_cfg_preproc.c
+ *
+ * Project:
+ * --------
+ * Maui_Software
+ *
+ * Description:
+ * ------------
+ * To calculate System Drive Disk Space accuratly in build time utilities ckSysDrv.pl ,
+ * flash configuration parameters is required by C pre-processor with this temporal C source code.
+ *
+ * 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 "flash_opt.h"
+#include "custom_flash.c" // for including flash configurations, e.g., RegionInfo...
+#include "custom_nvram_int_config.h"
+
+/*--------------------------------------------------
+ * ckSysDrv Switch On/Off
+ *--------------------------------------------------*/
+
+#if defined(__CCCIFS_SUPPORT__) || defined(__RAMDISK__)
+ int cksysdrv_enabled = 0; // ckSysDrv is disabled on Smart Phone project
+#else
+ int cksysdrv_enabled = 1;
+#endif
+
+/*--------------------------------------------------
+ * Auto adjust On/Off
+ *--------------------------------------------------*/
+#if defined(__FS_AUTO_CONFIG_SUPPORT__)
+ int fs_auto_config_support = 1;
+#else
+ int fs_auto_config_support = 0;
+#endif /* __FS_AUTO_CONFIG_SUPPORT__ */
+
+/*--------------------------------------------------
+ * Get system drive information by compile options
+ *--------------------------------------------------*/
+
+#if defined(APP_STORAGE_IN_SYS_DRV)
+ int app_storage_in_sys_drv = 1;
+#else
+ int app_storage_in_sys_drv = 0;
+#endif
+
+
+#if defined(__EMMC_BOOTING__)
+
+int system_drive_size = EMMC_FS_SYSTEM_DRIVE_SIZE;
+int system_drive_location = 3; // EMMC
+
+int allocated_fat_space = EMMC_FS_SIZE / 512;
+int partition_sectors = 0;
+int flash_base_address = EMMC_FS_BASE_ADDRESS / 512;
+
+#elif defined(_NAND_FLASH_BOOTING_) || defined(__FS_SYSDRV_ON_NAND__) // system drive on NAND
+
+int allocated_fat_space = NAND_ALLOCATED_FAT_SPACE;
+int partition_sectors = NAND_PARTITION_SECTORS;
+int flash_base_address = NAND_FLASH_BASE_ADDRESS;
+int system_drive_location = 1; // NAND
+
+#else /* !_NAND_FLASH_BOOTING_ && !__FS_SYSDRV_ON_NAND__ */ // system drive on NOR
+
+int allocated_fat_space = NOR_ALLOCATED_FAT_SPACE;
+int partition_sectors = NOR_PARTITION_SECTORS;
+int flash_base_address = NOR_FLASH_BASE_ADDRESS;
+int system_drive_location = 2; // NOR
+
+#endif /* _NAND_FLASH_BOOTING_ || __FS_SYSDRV_ON_NAND__ */
+
+/*----------------------------------------------------------
+ * File system format information for FlashTool Auto Format
+ *----------------------------------------------------------*/
+
+#if defined(__EMMC_BOOTING__)
+
+ int fs_nand_base_address = 0;
+ int fs_nand_length = 0;
+ int fs_nor_base_address = 0;
+ int fs_nor_length = 0;
+ int fs_emmc_base_address = EMMC_FS_BASE_ADDRESS / 512;
+
+ #if (EMMC_FS_SIZE == 0)
+ int fs_emmc_length = 0xFFFFFFFF;
+ #else
+ int fs_emmc_length = EMMC_FS_SIZE / 512;
+ #endif
+
+#else // !__EMMC_BOOTING__
+
+ #if defined(_NAND_FLASH_BOOTING_) || defined(__FS_SYSDRV_ON_NAND__) || (defined(__FOTA_DM__) && defined(__UP_PKG_ON_NAND__) && defined(NAND_SUPPORT))
+
+ int fs_nand_base_address = NAND_FLASH_BASE_ADDRESS;
+ int fs_nand_length = NAND_ALLOCATED_FAT_SPACE;
+
+ #endif /* _NAND_FLASH_BOOTING_ || __FS_SYSDRV_ON_NAND__ && (__FOTA_DM__ && __UP_PKG_ON_NAND__ && NAND_SUPPORT) */
+
+ #if !defined(_NAND_FLASH_BOOTING_) && !defined(__FS_SYSDRV_ON_NAND__)
+
+ int fs_nor_base_address = NOR_FLASH_BASE_ADDRESS;
+
+ /*
+ * If __NOR_SUPPORT_RAW_DISK__ is defined, there are at most 2 additional disks behind system and user drives.
+ * We must ensure that these additional disks could be auto-formatted by FlashTool.
+ */
+
+ #ifndef __NOR_SUPPORT_RAW_DISK__
+ int fs_nor_length = NOR_ALLOCATED_FAT_SPACE;
+ #else // __NOR_SUPPORT_RAW_DISK__
+
+ #if (2 == NOR_BOOTING_NOR_DISK_NUM)
+ int fs_nor_length = NOR_BOOTING_NOR_DISK1_BASE_ADDRESS + NOR_BOOTING_NOR_DISK1_SIZE - NOR_FLASH_BASE_ADDRESS;
+ #elif (1 == NOR_BOOTING_NOR_DISK_NUM)
+ int fs_nor_length = NOR_BOOTING_NOR_DISK0_BASE_ADDRESS + NOR_BOOTING_NOR_DISK0_SIZE - NOR_FLASH_BASE_ADDRESS;
+ #else
+ int fs_nor_length = NOR_ALLOCATED_FAT_SPACE;
+ #endif
+ #endif // !__NOR_SUPPORT_RAW_DISK__
+
+ #endif /* !_NAND_FLASH_BOOTING_ && !__FS_SYSDRV_ON_NAND__ */
+
+#endif // __EMMC_BOOTING__
+
+
+/*--------------------------------------------------
+ * File system information
+ *--------------------------------------------------*/
+
+#if !defined(__LOW_COST_SUPPORT_ULC__)
+ int fs_low_cost_support = 0;
+#else
+ int fs_low_cost_support = 1;
+#endif /* __LOW_COST_SUPPORT_ULC__ */
+
+/*--------------------------------------------------
+ * Flash geometry
+ *--------------------------------------------------*/
+
+#if defined(NAND_TOTAL_SIZE) && defined(NAND_BLOCK_SIZE)
+ int nand_total_size = NAND_TOTAL_SIZE; // (MB)
+ int nand_block_size = NAND_BLOCK_SIZE; // (KB)
+#else
+ int nand_total_size = 0;
+ int nand_block_size = 0;
+#endif
+
+/*--------------------------------------------------
+ * NAND FDM information
+ *--------------------------------------------------*/
+
+#if defined(__NAND_FDM_50__)
+ int nand_fdm_version = 5;
+#else
+ int nand_fdm_version = 4;
+#endif
+
+/*--------------------------------------------------
+ * NOR FDM information
+ *--------------------------------------------------*/
+
+// NRVAM max number of record sectors
+int nvram_custom_cfg_max_record_sector_num = NVRAM_CUSTOM_CFG_MAX_RECORD_SECTOR_NUM;
+
+// reserved blocks in NOR FDM
+ float nor_reserved_blocks = NOR_SYSTEM_DRIVE_RESERVED_BLOCK;
+ int nor_single_bank_support = 0;
+
+// FDM sector size
+#if defined(__INTEL_SIBLEY__)
+ int nor_sector_size = 1024;
+#else
+ int nor_sector_size = 512;
+#endif /* __INTEL_SIBLEY__ */
+
diff --git a/mcu/tools/NVRAMStatistic/src/fs_quota_entry_dump.c b/mcu/tools/NVRAMStatistic/src/fs_quota_entry_dump.c
new file mode 100644
index 0000000..0dad3be
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/fs_quota_entry_dump.c
@@ -0,0 +1,257 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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:
+ * ---------
+ * fs_quota_entry_dump.c
+ *
+ * Project:
+ * --------
+ * MAUI
+ *
+ * Description:
+ * ------------
+ * This file is intends for dump the fs quota setting
+ *
+ * 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!
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#ifdef __FS_QM_SUPPORT__
+
+#include "flash_opt.h"
+#include "kal_public_defs.h"
+#include "fs_gprot.h"
+
+/*****************************************************************************
+* Define
+* Aim to pass compile, dummy function or gloabl variable here
+*****************************************************************************/
+FS_QuotaStruct *gFS_IntQuotaSet;
+UINT FS_MAX_QSET;
+
+/*****************************************************************************
+* Local Variable
+*****************************************************************************/
+extern void nvram_gen_create_file(FILE **file_handle, char *file_path, char *file_name);
+
+/*****************************************************************************
+* FUNCTION
+* main
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void FS_QuotaInit(FS_QuotaStruct *quota, kal_uint32 total)
+{
+
+ printf("FS_QuotaInit: %X, %d\n", quota, total);
+ gFS_IntQuotaSet = quota;
+ FS_MAX_QSET = total;
+}
+
+int nvram_gen_fs_quota(char *pathname)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE* outputLog;
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ #ifndef __PUBLIC_DRIVE_AVAILABLE__
+ #ifdef MMS_SUPPORT
+ #ifdef MMS_IN_LARGE_STORAGE
+ fprintf(stderr, "Please set APP_STORAGE_IN_SYS_DRV as TRUE for those projects which disable phone drive!\n");
+ exit(2);
+ #endif
+ #endif
+ #endif
+
+ nvram_gen_create_file(&outputLog, pathname, "cksysdrv/~fs_quota_usage.log");
+
+ fprintf(outputLog, "gFS_ExtQuotaSet[]\n");
+ fprintf(outputLog, "-----------------------------------------------------------\n");
+
+ for (i = 0; i < FS_MAX_QSET ; i++)
+ {
+ printf("{ %-20s , %5d , %10d , 0x%x , 0x%x },\n",
+ gFS_IntQuotaSet[i].Path,
+ gFS_IntQuotaSet[i].Priority,
+ gFS_IntQuotaSet[i].Qmin,
+ gFS_IntQuotaSet[i].Qmax,
+ gFS_IntQuotaSet[i].Uint);
+
+ fprintf(outputLog, "{ %-20s , %5d , %10d , 0x%x , 0x%x },\n",
+ gFS_IntQuotaSet[i].Path,
+ gFS_IntQuotaSet[i].Priority,
+ gFS_IntQuotaSet[i].Qmin,
+ gFS_IntQuotaSet[i].Qmax,
+ gFS_IntQuotaSet[i].Uint);
+ }
+ printf("output finish\n");
+ fclose(outputLog);
+ printf("close successfully\n");
+}
+
+#else /* __FS_QM_SUPPORT__ */
+int nvram_gen_fs_quota(char *pathname)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE* outputLog;
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ nvram_gen_create_file(&outputLog, pathname, "cksysdrv/~fs_quota_usage.log");
+
+ fprintf(outputLog, "__FS_QM_SUPPORT__ Off\n");
+
+ fclose(outputLog);
+ return 0;
+}
+#endif
diff --git a/mcu/tools/NVRAMStatistic/src/md5_dgst.c b/mcu/tools/NVRAMStatistic/src/md5_dgst.c
new file mode 100644
index 0000000..fbede67
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/md5_dgst.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <stdio.h>
+#include "md5_locl.h"
+#include <openssl/opensslv.h>
+
+/*
+ * Implemented from RFC1321 The MD5 Message-Digest Algorithm
+ */
+
+#define INIT_DATA_A (unsigned long)0x67452301L
+#define INIT_DATA_B (unsigned long)0xefcdab89L
+#define INIT_DATA_C (unsigned long)0x98badcfeL
+#define INIT_DATA_D (unsigned long)0x10325476L
+
+int MD5_Init(MD5_CTX *c)
+{
+ memset(c, 0, sizeof(*c));
+ c->A = INIT_DATA_A;
+ c->B = INIT_DATA_B;
+ c->C = INIT_DATA_C;
+ c->D = INIT_DATA_D;
+ return 1;
+}
+
+#ifndef md5_block_data_order
+# ifdef X
+# undef X
+# endif
+void md5_block_data_order(MD5_CTX *c, const void *data_, size_t num)
+{
+ const unsigned char *data = data_;
+ register unsigned MD32_REG_T A, B, C, D, l;
+# ifndef MD32_XARRAY
+ /* See comment in crypto/sha/sha_locl.h for details. */
+ unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
+ XX8, XX9, XX10, XX11, XX12, XX13, XX14, XX15;
+# define X(i) XX##i
+# else
+ MD5_LONG XX[MD5_LBLOCK];
+# define X(i) XX[i]
+# endif
+
+ A = c->A;
+ B = c->B;
+ C = c->C;
+ D = c->D;
+
+ for (; num--;) {
+ (void)HOST_c2l(data, l);
+ X(0) = l;
+ (void)HOST_c2l(data, l);
+ X(1) = l;
+ /* Round 0 */
+ R0(A, B, C, D, X(0), 7, 0xd76aa478L);
+ (void)HOST_c2l(data, l);
+ X(2) = l;
+ R0(D, A, B, C, X(1), 12, 0xe8c7b756L);
+ (void)HOST_c2l(data, l);
+ X(3) = l;
+ R0(C, D, A, B, X(2), 17, 0x242070dbL);
+ (void)HOST_c2l(data, l);
+ X(4) = l;
+ R0(B, C, D, A, X(3), 22, 0xc1bdceeeL);
+ (void)HOST_c2l(data, l);
+ X(5) = l;
+ R0(A, B, C, D, X(4), 7, 0xf57c0fafL);
+ (void)HOST_c2l(data, l);
+ X(6) = l;
+ R0(D, A, B, C, X(5), 12, 0x4787c62aL);
+ (void)HOST_c2l(data, l);
+ X(7) = l;
+ R0(C, D, A, B, X(6), 17, 0xa8304613L);
+ (void)HOST_c2l(data, l);
+ X(8) = l;
+ R0(B, C, D, A, X(7), 22, 0xfd469501L);
+ (void)HOST_c2l(data, l);
+ X(9) = l;
+ R0(A, B, C, D, X(8), 7, 0x698098d8L);
+ (void)HOST_c2l(data, l);
+ X(10) = l;
+ R0(D, A, B, C, X(9), 12, 0x8b44f7afL);
+ (void)HOST_c2l(data, l);
+ X(11) = l;
+ R0(C, D, A, B, X(10), 17, 0xffff5bb1L);
+ (void)HOST_c2l(data, l);
+ X(12) = l;
+ R0(B, C, D, A, X(11), 22, 0x895cd7beL);
+ (void)HOST_c2l(data, l);
+ X(13) = l;
+ R0(A, B, C, D, X(12), 7, 0x6b901122L);
+ (void)HOST_c2l(data, l);
+ X(14) = l;
+ R0(D, A, B, C, X(13), 12, 0xfd987193L);
+ (void)HOST_c2l(data, l);
+ X(15) = l;
+ R0(C, D, A, B, X(14), 17, 0xa679438eL);
+ R0(B, C, D, A, X(15), 22, 0x49b40821L);
+ /* Round 1 */
+ R1(A, B, C, D, X(1), 5, 0xf61e2562L);
+ R1(D, A, B, C, X(6), 9, 0xc040b340L);
+ R1(C, D, A, B, X(11), 14, 0x265e5a51L);
+ R1(B, C, D, A, X(0), 20, 0xe9b6c7aaL);
+ R1(A, B, C, D, X(5), 5, 0xd62f105dL);
+ R1(D, A, B, C, X(10), 9, 0x02441453L);
+ R1(C, D, A, B, X(15), 14, 0xd8a1e681L);
+ R1(B, C, D, A, X(4), 20, 0xe7d3fbc8L);
+ R1(A, B, C, D, X(9), 5, 0x21e1cde6L);
+ R1(D, A, B, C, X(14), 9, 0xc33707d6L);
+ R1(C, D, A, B, X(3), 14, 0xf4d50d87L);
+ R1(B, C, D, A, X(8), 20, 0x455a14edL);
+ R1(A, B, C, D, X(13), 5, 0xa9e3e905L);
+ R1(D, A, B, C, X(2), 9, 0xfcefa3f8L);
+ R1(C, D, A, B, X(7), 14, 0x676f02d9L);
+ R1(B, C, D, A, X(12), 20, 0x8d2a4c8aL);
+ /* Round 2 */
+ R2(A, B, C, D, X(5), 4, 0xfffa3942L);
+ R2(D, A, B, C, X(8), 11, 0x8771f681L);
+ R2(C, D, A, B, X(11), 16, 0x6d9d6122L);
+ R2(B, C, D, A, X(14), 23, 0xfde5380cL);
+ R2(A, B, C, D, X(1), 4, 0xa4beea44L);
+ R2(D, A, B, C, X(4), 11, 0x4bdecfa9L);
+ R2(C, D, A, B, X(7), 16, 0xf6bb4b60L);
+ R2(B, C, D, A, X(10), 23, 0xbebfbc70L);
+ R2(A, B, C, D, X(13), 4, 0x289b7ec6L);
+ R2(D, A, B, C, X(0), 11, 0xeaa127faL);
+ R2(C, D, A, B, X(3), 16, 0xd4ef3085L);
+ R2(B, C, D, A, X(6), 23, 0x04881d05L);
+ R2(A, B, C, D, X(9), 4, 0xd9d4d039L);
+ R2(D, A, B, C, X(12), 11, 0xe6db99e5L);
+ R2(C, D, A, B, X(15), 16, 0x1fa27cf8L);
+ R2(B, C, D, A, X(2), 23, 0xc4ac5665L);
+ /* Round 3 */
+ R3(A, B, C, D, X(0), 6, 0xf4292244L);
+ R3(D, A, B, C, X(7), 10, 0x432aff97L);
+ R3(C, D, A, B, X(14), 15, 0xab9423a7L);
+ R3(B, C, D, A, X(5), 21, 0xfc93a039L);
+ R3(A, B, C, D, X(12), 6, 0x655b59c3L);
+ R3(D, A, B, C, X(3), 10, 0x8f0ccc92L);
+ R3(C, D, A, B, X(10), 15, 0xffeff47dL);
+ R3(B, C, D, A, X(1), 21, 0x85845dd1L);
+ R3(A, B, C, D, X(8), 6, 0x6fa87e4fL);
+ R3(D, A, B, C, X(15), 10, 0xfe2ce6e0L);
+ R3(C, D, A, B, X(6), 15, 0xa3014314L);
+ R3(B, C, D, A, X(13), 21, 0x4e0811a1L);
+ R3(A, B, C, D, X(4), 6, 0xf7537e82L);
+ R3(D, A, B, C, X(11), 10, 0xbd3af235L);
+ R3(C, D, A, B, X(2), 15, 0x2ad7d2bbL);
+ R3(B, C, D, A, X(9), 21, 0xeb86d391L);
+
+ A = c->A += A;
+ B = c->B += B;
+ C = c->C += C;
+ D = c->D += D;
+ }
+}
+#endif
diff --git a/mcu/tools/NVRAMStatistic/src/med_mem_info.c b/mcu/tools/NVRAMStatistic/src/med_mem_info.c
new file mode 100644
index 0000000..f7849da
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/med_mem_info.c
@@ -0,0 +1,169 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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:
+ * ---------
+ * fs_quota_entry_dump.c
+ *
+ * Project:
+ * --------
+ * MAUI
+ *
+ * Description:
+ * ------------
+ * This file is intends for dump med memory run-time info
+ *
+ * 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!
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#ifndef MED_NOT_PRESENT
+#ifdef __inline
+ #undef __inline
+#endif /* __inline */
+
+#ifdef __GNUC__
+ #define __inline static inline
+#else
+ #define __inline static
+#endif
+
+//MSBB remove #include "kal_non_specific_general_types.h"
+#include "med_global.h"
+
+/*****************************************************************************
+* Define
+* Aim to pass compile, dummy function or gloabl variable here
+*****************************************************************************/
+kal_int32 system_boot_mode;
+/*****************************************************************************
+* Local Variable
+*****************************************************************************/
+#ifdef _STACK_LTLCOM_H
+void free_int_ilm(ilm_struct *ilm_ptr, kal_char* file_name, kal_uint32 line)
+{ return;
+}
+#endif
+
+/*****************************************************************************
+* FUNCTION
+* main
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+int main()
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE* outputLog;
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ outputLog = fopen("..\\..\\..\\~med_mem_info.log","w+");
+
+ fprintf(outputLog, "***********************************************************************\n");
+ fprintf(outputLog, "Med Memory Information\n");
+ fprintf(outputLog, "***********************************************************************\n");
+ fprintf(outputLog, "sizeof(aud_ext_mem_union) == %d\n", sizeof(aud_ext_mem_union));
+ fprintf(outputLog, "sizeof(med_ext_mem_union) == %d\n", sizeof(med_ext_mem_union));
+ fprintf(outputLog, "sizeof(med_int_mem_union) == %d\n", sizeof(med_int_mem_union));
+ fclose(outputLog);
+ return 0;
+}
+
+#else /* MED_NOT_PRESENT */
+int main()
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE* outputLog;
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ outputLog = fopen("..\\..\\..\\~med_mem_info.log","w+");
+
+ fprintf(outputLog, "MED_NOT_PRESENT\n");
+
+ fclose(outputLog);
+ return 0;
+}
+#endif
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_auto_gen.c b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen.c
new file mode 100644
index 0000000..96f6bfb
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen.c
@@ -0,0 +1,3008 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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_auto_gen.c
+ *
+ * Project:
+ * --------
+ * MAUI
+ *
+ * Description:
+ * ------------
+ * This file is intends for generating NVRAM information.
+ *
+ * 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!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#ifndef NVRAM_NOT_PRESENT
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <sys/io.h>
+#include <errno.h>
+
+#include "nvram_auto_gen.h"
+#include "custom_nvram_config.h"
+#include "custom_nvram_sec.h" // add ,get checksum type/size.
+#include "nvram_editor_data_item.h"
+#include "nvram_group_editor.h" //add for break group files from header file
+#include "nvram_data_items.h"
+#include "nvram_hash_check.h"
+#include "nvram_group_def.h" //add for break group files from header file
+
+#if defined(__MMI_FMI__)
+#include "nvram_user_defs.h"
+
+#endif
+
+#ifndef __VENDOR_RELEASE__
+#include "custom_nvram_sec.h"
+#endif
+
+#ifdef __FS_RAMDISK__
+#include "driver/storage/ramdisk_gprot.h"
+#endif
+
+/* Add pseudo merge headfile */
+#include "nvram_pseudo_merge.h"
+
+#include "nvram_internal.h"
+
+#include "nvram_white_list.h"
+/*
+ * Variables
+ */
+extern kal_uint32 custpack_total_to_verify;
+
+extern nvram_ltable_entry_struct *logical_data_item_table;
+extern kal_uint32 nvram_gen_total_lid;
+
+#ifdef __NVRAM_OTP__
+extern kal_uint32 otp_total_to_verify;
+extern kal_uint32 otp_size_to_verify;
+#endif
+
+extern kal_uint32 secupack_total_to_verify;
+extern kal_uint32 secupack_size_to_verify;
+extern kal_uint16 secupack_idx;
+
+#ifdef __NVRAM_VENDOR_SUPPORT__
+extern kal_uint32 nvram_vendor_reserve_size;
+#endif
+
+#if defined(__NVRAM_SECURE_DATA_STORAGE__)
+extern kal_uint32 sds_total_to_verify;
+extern kal_uint32 sds_size_to_verify;
+#endif
+
+
+/* system cache configure*/
+extern nvram_sys_cache_entry nvram_sys_cache[];
+
+#ifdef __NV_CHKSUM_ENHANCE__
+/* CUSTOM_CHK_ALGO_CONFIG configure*/
+extern nvram_checksum_config CUSTOM_CHK_ALGO_CONFIG;
+#endif
+
+#define NVRAM_AUTO_GEN_BYTE 1
+#define NVRAM_AUTO_GEN_SHORT 2
+#define NVRAM_AUTO_GEN_INTEGER 4
+
+#define fprintf_blank_line(x) fprintf (x,"\n")
+
+static FILE* logOfSize;
+static FILE* logOfTools;
+#ifdef __NVRAM_PSEUDO_MERGE__
+static FILE* logOfSize_Package;
+#endif
+
+/* used to package samll lid */
+#ifdef __NVRAM_PSEUDO_MERGE__
+static int nvram_auto_package_num;
+static int nvram_auto_pack_file_offset = NVRAM_FILE_HEAD_SIZE;
+#endif
+
+static int nvram_restore_cache_system[NVRAM_APP_TOTAL][NVRAM_SYS_CACHE_MAX];
+static int nvram_restore_system_idx[NVRAM_APP_TOTAL];
+static char **nvram_restore_lid_enum_array;
+static char **nvram_restore_lid_description_point;
+static int nvram_max_length_lid_str;
+static int nvram_total_num_restore_lid;
+static char base_path[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+
+kal_uint32 nvram_long_length;
+kal_uint32 nvram_ptr_length;
+kal_uint32 nvram_padding_length;
+kal_uint32 nvram_ltable_entry_length;
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_check_sys_cache
+* DESCRIPTION
+* output system cache default value to nvram_mmi_cust_pack.h
+* PARAMETERS
+*
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_check_sys_cache(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int loop_idx;
+ int byte_idx;
+ int bit_idx;
+ kal_uint8 *data = &(nvram_sys_cache[NVRAM_SYS_CACHE_BEGIN-1].value1);
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ for (loop_idx = NVRAM_SYS_CACHE_BEGIN; loop_idx < NVRAM_SYS_CACHE_MAX; loop_idx++)
+ {
+ if(nvram_sys_cache[loop_idx].id != loop_idx+1)
+ {
+ fprintf(stderr, "ERROR: please check nvram_data_items.h and nvram_data_items.c: # sys cache enum (%d) and # sys cache entry must sync.", loop_idx);
+ exit(3);
+ }
+
+ byte_idx = loop_idx / 8;
+ bit_idx = loop_idx % 8;
+ if (nvram_sys_cache[loop_idx].restore)
+ {
+ data[byte_idx] |= (0x01 << bit_idx);
+ nvram_restore_cache_system[nvram_sys_cache[loop_idx].app_id][nvram_restore_system_idx[nvram_sys_cache[loop_idx].app_id]] = loop_idx;
+ nvram_restore_system_idx[nvram_sys_cache[loop_idx].app_id]++;
+ }
+ }
+}
+
+
+void nvram_gen_sys_cache_default(FILE *fh_file)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int loop_idx;
+ int loop_value_idx;
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ /* step 1: generate restore mark */
+ fprintf(fh_file, "kal_uint8 const NVRAM_EF_SYS_CACHE_OCTET_DEFAULT[NVRAM_EF_SYS_CACHE_OCTET_TOTAL * NVRAM_EF_SYS_CACHE_OCTET_SIZE] =\n");
+ fprintf(fh_file, "{\n");
+
+ /* step 2: generate default value */
+ for (loop_idx = NVRAM_SYS_CACHE_BEGIN; loop_idx < NVRAM_SYS_CACHE_MAX; loop_idx++)
+ {
+ for (loop_value_idx = 0; loop_value_idx < sizeof(double); loop_value_idx++)
+ {
+ fprintf(fh_file," 0x%02X, ",
+ *(kal_uint8 *)(&(nvram_sys_cache[loop_idx - 1].value1) + loop_value_idx));
+ }
+ fprintf(fh_file, "\n");
+ }
+
+ /* step 3: generate last */
+ for (loop_value_idx = 0; loop_value_idx < sizeof(double) - 1; loop_value_idx++)
+ {
+ fprintf(fh_file, " 0x%02X, ",
+ *(&(nvram_sys_cache[NVRAM_SYS_CACHE_MAX - 1].value1) + loop_value_idx));
+ }
+
+ fprintf(fh_file, " 0x%02X ", nvram_sys_cache[NVRAM_SYS_CACHE_MAX - 1].value8);
+
+ fprintf(fh_file, "\n");
+
+ fprintf(fh_file, "};\n");
+}
+
+
+void nvram_gen_sys_cache_res_func(FILE *fh_file)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int loop_app_idx;
+ int loop_app_cache_idx;
+ int loop_value_idx;
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ fprintf(fh_file, NVRAM_RESTORE_FUNCTION_NAME, "system");
+
+ for (loop_app_idx = 0; loop_app_idx < NVRAM_APP_TOTAL; loop_app_idx++)
+ {
+ if (nvram_restore_system_idx[loop_app_idx])
+ {
+ fprintf(fh_file," case %s :\n", nvram_sys_cache[nvram_restore_cache_system[loop_app_idx][0]].app_id_str);
+ }
+ else
+ {
+ continue;
+ }
+
+ for (loop_app_cache_idx = 0; loop_app_cache_idx < nvram_restore_system_idx[loop_app_idx]; loop_app_cache_idx++)
+ {
+ /*-----------------------------------------------------------
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_ID,
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].id_str);
+
+ for (loop_space = 0; loop_space < nvram_max_length_double_id_str - strlen(nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].id_str); loop_space++)
+ {
+ fprintf(fh_restore_dom_h, " ");
+ }
+
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_DESCRIPTION,
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].discription);
+ -----------------------------------------------------------*/
+
+ fprintf(fh_file, NVRAM_AUTO_GEN_COMMENT, nvram_sys_cache[nvram_restore_cache_system[loop_app_idx][loop_app_cache_idx]].description);
+
+ for (loop_value_idx = 0; loop_value_idx < sizeof(double); loop_value_idx++)
+ {
+ fprintf(fh_file," buffer[%d * (%s - 1) + %d] = 0x%02X;\n",
+ sizeof(double),
+ nvram_sys_cache[nvram_restore_cache_system[loop_app_idx][loop_app_cache_idx]].id_str,
+ loop_value_idx,
+ *(&(nvram_sys_cache[nvram_restore_cache_system[loop_app_idx][loop_app_cache_idx]].value1) + loop_value_idx));
+ }
+ }
+
+ fprintf(fh_file,NVRAM_RESTORE_FUNCTION_BREAK);
+ }
+ fprintf(fh_file, NVRAM_RESTORE_FUNCTION_TAIL);
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_lid_size
+* DESCRIPTION
+* Output NVRAM LID size Information.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+char s[512];
+char indirect_end_symbol[40];
+
+void nvram_gen_ltable_list(void)
+{
+
+ typedef enum
+ {
+ INDIRECT_PROCESS_YET,
+ INDIRECT_PROCESS_ING,
+ INDIRECT_PROCESS_FINISHED
+ }indirect_process_enum;
+
+ FILE* tbl_list = NULL;
+ FILE* map_file = NULL;
+ char pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+ indirect_process_enum process_indirect_init = INDIRECT_PROCESS_YET;
+
+
+ sprintf(pathname,"%s/nvram_auto_gen/nvram_ltable_list.h",base_path);
+ printf("%s\n", pathname);
+ tbl_list= fopen(pathname,"w+");
+ if (tbl_list == NULL)
+ {
+ fprintf(stderr, "error: %s - nvram_ltable_list.h\n", strerror(errno));
+ return;
+ }
+
+ sprintf(pathname,"%s/nvram_auto_gen/debug/nvram_auto_gen.map",base_path);
+ printf("%s\n", pathname);
+ map_file = fopen(pathname,"r");
+
+ if (map_file == NULL)
+ {
+ fprintf(stderr, "error: %s - nvram_auto_gen.map\n", strerror(errno));
+ fclose(tbl_list);
+ return;
+ }
+
+
+
+ while (fgets(s, 512, map_file) > 0)
+ {
+ char *ptr;
+ char *brk;
+ s[511] = 0;
+
+ brk = strchr(s, '\n');
+
+ if (brk)
+ *brk = 0;
+
+ if (process_indirect_init == INDIRECT_PROCESS_YET)
+ {
+ if ((ptr = strstr(s, "logical_data_item_table_")))
+ {
+
+ fprintf(tbl_list, "#pragma comment(linker, \"/INCLUDE:_%s\")\n", ptr);
+ }
+
+ if (strstr(s, "*(_indirect_init)"))
+ {
+ process_indirect_init = INDIRECT_PROCESS_ING;
+ fgets(s, 512, map_file); /* skip one line */
+ s[511] = 0;
+
+ if (strstr(s, indirect_end_symbol))
+ {
+ process_indirect_init = INDIRECT_PROCESS_FINISHED;
+ break;
+ }
+ }
+ }
+ else if (process_indirect_init == INDIRECT_PROCESS_ING)
+ {
+
+ if (strstr(s, indirect_end_symbol))
+ {
+ process_indirect_init = INDIRECT_PROCESS_FINISHED;
+ break;
+ }
+
+ ptr = strrchr(s, ' ') + 1;
+ printf("%s\n", ptr);
+
+ if (!strstr(ptr, "./build/"))
+ {
+ fprintf(tbl_list, "#pragma comment(linker, \"/INCLUDE:_%s\")\n", ptr);
+ }
+ }
+
+ }
+
+ fclose(map_file);
+ fclose(tbl_list);
+
+}
+
+#ifdef __NV_CHKSUM_ENHANCE__
+kal_uint32 get_checksum_size(nvram_ltable_entry_struct* ldi)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 nvram_checksum_size = NVRAM_CHKSUM_SIZE;
+
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ if(NVRAM_IS_ATTR_CHKSUM_ENHANC_ALGRTHM(ldi->attr))
+ {
+ if(CUSTOM_CHK_ALGO_CONFIG.enhance_algo_type == NVRAM_MD5)
+ {
+ nvram_checksum_size = NVRAM_CHKSUM_SIZE;
+ }
+ else
+ {
+ nvram_checksum_size = CUSTOM_CHK_ALGO_CONFIG.enhance_algo_size;
+ }
+ }
+ else
+ {
+ if(CUSTOM_CHK_ALGO_CONFIG.default_algo_type == NVRAM_MD5)
+ {
+ nvram_checksum_size = NVRAM_CHKSUM_SIZE;
+ }
+ else
+ {
+ nvram_checksum_size = CUSTOM_CHK_ALGO_CONFIG.default_algo_size;
+ }
+ }
+
+ return nvram_checksum_size;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_array
+* DESCRIPTION
+* Output formatted arrays to custom_nvram_secro, i.e. 16 bytes/line
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_chk_algo_config(FILE* handle)
+{
+ fprintf(handle, "\n %d, ", CUSTOM_CHK_ALGO_CONFIG.enhance_algo_size);
+ switch(CUSTOM_CHK_ALGO_CONFIG.enhance_algo_type)
+ {
+ case NVRAM_HMAC_SHA256:
+ fprintf(handle, "NVRAM_HMAC_SHA256, ");
+ break;
+ case NVRAM_MD5:
+ fprintf(handle, "NVRAM_MD5, ");
+ break;
+ default:
+ break;
+ }
+ fprintf(handle, "%d, ", CUSTOM_CHK_ALGO_CONFIG.default_algo_size);
+ switch(CUSTOM_CHK_ALGO_CONFIG.default_algo_type)
+ {
+ case NVRAM_HMAC_SHA256:
+ fprintf(handle, "NVRAM_HMAC_SHA256");
+ break;
+ case NVRAM_MD5:
+ fprintf(handle, "NVRAM_MD5");
+ break;
+ default:
+ break;
+ }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ * cache_info_table_generator
+ * DESCRIPTION
+ * Generate cache info table
+ * PARAMETERS
+ *
+ * RETURNS
+ *
+ *****************************************************************************/
+void chksum_algo_config_generator(char *base_path)
+{
+ /*******************************************/
+ kal_uint32 i = 0, tb_size;
+
+ char chksum_algo_config_file_path[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ char chksum_algo_config_file_name[] = "nvram_chksum_algo_config.c";
+ FILE *fp;
+
+ sprintf(chksum_algo_config_file_path, "%s/nvram_auto_gen/%s", base_path, chksum_algo_config_file_name);
+
+ fp = fopen(chksum_algo_config_file_path, "w");
+ fprintf(fp, COPYRIGHTS_HEADER, chksum_algo_config_file_name);
+ fprintf(fp, "#include \"custom_nvram_sec.h\"\n");
+ fprintf(fp, "\n");
+ #if defined (__NVRAM_UT_TEST__)
+ fprintf(fp, "\nnvram_checksum_config NVRAM_CHK_CONFIG = ");
+ #else
+ fprintf(fp, "\nconst nvram_checksum_config NVRAM_CHK_CONFIG = ");
+ #endif
+ fprintf(fp, "\n {");
+ nvram_gen_chk_algo_config(fp);
+ fprintf(fp, "\n };");
+
+ fclose(fp);
+}
+
+#endif
+
+void nvram_gen_lid_size(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+#ifdef __NVRAM_PSEUDO_MERGE__
+ kal_uint16 fake_lid;
+ int sum = 0;
+#endif
+ kal_uint32 i,j;
+ char pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+ kal_uint32 estimate_size = 0;
+ kal_uint32 estimate_fs_size = 0;
+ kal_uint32 bin_region_size = 0;
+ kal_uint32 protect_size = 0;
+ kal_uint32 remainLen = 0;
+ kal_uint32 nvram_checksum_size = 0;
+
+ #define FS_PAGE_SIZE 4096
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+
+ /* Gen information for tools */
+ sprintf(pathname, "%s/nvram_auto_gen/~nvram_lid_information.log", base_path);
+ logOfTools = fopen(pathname,"w+");
+ if (logOfTools == NULL)
+ {
+ fprintf(stderr, "error: %s - ~nvram_lid_information.log\n", strerror(errno));
+ }
+ else
+ {
+ fprintf(logOfTools,"----------------------------------------------------------------------------------------------------------------------------------------------\n");
+ fprintf(logOfTools,"----------------------------------------------------------------------------------------------------------------------------------------------\n");
+ fprintf(logOfTools,"%4s %55s %10s %10s %11s %10s %10s\n","LID","LID(String)","Filename","Verno","Description", "Category", "Attribute");
+ fprintf(logOfTools,"----------------------------------------------------------------------------------------------------------------------------------------------\n");
+ } /* end for tools */
+
+ sprintf(pathname, "%s/nvram_auto_gen/~nvram_lid_size.log", base_path);
+ logOfSize = fopen(pathname,"w+");
+ if (logOfSize == NULL)
+ {
+ fprintf(stderr, "error: %s - ~nvram_lid_size.log\n", strerror(errno));
+ }
+ else
+ {
+ kal_uint32 onefilesize = 0;
+ kal_uint32 onefilefssize = 0;
+ nvram_ltable_entry_struct *ldi;
+
+ fprintf(logOfSize, "00000 long:%d,char*:%d,padding:%d NVRAM_PADDING_TEST\n", nvram_long_length, nvram_ptr_length, (nvram_padding_length / 3));
+ fprintf(logOfSize, "--------------------------------------------------------------------------\n");
+
+ #ifdef __NVRAM_PSEUDO_MERGE__
+ sprintf(pathname, "%s/nvram_auto_gen/nvram_lid_size_merge.log", base_path);
+ logOfSize_Package = fopen(pathname,"w+");
+ if (logOfSize_Package == NULL)
+ {
+ fprintf(stderr, "error: %s - nvram_lid_size_merge.log\n", strerror(errno));
+ }
+ else
+ {
+ fprintf(logOfSize_Package, "%4s %10s %10s %10s %10s %10s %10s\n",
+ "ldi->LID", "fileprefix", "onefilesize", "oneLIDsize", "single_num", "single_offset", "file_size");
+ }
+
+ #endif
+
+ nvram_restore_lid_enum_array = malloc(sizeof(char *) * nvram_gen_total_lid);
+ nvram_restore_lid_description_point = malloc(sizeof(char *) * nvram_gen_total_lid);
+
+
+ for (i = 0;i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+
+ if (ldi == NULL ||
+ (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue; /* invalid LID */
+ }
+ #ifdef __NVRAM_PSEUDO_MERGE__
+ sum ++;
+ #endif
+ /* Output data item size */
+
+ #ifdef __NV_CHKSUM_ENHANCE__
+ nvram_checksum_size = get_checksum_size(ldi); // get nvram_checksum_size , read CUSTOM_CHK_ALGO_CONFIG.
+ #else
+ nvram_checksum_size = NVRAM_CHKSUM_SIZE;
+ #endif
+
+ if(ldi->attr & NVRAM_ATTR_CONFIDENTIAL
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ //if HW encrypt is enable
+ || ldi->attr & NVRAM_ATTR_MSP
+ #endif
+ )
+ {
+ remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_checksum_size);
+ onefilesize = (ldi->size + nvram_checksum_size + remainLen)*ldi->total_records + NVRAM_LDI_HEADER_SIZE;
+ }
+ else
+ {
+ onefilesize = (ldi->size + nvram_checksum_size) * ldi->total_records + NVRAM_LDI_HEADER_SIZE;
+ }
+ onefilefssize = (onefilesize+FS_PAGE_SIZE-1)/FS_PAGE_SIZE*FS_PAGE_SIZE; //align to FS_PAGE_SIZE
+
+ if(onefilesize)
+ {
+ /* Record data item will be restored (begin) */
+ if (NVRAM_IS_CATEGORY_FACTORY_RESET(ldi->category))
+ {
+ if (strlen(ldi->str_LID) > nvram_max_length_lid_str)
+ {
+ nvram_max_length_lid_str = strlen(ldi->str_LID);
+ }
+ nvram_restore_lid_enum_array[nvram_total_num_restore_lid] = ldi->str_LID;
+ nvram_restore_lid_description_point[nvram_total_num_restore_lid] = ldi->description;
+ nvram_total_num_restore_lid++;
+ }
+ /* Record data item will be restored (end) */
+ #ifdef __NVRAM_PSEUDO_MERGE__
+ if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+ {
+ /* Gen information for tools */
+ if (logOfTools)
+ {
+ fprintf(logOfTools,"%4d %55s %10s %10s %11s 0x%08x 0x%08x\n",ldi->LID,ldi->str_LID,"PACK","LID",ldi->description, ldi->category, ldi->attr);
+ }
+ /* end */
+
+ nvram_auto_package_num++;
+ {
+ fprintf(logOfSize_Package, "%40s", ldi->description);
+ ldi->description = nvram_auto_pack_file_offset;
+ nvram_auto_pack_file_offset += onefilesize;
+ fprintf(logOfSize_Package, "%4d %10s %10d %10d %10d %10d %10d\n",
+ ldi->LID, ldi->fileprefix, onefilesize, ldi->size, nvram_auto_package_num, (kal_int32)(ldi->description), nvram_auto_pack_file_offset);
+ }
+
+ fprintf(logOfSize, "%4d%10d%60s%20s\n", ldi->LID, 0, ldi->str_LID, NVRAM_IS_CATEGORY_CUSTPACK(ldi->category)?"CUSTPACK":"");
+
+ continue; /* already calculate in package file */
+ }
+ #endif
+ fprintf(logOfSize, "%4d%10d%60s%20s\n", ldi->LID, onefilesize, ldi->str_LID, NVRAM_IS_CATEGORY_CUSTPACK(ldi->category)?"CUSTPACK":"");
+ estimate_size += onefilesize;
+ estimate_fs_size += onefilefssize;
+
+ if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+ {
+ fprintf(logOfSize, "%4d%10d%60s%20s\n", ldi->LID, onefilesize, ldi->str_LID, NVRAM_IS_CATEGORY_CUSTPACK(ldi->category)?"CUSTPACK":"");
+ estimate_size += onefilesize;
+ estimate_fs_size += onefilefssize;
+ }
+
+ if(NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category))
+ {
+ bin_region_size += onefilefssize;
+ if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+ {
+ bin_region_size += onefilefssize;
+ }
+ }
+
+ if(!NVRAM_IS_CATEGORY_FACTORY_RESET(ldi->category))
+ {
+ protect_size += onefilefssize;
+ }
+
+ /* Gen information for tools */
+ if (logOfTools)
+ {
+ fprintf(logOfTools,"%4d %55s %10s %10s %11s 0x%08x 0x%08x\n",ldi->LID,ldi->str_LID,ldi->fileprefix,ldi->fileverno,ldi->description, ldi->category, ldi->attr);
+ }
+ /* end */
+ }
+ }
+
+ #ifdef __NVRAM_VENDOR_SUPPORT__
+ fprintf(logOfSize,
+ "%4d%10d%60s\n",
+ nvram_gen_total_lid,
+ nvram_vendor_reserve_size,
+ "NVRAM_EF_VENDOR_REMAIN_SPACE_LID"
+ );
+ #endif /* __NVRAM_VENDOR_SUPPORT__ */
+
+ #ifdef __NVRAM_PSEUDO_MERGE__
+ fake_lid = nvram_gen_total_lid;
+ #ifdef __NVRAM_VENDOR_SUPPORT__
+ fake_lid += 1;
+ #endif
+ fprintf(logOfSize, "%4d%10d%40s\n", fake_lid, nvram_auto_pack_file_offset, "Package file size");
+ /* LID information nvram_auto_package_num */
+ fprintf(logOfSize, "%4d%10d%40s\n", fake_lid + 1, nvram_auto_package_num * (sizeof(LID_info_struct) + 2), "Info file A");
+ fprintf(logOfSize, "%4d%10d%40s\n", fake_lid + 2, nvram_auto_package_num * (sizeof(LID_info_struct) + 2), "Info file B");
+ /* extra cluster is need, for temp file, package file, truncate file */
+ fprintf(logOfSize, "%4d%10d%40s\n", fake_lid + 3, 3 * 512,"Extra size");
+ /***
+ * fprintf(logOfSize,"sum: %4d nvram_auto_package_num = %4d\n",sum,nvram_auto_package_num);
+ */
+ #endif /* __NVRAM_PSEUDO_MERGE__ */
+
+ fprintf(logOfSize, "--------------------------------------------------------------------------\n");
+
+ #ifdef __NVRAM_COMPRESS_SUPPORT__
+ fprintf(logOfSize, "NVRAM_COMPRESS=1\n");
+ #else
+ fprintf(logOfSize, "NVRAM_COMPRESS=0\n");
+ #endif
+ fprintf(logOfSize, "NVRAM_ESTIMATE_SIZE=%d\n", estimate_size);
+ fprintf(logOfSize, "NVRAM_ESTIMATE_FS_SIZE=%d\n", estimate_fs_size);
+ fprintf(logOfSize, "bin_region_size=%d\n", bin_region_size);
+ fprintf(logOfSize, "protect_size=%d\n", protect_size);
+ #ifdef __FS_RAMDISK__
+ fprintf(logOfSize, "RAMDISK_SIZE=%d\n", RAM_FS_SIZE);
+ #endif
+
+ fclose(logOfSize);
+ #ifdef __NVRAM_PSEUDO_MERGE__
+ fclose(logOfSize_Package);
+ #endif
+ }
+
+ #ifdef __NV_CHKSUM_ENHANCE__
+ /* Gen information for tools */
+ if (logOfTools)
+ {
+ fprintf(logOfTools,"--------------------------------------------------------------------------------------------\n");
+ fprintf(logOfTools, "enhance_algo_size=%d\n", CUSTOM_CHK_ALGO_CONFIG.enhance_algo_size);
+ fprintf(logOfTools, "enhance_algo_type=%d\n", CUSTOM_CHK_ALGO_CONFIG.enhance_algo_type);
+ fprintf(logOfTools, "default_algo_size=%d\n", CUSTOM_CHK_ALGO_CONFIG.default_algo_size);
+ fprintf(logOfTools, "default_algo_type=%d\n", CUSTOM_CHK_ALGO_CONFIG.default_algo_type);
+ fclose(logOfTools);
+ }
+ #endif
+ /* end */
+
+ for (i = 0;i < nvram_gen_total_lid; i++)
+ {
+ nvram_ltable_entry_struct *ldi1, *ldi2;
+
+ ldi1 = &logical_data_item_table[i];
+
+ if (ldi1 == NULL || (ldi1->LID == 0 && ldi1->size == 0 && ldi1->total_records == 0))
+ {
+ continue; /* invalid LID */
+ }
+
+ if (strcasecmp(ldi1->fileprefix, "") == 0)
+ {
+ fprintf(stderr, "error: fileprefix of %s = %d cannot be NULL!\n", ldi1->str_LID, ldi1->LID);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ if (strlen(ldi1->fileprefix) != FILE_PREFIX_LEN)
+ {
+ fprintf(stderr, "error: fileprefix length of %s is invalid!\n", ldi1->str_LID);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ if (strlen(ldi1->fileverno) != FILE_VERNO_LEN)
+ {
+ fprintf(stderr, "error: fileverno length of %s is invalid!\n", ldi1->str_LID);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ for (j = i + 1 ;j < nvram_gen_total_lid; j++)
+ {
+ ldi2 = &logical_data_item_table[j];
+
+ if (ldi2 == NULL || (ldi2->LID == 0 && ldi2->size == 0 && ldi2->total_records == 0))
+ {
+ continue; /* invalid LID */
+ }
+ if (strcasecmp(ldi1->fileprefix, ldi2->fileprefix) == 0)
+ {
+ fprintf(stderr, "error: duplicated fileprefix and fileverno %s %s of %s and %s\n", ldi1->fileprefix, ldi1->fileverno, ldi1->str_LID, ldi2->str_LID);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+
+ }
+
+#ifdef __FS_RAMDISK__
+ if(estimate_fs_size > RAM_FS_SIZE)
+ {
+ fprintf(stderr, "error: RAMDISK size is not enough.\n");
+ fprintf(stderr, "error: NVRAM_ESTIMATE_FS_SIZE=%d\n", estimate_fs_size);
+ fprintf(stderr, "error: RAMDISK_SIZE=%d\n", RAM_FS_SIZE);
+
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+#endif
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_statistic
+* DESCRIPTION
+* Output nvram_lid_statistic.h
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_statistic(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 error = 0;
+ FILE* outputHeader;
+ kal_uint8 sys_str[2048];
+ char pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+ char pathnameOrg[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(pathname, "%s/nvram_auto_gen/nvram_lid_statistics_bak.h", base_path);
+ sprintf(pathnameOrg, "%s/nvram_auto_gen/nvram_lid_statistics.h", base_path);
+ outputHeader = fopen(pathname,"w+");
+ if (outputHeader == NULL)
+ {
+ fprintf(stderr, "error: %s - %s\n",strerror(errno) ,pathname);
+ }
+ else
+ {
+
+ fprintf(outputHeader, COPYRIGHTS_HEADER, "nvram_lid_statistics_bak.h");
+
+ fprintf(outputHeader, "#ifndef NVRAM_LID_STATISTIC_H\n#define NVRAM_LID_STATISTIC_H\n");
+
+ #ifdef __NVRAM_OTP__
+ fprintf(outputHeader, "#define NVRAM_OTP_SIZE %d\n", otp_size_to_verify);
+ fprintf(outputHeader, "#define NVRAM_OTP_TOTAL %d\n", otp_total_to_verify);
+ #endif
+
+ fprintf(outputHeader, "#define NVRAM_CUSTPACK_TOTAL %d\n", custpack_total_to_verify);
+
+ fprintf(outputHeader, "#define NVRAM_SECUPACK_SIZE %d\n", secupack_size_to_verify);
+ fprintf(outputHeader, "#define NVRAM_SECUPACK_TOTAL %d\n", secupack_total_to_verify);
+
+ #if defined(__NVRAM_SECURE_DATA_STORAGE__)
+ fprintf(outputHeader, "#define NVRAM_SDS_TOTAL %d\n", sds_total_to_verify);
+ fprintf(outputHeader, "#define NVRAM_SDS_SIZE %d\n", sds_size_to_verify);
+ #endif
+
+ #ifdef __NVRAM_PSEUDO_MERGE__
+ fprintf_blank_line(outputHeader);
+ fprintf(outputHeader, "#ifdef __NVRAM_PSEUDO_MERGE__\n");
+ fprintf(outputHeader, "#define NVRAM_PACKAGE_LID_NUM %d\n", nvram_auto_package_num);
+ fprintf(outputHeader, "#define NVRAM_PACKAGE_LID_SIZE %d\n", nvram_auto_pack_file_offset);
+ fprintf(outputHeader, "#endif /* __NVRAM_PSEUDO_MERGE__ */\n");
+ #endif
+
+ fprintf(outputHeader,"\n#endif /* NVRAM_LID_STATISTIC_H */\n\n");
+ fclose(outputHeader);
+
+#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 !*/
+#endif
+ }
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_array
+* DESCRIPTION
+* Output formatted arrays to custom_nvram_secro, i.e. 16 bytes/line
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_array(FILE* handle, kal_char* indent, kal_uint8 type, kal_uint32 max_size, kal_uint8 *array, kal_bool calc_cksum, kal_bool last_block)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 i;
+ kal_uint8 byte_chksum[2] = {0};
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ /* We only support checksum on NVRAM_AUTO_GEN_BYTE */
+
+ for (i = 0; i < max_size; i += type)
+ {
+ if (calc_cksum && type == NVRAM_AUTO_GEN_BYTE)
+ {
+ if (i & 0x1)
+ {
+ byte_chksum[1] += array[i];
+ }
+ else
+ {
+ byte_chksum[0] += array[i];
+ }
+ }
+
+ if (i % 16 == 0)
+ {
+ fprintf(handle, "\n%s", indent);
+ }
+
+ switch (type)
+ {
+ case NVRAM_AUTO_GEN_INTEGER:
+ fprintf(handle, "0x%02X%02X%02X%02X", array[i + 3], array[i + 2], array[i + 1], array[i]);
+ break;
+ case NVRAM_AUTO_GEN_SHORT:
+ fprintf(handle, "0x%02X%02X", array[i + 1], array[i]);
+ break;
+ case NVRAM_AUTO_GEN_BYTE:
+ default:
+ fprintf(handle, "0x%02X", array[i]);
+ break;
+ }
+
+ if (i == max_size - type)
+ {
+ if (calc_cksum && type == NVRAM_AUTO_GEN_BYTE)
+ fprintf(handle, ",\n%s/* check sum */\n%s0x%02x, 0x%02x", indent, indent, byte_chksum[0], byte_chksum[1]);
+
+ if (!last_block)
+ {
+ fprintf(handle, ", ");
+ }
+ }
+ else
+ {
+ fprintf(handle, ", ");
+ }
+ }
+
+
+}
+
+#ifndef __VENDOR_RELEASE__
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_secro
+* DESCRIPTION
+* Output custom_nvram_secro.c.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_secro(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i = 0;
+ FILE* outputHeader;
+ FILE* outputHeader2;
+ char pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(pathname, "%s/nvram_auto_gen/custom_nvram_secro.c", base_path);
+ outputHeader = fopen(pathname,"w+");
+ sprintf(pathname, "%s/nvram_auto_gen/custom_nvram_secro_tbl.c", base_path);
+ outputHeader2 = fopen(pathname,"w+");
+
+ if ((outputHeader == NULL) || (outputHeader2 == NULL)) {
+ fprintf(stderr, "error: %s - custom_nvram_secro.c\n", strerror(errno));
+ if(outputHeader != NULL)
+ {
+ fclose(outputHeader);
+ }
+ if(outputHeader2 != NULL)
+ {
+ fclose(outputHeader2);
+ }
+ }
+ else
+ {
+ fprintf(outputHeader, COPYRIGHTS_HEADER, "custom_nvram_secro.c");
+
+ fprintf(outputHeader, "#if !defined(NVRAM_NOT_PRESENT)");
+
+ fprintf(outputHeader, "\n#include \"kal_general_types.h\"");
+ fprintf(outputHeader, "\n#include \"custom_nvram_sec.h\"");
+
+
+
+
+ i = 0;
+ secupack_idx = 0;
+ fprintf(outputHeader2, "#if defined(NVRAM_SEC_C_ONLY)");
+ fprintf(outputHeader2, "\nconst nvram_lid_enum secupack_nvram_lid_tbl[%d] = ", secupack_total_to_verify);
+ fprintf(outputHeader2, "\n{");
+
+ while (i < nvram_gen_total_lid)
+ {
+ nvram_ltable_entry_struct *ldi = &logical_data_item_table[i];
+ if (ldi && ldi->category & NVRAM_CATEGORY_SECUPACK)
+ {
+ fprintf(outputHeader2, "\n %d,", ldi->LID);
+
+
+ secupack_idx++;
+ }
+ i++;
+ }
+
+
+ fprintf(outputHeader2, "\n};");
+ fprintf(outputHeader2, "\n#endif");
+ fclose(outputHeader2);
+
+ fprintf(outputHeader, "\nconst kal_uint8 NVRAM_CUSTOM_KEY[] = ");
+
+ fprintf(outputHeader, "\n {");
+ nvram_gen_array(outputHeader, " ", NVRAM_AUTO_GEN_BYTE, NVRAM_SECRET_KEY_SIZE, custom_secret_key, KAL_FALSE, KAL_TRUE);
+ fprintf(outputHeader, "\n };");
+
+
+ fprintf(outputHeader, "\nconst kal_uint8 NVRAM_CUSTOM_KEY_SEED[] = ");
+ fprintf(outputHeader, "\n {");
+ nvram_gen_array(outputHeader, " ", NVRAM_AUTO_GEN_BYTE, NVRAM_CUSTOM_KEY_SEED_SIZE, custom_key_seed, KAL_FALSE, KAL_TRUE);
+ fprintf(outputHeader, "\n };");
+ // #endif
+ fprintf(outputHeader, "\n#if defined(__RES_PROT__)");
+ fprintf(outputHeader, "\n__attribute__((section(\"PROTECTED_RES_RW\")))");
+ fprintf(outputHeader, "\n#endif");
+
+ fprintf(outputHeader, "\nconst kal_uint8 NVRAM_SECUPACK_DEFAULT[] = ");
+
+ fprintf(outputHeader, "\n {");
+
+ i = 0;
+ secupack_idx = 0;
+ while (i < nvram_gen_total_lid)
+ {
+ nvram_ltable_entry_struct *ldi = &logical_data_item_table[i];
+ if (ldi && ldi->category & NVRAM_CATEGORY_SECUPACK)
+ {
+ #ifndef __NVRAM_PSEUDO_MERGE__
+ if (secupack_idx != 0)
+ fprintf(outputHeader, "\n");
+
+ fprintf(outputHeader, "\n /* %s */", ldi->str_LID);
+ #endif
+ nvram_gen_array(outputHeader,
+ " ",
+ NVRAM_AUTO_GEN_BYTE,
+ ldi->size * (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT? ldi->total_records : 1),
+ (kal_uint8 *)ldi->default_value,
+ KAL_TRUE,
+ (secupack_idx + 1 == secupack_total_to_verify));
+ secupack_idx++;
+ }
+ i++;
+ }
+
+
+ /* Fake data for special case */
+ if (secupack_total_to_verify == 0)
+ {
+ fprintf(outputHeader, "\n 0x00, 0x00");
+ }
+
+ fprintf(outputHeader, "\n };");
+
+
+
+ fprintf(outputHeader, "\nkal_uint32 secupack_total_to_verify = %d;", secupack_total_to_verify);
+ fprintf(outputHeader, "\n#endif /* NVRAM_NOT_PRESENT */");
+ fclose(outputHeader);
+ }
+}
+#endif /* __VENDOR_RELEASE__ */
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_mmi_cache
+* DESCRIPTION
+* output restore head file to nvram_restore_headfile.h
+* PARAMETERS
+* project_name [IN]
+* broad_ver [IN]
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_create_file(FILE **file_handle, char *file_path, char *file_name)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int mode_result;
+ char file_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(file_pathname, "%s/%s", file_path, file_name);
+
+ mode_result = access(file_pathname, 0);
+
+ if (mode_result == 0)
+ {
+ /* exists,but check if it can be written. */
+ mode_result = access(file_pathname, 2);
+ if (mode_result != 0)
+ {
+ fprintf(stderr, "error: %s exists,but it cannot be written.\n", file_name);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+ else
+ {
+ /* file not exist*/
+ mode_result = access(file_path, 2);
+ if (mode_result != 0)
+ {
+ fprintf(stderr, "error: cannot create file in folder: %s\n", file_path);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+
+ *file_handle = fopen(file_pathname, "w+");
+ if (*file_handle == NULL)
+ {
+ fprintf(stderr, "error: cannot write to %s in folder: %s(%s)\n", file_name, file_path, strerror(errno));
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ else
+ {
+ printf("Create %x:%s successfully!\n", *file_handle, file_pathname);
+ }
+ return;
+}
+
+void nvram_gen_close_file(FILE **file_handle)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ fclose(*file_handle);
+}
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_restore_function
+* DESCRIPTION
+* output restore function to nvram_user_restore_factory.c
+* PARAMETERS
+* project_name [IN]
+* broad_ver [IN]
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_restore_function(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *fh_restore_factory_c;
+ FILE *fh_restore_dom_h;
+ char output_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ int loop_app_idx;
+ int loop_space;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_pathname, "nvram_auto_gen/custom_nvram_restore.c");
+ nvram_gen_create_file(&fh_restore_factory_c,base_path,output_pathname);
+
+ sprintf(output_pathname,"nvram_auto_gen/nvram_restore_dom.h");
+ nvram_gen_create_file(&fh_restore_dom_h,base_path,output_pathname);
+
+ /* generate head file */
+ fprintf(fh_restore_factory_c, COPYRIGHTS_HEADER, "nvram_user_restore_factory.h");
+
+ fprintf_blank_line(fh_restore_factory_c);
+
+ fprintf(fh_restore_factory_c, "#ifndef NVRAM_NOT_PRESENT\n");
+ fprintf(fh_restore_factory_c, "#include \"kal_general_types.h\"\n");
+ fprintf(fh_restore_factory_c, "#include \"nvram_enums.h\"\n");
+ fprintf(fh_restore_factory_c, "#include \"custom_nvram_config.h\"\n");
+ fprintf(fh_restore_factory_c, "#include \"nvram_data_items.h\"\n");
+
+
+ /*
+ * Begin deal with system cache
+ */
+ nvram_gen_check_sys_cache();
+ nvram_gen_sys_cache_default(fh_restore_factory_c);
+ nvram_gen_sys_cache_res_func(fh_restore_factory_c);
+
+ /* Dom: data item (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_COMMENT, "LID");
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_BEGIN);
+
+ for (loop_app_idx = 0; loop_app_idx < nvram_total_num_restore_lid; loop_app_idx++)
+ {
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_ID, nvram_restore_lid_enum_array[loop_app_idx]);
+ for (loop_space = 0; loop_space < nvram_max_length_lid_str - strlen(nvram_restore_lid_enum_array[loop_app_idx]); loop_space++)
+ {
+ fprintf(fh_restore_dom_h, " ");
+ }
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_DESCRIPTION, nvram_restore_lid_description_point[loop_app_idx]);
+ }
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_END, "LID", "LID");
+ /* Dom: data item (begin) */
+
+ /*
+ * End deal with system cache
+ */
+
+ fprintf(fh_restore_factory_c, "#endif /* NVRAM_NOT_PRESENT */");
+
+ nvram_gen_close_file(&fh_restore_factory_c);
+ nvram_gen_close_file(&fh_restore_dom_h);
+}
+
+#ifndef __VENDOR_RELEASE__
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_database_key
+* DESCRIPTION
+* This function is used to generate the database key into custom_nvram_database.h
+* After that, codegen will use this file and generate the key into NVRAM database.
+* Metatool will read the key from database also.
+* Please notify codegen owner and metatool owner if you want to change the format.
+* PARAMETERS
+* void
+* RETURNS
+* void
+*****************************************************************************/
+void nvram_gen_database_key(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *database_h;
+ FILE *fh_restore_dom_h;
+ char output_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_pathname, "nvram_auto_gen/custom_nvram_database.h");
+ nvram_gen_create_file(&database_h,base_path,output_pathname);
+
+ nvram_gen_close_file(&database_h);
+}
+#endif /* __VENDOR_RELEASE__ */
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_custpack_table
+* DESCRIPTION
+* PARAMETERS
+* RETURNS
+*****************************************************************************/
+void nvram_gen_custpack_table(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *output, *output2;
+ char output_path[NVRAM_AUTO_GEN_MAX_PATH_LEN*2], output_path2[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+ int i,j;
+ nvram_ltable_entry_struct *ldi;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_path, "%s/nvram_auto_gen/nvram_custpack_table.c", base_path);
+ sprintf(output_path2, "%s/nvram_auto_gen/nvram_custpack_table_lid.c", base_path);
+
+ if(!(output = fopen(output_path, "w+")))
+ {
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ if(!(output2 = fopen(output_path2, "w+")))
+ {
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ fprintf(output,"#if defined(NVRAM_INTERNAL_USE) && !defined(NVRAM_NOT_PRESENT)\n");
+ fprintf(output,"/********************************************************\n");
+ fprintf(output," * This file is generated automatically by nvram_auto_gen\n");
+ fprintf(output," * Please do not modify it here manually \n");
+ fprintf(output," ***********************************************************/\n");
+
+ fprintf(output2,"#if defined(NVRAM_LTABLE_C_ONLY)\n");
+/*
+ for (i = NVRAM_EF_START, j = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+
+ if (ldi == NULL ||
+ (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue;
+ }
+
+ if (NVRAM_IS_CATEGORY_CUSTPACK(ldi->category))
+ {
+ j++;
+ fprintf(output, "extern kal_uint8 *%s;\n", ldi->str_default_value);
+ }
+ }
+
+ fprintf(output,"\n");
+*/
+ fprintf(output, "const custpack_nvram_header custpack_nvram_ptr = \n");
+ fprintf(output2, "const nvram_custpack_lid_tbl_struct custpack_nvram_lid_tbl = \n");
+
+ fprintf(output, "{\n"); fprintf(output2, "{\n");
+ fprintf(output, " 0,\n"); fprintf(output2, " 0,\n");
+ fprintf(output, " {\n"); fprintf(output2, " {\n");
+
+ for (i = NVRAM_EF_START, j = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+
+ if (ldi == NULL ||
+ (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue;
+ }
+
+ if (NVRAM_IS_CATEGORY_CUSTPACK(ldi->category))
+ {
+ j++;
+ fprintf(output, " %s", ldi->str_default_value);
+ fprintf(output2, " %d", ldi->LID);
+
+ if (j != custpack_total_to_verify)
+ {
+ fprintf(output,","); fprintf(output2,",");
+ }
+ fprintf(output,"\n"); fprintf(output2,"\n");
+ }
+ }
+
+
+ fprintf(output, " }\n"); fprintf(output2, " }\n");
+ fprintf(output, "};\n"); fprintf(output2, "};\n");
+ fprintf(output, "#endif /* NVRAM_INTERNAL_USE && NVRAM_NOT_PRESENT */\n\n");
+ fprintf(output2, "#endif\n\n");
+
+ fclose(output); fclose(output2);
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_parsing_size_from_mapfile
+* DESCRIPTION
+* get default value size.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+kal_uint32 nvram_parsing_size_from_mapfile(char *line_buf)
+{
+ char *pos = strrchr(line_buf, ' ');
+ kal_uint32 val = 0;
+
+ //skip LID name
+ if(pos == NULL) {
+ return 0;
+ }
+ *pos = '\0';
+ pos = strrchr(line_buf, '0');
+ if(pos == NULL) {
+ return 0;
+ }
+ pos = strrchr(line_buf, '\t');
+ if(pos == NULL) {
+ return 0;
+ }
+ val = strtol(++pos, NULL, 16);
+ //printf("%s:%d\n", pos, val);
+ return val;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_parsing_size_from_mapfile
+* DESCRIPTION
+* get default value size.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+kal_uint32 nvram_split(char *line_buf, char **dest)
+{
+ kal_uint32 num = 0;
+ char *pNext = line_buf;
+
+ while(*pNext != '\0' && (*pNext == ' ' || *pNext == '\t')) {
+ pNext++;
+ }
+ *dest = pNext;
+ while(*pNext != '\0') {
+ if(*pNext == ' ' || *pNext == '\t') {
+ *pNext = '\0';
+ while(*(++pNext) != '\0' && (*pNext == ' ' || *pNext == '\t'));
+ *(++dest) = pNext;
+ ++num;
+ }
+ pNext++;
+ }
+ return num;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_parsing_default_from_elf
+* DESCRIPTION
+* get default value from elf.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+kal_uint32 nvram_parsing_default_from_elf(char *file_path, nvram_ltable_entry_struct *ldi)
+{
+ kal_uint32 offset = 0, session = 0;
+ kal_uint32 offset4 = 0, offset5 = 0, size = 0;
+ FILE *file_handle = NULL;
+ char file_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN] = {0};
+ char line_buf[128];
+ char session_name[128];
+ char *dest[16];
+ char *str_default_value = ldi->str_default_value;
+
+ while(*str_default_value == '&') {
+ str_default_value++;
+ }
+ //Get default value start address from map
+ sprintf(file_pathname, "%s.map", file_path);
+ file_handle = fopen(file_pathname, "r");
+ if (file_handle == NULL)
+ {
+ printf("fail to open file %s\n", file_pathname);
+ return 0;
+ }
+ while(!feof(file_handle))
+ {
+ fgets(line_buf, 128, file_handle);
+ if((offset == 0) && strstr(line_buf, str_default_value)) {
+ nvram_split(line_buf, dest);
+ strcpy(session_name, dest[3]);
+ sscanf(dest[0],"%x", &offset);
+ sscanf(dest[4],"%x", &size);
+ ldi->default_value = malloc(size);
+ fseek(file_handle, 0, SEEK_SET);
+ continue;
+ }
+ if((offset > 0) && strstr(line_buf, session_name)) {
+ nvram_split(line_buf, dest);
+ sscanf(dest[4],"%x", &offset4);
+ sscanf(dest[5],"%x", &offset5);
+ offset -= (offset4 - offset5);
+ break;
+ }
+ }
+ fclose(file_handle);
+ file_handle = fopen(file_path, "rb");
+ if (file_handle == NULL)
+ {
+ printf("fail to open file %s\n", file_path);
+ return 0;
+ }
+ fseek(file_handle, offset, SEEK_SET);
+ fread(ldi->default_value, size, 1, file_handle);
+ fclose(file_handle);
+
+ return offset;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_default_value_check
+* DESCRIPTION
+* Check NVRAM LID size fit default value.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_default_value_check()
+{
+ kal_bool err = KAL_FALSE;
+ int mode_result;
+ FILE *file_handle;
+ char file_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ char line_buf[128];
+ nvram_ltable_entry_struct *ldi;
+ kal_uint32 i, default_val_size, ldi_size;
+
+ sprintf(file_pathname, "%s/nvram_auto_gen/nvram_auto_gen_target.map", base_path);
+ mode_result = access(file_pathname, 0);
+
+ if (mode_result != 0)
+ {
+ sprintf(file_pathname, "%s/nvram_auto_gen/nvram_auto_gen.map", base_path);
+ mode_result = access(file_pathname, 0);
+ if (mode_result != 0)
+ {
+ //file not exist
+ printf("MAP file not exist: %s\n", file_pathname);
+ return;
+ }
+ }
+
+ file_handle = fopen(file_pathname, "r");
+ if (file_handle == NULL)
+ {
+ fprintf(stderr, "error: cannot open file %s\n", file_pathname);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ while(!feof(file_handle))
+ {
+ fgets(line_buf, 128, file_handle);
+ for (i = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+ if((ldi->default_value == NVRAM_EF_FF_DEFAULT) ||
+ (ldi->default_value == NVRAM_EF_ZERO_DEFAULT) ||
+ (ldi->default_value == NVRAM_EF_SPECIAL_DEFAULT) ||
+ (ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT))
+ {
+ continue;
+ }
+ if(strstr(line_buf, ldi->str_default_value))
+ {
+ printf("%s", line_buf);
+ default_val_size = nvram_parsing_size_from_mapfile(line_buf);
+ if(!default_val_size) {
+ continue;
+ }
+ if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT) {
+ ldi_size = ldi->size * ldi->total_records;
+ }
+ else {
+ ldi_size = ldi->size;
+ }
+
+ if(default_val_size < ldi_size) {
+ fprintf(stderr, "error: %s[%d] does not match with %s (size %d)\n", ldi->str_default_value, default_val_size, ldi->str_LID, ldi_size);
+ err = KAL_TRUE;
+ }
+ else if((default_val_size > ldi_size) && (default_val_size % ldi_size)) {
+ fprintf(stderr, "error: %s[%d] does not match with %s (size %d)\n", ldi->str_default_value, default_val_size, ldi->str_LID, ldi_size);
+ err = KAL_TRUE;
+ }
+ }
+ }
+ }
+ fclose(file_handle);
+
+ if(err) {
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ return;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_cat_xml
+* DESCRIPTION
+* Output NVRAM LID size Information.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_cat_xml(void)
+{
+
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *cat_xml_file;
+ char output_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ kal_int32 i,j;
+ nvram_ltable_entry_struct *ldi;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_pathname, "nvram_auto_gen/custom_nvram_lid_cat.xml");
+ nvram_gen_create_file(&cat_xml_file,base_path,output_pathname);
+
+ fprintf(cat_xml_file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fprintf(cat_xml_file, "<APP>\n");
+
+ for (i = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+
+ if (ldi == NULL || (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue;
+ }
+
+ fprintf(cat_xml_file, " <NVRAMITEM id=\"%s\"", ldi->str_LID);
+ fprintf(cat_xml_file, " prefix=\"%s\"", ldi->fileprefix);
+ fprintf(cat_xml_file, " version=\"%s\"", ldi->fileverno);
+ fprintf(cat_xml_file, " record_size=\"%d\"", ldi->size);
+ fprintf(cat_xml_file, " total_record=\"%d\"", ldi->total_records);
+ fprintf(cat_xml_file, " lid_enum=\"%d\"", ldi->LID);
+ fprintf(cat_xml_file, " category=\"0x%x\"", ldi->category);
+ fprintf(cat_xml_file, " attribute=\"0x%x\">\n", ldi->attr);
+ if (ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT)
+ {
+ fprintf(cat_xml_file, " <DEFAULT_VALUE defaultByteFill=\"%s()\"></DEFAULT_VALUE>\n", ldi->str_default_value);
+ }
+ else if (ldi->default_value == NVRAM_EF_FF_DEFAULT)
+ {
+ fprintf(cat_xml_file, " <DEFAULT_VALUE defaultByteFill=\"0xFF\"></DEFAULT_VALUE>\n");
+ }
+ else if (ldi->default_value == NVRAM_EF_ZERO_DEFAULT)
+ {
+ fprintf(cat_xml_file, " <DEFAULT_VALUE defaultByteFill=\"0x00\"></DEFAULT_VALUE>\n");
+ }
+ else if (ldi->default_value == NVRAM_EF_SPECIAL_DEFAULT)
+ {
+ fprintf(cat_xml_file, " <DEFAULT_VALUE defaultByteFill=\"0x00\"></DEFAULT_VALUE>\n");
+ }
+ else
+ {
+ kal_uint32 default_value_size;
+
+
+ if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+ {
+ fprintf(cat_xml_file, " <DEFAULT_VALUE isMultiple=\"TRUE\"> \n");
+ default_value_size = ldi->size * ldi->total_records;
+ }
+ else
+ {
+ fprintf(cat_xml_file, " <DEFAULT_VALUE> \n");
+ default_value_size = ldi->size;
+ }
+ if(ldi->default_value == NULL) {
+ default_value_size = 0;
+ }
+
+ for ( j = 0 ; j < default_value_size ; j++)
+ {
+ if(default_value_size == 1)
+ {
+ fprintf(cat_xml_file, " [0x%02X]\n </DEFAULT_VALUE>\n", ldi->default_value[j]);
+ }
+ else if (j == 0)
+ {
+ fprintf(cat_xml_file, " [0x%02X,", ldi->default_value[j]);
+ }
+ else if (j == (default_value_size - 1))
+ {
+ fprintf(cat_xml_file, " 0x%02X]\n </DEFAULT_VALUE>\n", ldi->default_value[j]);
+ }
+ else if ((j & 0x0F) == 0x0F)
+ {
+ fprintf(cat_xml_file, " 0x%02X,\n", ldi->default_value[j]);
+ }
+ else if ((j & 0x0F) == 0)
+ {
+ fprintf(cat_xml_file, " 0x%02X,", ldi->default_value[j]);
+ }
+ else
+ {
+ fprintf(cat_xml_file, " 0x%02X,", ldi->default_value[j]);
+ }
+ }
+ }
+
+ //fprintf(cat_xml_file, " <DESCRIPTION> %s </DESCRIPTION>\n", ldi->description);
+ fprintf(cat_xml_file, " <DESCRIPTION> %s </DESCRIPTION>\n", ldi->str_LID);
+ fprintf(cat_xml_file, " </NVRAMITEM>\n");
+ }
+
+ fprintf(cat_xml_file, "</APP>\n");
+
+ nvram_gen_close_file(&cat_xml_file);
+}
+
+#ifndef __VENDOR_RELEASE__
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_cat_xml
+* DESCRIPTION
+* Output NVRAM LID size Information.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_trace(void)
+{
+
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *trace_file;
+ char output_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ kal_int32 i,j;
+ nvram_ltable_entry_struct *ldi;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_pathname, "nvram_auto_gen/nvram_gen_trc.h");
+ nvram_gen_create_file(&trace_file,base_path,output_pathname);
+
+ fprintf(trace_file, "typedef enum {\n");
+
+ for (i = NVRAM_EF_SYS_LID; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+
+ if (ldi == NULL || (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue;
+ }
+ else
+ {
+ fprintf(trace_file, " _%s = %d,\n", ldi->str_LID, ldi->LID);
+ }
+ }
+
+ fprintf(trace_file, " NVRAM_TRC_LID_TOTAL\n}nvram_trc_lid_enum;\n");
+
+ nvram_gen_close_file(&trace_file);
+}
+
+#endif //__VENDOR_RELEASE__
+#endif /* NVRAM_NOT_PRESENT */
+
+void nvram_gen_check_multiple_attr_white_list()
+{
+ int i, j;
+ nvram_ltable_entry_struct *ldi;
+ kal_bool in_list;
+ kal_bool check_result = KAL_TRUE;
+
+
+ for (i = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+ if (ldi == NULL || (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue;
+ }
+
+ if (!NVRAM_IS_ATTR_MULTIPLE(ldi->attr))
+ {
+ continue;
+ }
+
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+ if (ldi->attr & NVRAM_ATTR_MSP)
+ {
+ continue;
+ }
+ #endif
+
+ if (ldi->str_LID == NULL) {
+ continue;
+ }
+
+ in_list = KAL_FALSE;
+
+ for (j = 0; j < g_nr_nvram_white_list_for_multiple_attr; j++)
+ {
+ if (0 == strcmp(ldi->str_LID, g_nvram_white_list_for_multiple_attr[j])) {
+ in_list = KAL_TRUE;
+ break;
+ }
+ }
+
+ if (KAL_TRUE != in_list) {
+ // Not in white list
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: LID %s have MULTIPLE attribute but not in white list!!\n", ldi->str_LID);
+ }
+ }
+
+ if (KAL_TRUE != check_result) {
+ fprintf(stderr, "error: Please contact NVRAM owner if you really need this attribute for the LID\n");
+ exit(-1);
+ }
+}
+
+
+void nvram_gen_check_write_protect_attr_white_list()
+{
+ int i, j;
+ nvram_ltable_entry_struct *ldi;
+ kal_bool in_list;
+ kal_bool check_result = KAL_TRUE;
+
+ for (i = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+ if (ldi == NULL || (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue;
+ }
+
+ if (!NVRAM_IS_ATTR_WRITEPROTECT(ldi->attr))
+ {
+ continue;
+ }
+
+ if (ldi->str_LID == NULL) {
+ continue;
+ }
+
+ in_list = KAL_FALSE;
+
+ for (j = 0; j < g_nr_nvram_white_list_for_write_protect_attr; j++)
+ {
+ if (0 == strcmp(ldi->str_LID, g_nvram_white_list_for_write_protect_attr[j])) {
+ in_list = KAL_TRUE;
+ break;
+ }
+ }
+
+ if (KAL_TRUE != in_list) {
+ // Not in white list
+ check_result = KAL_FALSE;
+ fprintf(stderr, "LID %s have WRITE_PROTECT attribute but not in white list!!\n", ldi->str_LID);
+ }
+ }
+
+ if (KAL_TRUE != check_result) {
+ fprintf(stderr, "Please contact NVRAM owner if you really need this attribute for the LID(s)\n");
+ exit(-2);
+ }
+}
+
+void nvram_gen_check_lid_enum_overlapping()
+{
+ int i, j;
+ nvram_ltable_entry_struct *ldi1;
+ nvram_ltable_entry_struct *ldi2;
+
+ kal_bool check_result = KAL_TRUE;
+
+ if(nvram_gen_total_lid < 2) {
+ fprintf(stderr, "error: Invalid nvram_gen_total_lid during nvram_gen_check_lid_enum_overlapping()\n");
+ exit(-3);
+ }
+ for (i = 0; i < nvram_gen_total_lid-1; i++)
+ {
+ ldi1 = &logical_data_item_table[i];
+ for (j = i+1; j < nvram_gen_total_lid; j++) {
+ ldi2 = &logical_data_item_table[j];
+ if (ldi1->LID == ldi2->LID) {
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: %d:%s and %d:%s have same enum value, please check if LID duplicated defined or enum value overlapped\n", i, ldi1->str_LID, j, ldi2->str_LID);
+ }
+ }
+ }
+
+ if (KAL_TRUE != check_result) {
+ fprintf(stderr, "error: Please contact NVRAM owner if your NVRAM sub-group size should be enlarged\n");
+ exit(-3);
+ }
+}
+
+
+typedef enum {
+ NVRAM_CONFLICT_ATTR_ATTR,
+ NVRAM_CONFLICT_CATE_ATTR,
+ NVRAM_CONFLICT_CATE_CATE,
+} nvram_CATE_ATTR_conflict_type_enum;
+
+typedef struct {
+ nvram_CATE_ATTR_conflict_type_enum type;
+ kal_uint32 cate_attr1;
+ kal_char *cate_attr1_str;
+ kal_uint32 cate_attr2;
+ kal_char *cate_attr2_str;
+}nvram_CATE_ATTR_conflict_struct;
+
+#define CATE_ATTR(x) (x), #x
+
+static nvram_CATE_ATTR_conflict_struct nvram_CATE_ATTR_conflict_table[] =
+{
+ // Attribute conflicts
+ {NVRAM_CONFLICT_ATTR_ATTR, CATE_ATTR(NVRAM_ATTR_MULTIPLE), CATE_ATTR(NVRAM_ATTR_PACKAGE)},
+ {NVRAM_CONFLICT_ATTR_ATTR, CATE_ATTR(NVRAM_ATTR_OTA_RESET), CATE_ATTR(NVRAM_ATTR_RESERVE_BACKWARD)},
+ {NVRAM_CONFLICT_ATTR_ATTR, CATE_ATTR(NVRAM_ATTR_RAW_DATA), CATE_ATTR(NVRAM_ATTR_PACKAGE|NVRAM_ATTR_MULTIPLE|NVRAM_ATTR_RING)},
+ {NVRAM_CONFLICT_ATTR_ATTR, CATE_ATTR(NVRAM_ATTR_RAW_DATA), CATE_ATTR(NVRAM_ATTR_WRITEPROTECT|NVRAM_ATTR_CONFIDENTIAL|NVRAM_ATTR_MSP)},
+
+ // Categories conflicts
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_FUNC_DEFAULT), CATE_ATTR(NVRAM_CATEGORY_CUSTPACK|NVRAM_CATEGORY_SECUPACK)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_CALIBRAT), CATE_ATTR(~(NVRAM_CATEGORY_FUNC_DEFAULT|NVRAM_CATEGORY_CUSTPACK|NVRAM_CATEGORY_SECUPACK))},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_IMPORTANT), CATE_ATTR(NVRAM_CATEGORY_IMPORTANT_L1|NVRAM_CATEGORY_IMPORTANT_L4|NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_OTP)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_IMPORTANT_L4), CATE_ATTR(NVRAM_CATEGORY_IMPORTANT_L1|NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_OTP)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_IMPORTANT_L1), CATE_ATTR(NVRAM_CATEGORY_INTERNAL|NVRAM_CATEGORY_OTP)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_INTERNAL), CATE_ATTR(NVRAM_CATEGORY_CUSTOM_SENSITIVE |NVRAM_CATEGORY_OTP)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_CUSTOM_SENSITIVE), CATE_ATTR(NVRAM_CATEGORY_CUSTPACK|NVRAM_CATEGORY_SECUPACK|NVRAM_CATEGORY_OTP)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_CUSTPACK), CATE_ATTR(NVRAM_CATEGORY_SECUPACK|NVRAM_CATEGORY_OTP)},
+ {NVRAM_CONFLICT_CATE_CATE, CATE_ATTR(NVRAM_CATEGORY_SECUPACK), CATE_ATTR(NVRAM_CATEGORY_OTP)},
+
+ // Attribute & Category conflicts
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_CALIBRAT), CATE_ATTR(NVRAM_ATTR_MULTIPLE|NVRAM_ATTR_MSP|NVRAM_ATTR_RING)},
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_CALIBRAT), CATE_ATTR(NVRAM_ATTR_OTA_RESET|NVRAM_ATTR_RESERVE_BACKWARD)},
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_INTERNAL), CATE_ATTR(NVRAM_ATTR_PACKAGE)},
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_SECUPACK), CATE_ATTR(NVRAM_ATTR_PACKAGE|NVRAM_ATTR_RAW_DATA)},
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_CUSTPACK), CATE_ATTR(NVRAM_ATTR_RAW_DATA)},
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_FUNC_DEFAULT), CATE_ATTR(NVRAM_ATTR_RAW_DATA)},
+ {NVRAM_CONFLICT_CATE_ATTR, CATE_ATTR(NVRAM_CATEGORY_OTP), CATE_ATTR(NVRAM_ATTR_AVERAGE)},
+};
+
+static kal_int32 nvram_CATE_ATTR_conflict_table_entries = sizeof(nvram_CATE_ATTR_conflict_table)/sizeof(nvram_CATE_ATTR_conflict_table[0]);
+
+void nvram_gen_check_cate_attr_confilicts()
+{
+ int i, j;
+ nvram_ltable_entry_struct *ldi;
+
+ kal_bool check_result = KAL_TRUE;
+
+ for (i = 0; i < nvram_gen_total_lid-1; i++)
+ {
+ ldi = &logical_data_item_table[i];
+ for (j = 0; j < nvram_CATE_ATTR_conflict_table_entries; j++) {
+ nvram_CATE_ATTR_conflict_struct *check_cond = &nvram_CATE_ATTR_conflict_table[j];
+ switch (check_cond->type) {
+ case NVRAM_CONFLICT_ATTR_ATTR:
+ if ((ldi->attr & check_cond->cate_attr1) != 0 && (ldi->attr & (~check_cond->cate_attr1) & check_cond->cate_attr2) != 0) {
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: LID %s have conflict attributes %s and %s\n", ldi->str_LID, check_cond->cate_attr1_str, check_cond->cate_attr2_str);
+ }
+ break;
+ case NVRAM_CONFLICT_CATE_ATTR:
+ if ((ldi->category & check_cond->cate_attr1) != 0 && (ldi->attr & check_cond->cate_attr2) != 0) {
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: LID %s have conflict category %s with attribute %s\n", ldi->str_LID, check_cond->cate_attr1_str, check_cond->cate_attr2_str);
+ }
+ break;
+ case NVRAM_CONFLICT_CATE_CATE:
+ if ((ldi->category & check_cond->cate_attr1) != 0 && (ldi->category & (~check_cond->cate_attr1) & check_cond->cate_attr2) != 0) {
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: LID %s have conflict categories %s and %s\n", ldi->str_LID, check_cond->cate_attr1_str, check_cond->cate_attr2_str);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (KAL_TRUE != check_result) {
+ fprintf(stderr, "error: Please adjust LID's attributes and/or categories\n");
+ exit(-4);
+ }
+}
+
+void nvram_gen_check_special_lid_parameter()
+{
+ int i, j;
+ nvram_ltable_entry_struct *ldi;
+ kal_bool check_result = KAL_TRUE;
+
+ for (i = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+
+ // check RAW_DATA size and default value
+ if(ldi->attr & NVRAM_ATTR_RAW_DATA) {
+ if(ldi->total_records > 1) {
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: NVRAM_ATTR_RAW_DATA can not support multiple record.\n");
+ }
+ if(ldi->default_value != NVRAM_EF_ZERO_DEFAULT) {
+ check_result = KAL_FALSE;
+ fprintf(stderr, "error: NVRAM_ATTR_RAW_DATA can only use NVRAM_EF_ZERO_DEFAULT.\n");
+ }
+ }
+
+ #if (defined(__NVRAM_LID_HASH_CHECK__) && defined(__MTK_INTERNAL__))
+ // check LID hash key
+ printf("check %s hash key 0x%08x\n", ldi->str_LID, ldi->hash_key);
+ if(!(ldi->fileprefix[0]=='C' && ldi->fileprefix[1]=='U')) {
+ if(!nvram_hash_check(ldi)) {
+ check_result = KAL_FALSE;
+ }
+ }
+ #endif
+ }
+
+ if (KAL_TRUE != check_result) {
+ exit(-5);
+ }
+}
+
+void nvram_fix_lid_size()
+{
+ kal_uint32 i, j, offset = 0;
+ FILE *file_handle = NULL;
+ char file_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN] = {0};
+ nvram_ltable_entry_struct *ldi = NULL;
+ nvram_ltable_entry_struct_target *ldi_target = NULL;
+ char line_buf[128], *dest[16];
+ char *ldi_buf = NULL;
+
+ //Get NVRAM_LTABLE Start
+ sprintf(file_pathname, "%s/nvram_auto_gen/nvram_auto_gen_target.map", base_path);
+ file_handle = fopen(file_pathname, "r");
+ if (file_handle == NULL)
+ {
+ printf("fail to open file %s\n", file_pathname);
+ return;
+ }
+ while(!feof(file_handle))
+ {
+ fgets(line_buf, 128, file_handle);
+ if(!offset && strstr(line_buf, "NVRAM_LTABLE")) {
+ nvram_split(line_buf, dest);
+ sscanf(dest[5],"%x", &offset);
+ continue;
+ }
+ if(strstr(line_buf, "nvram_long_length")) {
+ nvram_split(line_buf, dest);
+ sscanf(dest[4],"%x", &nvram_long_length);
+ continue;
+ }
+ if(strstr(line_buf, "nvram_ptr_length")) {
+ nvram_split(line_buf, dest);
+ sscanf(dest[4],"%x", &nvram_ptr_length);
+ continue;
+ }
+ if(strstr(line_buf, "nvram_padding_length")) {
+ nvram_split(line_buf, dest);
+ sscanf(dest[4],"%x", &nvram_padding_length);
+ continue;
+ }
+ if(strstr(line_buf, "nvram_ltable_entry_length")) {
+ nvram_split(line_buf, dest);
+ sscanf(dest[4],"%x", &nvram_ltable_entry_length);
+ continue;
+ }
+ }
+ fclose(file_handle);
+
+ //Fix LID size in ltable
+ sprintf(file_pathname, "%s/nvram_auto_gen/nvram_auto_gen_target", base_path);
+ file_handle = fopen(file_pathname, "rb");
+ if (file_handle == NULL)
+ {
+ printf("fail to open file %s\n", file_pathname);
+ return;
+ }
+ fseek(file_handle, offset, SEEK_SET);
+ ldi_buf = malloc(nvram_ltable_entry_length * nvram_gen_total_lid);
+ fread(ldi_buf, nvram_ltable_entry_length * nvram_gen_total_lid, 1, file_handle);
+ fclose(file_handle);
+
+ for (i = 0; i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+ // search lid in target load
+ for(j = 0; j < nvram_gen_total_lid; j++) {
+ ldi_target = &ldi_buf[nvram_ltable_entry_length * j];
+ if((ldi->LID == ldi_target->LID) &&
+ (*(kal_uint32*)ldi->fileprefix == *(kal_uint32*)ldi_target->fileprefix) )
+ {
+ break;
+ }
+ }
+ if(ldi->LID != ldi_target->LID) {
+ if((ldi->LID & 0xFF00) != NVRAM_LID_GRP_INTERNAL(0)) {
+ printf("%s[%d] search fail in target load.\n", ldi->str_LID, ldi->LID);
+ }
+ continue;
+ }
+ if(ldi->size != ldi_target->size) {
+ printf("%s[%d] fix record %s(size %d) <= %s(size %d)\n", ldi->str_LID, ldi->LID, ldi->fileprefix, ldi->size, ldi_target->fileprefix, ldi_target->size);
+ ldi->size = ldi_target->size;
+ //Mark default value mistake
+ if (!(ldi->category & NVRAM_CATEGORY_FUNC_DEFAULT) &&
+ (ldi->default_value != NVRAM_EF_FF_DEFAULT) &&
+ (ldi->default_value != NVRAM_EF_ZERO_DEFAULT) )
+ {
+ offset = nvram_parsing_default_from_elf(file_pathname, ldi);
+ printf("%s[%d] fix default %s from 0x%X\n", ldi->str_LID, ldi->LID, ldi->str_default_value, offset);
+ }
+ }
+ else {
+ //printf("%s[%d] check pass.\n", ldi->str_LID, ldi->LID);
+ }
+ }
+
+}
+
+void nvram_gen_mcf_ota_lid_list(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 i,j;
+ FILE* ota_lid_list_hdl;
+ nvram_ltable_entry_struct *ldi;
+ static char **nvram_ota_lid_str_point;
+ static char **nvram_ota_by_op_lid_str_point;
+ int nvram_total_num_ota_lid = 0;
+ int nvram_total_num_ota_by_op_lid = 0;
+ char pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN*2];
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ /* Gen information for tools */
+ sprintf(pathname, "%s/nvram_auto_gen/nvram_lid_list_for_mcf.h", base_path);
+ ota_lid_list_hdl = fopen(pathname,"w+");
+ if (ota_lid_list_hdl == NULL)
+ {
+ fprintf(stderr, "error: %s - nvram_lid_list_for_mcf.h\n", strerror(errno));
+ }
+ else
+ {
+ nvram_ota_lid_str_point = malloc(sizeof(char *) * nvram_gen_total_lid);
+ nvram_ota_by_op_lid_str_point = malloc(sizeof(char *) * nvram_gen_total_lid);
+ for (i = 0;i < nvram_gen_total_lid; i++)
+ {
+ ldi = &logical_data_item_table[i];
+ if (ldi == NULL ||
+ (ldi->LID == 0 && ldi->size == 0 && ldi->total_records == 0))
+ {
+ continue; /* invalid LID */
+ }
+ if(ldi->attr & NVRAM_ATTR_MCF_OTA)
+ {
+ nvram_ota_lid_str_point[nvram_total_num_ota_lid] = ldi->str_LID;
+ nvram_total_num_ota_lid++;
+ }
+ else if(ldi->attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY)
+ {
+ nvram_ota_lid_str_point[nvram_total_num_ota_lid] = ldi->str_LID;
+ nvram_total_num_ota_lid++;
+ }
+ if(ldi->attr & NVRAM_ATTR_MCF_OTA_BY_OP)
+ {
+ nvram_ota_by_op_lid_str_point[nvram_total_num_ota_by_op_lid] = ldi->str_LID;
+ nvram_total_num_ota_by_op_lid++;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ fprintf(ota_lid_list_hdl, COPYRIGHTS_HEADER, "nvram_lid_list_for_mcf.h");
+
+ fprintf(ota_lid_list_hdl, "#ifndef __NVRAM_LID_LIST_FOR_MCF__\n");
+ fprintf(ota_lid_list_hdl, "#define __NVRAM_LID_LIST_FOR_MCF__\n");
+ fprintf(ota_lid_list_hdl, "#include \"kal_general_types.h\"\n");
+
+ fprintf(ota_lid_list_hdl, R_F_DOM_ENUM_BEGIN);
+ for(j = 0; j < nvram_total_num_ota_lid;j++)
+ {
+ fprintf(ota_lid_list_hdl, " %s, \n", nvram_ota_lid_str_point[j]);
+ }
+ fprintf(ota_lid_list_hdl, R_F_MCF_ENUM_END, "LID", "nvram_mcf_ota_lid");
+
+ fprintf(ota_lid_list_hdl, R_F_DOM_ENUM_BEGIN);
+ for(j = 0; j < nvram_total_num_ota_by_op_lid;j++)
+ {
+ fprintf(ota_lid_list_hdl, " %s, \n", nvram_ota_by_op_lid_str_point[j]);
+ }
+ fprintf(ota_lid_list_hdl, R_F_MCF_ENUM_END, "LID", "nvram_mcf_ota_by_operator_lid");
+ fprintf(ota_lid_list_hdl, "#endif\n");
+ fclose(ota_lid_list_hdl);
+ }
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* main
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+int main(int argc, char *argv[])
+{
+
+#ifndef NVRAM_NOT_PRESENT
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ if (argc > 0)
+ {
+
+ typedef void (*_indirect_init_func)(void);
+ extern unsigned char indirect_init_begin, indirect_init_end;
+ extern void fs_quota_init(void);
+
+ kal_uint32 *value = (kal_uint32 *)&indirect_init_begin;
+ kal_uint32 i, total = (kal_uint32)(&indirect_init_end - &indirect_init_begin)/sizeof(_indirect_init_func);
+
+ printf("begin:%x, end:%x\n", &indirect_init_begin, &indirect_init_end);
+ printf("init_func = %x, total = %d\n", *value, total);
+ for (i = 0; i < total; i++)
+ {
+ _indirect_init_func init_func = (_indirect_init_func)*value + i ;
+
+ printf("init_func[%i] = %x\n", i, init_func);
+ if (init_func)
+ {
+ init_func();
+ }
+ }
+
+ printf("argv[1] = %s, argv[2] = %s\n", argv[1], argv[2]);
+
+ if (strcasecmp(argv[1], "MSWin32") == 0)
+ {
+ sprintf(indirect_end_symbol, "_indirect_init_end = .");
+ }
+ else
+ {
+ sprintf(indirect_end_symbol, "indirect_init_end = .");
+ }
+
+
+ printf("nvram_gen_construct_ltable\n");
+ nvram_gen_construct_ltable();
+
+ sprintf(base_path, "%s", argv[1]);
+
+ printf("nvram_fix_lid_size\n");
+ nvram_fix_lid_size();
+ #if defined(__NVRAM_LID_CACHE__)
+ printf("nvram construct cache info table\n");
+ cache_info_table_generator(base_path);
+ #endif
+
+ #if defined(__NV_CHKSUM_ENHANCE__)
+ chksum_algo_config_generator(base_path);
+ #endif
+
+ printf("nvram_default_value_check\n");
+ nvram_default_value_check();
+
+ #ifndef __VENDOR_RELEASE__
+ printf("nvram_gen_trace\n");
+ nvram_gen_trace();
+ #endif
+
+ printf("nvram_gen_cat_xml\n");
+ nvram_gen_cat_xml();
+
+ printf("nvram_gen_lid_size\n");
+ nvram_gen_lid_size();
+
+ printf("nvram_gen_statistic\n");
+ nvram_gen_statistic();
+
+ printf("nvram_gen_restore_function\n");
+ nvram_gen_restore_function();
+
+ #if !defined(__L1_STANDALONE__) && defined(__MMI_FMI__)
+ printf("nvram_gen_custpack_table\n");
+ nvram_gen_custpack_table();
+ #endif
+
+ #ifndef __VENDOR_RELEASE__
+ printf("nvram_gen_secro\n");
+ nvram_gen_secro();
+ #endif
+
+ #if !defined(__VENDOR_RELEASE__)
+ printf("nvram_gen_database_key\n");
+ nvram_gen_database_key();
+ #endif
+
+ printf("nvram_gen_fs_quota: begin\n");
+ nvram_gen_fs_quota(base_path);
+ printf("nvram_gen_fs_quota: end\n");
+
+ printf("build time check: begin\n");
+ printf("build time check: lid enum overlapping\n");
+ nvram_gen_check_lid_enum_overlapping();
+ //printf("build time check: multiple attr white list\n");
+ //nvram_gen_check_multiple_attr_white_list();
+ printf("build time check: write protect attr white list\n");
+ nvram_gen_check_write_protect_attr_white_list();
+ printf("build time check: cate attr confilicts\n");
+ nvram_gen_check_cate_attr_confilicts();
+ printf("build time check: special lid parameter\n");
+ nvram_gen_check_special_lid_parameter();
+ printf("build time check: end\n");
+
+ nvram_gen_ltable_list();
+ nvram_gen_mcf_ota_lid_list();
+
+
+
+ }
+ return 0;
+#else
+ printf("NVRAM_NOT_PRESENT\n");
+ return 0;
+#endif
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_auto_gen.txt b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen.txt
new file mode 100644
index 0000000..ccf5661
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen.txt
@@ -0,0 +1,121 @@
+OUTPUT_FORMAT(pei-i386)
+SEARCH_DIR("/mingw/mingw32/lib"); SEARCH_DIR("/mingw/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");
+ENTRY(_mainCRTStartup)
+SECTIONS
+{
+ .text __image_base__ + __section_alignment__ :
+ {
+ *(.init)
+ *(.text)
+ *(SORT(.text$*))
+ *(.glue_7t)
+ *(.glue_7)
+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
+ LONG (-1); *(SORT(.ctors.*)); *(.ctors); *(.ctor); LONG (0);
+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
+ LONG (-1); *(SORT(.dtors.*)); *(.dtors); *(.dtor); LONG (0);
+ *(.fini)
+ /* ??? Why is .gcc_exc here? */
+ *(.gcc_exc)
+ etext = .;
+ *(.gcc_except_table)
+ }
+ /* The Cygwin32 library uses a section to avoid copying certain data
+ on fork. This used to be named ".data". The linker used
+ to include this between __data_start__ and __data_end__, but that
+ breaks building the cygwin32 dll. Instead, we name the section
+ ".data_cygwin_nocopy" and explictly include it after __data_end__. */
+ .data BLOCK(__section_alignment__) :
+ {
+ __data_start__ = . ;
+ *(.data)
+ *(.data2)
+ *(SORT(.data$*))
+ __data_end__ = . ;
+ *(.data_cygwin_nocopy)
+ }
+ .rdata BLOCK(__section_alignment__) :
+ {
+ *(.rdata)
+ *(SORT(.rdata$*))
+ *(.eh_frame)
+ ___RUNTIME_PSEUDO_RELOC_LIST__ = .;
+ __RUNTIME_PSEUDO_RELOC_LIST__ = .;
+ *(.rdata_runtime_pseudo_reloc)
+ ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
+ __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
+ }
+ .pdata BLOCK(__section_alignment__) :
+ {
+ *(.pdata)
+ }
+ .bss BLOCK(__section_alignment__) :
+ {
+ __bss_start__ = . ;
+ *(.bss)
+ *(COMMON)
+ __bss_end__ = . ;
+ }
+ .edata BLOCK(__section_alignment__) :
+ {
+ *(.edata)
+ }
+ /DISCARD/ :
+ {
+ *(.debug$S)
+ *(.debug$T)
+ *(.debug$F)
+ *(.drectve)
+ }
+ .idata BLOCK(__section_alignment__) :
+ {
+ /* This cannot currently be handled with grouped sections.
+ See pe.em:sort_sections. */
+ SORT(*)(.idata$2)
+ SORT(*)(.idata$3)
+ /* These zeroes mark the end of the import list. */
+ LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
+ SORT(*)(.idata$4)
+ SORT(*)(.idata$5)
+ SORT(*)(.idata$6)
+ SORT(*)(.idata$7)
+ }
+ .CRT BLOCK(__section_alignment__) :
+ {
+ *(SORT(.CRT$*))
+ }
+ .endjunk BLOCK(__section_alignment__) :
+ {
+ /* end is deprecated, don't use it */
+ end = .;
+ _end = .;
+ __end__ = .;
+ }
+ .rsrc BLOCK(__section_alignment__) :
+ {
+ *(.rsrc)
+ *(SORT(.rsrc$*))
+ }
+ .reloc BLOCK(__section_alignment__) :
+ {
+ *(.reloc)
+ }
+ .stab BLOCK(__section_alignment__) (NOLOAD) :
+ {
+ [ .stab ]
+ }
+ .stabstr BLOCK(__section_alignment__) (NOLOAD) :
+ {
+ [ .stabstr ]
+ }
+
+ NVRAM_LTABLE :
+ {
+ _nvram_ltable_begin = .;
+ *(_nvram_ltable)
+ _nvram_ltable_end = .;
+ _indirect_init_begin = .;
+ *(_indirect_init)
+ _indirect_init_end = .;
+ }
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_TARGET.c b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_TARGET.c
new file mode 100644
index 0000000..ae4e4cf
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_TARGET.c
@@ -0,0 +1,473 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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_auto_gen_TARGET.c
+ *
+ * Project:
+ * --------
+ * UMOLYA
+ *
+ * Description:
+ * ------------
+ * This file is intends for generating NVRAM ltable information. Not for execute.
+ *
+ * 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!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stddef.h>
+
+#include "nvram_auto_gen.h"
+#include "custom_nvram_config.h"
+#include "nvram_editor_data_item.h"
+#include "nvram_data_items.h"
+
+#if defined(__MMI_FMI__)
+#include "nvram_user_defs.h"
+#endif
+
+#ifndef __VENDOR_RELEASE__
+#include "custom_nvram_sec.h"
+#endif
+
+/* Add pseudo merge headfile */
+#include "nvram_pseudo_merge.h"
+
+#include "nvram_internal.h"
+
+#include "nvram_white_list.h"
+#ifdef __NVRAM_AUTOGEN_V2__
+#include "nvram_lid_stu_tmp.h"
+#endif
+
+
+typedef struct {
+ kal_uint8 test;
+ kal_uint16 test2;
+}nvram_padding_structure2;
+typedef struct {
+ nvram_padding_structure2 test[3];
+}nvram_padding_structure;
+
+kal_char const nvram_long_length[sizeof(long)] = {0};
+kal_char const nvram_ptr_length[sizeof(char*)] = {0};
+kal_char const nvram_padding_length[sizeof(nvram_padding_structure)] = {0};
+kal_char const nvram_ltable_entry_length[sizeof(nvram_ltable_entry_struct)] = {0};
+
+kal_uint32 nvram_ltable_entry_size = sizeof(nvram_ltable_entry_struct);
+kal_uint16 ent_oft_lid = offsetof(nvram_ltable_entry_struct, LID);
+kal_uint16 ent_oft_trecords = offsetof(nvram_ltable_entry_struct, total_records);
+kal_uint16 ent_oft_size = offsetof(nvram_ltable_entry_struct, size);
+kal_uint16 ent_oft_str_dval = offsetof(nvram_ltable_entry_struct, str_default_value);
+kal_uint16 ent_oft_d_val = offsetof(nvram_ltable_entry_struct, default_value);
+kal_uint16 ent_oft_cate = offsetof(nvram_ltable_entry_struct, category);
+kal_uint16 ent_oft_attr = offsetof(nvram_ltable_entry_struct, attr);
+kal_uint16 ent_oft_fprefix = offsetof(nvram_ltable_entry_struct, fileprefix);
+kal_uint16 ent_oft_fverno = offsetof(nvram_ltable_entry_struct, fileverno);
+kal_uint16 ent_oft_s_lid = offsetof(nvram_ltable_entry_struct, str_LID);
+kal_uint16 ent_oft_desc = offsetof(nvram_ltable_entry_struct, description);
+
+#if(defined(__NVRAM_LID_HASH_CHECK__) && defined(__MTK_INTERNAL__))
+kal_uint16 ent_oft_hash = offsetof(nvram_ltable_entry_struct, hash_key);
+#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
+
+
+// =============internal ltable ======================
+
+ltable_entry_struct logical_data_item_table_internal[] =
+{
+ {
+ NVRAM_EF_SYS_LID,
+ NVRAM_EF_SYS_TOTAL,
+ NVRAM_EF_SYS_SIZE,
+ NVRAM_NORMAL(NVRAM_EF_FF_DEFAULT),
+ NVRAM_CATEGORY_IMPORTANT_L1 ,
+ NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_MULTIPLE ,
+ "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_NORMAL(NVRAM_EF_FF_DEFAULT),
+ NVRAM_CATEGORY_IMPORTANT ,
+ NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_FAULT_ASSERT | NVRAM_ATTR_COMMITTED
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+ | NVRAM_ATTR_MSP | NVRAM_ATTR_MULTIPLE
+ #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,
+ "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_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+ NVRAM_CATEGORY_USER,
+ NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_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
+
+};
+
+
+/*****************************************************************************
+* FUNCTION
+* main
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+int main(int argc, char *argv[])
+{
+#ifndef NVRAM_NOT_PRESENT
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ return 0;
+#else
+ return 0;
+#endif
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_TARGET.txt b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_TARGET.txt
new file mode 100644
index 0000000..935a665
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_TARGET.txt
@@ -0,0 +1,220 @@
+ENTRY(_start)
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . =
+SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
+
+ .interp : { *(.interp) }
+ .note.gnu.build-id : { *(.note.gnu.build-id) }
+ .hash : { *(.hash) }
+ .gnu.hash : { *(.gnu.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rela.dyn :
+ {
+ *(.rela.init)
+ *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
+ *(.rela.fini)
+ *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
+ *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
+ *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
+ *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
+ *(.rela.ctors)
+ *(.rela.dtors)
+ *(.rela.got)
+ *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
+ *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
+ *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
+ *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
+ *(.rela.ifunc)
+ }
+ .rela.plt :
+ {
+ *(.rela.plt)
+ PROVIDE_HIDDEN (__rela_iplt_start = .);
+ *(.rela.iplt)
+ PROVIDE_HIDDEN (__rela_iplt_end = .);
+ }
+ .init :
+ {
+ KEEP (*(.init))
+ } =0x90909090
+ .plt : { *(.plt) *(.iplt) }
+ .text :
+ {
+ *(.text.unlikely .text.*_unlikely)
+ *(.text .stub .text.* .gnu.linkonce.t.*)
+ /* .gnu.warning sections are handled specially by elf32.em. */
+ *(.gnu.warning)
+ } =0x90909090
+ .fini :
+ {
+ KEEP (*(.fini))
+ } =0x90909090
+ PROVIDE (__etext = .);
+ PROVIDE (_etext = .);
+ PROVIDE (etext = .);
+ .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
+ .rodata1 : { *(.rodata1) }
+ .eh_frame_hdr : { *(.eh_frame_hdr) }
+ .eh_frame : { KEEP (*(.eh_frame)) }
+ .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
+ /* Adjust the address for the data segment. We want to adjust up to
+ the same address within the page on the next page up. */
+ . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (
+CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE),
+CONSTANT (COMMONPAGESIZE));
+
+ /* Exception handling */
+ .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+ /* Thread Local Storage sections */
+ .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
+ .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
+ .preinit_array :
+ {
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ }
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(.fini_array))
+ KEEP (*(SORT(.fini_array.*)))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ }
+ .ctors :
+ {
+ /* gcc uses crtbegin.o to find the start of
+ the constructors, so we make sure it is
+ first. Because this is a wildcard, it
+ doesn't matter if the user does not
+ actually link against crtbegin.o; the
+ linker won't look for a file to match a
+ wildcard. The wildcard also means that it
+ doesn't matter which directory crtbegin.o
+ is in. */
+ KEEP (*crtbegin.o(.ctors))
+ KEEP (*crtbegin?.o(.ctors))
+ /* We don't want to include the .ctor section from
+ the crtend.o file until after the sorted ctors.
+ The .ctor section from the crtend file contains the
+ end of ctors marker and it must be last */
+ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ }
+ .dtors :
+ {
+ KEEP (*crtbegin.o(.dtors))
+ KEEP (*crtbegin?.o(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ }
+ .jcr : { KEEP (*(.jcr)) }
+ .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.
+data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
+
+ .dynamic : { *(.dynamic) }
+ .got : { *(.got) *(.igot) }
+ . = DATA_SEGMENT_RELRO_END (24, .);
+ .got.plt : { *(.got.plt) *(.igot.plt) }
+ .data :
+ {
+ *(.data .data.* .gnu.linkonce.d.*)
+ SORT(CONSTRUCTORS)
+ }
+ .data1 : { *(.data1) }
+ _edata = .; PROVIDE (edata = .);
+ __bss_start = .;
+ .bss :
+ {
+ *(.dynbss)
+ *(.bss .bss.* .gnu.linkonce.b.*)
+ *(COMMON)
+ /* Align here to ensure that the .bss section occupies space up to
+ _end. Align after .bss to ensure correct alignment even if the
+ .bss section disappears because there are no input sections.
+ FIXME: Why do we need it? When there is no .bss section, we don't
+ pad the .data section. */
+ . = ALIGN(. != 0 ? 64 / 8 : 1);
+ }
+ .lbss :
+ {
+ *(.dynlbss)
+ *(.lbss .lbss.* .gnu.linkonce.lb.*)
+ *(LARGE_COMMON)
+ }
+ NVRAM_LTABLE :
+ { nvram_ltable_begin = .;
+ *(_nvram_ltable) nvram_ltable_end = .;
+ indirect_init_begin = .;
+ *(_indirect_init)
+ indirect_init_end = .; }
+ . = ALIGN(64 / 8);
+ .lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)
+) :
+
+ {
+ *(.lrodata .lrodata.* .gnu.linkonce.lr.*)
+ }
+ .ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
+ {
+ *(.ldata .ldata.* .gnu.linkonce.l.*)
+ . = ALIGN(. != 0 ? 64 / 8 : 1);
+ }
+ . = ALIGN(64 / 8);
+ _end = .; PROVIDE (end = .);
+ . = DATA_SEGMENT_END (.);
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+ /* SGI/MIPS DWARF 2 extensions */
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+ /* DWARF 3 */
+ .debug_pubtypes 0 : { *(.debug_pubtypes) }
+ .debug_ranges 0 : { *(.debug_ranges) }
+ .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
+ /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
+
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_linux.txt b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_linux.txt
new file mode 100644
index 0000000..c128761
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_linux.txt
@@ -0,0 +1,229 @@
+OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
+ "elf64-x86-64")
+OUTPUT_ARCH(i386:x86-64)
+ENTRY(_start)
+SEARCH_DIR("/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("/usr/local/lib64");
+SEARCH_DIR("/lib64"); SEARCH_DIR("/usr/lib64"); SEARCH_DIR("/usr/x86_64-linux-
+gnu/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/
+lib");
+
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . =
+SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
+
+ .interp : { *(.interp) }
+ .note.gnu.build-id : { *(.note.gnu.build-id) }
+ .hash : { *(.hash) }
+ .gnu.hash : { *(.gnu.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rela.dyn :
+ {
+ *(.rela.init)
+ *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
+ *(.rela.fini)
+ *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
+ *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
+ *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
+ *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
+ *(.rela.ctors)
+ *(.rela.dtors)
+ *(.rela.got)
+ *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
+ *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
+ *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
+ *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
+ *(.rela.ifunc)
+ }
+ .rela.plt :
+ {
+ *(.rela.plt)
+ PROVIDE_HIDDEN (__rela_iplt_start = .);
+ *(.rela.iplt)
+ PROVIDE_HIDDEN (__rela_iplt_end = .);
+ }
+ .init :
+ {
+ KEEP (*(.init))
+ } =0x90909090
+ .plt : { *(.plt) *(.iplt) }
+ .text :
+ {
+ *(.text.unlikely .text.*_unlikely)
+ *(.text .stub .text.* .gnu.linkonce.t.*)
+ /* .gnu.warning sections are handled specially by elf32.em. */
+ *(.gnu.warning)
+ } =0x90909090
+ .fini :
+ {
+ KEEP (*(.fini))
+ } =0x90909090
+ PROVIDE (__etext = .);
+ PROVIDE (_etext = .);
+ PROVIDE (etext = .);
+ .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
+ .rodata1 : { *(.rodata1) }
+ .eh_frame_hdr : { *(.eh_frame_hdr) }
+ .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+ .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
+ /* Adjust the address for the data segment. We want to adjust up to
+ the same address within the page on the next page up. */
+ . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (
+CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE),
+CONSTANT (COMMONPAGESIZE));
+
+ /* Exception handling */
+ .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+ .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+ /* Thread Local Storage sections */
+ .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
+ .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
+ .preinit_array :
+ {
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ }
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(.fini_array))
+ KEEP (*(SORT(.fini_array.*)))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ }
+ .ctors :
+ {
+ /* gcc uses crtbegin.o to find the start of
+ the constructors, so we make sure it is
+ first. Because this is a wildcard, it
+ doesn't matter if the user does not
+ actually link against crtbegin.o; the
+ linker won't look for a file to match a
+ wildcard. The wildcard also means that it
+ doesn't matter which directory crtbegin.o
+ is in. */
+ KEEP (*crtbegin.o(.ctors))
+ KEEP (*crtbegin?.o(.ctors))
+ /* We don't want to include the .ctor section from
+ the crtend.o file until after the sorted ctors.
+ The .ctor section from the crtend file contains the
+ end of ctors marker and it must be last */
+ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ }
+ .dtors :
+ {
+ KEEP (*crtbegin.o(.dtors))
+ KEEP (*crtbegin?.o(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ }
+ .jcr : { KEEP (*(.jcr)) }
+ .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.
+data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
+
+ .dynamic : { *(.dynamic) }
+ .got : { *(.got) *(.igot) }
+ . = DATA_SEGMENT_RELRO_END (24, .);
+ .got.plt : { *(.got.plt) *(.igot.plt) }
+ .data :
+ {
+ *(.data .data.* .gnu.linkonce.d.*)
+ SORT(CONSTRUCTORS)
+ }
+ .data1 : { *(.data1) }
+ _edata = .; PROVIDE (edata = .);
+ __bss_start = .;
+ .bss :
+ {
+ *(.dynbss)
+ *(.bss .bss.* .gnu.linkonce.b.*)
+ *(COMMON)
+ /* Align here to ensure that the .bss section occupies space up to
+ _end. Align after .bss to ensure correct alignment even if the
+ .bss section disappears because there are no input sections.
+ FIXME: Why do we need it? When there is no .bss section, we don't
+ pad the .data section. */
+ . = ALIGN(. != 0 ? 64 / 8 : 1);
+ }
+ .lbss :
+ {
+ *(.dynlbss)
+ *(.lbss .lbss.* .gnu.linkonce.lb.*)
+ *(LARGE_COMMON)
+ }
+ NVRAM_LTABLE :
+ { nvram_ltable_begin = .;
+ *(_nvram_ltable) nvram_ltable_end = .;
+ indirect_init_begin = .;
+ *(_indirect_init)
+ indirect_init_end = .; }
+ . = ALIGN(64 / 8);
+ .lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)
+) :
+
+ {
+ *(.lrodata .lrodata.* .gnu.linkonce.lr.*)
+ }
+ .ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
+ {
+ *(.ldata .ldata.* .gnu.linkonce.l.*)
+ . = ALIGN(. != 0 ? 64 / 8 : 1);
+ }
+ . = ALIGN(64 / 8);
+ _end = .; PROVIDE (end = .);
+ . = DATA_SEGMENT_END (.);
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+ /* SGI/MIPS DWARF 2 extensions */
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+ /* DWARF 3 */
+ .debug_pubtypes 0 : { *(.debug_pubtypes) }
+ .debug_ranges 0 : { *(.debug_ranges) }
+ .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
+ /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
+
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_windows.txt b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_windows.txt
new file mode 100644
index 0000000..ccf5661
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_auto_gen_windows.txt
@@ -0,0 +1,121 @@
+OUTPUT_FORMAT(pei-i386)
+SEARCH_DIR("/mingw/mingw32/lib"); SEARCH_DIR("/mingw/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");
+ENTRY(_mainCRTStartup)
+SECTIONS
+{
+ .text __image_base__ + __section_alignment__ :
+ {
+ *(.init)
+ *(.text)
+ *(SORT(.text$*))
+ *(.glue_7t)
+ *(.glue_7)
+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
+ LONG (-1); *(SORT(.ctors.*)); *(.ctors); *(.ctor); LONG (0);
+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
+ LONG (-1); *(SORT(.dtors.*)); *(.dtors); *(.dtor); LONG (0);
+ *(.fini)
+ /* ??? Why is .gcc_exc here? */
+ *(.gcc_exc)
+ etext = .;
+ *(.gcc_except_table)
+ }
+ /* The Cygwin32 library uses a section to avoid copying certain data
+ on fork. This used to be named ".data". The linker used
+ to include this between __data_start__ and __data_end__, but that
+ breaks building the cygwin32 dll. Instead, we name the section
+ ".data_cygwin_nocopy" and explictly include it after __data_end__. */
+ .data BLOCK(__section_alignment__) :
+ {
+ __data_start__ = . ;
+ *(.data)
+ *(.data2)
+ *(SORT(.data$*))
+ __data_end__ = . ;
+ *(.data_cygwin_nocopy)
+ }
+ .rdata BLOCK(__section_alignment__) :
+ {
+ *(.rdata)
+ *(SORT(.rdata$*))
+ *(.eh_frame)
+ ___RUNTIME_PSEUDO_RELOC_LIST__ = .;
+ __RUNTIME_PSEUDO_RELOC_LIST__ = .;
+ *(.rdata_runtime_pseudo_reloc)
+ ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
+ __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
+ }
+ .pdata BLOCK(__section_alignment__) :
+ {
+ *(.pdata)
+ }
+ .bss BLOCK(__section_alignment__) :
+ {
+ __bss_start__ = . ;
+ *(.bss)
+ *(COMMON)
+ __bss_end__ = . ;
+ }
+ .edata BLOCK(__section_alignment__) :
+ {
+ *(.edata)
+ }
+ /DISCARD/ :
+ {
+ *(.debug$S)
+ *(.debug$T)
+ *(.debug$F)
+ *(.drectve)
+ }
+ .idata BLOCK(__section_alignment__) :
+ {
+ /* This cannot currently be handled with grouped sections.
+ See pe.em:sort_sections. */
+ SORT(*)(.idata$2)
+ SORT(*)(.idata$3)
+ /* These zeroes mark the end of the import list. */
+ LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
+ SORT(*)(.idata$4)
+ SORT(*)(.idata$5)
+ SORT(*)(.idata$6)
+ SORT(*)(.idata$7)
+ }
+ .CRT BLOCK(__section_alignment__) :
+ {
+ *(SORT(.CRT$*))
+ }
+ .endjunk BLOCK(__section_alignment__) :
+ {
+ /* end is deprecated, don't use it */
+ end = .;
+ _end = .;
+ __end__ = .;
+ }
+ .rsrc BLOCK(__section_alignment__) :
+ {
+ *(.rsrc)
+ *(SORT(.rsrc$*))
+ }
+ .reloc BLOCK(__section_alignment__) :
+ {
+ *(.reloc)
+ }
+ .stab BLOCK(__section_alignment__) (NOLOAD) :
+ {
+ [ .stab ]
+ }
+ .stabstr BLOCK(__section_alignment__) (NOLOAD) :
+ {
+ [ .stabstr ]
+ }
+
+ NVRAM_LTABLE :
+ {
+ _nvram_ltable_begin = .;
+ *(_nvram_ltable)
+ _nvram_ltable_end = .;
+ _indirect_init_begin = .;
+ *(_indirect_init)
+ _indirect_init_end = .;
+ }
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_compress.c b/mcu/tools/NVRAMStatistic/src/nvram_compress.c
new file mode 100644
index 0000000..ad08a84
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_compress.c
@@ -0,0 +1,1521 @@
+/*****************************************************************************
+* 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_compress.c
+ *
+ * Project:
+ * --------
+ * MAUI
+ *
+ * Description:
+ * ------------
+ * compress nvram 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!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <io.h>
+
+#ifdef __NVRAM_COMPRESS_SUPPORT__
+/*****************************************************************************
+ * Header file
+ *****************************************************************************/
+#include "nvram_auto_gen.h"
+
+#include "zlib.h"
+
+#if defined(__MMI_FMI__)
+#include "custom_mmi_default_value.h"
+#include "nvram_user_defs.h"
+#endif
+
+/*****************************************************************************
+ * Typedef
+ *****************************************************************************/
+#define RESULT_HEADER_PATH "..\\..\\..\\custom\\common\\pluto_mmi\\nvram_default_value.h"
+#define RESULT_SRC_PATH "..\\..\\..\\custom\\common\\pluto_mmi\\nvram_default_value.c"
+#define CUSTPACK_PATH "..\\..\\..\\custom\\common\\pluto_mmi\\nvram_cust_pack_default_value.c"
+#define COMPRESS_REPORT_FILE "..\\..\\..\\~nvram_compress.txt"
+
+#define CUSTPACK_FILE_INCLUDE "\n#include \"kal_release.h\"\n#include \"nvram_defs.h\"\n"
+
+#define FILE_HEADER "\/* \nThis file is generated by nvram auto gen, all modification will be lost, \n Author: Wen Wu(MTK80153)\n *\/"
+#define FILE_INCLUDE "\n#include \"kal_general_types.h\"\n"
+#define FILE_COMPILE_OPTION_START "\n#ifdef __NVRAM_COMPRESS_SUPPORT__\n"
+#define FILE_COMPILE_OPTION_END "\n#endif\n\n"
+#define CUSTPACK_FILE_COMPILE_OPTION_START "\n#ifdef NVRAM_INTERNAL_USE\n#ifdef __NVRAM_COMPRESS_SUPPORT__\n"
+#define CUSTPACK_FILE_COMPILE_OPTION_END "\n#endif\n#endif\n\n"
+
+#define VALUE_MACRO_START "\n#ifndef __NVRAM_DEFAULT_VALUE_H__\n#define __NVRAM_DEFAULT_VALUE_H__\n"
+#define VALUE_MACRO_END "\n#endif\n\n"
+
+#define VALUE_START "\nconst kal_uint8 %s_ZIP[%d] =\n"
+#define VALUE_BRACE "{"
+#define VALUE_END "\n};\n"
+
+#define VALUE_EXTERN "\nextern const kal_uint8 %s_ZIP[];\n"
+#define VALUE_REDEFINE "\n#define %s_ZIP %s\n"
+#define VAR_TABLE_ENTRY "\t{%s,%d,%d},\n"
+
+#define VALUE_MAX_SIZE "\n#define NVRAM_MAX_DEFAULE_VALUE_SIZE %d\n"
+
+#define BUFFER_FOR_LEN 4
+
+/* High trace will exist current env */
+#define NVRAM_TRC_HIGH(x) { printf(x); exit(3);}
+#define NVRAM_TRC_HIGH1(x,y) { printf(x,y); exit(3);}
+#define NVRAM_TRC_LOW(x) { printf(x);}
+#define NVRAM_TRC_LOW1(xx, x) { printf(xx,x);}
+#define NVRAM_TRC_LOW2(xx, x, y) { printf(xx, x, y);}
+
+#define RETURN_IF_FAIL(p) if(!(p)){printf("NVRAM abormal return at line %d\n", __LINE__);return;}
+#define RETURN_VAL_IF_FAIL(p, ret) if(!(p)){ printf("NVRAM return fail at line %d\n", __LINE__); return (ret);}
+
+#define NVRAM_MALLOC(size) malloc(size)
+#define NVRAM_MFREE(p) if(!p) {free(p); p = NULL;}
+
+#define NVRAM_MEM_FACTOR1 10
+#define NVRAM_MEM_FACTOR2 50
+
+#define NVRAM_TEMP_BUFFER_SIZE 512
+#define NVRAM_ZLIB_BUFF_SIZE (80*1024)
+
+/*
+ * conv between unsigned char to unsigned int
+ */
+#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
+ *****************************************************************************/
+typedef enum{
+ RET_OK,
+ RET_STOP,
+ RET_OOM,
+ RET_TOTAL
+}Ret;
+
+typedef kal_int32 (*compress_funcptr)(kal_uint8 *dest, kal_uint32 *destLen,const kal_uint8 *source, kal_uint32 sourceLen, kal_int32 level);
+typedef kal_int32 (*uncompress_funcptr)(kal_uint8 *dest, kal_uint32 *destLen, const kal_uint8 *source, kal_uint32 sourceLen);
+typedef Ret (*visit_funcptr)(void *data, void* usr_data);
+
+
+typedef struct _NvramCompress
+{
+ compress_funcptr onCompress;
+ uncompress_funcptr onUncompress;
+ kal_uint32 count;
+ kal_uint32 org_total_size;
+ kal_uint32 compress_total_size;
+ kal_uint32 max_default_value;
+ kal_uint32 last_custpack;
+ kal_uint32 custpack_index;
+ kal_uint32 custpack_total;
+ FILE *result_src_fp;
+ FILE *custpack_fp;
+ FILE *result_header_fp;
+ FILE *report_fp;
+}NvramCompress;
+
+/*****************************************************************************
+ * Global variable
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Local variable
+ *****************************************************************************/
+static NvramCompress g_nvram_compress_cntx;
+
+/*****************************************************************************
+ * Local Function
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Global Function
+ *****************************************************************************/
+
+/*****************************************************************************
+* FUNCTION
+* nvram_for_each
+* DESCRIPTION
+* scan all the lid of the table
+* PARAMETERS
+* table [IN] the logical table
+* visit [IN] vist function pointer
+* usr_data [IN] user data
+* RETURNS
+* void
+*****************************************************************************/
+static void nvram_for_each(const ltable_entry_struct *table, visit_funcptr visit, void *usr_data)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ nvram_lid_enum i = 0;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_IF_FAIL(table != NULL && visit != NULL);
+
+ while (table[i].LID != NVRAM_EF_RESERVED_LID &&
+ table[i].LID < NVRAM_EF_LAST_LID_CUST)
+ {
+ if (visit(&table[i], usr_data) == RET_STOP)
+ {
+ break;
+ }
+ i++;
+ }
+
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_mem_dump
+* DESCRIPTION
+* Dump memory
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+static void nvram_compress_mem_dump(kal_uint8 *str1, kal_uint8 *buffer, kal_uint32 size, FILE* fp)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ fprintf(fp, "\nMemoryDump:");
+ fprintf(fp, "%s:{",str1);
+
+ for(i = 0; i < size; i++)
+ {
+ if ((i % 20 == 0))
+ {
+ fprintf(fp, "\n\t");
+ }
+
+ fprintf(fp, "%2x,", buffer[i]);
+ }
+ fprintf(fp, "}\n");
+ fflush(fp);
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_check_compress
+* DESCRIPTION
+* To check whether the entry can be compressed
+* PARAMETERS
+* entry [IN] the logical table
+* RETURNS
+* kal_bool
+*****************************************************************************/
+static kal_bool nvram_check_compress(const ltable_entry_struct *entry)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_VAL_IF_FAIL(entry != NULL, KAL_FALSE);
+
+ /* No data */
+ if (entry == NULL ||
+ entry->LID == 0 ||
+ entry->size == 0 ||
+ entry->total_records == 0)
+ {
+ return KAL_FALSE;
+ }
+
+ /* Some default value can't be compressed */
+ if (strstr(entry->str_default_value, "NVRAM_EF_ZERO_DEFAULT") != NULL ||
+ strstr(entry->str_default_value, "NVRAM_EF_FF_DEFAULT") != NULL)
+ {
+ return KAL_FALSE;
+ }
+
+ return KAL_TRUE;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_custpack_callback
+* DESCRIPTION
+* Compress the custpack entry
+* PARAMETERS
+* data [IN]data item
+* usr_data [IN]user data
+* RETURNS
+* Ret
+*****************************************************************************/
+static Ret nvram_compress_custpack_callback(void *data, void* usr_data)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ ltable_entry_struct *entry;
+ kal_uint32 size, value_size;
+ kal_int32 ret;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_VAL_IF_FAIL(data != NULL && usr_data != NULL, RET_STOP);
+
+ entry = (ltable_entry_struct *)data;
+
+ /*
+ * Only care about custpack entry in this callback
+ */
+ if (NVRAM_IS_CATEGORY_CUSTPACK(entry->category))
+ {
+ nvram_compress_callback(entry, usr_data);
+ }
+
+ return RET_OK;
+}
+
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_callback
+* DESCRIPTION
+* Compress the entry
+* PARAMETERS
+* data [IN]data item
+* usr_data [IN]user data
+* RETURNS
+* Ret
+*****************************************************************************/
+static Ret nvram_compress_callback(void *data, void* usr_data)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ ltable_entry_struct *entry;
+ kal_uint32 size, value_size, i;
+ kal_uint32 *compress_size;
+ kal_int32 ret;
+ kal_uint8 *dest = NULL, *data_ptr, *str, *default_value;
+ NvramCompress *thiz;
+ FILE* fp;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_VAL_IF_FAIL(data != NULL && usr_data != NULL, RET_STOP);
+
+ thiz = (NvramCompress *)usr_data;
+ entry = (ltable_entry_struct *)data;
+
+ if (!nvram_check_compress(entry))
+ {
+ return RET_OK;
+ }
+
+ /* Port default value to nvram_default_value.c */
+ str = nvram_compress_locate_default_value(entry->str_default_value);
+ if (str == NULL)
+ {
+ NVRAM_TRC_HIGH1("No default value! %d", entry->LID);
+ return RET_OK;
+ }
+
+ /* we only compress the data in internal category */
+ if (NVRAM_IS_CATEGORY_INTERNAL(entry->category) ||
+ NVRAM_IS_CATEGORY_CALIBRAT(entry->category) ||
+ NVRAM_IS_CATEGORY_IMPORTANT(entry->category) ||
+ NVRAM_IS_CATEGORY_SECUPACK(entry->category))
+ {
+ fprintf(thiz->result_header_fp, VALUE_REDEFINE, str, str);
+ return RET_OK;
+ }
+
+
+ if (NVRAM_IS_ATTR_NOT_ZIP_DEFAULT(entry->attr))
+ {
+ if (NVRAM_IS_CATEGORY_CUSTPACK(entry->category))
+ {
+ NVRAM_TRC_HIGH1("Custpack with not compress attribute %d!\n", entry->LID);
+ }
+
+ fprintf(thiz->result_header_fp, VALUE_REDEFINE, str, str);
+ return RET_OK;
+ }
+
+ if (NVRAM_IS_ATTR_MULTI_DEFAULT(entry->attr))
+ {
+ value_size = entry->size * entry->total_records;
+ }
+ else
+ {
+ value_size = entry->size;
+ }
+
+ /*
+ * 1. For custpack default value, redirect it to nvram_custpack_default_value.c
+ * because ExtractObj.exe needs to find nvram default value from nvram_cust_pack.obj.
+ * 2. always compress custpack so that custpack tool don't need to care which data is compressed or not.
+ */
+ if (NVRAM_IS_CATEGORY_CUSTPACK(entry->category))
+ {
+ thiz->last_custpack = entry->LID;
+ fp = thiz->custpack_fp;
+ default_value = custpack_nvram_ptr.custpack_default[thiz->custpack_index];
+ thiz->custpack_index++;
+ }
+ else
+ {
+ fp = thiz->result_src_fp;
+ default_value = entry->default_value;
+ }
+
+ if (default_value == NVRAM_EF_FF_DEFAULT ||
+ default_value == NVRAM_EF_ZERO_DEFAULT)
+ {
+ NVRAM_TRC_LOW(("Wrong default to compress for LID:%d \n", entry->str_LID));
+ NVRAM_TRC_HIGH("ZERO or FF default!\n");
+ }
+
+ /* At compressing state */
+ if (value_size < 20)
+ {
+ size = NVRAM_MEM_FACTOR2 * value_size;
+ }
+ else
+ {
+ size = NVRAM_MEM_FACTOR1 * value_size;
+ }
+
+ dest = (kal_uint8*)NVRAM_MALLOC(size);
+
+ if (dest == NULL)
+ {
+ NVRAM_TRC_HIGH("No Memory!\n");
+ }
+
+ /* compress function need to know the output buffer size. */
+ /*The first 4 bytes will be compressed buffer size, after this int, there will be compressed data */
+ data_ptr = dest + BUFFER_FOR_LEN;
+ size -= BUFFER_FOR_LEN;
+ ret = thiz->onCompress(data_ptr, &size, default_value, value_size, Z_BEST_COMPRESSION);
+ if (ret != Z_OK)
+ {
+ nvram_compress_mem_dump(entry->str_LID, default_value, value_size, thiz->report_fp);
+ NVRAM_TRC_LOW2("Compress [%s]not Z_OK, %d!\n",entry->str_LID, ret);
+
+ NVRAM_MFREE(dest);
+ return RET_OK;
+ }
+ NVRAM_TRC_LOW(("Compress [%s] OK!\n", entry->str_LID));
+
+ /* Uncompress and verify the data */
+ nvram_compress_verify(thiz, default_value, value_size, data_ptr, size);
+
+ CONV_INT_TO_4BYTES(dest, size);
+
+ if (thiz->max_default_value < value_size)
+ {
+ thiz->max_default_value = value_size;
+ }
+
+ size += BUFFER_FOR_LEN;
+ thiz->org_total_size += value_size;
+ thiz->compress_total_size += size;
+
+ nvram_compress_port_default_value_to_file(str, dest, size, fp);
+
+ /* Port default value extern to nvram_default_value.h */
+ fprintf(thiz->result_header_fp, VALUE_EXTERN, str);
+ /* Write data struct to table */
+ fprintf(thiz->report_fp, VAR_TABLE_ENTRY, entry->str_LID, size, value_size);
+ fflush(thiz->report_fp);
+
+ NVRAM_MFREE(dest);
+
+ return RET_OK;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_compress_verify
+ * DESCRIPTION
+ * Verify the compressed data
+ * PARAMETERS
+ * thiz [IN]
+ * org_buff [IN]
+ * org_buff_size [IN]
+ * buffer [IN]
+ * buff_size [IN]
+ * RETURNS
+ * Ret
+ *****************************************************************************/
+static void nvram_compress_verify(NvramCompress *thiz,
+ kal_uint8 *org_buff,
+ kal_uint32 org_buff_size,
+ kal_uint8 *buffer,
+ kal_uint32 buff_size)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_int32 ret;
+ kal_uint8* dbuffer;
+ kal_uint32 size;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_IF_FAIL(thiz != NULL);
+ RETURN_IF_FAIL(org_buff != NULL && org_buff_size != 0);
+ RETURN_IF_FAIL(buffer != NULL && buff_size != 0);
+
+ size = 50 * org_buff_size;
+ dbuffer = NVRAM_MALLOC(size);
+ ret = thiz->onUncompress(dbuffer, &size, buffer, buff_size);
+ if (ret != Z_OK)
+ {
+ NVRAM_TRC_HIGH1("Uncompress verify failed 1, ret=%d!\n", ret);
+ }
+
+ if (size != org_buff_size)
+ {
+ NVRAM_TRC_HIGH("Uncompress verify failed 2!\n");
+ }
+
+ if (memcmp(dbuffer, org_buff, org_buff_size) != 0)
+ {
+ NVRAM_TRC_HIGH("Uncompress verify failed 3!\n");
+ }
+
+ NVRAM_MFREE(dbuffer);
+
+ NVRAM_TRC_LOW("Uncompress verify OK!\n");
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_compress_locate_default_value
+ * DESCRIPTION
+ * Locate the default value string
+ * PARAMETERS
+ * value [IN]
+ * RETURNS
+ * kal_uint8 *
+ *****************************************************************************/
+static kal_uint8 *nvram_compress_locate_default_value(const kal_uint8 *value)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint8 *str;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_VAL_IF_FAIL(value != NULL, NULL);
+
+ str = strstr(value, ")");
+ if (str == NULL)
+ {
+ str = value;
+ }
+ else
+ {
+ str++;
+ }
+
+ if (*str == '&')
+ {
+ str++;
+ }
+
+ return str;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_compress_port_default_value_to_file
+ * DESCRIPTION
+ * Port default value to another file
+ * PARAMETERS
+ * value_name [IN]
+ * buffer [IN]
+ * buffer_len [IN]
+ * fp [IN]
+ * RETURNS
+ * void
+ *****************************************************************************/
+static void nvram_compress_port_default_value_to_file(
+ const kal_uint8 *value_name,
+ const kal_uint8 *buffer,
+ const kal_uint32 buffer_len,
+ FILE *fp)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_IF_FAIL(value_name != NULL);
+ RETURN_IF_FAIL(buffer != NULL && buffer_len != 0);
+ RETURN_IF_FAIL(fp != NULL);
+
+ fprintf(fp, VALUE_START, value_name, buffer_len);
+ fprintf(fp, VALUE_BRACE);
+
+ for(i = 0; i < buffer_len; i++)
+ {
+ if ((i % 8 == 0))
+ {
+ fprintf(fp, "\n\t");
+ }
+
+ if ((i + 1) == buffer_len)
+ {
+ fprintf(fp, "0x%02X", buffer[i]);
+ }
+ else
+ {
+ fprintf(fp, "0x%02X,", buffer[i]);
+ }
+ }
+
+ fprintf(fp, VALUE_END);
+ fflush(fp);
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_compress_custpack_jump_tbl_callback
+ * DESCRIPTION
+ * regenerate jump table callback
+ * PARAMETERS
+ * data [IN]
+ * usr_data [IN]
+ * RETURNS
+ * Ret
+ *****************************************************************************/
+static Ret nvram_compress_custpack_jump_tbl_callback(void *data, void* usr_data)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ ltable_entry_struct *entry;
+ NvramCompress *thiz;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_VAL_IF_FAIL(data != NULL && usr_data != NULL, RET_STOP);
+
+ thiz = (NvramCompress *)usr_data;
+ entry = (ltable_entry_struct *)data;
+
+ if (entry == NULL ||
+ entry->LID == 0 ||
+ entry->size == 0 ||
+ entry->total_records == 0)
+ {
+ return RET_OK;
+ }
+
+ if (strstr(entry->str_default_value, "NVRAM_EF_ZERO_DEFAULT") ||
+ strstr(entry->str_default_value, "NVRAM_EF_FF_DEFAULT"))
+ {
+ return RET_OK;
+ }
+
+ if (NVRAM_IS_CATEGORY_CUSTPACK(entry->category))
+ {
+ fprintf(thiz->custpack_fp, " %s_ZIP", entry->str_default_value);
+ if (thiz->last_custpack != entry->LID)
+ {
+ fprintf(thiz->custpack_fp, ",");
+ }
+ fprintf(thiz->custpack_fp, "\n");
+ }
+
+ return RET_OK;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_compress_custpack_jump_tbl
+ * DESCRIPTION
+ * regenerate jump table callback
+ * PARAMETERS
+ * data [IN]
+ * usr_data [IN]
+ * RETURNS
+ * Ret
+ *****************************************************************************/
+static void nvram_compress_custpack_jump_tbl(NvramCompress *thiz, FILE* output)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 i, tbl_idx = sizeof(table_pool)/sizeof(nvram_ltable_tbl_struct) - 1;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_IF_FAIL(thiz != NULL && output != NULL);
+
+ fprintf(output, "const custpack_nvram_header custpack_nvram_ptr = \n");
+ fprintf(output, "{\n");
+ fprintf(output, " %d,\n", 0);
+ fprintf(output, " {\n");
+ for (;tbl_idx >= 0; tbl_idx--)
+ {
+ ltable_entry_struct **ltable = table[tbl_idx].ltable;
+
+ nvram_for_each(ltable, nvram_compress_custpack_jump_tbl_callback, thiz);
+ }
+
+ fprintf(output, " }\n");
+ fprintf(output, "};\n");
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_create
+* DESCRIPTION
+* create nvram compresser handler
+* PARAMETERS
+* void
+* RETURNS
+* NvramCompress
+*****************************************************************************/
+static NvramCompress* nvram_compress_create(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ return &g_nvram_compress_cntx;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_init
+* DESCRIPTION
+* init comprresser struct
+* PARAMETERS
+* thiz
+* RETURNS
+* void
+*****************************************************************************/
+static void nvram_compress_init(NvramCompress *thiz)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_IF_FAIL(thiz != NULL);
+
+ thiz->count = 0;
+ thiz->max_default_value = 0;
+
+ thiz->report_fp = fopen(COMPRESS_REPORT_FILE, "w+");
+ if (thiz->report_fp == NULL)
+ {
+ NVRAM_TRC_HIGH("File Create Failed!\n");
+ }
+
+ thiz->result_header_fp = fopen(RESULT_HEADER_PATH, "w+");
+ if (thiz->result_header_fp == NULL)
+ {
+ NVRAM_TRC_HIGH("File Create Failed!\n");
+ }
+
+ fprintf(thiz->result_header_fp, FILE_HEADER);
+ fprintf(thiz->result_header_fp, VALUE_MACRO_START);
+
+
+ thiz->result_src_fp = fopen(RESULT_SRC_PATH, "w+");
+ if (thiz->result_src_fp == NULL)
+ {
+ NVRAM_TRC_HIGH("File Create Failed!\n");
+ }
+ fprintf(thiz->result_src_fp, FILE_HEADER);
+ fprintf(thiz->result_src_fp, FILE_INCLUDE);
+ fprintf(thiz->result_src_fp, FILE_COMPILE_OPTION_START);
+
+ // custpack default value file
+ thiz->custpack_fp = fopen(CUSTPACK_PATH, "w+");
+ if (thiz->custpack_fp == NULL)
+ {
+ NVRAM_TRC_HIGH("Custpack file create failed!\n");
+ }
+
+ fprintf(thiz->custpack_fp, FILE_HEADER);
+ fprintf(thiz->custpack_fp, CUSTPACK_FILE_INCLUDE);
+ fprintf(thiz->custpack_fp, CUSTPACK_FILE_COMPILE_OPTION_START);
+
+ thiz->org_total_size = 0;
+ thiz->compress_total_size = 0;
+ thiz->onCompress = compress2;
+ thiz->onUncompress = uncompress;
+
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_close
+* DESCRIPTION
+* close comprresser handler
+* PARAMETERS
+* thiz
+* RETURNS
+* void
+*****************************************************************************/
+static void nvram_compress_close(NvramCompress *thiz)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint8 buffer[NVRAM_TEMP_BUFFER_SIZE];
+ kal_uint32 size;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_IF_FAIL(thiz != NULL);
+
+ /* header file */
+ fprintf(thiz->result_header_fp, VALUE_MAX_SIZE, thiz->max_default_value);
+ fprintf(thiz->result_header_fp, VALUE_MACRO_END);
+ fclose(thiz->result_header_fp);
+
+ nvram_compress_custpack_jump_tbl(thiz, thiz->custpack_fp);
+
+ fprintf(thiz->custpack_fp, CUSTPACK_FILE_COMPILE_OPTION_END);
+ fclose(thiz->custpack_fp);
+
+ /* move table item to src file */
+ fclose(thiz->report_fp);
+
+ fprintf(thiz->result_src_fp, FILE_COMPILE_OPTION_END);
+ fclose(thiz->result_src_fp);
+
+ NVRAM_TRC_LOW2("\n\nTotal: original data=%d, compressed data=%d\n", thiz->org_total_size, thiz->compress_total_size);
+
+ thiz->count = 0;
+ thiz->onCompress = NULL;
+ thiz->onUncompress = NULL;
+ thiz->org_total_size = 0;
+ thiz->compress_total_size = 0;
+}
+
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress
+* DESCRIPTION
+* compress all nvram default value
+* PARAMETERS
+* void
+* RETURNS
+* void
+*****************************************************************************/
+static void nvram_compress(char *project_name, char *broad_ver)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ NvramCompress *thiz = nvram_compress_create();
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ nvram_compress_init(thiz);
+
+ /* Only compress comm and cust table */
+ nvram_for_each(logical_data_item_table_core, nvram_compress_callback, thiz);
+ nvram_for_each(logical_data_item_table_comm_app, nvram_compress_callback, thiz);
+ nvram_for_each(logical_data_item_table_cust, nvram_compress_callback, thiz);
+
+ nvram_compress_close(thiz);
+}
+
+
+#endif /* __NVRAM_COMPRESS_SUPPORT__ */
+
+#ifdef NVRAM_GEN_LID_TABLE
+
+/* core folder */
+#define NVRAM_FS_COREITEM_PATH "Z:\\NVRAM\\NVD_CORE"
+#define NVRAM_FS_CALIBRAT_DATAITEM_PATH "Z:\\NVRAM\\CALIBRAT"
+#define NVRAM_FS_IMPT_DATAITEM_PATH "Z:\\NVRAM\\NVD_IMEI"
+#define NVRAM_FS_CUST_DATAITEM_PATH "Z:\\NVRAM\\NVD_CUST"
+#define NVRAM_FS_IMPORTNT_DATAITEM_PATH "Z:\\NVRAM\\IMPORTNT"
+
+#ifdef __NVRAM_BACKUP_DISK_FAT__
+#if defined(__TC01__) && defined(__MTK_TARGET__)
+#define NVRAM_FS_BACKUP_ROOT_PATH "G:\\NVRAM"
+#else
+#define NVRAM_FS_BACKUP_ROOT_PATH "Z:\\NVRAM_BAK"
+#endif
+#endif
+
+
+#define NVRAM_FS_DATAITEM_PATH "Z:\\NVRAM\\NVD_DATA"
+
+#if defined (__NVRAM_UT_TEST__)
+/* paths defined in __NVRAM_UT_TEST__ is used for nvram first init test*/
+
+/* NVRAM Test Folder Path */
+#define NVRAM_TEST_FS_COREITEM_PATH "Z:\\NV_TEST\\NVD_CORE"
+#define NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH "Z:\\NV_TEST\\CALIBRAT"
+#define NVRAM_TEST_FS_IMPT_DATAITEM_PATH "Z:\\NV_TEST\\NVD_IMEI"
+#define NVRAM_TEST_FS_CUST_DATAITEM_PATH "Z:\\NV_TEST\\NVD_CUST"
+#define NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH "Z:\\NV_TEST\\IMPORTNT"
+#define NVRAM_TEST_FS_DATAITEM_PATH "Z:\\NV_TEST\\NVD_DATA"
+
+extern kal_taskid nvram_test_task1_id;
+extern kal_uint8 is_insulation_access;
+#endif //__NVRAM_UT_TEST__
+
+
+#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))\
+ sprintf(buf, "%s\\%s", NVRAM_TEST_FS_DATAITEM_PATH, name);\
+ else \
+ sprintf(buf, "%s\\%s", NVRAM_FS_DATAITEM_PATH, name)
+
+#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))\
+ sprintf(buf, "%s\\%s", NVRAM_TEST_FS_COREITEM_PATH, name);\
+ else \
+ sprintf(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))\
+ sprintf(buf, "%s\\%s", NVRAM_TEST_FS_CALIBRAT_DATAITEM_PATH, name);\
+ else \
+ sprintf(buf, "%s\\%s", NVRAM_FS_CALIBRAT_DATAITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_CRITICAL_IMEI_PATH_FILENAME(buf, name) if((is_insulation_access) && (nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id))\
+ sprintf(buf, "%s\\%s", NVRAM_TEST_FS_IMPT_DATAITEM_PATH, name);\
+ else \
+ sprintf(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))\
+ sprintf(buf, "%s\\%s", NVRAM_TEST_FS_CUST_DATAITEM_PATH, name);\
+ else \
+ sprintf(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))\
+ sprintf(buf, "%s\\%s", NVRAM_TEST_FS_IMPORTNT_DATAITEM_PATH, name);\
+ else \
+ sprintf(buf, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH, name)
+
+#else
+#define NVRAM_FS_MAKE_LID_PATH_FILENAME_1( buf, name ) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_DATAITEM_PATH, name)
+
+#define NVRAM_FS_MAKE_CORE_PATH_FILENAME(buf, name) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_COREITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_CRITICAL_CALIBRAT_PATH_FILENAME(buf, name) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_CALIBRAT_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_CRITICAL_IMPT_PATH_FILENAME(buf, name) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_IMPT_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_CUST_PATH_FILENAME(buf, name) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_CUST_DATAITEM_PATH, name);
+
+#define NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME(buf, name) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_IMPORTNT_DATAITEM_PATH, name);
+
+#endif
+
+#ifdef __NVRAM_BACKUP_DISK_FAT__
+#define NVRAM_FS_MAKE_BACKUP_PATH_FILENAME(buf, name) \
+ sprintf(buf, "%s\\%s", NVRAM_FS_BACKUP_ROOT_PATH, name);
+#endif
+
+
+#define NVRAM_MAKE_LID_FILENAME(buf, prefix, M, verno) {\
+ ((kal_char*) (buf))[0] = ((kal_char*) (prefix))[0]; \
+ ((kal_char*) (buf))[1] = ((kal_char*) (prefix))[1]; \
+ ((kal_char*) (buf))[2] = ((kal_char*) (prefix))[2]; \
+ ((kal_char*) (buf))[3] = ((kal_char*) (prefix))[3]; \
+ ((kal_char*) (buf))[4] = (kal_char) (M); \
+ ((kal_char*) (buf))[5] = ((kal_char*) (verno))[0]; \
+ ((kal_char*) (buf))[6] = ((kal_char*) (verno))[1]; \
+ ((kal_char*) (buf))[7] = ((kal_char*) (verno))[2]; \
+ ((kal_char*) (buf))[8] = '\0'; \
+};
+
+#define NVRAM_MAKE_PACKAGE_FILENAME(buf, M) { \
+ ((kal_char*) (buf))[0] = 'P'; \
+ ((kal_char*) (buf))[1] = 'A'; \
+ ((kal_char*) (buf))[2] = 'C'; \
+ ((kal_char*) (buf))[3] = 'K'; \
+ ((kal_char*) (buf))[4] = (kal_char) (M); \
+ ((kal_char*) (buf))[5] = 'L'; \
+ ((kal_char*) (buf))[6] = 'I'; \
+ ((kal_char*) (buf))[7] = 'D'; \
+ ((kal_char*) (buf))[8] = '\0'; \
+};
+
+#define TABLE_FILE "..\\..\\..\\~nvram_lid_table.xls"
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_make_lid_filename
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+static void nvram_util_make_lid_filename(ltable_entry_struct *ldi, NVRAM_FILE_NAME nvramname, kal_bool first_copy)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ if (ldi == NULL)
+ {
+ NVRAM_TRC_HIGH("Empty ldi ");
+ 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_MAKE_LID_FILENAME(nvramname, ldi->fileprefix, 'A', ldi->fileverno);
+ }
+ else
+ {
+ NVRAM_MAKE_LID_FILENAME(nvramname, ldi->fileprefix, 'B', ldi->fileverno);
+ }
+ }
+ else
+ {
+ NVRAM_MAKE_LID_FILENAME(nvramname, ldi->fileprefix, '_', ldi->fileverno);
+ }
+
+ return;
+
+}
+
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_query_folder_index
+ * DESCRIPTION
+ * Get the index of folder
+ * PARAMETERS
+ * category
+ * RETURNS
+ * Success or Fail
+ *****************************************************************************/
+static nvram_folder_enum nvram_query_folder_index(nvram_category_enum category)
+{
+ /*----------------------------------------------------------------*/
+ /* 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 __CCCIFS_SUPPORT__
+ else if (category & NVRAM_CATEGORY_IMPORTANT_L4)
+ {
+ 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;
+}
+
+
+/*****************************************************************************
+ * 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
+ *****************************************************************************/
+static 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_IMEI_PATH_FILENAME(filename, nvramname);
+ break;
+ }
+ #ifdef __CCCIFS_SUPPORT__
+ case NVRAM_NVD_IMPNT:
+ {
+ NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME(filename, nvramname);
+ break;
+ }
+ #endif
+ #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_TRC_HIGH("Wrong folder idex !");
+ break;
+ }
+ }
+
+ return filename;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_table_callback
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+static Ret nvram_gen_table_callback(void *data, void* usr_data)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ ltable_entry_struct *entry;
+ FILE* fp;
+ kal_uint8 filename[9];
+ kal_uint16 folder_idx;
+ kal_char src_path[32];
+
+ kal_char nvramname[9];
+
+ #define TABLE_PATTARN "\n%s\t%s\t%s"
+ #define TABLE_SEL_FLAG "\t#"
+ #define TABLE_UNSEL_FLAG "\t"
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ RETURN_VAL_IF_FAIL(data != NULL && usr_data != NULL, RET_STOP);
+ entry = (ltable_entry_struct *)data;
+ fp = (FILE *)usr_data;
+
+ folder_idx = nvram_query_folder_index(entry->category);
+
+ nvram_util_make_lid_filename(entry, nvramname, KAL_TRUE);
+ nvram_query_file_name(folder_idx, nvramname, src_path);
+
+ fprintf(fp, TABLE_PATTARN, entry->str_LID, entry->description, src_path);
+
+ /* System */
+ if (entry->attr & NVRAM_ATTR_OTA_RESET)
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+ /* custpack */
+ if (NVRAM_IS_CATEGORY_CUSTPACK(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+ /* Calibartion */
+ if (NVRAM_IS_CATEGORY_CALIBRAT(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+ /* Internal */
+ if (NVRAM_IS_CATEGORY_INTERNAL(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+ /* Important */
+ if (NVRAM_IS_CATEGORY_IMPORTANT(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+ /* Secupack */
+ if (NVRAM_IS_CATEGORY_SECUPACK(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+ /* Factory Reset */
+ if (NVRAM_IS_CATEGORY_FACTORY_RESET(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+#ifdef __NVRAM_COMPRESS_SUPPORT__
+ /* Zip default value */
+ if ((entry->attr & NVRAM_ATTR_ZIP_DEFAULT) ||
+ NVRAM_IS_CATEGORY_CUSTPACK(entry->category))
+ {
+ fprintf(fp, TABLE_SEL_FLAG);
+ }
+ else
+#endif /* __NVRAM_COMPRESS_SUPPORT__ */
+ {
+ fprintf(fp, TABLE_UNSEL_FLAG);
+ }
+
+
+ return RET_OK;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_compress_gen_lid_table
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_lid_table(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *fp;
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ fp = fopen(TABLE_FILE, "w");
+ if (fp == NULL)
+ {
+ NVRAM_TRC_HIGH("File Open Error!");
+ }
+ fprintf(fp, "LID \t LID_description \t folder \t System \t Custpack \t Calibartion \t Internal \t Important \t Secupack \t Restore \t compress");
+
+ nvram_for_each(logical_data_item_table_core, nvram_gen_table_callback, fp);
+ nvram_for_each(logical_data_item_table_comm_app, nvram_gen_table_callback, fp);
+ nvram_for_each(logical_data_item_table_cust, nvram_gen_table_callback, fp);
+
+ fclose(fp);
+}
+#endif /* NVRAM_GEN_LID_TABLE */
+
+/*****************************************************************************
+* FUNCTION
+* main
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+int main(int argc, char *argv[])
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ if (argc > 1)
+ {
+ #ifdef __NVRAM_COMPRESS_SUPPORT__
+ NVRAM_TRC_LOW("\nNvram default value compressing....\n");
+ nvram_compress(argv[1], argv[2]);
+
+ #else /* __NVRAM_COMPRESS_SUPPORT__ */
+ printf("\nDon't support nvram compress!\n");
+ #endif /* __NVRAM_COMPRESS_SUPPORT__ */
+
+ #ifdef NVRAM_GEN_LID_TABLE
+ nvram_gen_lid_table();
+ #endif
+ }
+ return 0;
+}
+
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_gen_cache_table.c b/mcu/tools/NVRAMStatistic/src/nvram_gen_cache_table.c
new file mode 100644
index 0000000..684e752
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_gen_cache_table.c
@@ -0,0 +1,544 @@
+#ifndef NVRAM_NOT_PRESENT
+/*
+ * Include
+ */
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <sys/io.h>
+#include <string.h>
+
+#if defined(__MMI_FMI__)
+#include "nvram_user_defs.h"
+#endif
+#include "custom_nvram_cat.h"
+#include "custom_nvram_config.h" /* __NVRAM_VENDOR_SUPPORT__ */
+#include "nvram_editor_data_item.h"
+#include "nvram_group_editor.h" //add for break group files from header file
+#ifdef __NVRAM_PSEUDO_MERGE__
+#include "nvram_pseudo_merge.h"
+#endif
+
+#include "custom_nvram_int_config.h"
+#include "nvram_gen_cache_table.h"
+#ifdef __NV_CHKSUM_ENHANCE__
+#include "custom_nvram_sec.h" // add ,get checksum type/size.
+
+/* CUSTOM_CHK_ALGO_CONFIG configure*/
+extern nvram_checksum_config CUSTOM_CHK_ALGO_CONFIG;
+kal_uint32 get_checksum_size(nvram_ltable_entry_struct* ldi);
+#endif
+kal_uint32 nvram_gen_total_cache_lid = 0;
+
+
+#ifdef __NVRAM_PARTIAL_CACHE__
+/*You must synchronization modify the nvram_lid_noncache_list in service/nvram/src/nvram_cache_white_list.c if you want to add or delete a member of below list.*/
+kal_uint32 autogen_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*/
+};
+
+kal_uint16 autogen_nvram_lid_noncache_list_amount = sizeof(autogen_nvram_lid_noncache_list)/sizeof(kal_uint32);
+
+#endif
+
+extern nvram_ltable_entry_struct *logical_data_item_table;
+static kal_uint32 cache_data_offset = 0;
+static kal_uint32 dirty_bit_table_offset = 0;
+static kal_uint32 dirty_bit_table_length = 0;
+
+/*****************************************************************************
+ * FUNCTION
+ * autogen_is_in_noncache_list
+ * DESCRIPTION
+ * NVRAM lid whether in non-cache list
+ * PARAMETERS
+ * LDI [IN]
+ * RETURNS
+ * success or fail
+ *You must synchronization modify the is_in_noncache_list in service/nvram/src/nvram_cache_white_list.c if you want to add or delete a member of below list.
+ *****************************************************************************/
+kal_bool autogen_is_in_noncache_list(nvram_lid_enum LID)
+{
+ #ifdef __NVRAM_PARTIAL_CACHE__
+ kal_uint32 idx;
+ for(idx = 0; idx < autogen_nvram_lid_noncache_list_amount; idx++)
+ {
+ if(autogen_nvram_lid_noncache_list[idx] == LID)
+ {
+ return KAL_TRUE;
+ }
+ }
+ #endif
+ return KAL_FALSE;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_query_folder_index
+ * DESCRIPTION
+ * Get the index of folder
+ * PARAMETERS
+ * category
+ * RETURNS
+ * Success or Fail
+ *****************************************************************************/
+nvram_folder_enum nvram_query_folder_index(nvram_category_enum category)
+{
+ /*----------------------------------------------------------------*/
+ /* 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 __CCCIFS_SUPPORT__
+ else if (category & NVRAM_CATEGORY_IMPORTANT_L4)
+ {
+ 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;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_util_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)
+ {
+ NVRAM_TRC_HIGH("Empty ldi ");
+ 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_MAKE_LID_FILENAME(nvramname, ldi->fileprefix, 'A', ldi->fileverno);
+ }
+ else
+ {
+ NVRAM_MAKE_LID_FILENAME(nvramname, ldi->fileprefix, 'B', ldi->fileverno);
+ }
+ }
+ else
+ {
+ NVRAM_MAKE_LID_FILENAME(nvramname, ldi->fileprefix, '_', ldi->fileverno);
+ }
+
+ return;
+}
+
+/*****************************************************************************
+ * 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_IMEI_PATH_FILENAME(filename, nvramname);
+ break;
+ }
+ #ifdef __CCCIFS_SUPPORT__
+ case NVRAM_NVD_IMPNT:
+ {
+ NVRAM_FS_MAKE_IMPORTNT_PATH_FILENAME(filename, nvramname);
+ break;
+ }
+ #endif
+ #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_TRC_HIGH("Wrong folder idex !");
+ break;
+ }
+ }
+
+ return filename;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ * filepath_finder
+ * DESCRIPTION
+ * Get lid filepath
+ * PARAMETERS
+ * ldi : nvram lid entry
+ * RETURNS
+ * Full path
+ *****************************************************************************/
+kal_char* path_finder(nvram_ltable_entry_struct *ldi, kal_char *src_path)
+{
+ NVRAM_FILE_NAME nvramname;
+ nvram_folder_enum folder_idx;
+
+ folder_idx = nvram_query_folder_index(ldi->category);
+
+ /* prefix */
+ if (NVRAM_IS_CATEGORY_SECUPACK(ldi->category))
+ {
+ ldi->fileprefix[0] = 'S';
+ ldi->fileprefix[1] = 'T';
+ }
+ nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE);
+ nvram_query_file_name(folder_idx, nvramname, src_path);
+ return src_path;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ * filepath_finder
+ * DESCRIPTION
+ * Get lid filepath
+ * PARAMETERS
+ * ldi : nvram lid entry
+ * RETURNS
+ * Full path
+ *****************************************************************************/
+kal_uint32 file_size_collector(nvram_ltable_entry_struct *ldi)
+{
+ kal_uint32 onefilesize = 0;
+ kal_uint32 onefilefssize = 0; // 32 byte padding
+ kal_uint32 remainLen = 0;
+ static kal_uint32 esfilesize = 0;
+ kal_uint32 nvram_checksum_size = 0;
+
+ #ifdef __NV_CHKSUM_ENHANCE__
+ nvram_checksum_size = get_checksum_size(ldi); // get nvram_checksum_size , read CUSTOM_CHK_ALGO_CONFIG.
+ #else
+ nvram_checksum_size = NVRAM_CHKSUM_SIZE;
+ #endif
+
+ if(ldi->attr & NVRAM_ATTR_CONFIDENTIAL
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ //if HW encrypt is enable
+ || ldi->attr & NVRAM_ATTR_MSP
+ #endif
+ )
+ {
+ remainLen = NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_checksum_size);
+ onefilesize = (ldi->size + nvram_checksum_size + remainLen)*ldi->total_records + NVRAM_LDI_HEADER_SIZE;
+ }
+ else
+ {
+ onefilesize = (ldi->size + nvram_checksum_size) * ldi->total_records + NVRAM_LDI_HEADER_SIZE;
+ }
+ if(ldi->attr & NVRAM_ATTR_CHKSUM_INTEGRATE)
+ {
+ printf("checksum integrate: lid: %s\n", ldi->str_LID);
+ onefilesize = onefilesize + NVRAM_LDI_APPENDIX_HEADER_SIZE + nvram_checksum_size * ldi->total_records;
+ }
+ return onefilesize;
+}
+
+void cache_header_writer(FILE *fp, nvram_lid_cache_header *cache_header)
+{
+ fprintf(fp, "nvram_lid_cache_header cache_info_header = {\n");
+
+ fprintf(fp, "\t%u,\n", cache_header->cache_lid_num);
+ fprintf(fp, "\t%u,\n", cache_header->table_index_offset);
+ fprintf(fp, "\t%u,\n", cache_header->table_index_size);
+ fprintf(fp, "\t%u,\n", cache_header->dirty_mapping_offset);
+ fprintf(fp, "\t%u,\n", cache_header->valid_mapping_offset);
+ fprintf(fp, "\t%u,\n", cache_header->dirty_mapping_size);
+ fprintf(fp, "\t%u,\n", cache_header->cache_table_offset);
+ fprintf(fp, "\t%u\n", cache_header->cache_table_size);
+ fprintf(fp, "};\n\n");
+}
+
+
+void cache_table_writer(FILE *fp, nvram_lid_cache_table_struct *cache_info)
+{
+ fprintf(fp, "\t{\n");
+ fprintf(fp, "\t\t%hu,\n", cache_info->LID);
+ fprintf(fp, "\t\t%u,\n", cache_info->total_records);
+ fprintf(fp, "\t\t%u,\n", cache_info->file_length);
+ fprintf(fp, "\t\t%u,\n", cache_info->cache_offset);
+ fprintf(fp, "\t\t%u,\n", cache_info->dirty_offset);
+ fprintf(fp, "\t\t%u,\n", cache_info->valid_offset);
+ fprintf(fp, "\t\t\"%s\"\n", cache_info->file_path);
+ fprintf(fp, "\t},\n");
+}
+
+void cache_header_generator(FILE *fp, nvram_lid_cache_header *cache_info_header)
+{
+ kal_uint32 data_base_offset = 0;
+ // align 32byte
+ data_base_offset = sizeof(nvram_lid_cache_header) + sizeof(nvram_lid_cache_table_struct)* nvram_gen_total_cache_lid;
+ data_base_offset = ((data_base_offset + SHARE_MEM_64BYTE_ALIGN -1)/SHARE_MEM_64BYTE_ALIGN)*SHARE_MEM_64BYTE_ALIGN;
+ printf("nvram gen total cache lid num: %d\n", nvram_gen_total_cache_lid);
+ // Fill cache info header
+ cache_info_header->cache_lid_num = nvram_gen_total_cache_lid;
+ cache_info_header->table_index_offset = sizeof(nvram_lid_cache_header);
+ cache_info_header->table_index_size = sizeof(nvram_lid_cache_table_struct)* nvram_gen_total_cache_lid;
+ cache_info_header->dirty_mapping_offset = data_base_offset;
+ dirty_bit_table_length = ((dirty_bit_table_length + SHARE_MEM_64BYTE_ALIGN -1)/SHARE_MEM_64BYTE_ALIGN)*SHARE_MEM_64BYTE_ALIGN; //align to cache line
+ cache_info_header->dirty_mapping_size = dirty_bit_table_length;
+ data_base_offset = data_base_offset + dirty_bit_table_length;
+ cache_info_header->valid_mapping_offset = data_base_offset;
+
+ // valid block has same size as dirty block
+ data_base_offset += dirty_bit_table_length;
+ cache_info_header->cache_table_offset = data_base_offset;
+ cache_info_header->cache_table_size = cache_data_offset;
+ //
+ cache_header_writer(fp, cache_info_header);
+
+ if ((cache_info_header->cache_table_offset + cache_info_header->cache_table_size) >= SHARE_MEMORY_SIZE) {
+ fprintf(stderr, "Error: Please contact NVRAM owner, the NV Cache Share Memory Size Too small. currently total LID size is: %x.\n",(cache_info_header->cache_table_offset + cache_info_header->cache_table_size));
+ exit(-1);
+ }
+ // return cache_info_header;
+}
+
+void gen_cache_file(char *base_path)
+{
+ char cache_header_path[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ char cache_source_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ FILE *fp;
+
+ sprintf(cache_header_path, "nvram_auto_gen/nvram_cache_info.h");
+ nvram_gen_create_file(&fp,base_path,cache_header_path);
+ fprintf(fp, COPYRIGHTS_HEADER, cache_header_path);
+ fprintf(fp, "#ifndef NVRAM_CACHE_INFO_H\n");
+ fprintf(fp, "#define NVRAM_CACHE_INFO_H\n");
+ fprintf(fp, "#include \"nvram_cache.h\"\n");
+ fprintf(fp, "#include \"nvram_enums.h\"\n");
+ fprintf(fp, "#include \"kal_general_types.h\"\n\n");
+ fprintf(fp, "extern nvram_lid_cache_table_struct cache_info_table[];\n");
+ fprintf(fp, "extern nvram_lid_cache_header cache_info_header;\n\n");
+ fprintf(fp, "#endif /*NVRAM_CACHE_INFO_H*/\n");
+
+ nvram_gen_close_file(&fp);
+
+}
+
+
+int ltable_enum_cmp(nvram_ltable_entry_struct *ent_a, nvram_ltable_entry_struct *ent_b)
+{
+ return (int)(ent_a->LID - ent_b->LID);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * ltable_enum_sort
+ * DESCRIPTION
+ * Sort lid by LID enum
+ * PARAMETERS
+ *
+ * RETURNS
+ *
+ *****************************************************************************/
+void lid_table_enum_sort(nvram_ltable_entry_struct *lid_ltable_array)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ // extern unsigned char nvram_ltable_begin, nvram_ltable_end;
+ kal_uint32 i = 0;
+ size_t table_size = sizeof(nvram_ltable_entry_struct);
+ printf("cache_table size: %d\n", table_size);
+ qsort(lid_ltable_array, nvram_gen_total_lid, table_size, ltable_enum_cmp);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ * cache_info_table_generator
+ * DESCRIPTION
+ * Generate cache info table
+ * PARAMETERS
+ *
+ * RETURNS
+ *
+ *****************************************************************************/
+void cache_info_table_generator(char *base_path)
+{
+ /*******************************************/
+ extern unsigned char nvram_ltable_begin, nvram_ltable_end;
+ kal_uint32 i = 0, tb_size;
+
+ char cache_file_path[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ char cache_file_name[] = "nvram_cache_info.c";
+ FILE *fp;
+ nvram_ltable_entry_struct *ldi;
+ nvram_ltable_entry_struct *ltable_bak;
+ nvram_lid_cache_table_struct info_item = {};
+ // nvram_lid_cache_table_struct *cache_info_array;
+ nvram_lid_cache_header cache_info_header;
+
+ cache_data_offset = 0;
+ dirty_bit_table_offset = 0;
+ dirty_bit_table_length = 0;
+ sprintf(cache_file_path, "%s/nvram_auto_gen/%s", base_path, cache_file_name);
+ tb_size = (kal_uint32)(&nvram_ltable_end - &nvram_ltable_begin);
+ ltable_bak = (nvram_ltable_entry_struct *)malloc(tb_size);
+ memcpy(ltable_bak, logical_data_item_table,tb_size);
+ lid_table_enum_sort(ltable_bak);
+
+ fp = fopen(cache_file_path, "w");
+ fprintf(fp, COPYRIGHTS_HEADER, cache_file_name);
+ fprintf(fp, "#include \"nvram_cache_info.h\"\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "nvram_lid_cache_table_struct cache_info_table[] = {\n");
+
+ for(i=0; i< nvram_gen_total_lid; i++)
+ {
+ ldi = <able_bak[i];
+ #ifdef __NVRAM_PARTIAL_CACHE__
+ if(autogen_is_in_noncache_list(ldi->LID))
+ {
+ continue;
+ }
+ #endif
+ info_item.LID = ldi->LID;
+ info_item.total_records = ldi->total_records;
+
+ info_item.cache_offset = cache_data_offset;
+ // find file lenght
+ info_item.file_length = file_size_collector(ldi);
+ cache_data_offset += ((info_item.file_length+SHARE_MEM_64BYTE_ALIGN-1)/SHARE_MEM_64BYTE_ALIGN)*SHARE_MEM_64BYTE_ALIGN; //align to cache line
+ info_item.dirty_offset = dirty_bit_table_offset;
+ info_item.valid_offset = dirty_bit_table_offset;
+ dirty_bit_table_offset += ((ldi->total_records + 1 + DIRTY_BLOCK_SIZE -1)/DIRTY_BLOCK_SIZE) * DIRTY_4BYTE_ALIGN;
+ path_finder(ldi, info_item.file_path);
+
+ // cache_table_writer(fp, &info_item);
+ fprintf(fp, "\t{\n");
+ fprintf(fp, "\t\t%hu,\n", info_item.LID);
+ fprintf(fp, "\t\t%hu,\n", 0);
+ fprintf(fp, "\t\t%u,\n", info_item.total_records);
+ fprintf(fp, "\t\t%u,\n", info_item.file_length);
+ fprintf(fp, "\t\t%u,\n", info_item.cache_offset);
+ fprintf(fp, "\t\t%u,\n", info_item.dirty_offset);
+ fprintf(fp, "\t\t%u,\n", info_item.valid_offset);
+ fprintf(fp, "\t\t\"%s\"\n", info_item.file_path);
+ fprintf(fp, "\t},\n");
+ nvram_gen_total_cache_lid += 1;
+ }
+ fprintf(fp, "};\n\n");
+ dirty_bit_table_length = dirty_bit_table_offset;
+ // cache header;
+ cache_header_generator(fp, &cache_info_header);
+ fclose(fp);
+ gen_cache_file(base_path);
+ free(ltable_bak);
+}
+
+
+#endif /* NVRAM_NOT_PRESENT */
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_gen_mmi_cache.c b/mcu/tools/NVRAMStatistic/src/nvram_gen_mmi_cache.c
new file mode 100644
index 0000000..7a3242c
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_gen_mmi_cache.c
@@ -0,0 +1,1873 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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_auto_gen.c
+ *
+ * Project:
+ * --------
+ * MAUI
+ *
+ * Description:
+ * ------------
+ * This file is intends for generating NVRAM information.
+ *
+ * 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!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#ifndef NVRAM_NOT_PRESENT
+#if defined(NEPTUNE_MMI)
+/*****************************************************************************
+* Include
+*****************************************************************************/
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <io.h>
+
+#include "nvram_auto_gen.h"
+
+#if defined(__MMI_FMI__)
+#include "nvram_common_defs.h"
+#include "nvram_mmi_cache_defs.h"
+#endif
+
+#define BYTE_ENTRY_COUNT (NVRAM_CACHE_SIZE)
+#define SHORT_ENTRY_COUNT (NVRAM_CACHE_SIZE >> 1)
+#define DOUBLE_ENTRY_COUNT (NVRAM_CACHE_SIZE >> 3)
+
+extern mmi_cache_byte_entry common_mmi_cache_byte[];
+extern mmi_cache_short_entry common_mmi_cache_short[];
+extern mmi_cache_double_entry common_mmi_cache_double[];
+
+extern mmi_cache_byte_entry custom_mmi_cache_byte[];
+extern mmi_cache_short_entry custom_mmi_cache_short[];
+extern mmi_cache_double_entry custom_mmi_cache_double[];
+
+#ifndef __OPTR_NONE__
+extern mmi_cache_byte_entry operator_mmi_cache_byte[];
+extern mmi_cache_short_entry operator_mmi_cache_short[];
+extern mmi_cache_double_entry operator_mmi_cache_double[];
+#endif /* __OPTR_NONE__ */
+
+static int nvram_gen_compare_byte(const void *a, const void *b);
+static int nvram_gen_compare_short(const void *a, const void *b);
+static int nvram_gen_compare_double(const void *a, const void *b);
+static int nvram_sort_byte(void);
+static int nvram_sort_short(void);
+static int nvram_sort_double(void);
+static int nvram_merge_byte(
+ mmi_cache_byte_entry[],
+ int,
+ mmi_cache_byte_entry[],
+ int,
+ mmi_cache_byte_entry[]);
+static int nvram_merge_short(
+ mmi_cache_short_entry[],
+ int,
+ mmi_cache_short_entry[],
+ int,
+ mmi_cache_short_entry[]);
+static int nvram_merge_double(
+ mmi_cache_double_entry[],
+ int,
+ mmi_cache_double_entry[],
+ int,
+ mmi_cache_double_entry[]);
+
+/* get user fills count */
+static int nvram_get_byte_entry_count(mmi_cache_byte_entry[]);
+static int nvram_get_short_entry_count(mmi_cache_short_entry[]);
+static int nvram_get_double_entry_count(mmi_cache_double_entry[]);
+
+/* The following should be initialized in main function */
+static int nvram_common_byte_count;
+static int nvram_common_short_count;
+static int nvram_common_double_count;
+
+static int nvram_custom_byte_count;
+static int nvram_custom_short_count;
+static int nvram_custom_double_count;
+
+/* if operator exists */
+#ifndef __OPTR_NONE__
+static int nvram_operator_byte_count;
+static int nvram_operator_short_count;
+static int nvram_operator_double_count;
+#endif
+
+
+/* After merge */
+/* used to save the result of merging common and custom part */
+static int nvram_byte_count;
+static int nvram_short_count;
+static int nvram_double_count;
+
+/* used to save the result of final result */
+#ifndef __OPTR_NONE__
+static int nvram_op_byte_count;
+static int nvram_op_short_count;
+static int nvram_op_double_count;
+#endif /* __OPTR_NONE__ */
+
+
+/* used to save the final result */
+static mmi_cache_byte_entry nvram_mmi_cache_byte[BYTE_ENTRY_COUNT];
+static mmi_cache_short_entry nvram_mmi_cache_short[SHORT_ENTRY_COUNT];
+static mmi_cache_double_entry nvram_mmi_cache_double[DOUBLE_ENTRY_COUNT];
+
+
+/* used to save the result of merging common and custom part */
+#ifndef __OPTR_NONE__
+static mmi_cache_byte_entry nvram_op_byte[BYTE_ENTRY_COUNT];
+static mmi_cache_short_entry nvram_op_short[SHORT_ENTRY_COUNT];
+static mmi_cache_double_entry nvram_op_double[DOUBLE_ENTRY_COUNT];
+#endif /* __OPTR_NONE__ */
+static int nvram_restore_cache_byte[NVRAM_APP_TOTAL][BYTE_ENTRY_COUNT];
+static int nvram_restore_cache_short[NVRAM_APP_TOTAL][SHORT_ENTRY_COUNT];
+static int nvram_restore_cache_double[NVRAM_APP_TOTAL][DOUBLE_ENTRY_COUNT];
+/* record total number of each application */
+static int nvram_restore_byte_idx[NVRAM_APP_TOTAL];
+static int nvram_restore_short_idx[NVRAM_APP_TOTAL];
+static int nvram_restore_double_idx[NVRAM_APP_TOTAL];
+
+/* record max length of id str */
+static int nvram_max_length_byte_id_str;
+static int nvram_max_length_short_id_str;
+static int nvram_max_length_double_id_str;
+
+static char nvram_auto_gen_output_path[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_compare_byte
+* DESCRIPTION
+* used by quick sort function
+* PARAMETERS
+* a [IN]
+* b [IN]
+* RETURNS
+* none
+*****************************************************************************/
+int nvram_gen_compare_byte(const void *a, const void *b)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ mmi_cache_byte_entry *former, *latter;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ former = a;
+ latter = b;
+ if ((former->id < 0 || former->id >= BYTE_ENTRY_COUNT) ||
+ (latter->id < 0 || latter->id >= BYTE_ENTRY_COUNT))
+ {
+ /* assert(0); */
+ return 0;
+ }
+ if (former->id < latter->id)
+ {
+ return -1;
+ }
+ else if (former->id > latter->id)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ return 0;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_compare_short
+* DESCRIPTION
+* used by quick sort function
+* PARAMETERS
+* a [IN]
+* b [IN]
+* RETURNS
+* none
+*****************************************************************************/
+int nvram_gen_compare_short(const void *a, const void *b)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ mmi_cache_short_entry *former, *latter;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ former = a;
+ latter = b;
+ if ((former->id < 0 || former->id >= SHORT_ENTRY_COUNT) ||
+ (latter->id < 0 || latter->id >= SHORT_ENTRY_COUNT))
+ {
+ /* assert(0); */
+ return 0;
+ }
+ if (former->id < latter->id)
+ {
+ return -1;
+ }
+ else if (former->id > latter->id)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ return 0;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_compare_double
+* DESCRIPTION
+* used by quick sort function
+* PARAMETERS
+* a [IN]
+* b [IN]
+* RETURNS
+* none
+*****************************************************************************/
+int nvram_gen_compare_double(const void *a, const void *b)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ mmi_cache_double_entry *former, *latter;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ former = a;
+ latter = b;
+ if ((former->id < 0 || former->id >= DOUBLE_ENTRY_COUNT) ||
+ (latter->id < 0 || latter->id >= DOUBLE_ENTRY_COUNT))
+ {
+ /* assert(0); */
+ return 0;
+ }
+ if (former->id < latter->id)
+ {
+ return -1;
+ }
+ else if (former->id > latter->id)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ return 0;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_merge_byte
+* DESCRIPTION
+* merge two byte_cache array
+* PARAMETERS
+* low_pri [IN]
+* low_count [IN]
+* high_pri [IN]
+* high_count [IN]
+* result_array [OUT]
+* RETURNS
+* the count of result array after merging
+*****************************************************************************/
+int nvram_merge_byte(
+ mmi_cache_byte_entry low_pri[],
+ int low_count,
+ mmi_cache_byte_entry high_pri[],
+ int high_count,
+ mmi_cache_byte_entry result_array[]
+ )
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i, low_pri_p, high_pri_p;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ i = 0;
+ low_pri_p = 0;
+ high_pri_p = 0;
+ while (low_pri_p < low_count || high_pri_p < high_count)
+ {
+ if (low_pri_p >= low_count)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_byte_entry));
+ i++;
+ high_pri_p++;
+ continue;
+ }
+ if (high_pri_p >= high_count)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == low_pri[low_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ low_pri + low_pri_p,
+ sizeof(mmi_cache_byte_entry));
+ i++;
+ low_pri_p++;
+ continue;
+ }
+ if (low_pri[low_pri_p].id == high_pri[high_pri_p].id)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_byte_entry));
+ i++;
+ low_pri_p++;
+ high_pri_p++;
+ }
+ else if (low_pri[low_pri_p].id < high_pri[high_pri_p].id)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == low_pri[low_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ low_pri + low_pri_p,
+ sizeof(mmi_cache_byte_entry));
+ i++;
+ low_pri_p++;
+ }
+ else
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_byte_entry));
+ i++;
+ high_pri_p++;
+ }
+ }
+ return i;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_merge_short
+* DESCRIPTION
+* merge two short_cache array
+* PARAMETERS
+* low_pri [IN]
+* low_count [IN]
+* high_pri [IN]
+* high_count [IN]
+* result_array [OUT]
+* RETURNS
+* the count of result array after merging
+*****************************************************************************/
+int nvram_merge_short(
+ mmi_cache_short_entry low_pri[],
+ int low_count,
+ mmi_cache_short_entry high_pri[],
+ int high_count,
+ mmi_cache_short_entry result_array[])
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i, low_pri_p, high_pri_p;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ i = 0;
+ low_pri_p = 0;
+ high_pri_p = 0;
+ while (low_pri_p < low_count || high_pri_p < high_count)
+ {
+ if (low_pri_p >= low_count)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_short_entry));
+ i++;
+ high_pri_p++;
+ continue;
+ }
+ if (high_pri_p >= high_count)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == low_pri[low_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ low_pri + low_pri_p,
+ sizeof(mmi_cache_short_entry));
+ i++;
+ low_pri_p++;
+ continue;
+ }
+ if (low_pri[low_pri_p].id == high_pri[high_pri_p].id)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_short_entry));
+ i++;
+ low_pri_p++;
+ high_pri_p++;
+ }
+ else if (low_pri[low_pri_p].id < high_pri[high_pri_p].id)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == low_pri[low_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ low_pri + low_pri_p,
+ sizeof(mmi_cache_short_entry));
+ i++;
+ low_pri_p++;
+ }
+ else
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_short_entry));
+ i++;
+ high_pri_p++;
+ }
+ }
+ return i;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_merge_double
+* DESCRIPTION
+* merge two double_cache array
+* PARAMETERS
+* low_pri [IN]
+* low_count [IN]
+* high_pri [IN]
+* high_count [IN]
+* result_array [OUT]
+* RETURNS
+* the count of result array after merging
+*****************************************************************************/
+int nvram_merge_double(
+ mmi_cache_double_entry low_pri[],
+ int low_count,
+ mmi_cache_double_entry high_pri[],
+ int high_count,
+ mmi_cache_double_entry result_array[])
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i, low_pri_p, high_pri_p;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ i = 0;
+ low_pri_p = 0;
+ high_pri_p = 0;
+ while (low_pri_p < low_count || high_pri_p < high_count)
+ {
+ if (low_pri_p >= low_count)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_double_entry));
+ i++;
+ high_pri_p++;
+ continue;
+ }
+ if (high_pri_p >= high_count)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == low_pri[low_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ low_pri + low_pri_p,
+ sizeof(mmi_cache_double_entry));
+ i++;
+ low_pri_p++;
+ continue;
+ }
+ if (low_pri[low_pri_p].id == high_pri[high_pri_p].id)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_double_entry));
+ i++;
+ low_pri_p++;
+ high_pri_p++;
+ }
+ else if (low_pri[low_pri_p].id < high_pri[high_pri_p].id)
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == low_pri[low_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ low_pri + low_pri_p,
+ sizeof(mmi_cache_double_entry));
+ i++;
+ low_pri_p++;
+ }
+ else
+ {
+ /* Avoid same */
+ if (i > 0)
+ {
+ if (result_array[i - 1].id == high_pri[high_pri_p].id)
+ {
+ return -1;
+ }
+ }
+ memcpy(result_array + i,
+ high_pri + high_pri_p,
+ sizeof(mmi_cache_double_entry));
+ i++;
+ high_pri_p++;
+ }
+ }
+ return i;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_get_byte_entry_count
+* DESCRIPTION
+* get entries count of a byte_cache
+* PARAMETERS
+* mmi_cache_byte_array [IN]
+* RETURNS
+* the count of the entries
+*****************************************************************************/
+int nvram_get_byte_entry_count(mmi_cache_byte_entry mmi_cache_byte_array[])
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ i = 0;
+ while (1)
+ {
+ if (mmi_cache_byte_array[i].id == 0xFF &&
+ mmi_cache_byte_array[i].value == 0xFF &&
+ *(mmi_cache_byte_array[i].id_str) == '\0')
+ {
+ break;
+ }
+ else
+ {
+ i++;
+ }
+ if (i >= BYTE_ENTRY_COUNT)
+ {
+ /* exceed the max count */
+ return -1;
+ }
+ }
+ return i;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_get_short_entry_count
+* DESCRIPTION
+* get entries count of a short_cache
+* PARAMETERS
+* mmi_cache_short_array [IN]
+* RETURNS
+* the count of the entries
+*****************************************************************************/
+int nvram_get_short_entry_count(mmi_cache_short_entry mmi_cache_short_array[])
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ i = 0;
+ while (1)
+ {
+ if (mmi_cache_short_array[i].id == 0xFF &&
+ mmi_cache_short_array[i].value1 == 0xFF &&
+ mmi_cache_short_array[i].value2 == 0xFF &&
+ *(mmi_cache_short_array[i].id_str) == '\0')
+ {
+ break;
+ }
+ else
+ {
+ i++;
+ }
+ if (i >= SHORT_ENTRY_COUNT)
+ {
+ /* exceed the max count */
+ return -1;
+ }
+ }
+ return i;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_get_double_entry_count
+* DESCRIPTION
+* get entries count of a double_cache
+* PARAMETERS
+* mmi_cache_double_array [IN]
+* RETURNS
+* the count of the entries
+*****************************************************************************/
+int nvram_get_double_entry_count(mmi_cache_double_entry mmi_cache_double_array[])
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int i;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ i = 0;
+ while (1)
+ {
+ if (mmi_cache_double_array[i].id == 0xFF &&
+ mmi_cache_double_array[i].value1 == 0xFF &&
+ mmi_cache_double_array[i].value2 == 0xFF &&
+ mmi_cache_double_array[i].value3 == 0xFF &&
+ mmi_cache_double_array[i].value4 == 0xFF &&
+ mmi_cache_double_array[i].value5 == 0xFF &&
+ mmi_cache_double_array[i].value6 == 0xFF &&
+ mmi_cache_double_array[i].value7 == 0xFF &&
+ mmi_cache_double_array[i].value8 == 0xFF &&
+ *(mmi_cache_double_array[i].id_str) == '\0')
+ {
+ break;
+ }
+ else
+ {
+ i++;
+ }
+ if (i >= DOUBLE_ENTRY_COUNT)
+ {
+ /* exceed the max count */
+ return -1;
+ }
+ }
+ return i;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_sort_byte
+* DESCRIPTION
+* sort one byte_cache
+* PARAMETERS
+* none
+* RETURNS
+* none
+*****************************************************************************/
+int nvram_sort_byte(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ /* sort common */
+ qsort((void *)common_mmi_cache_byte, nvram_common_byte_count, sizeof(mmi_cache_byte_entry), &nvram_gen_compare_byte);
+
+ /* sort custom */
+ qsort((void *)custom_mmi_cache_byte, nvram_custom_byte_count, sizeof(mmi_cache_byte_entry), &nvram_gen_compare_byte);
+
+ /* sort operator */
+#ifndef __OPTR_NONE__
+ qsort((void *)operator_mmi_cache_byte, nvram_operator_byte_count, sizeof(mmi_cache_byte_entry), &nvram_gen_compare_byte);
+#endif
+ return 0;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_sort_short
+* DESCRIPTION
+* sort one short_cache
+* PARAMETERS
+* none
+* RETURNS
+* none
+*****************************************************************************/
+int nvram_sort_short(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ /* sort common */
+ qsort((void *)common_mmi_cache_short, nvram_common_short_count, sizeof(mmi_cache_short_entry), &nvram_gen_compare_short);
+
+ /* sort custom */
+ qsort((void *)custom_mmi_cache_short, nvram_custom_short_count, sizeof(mmi_cache_short_entry), &nvram_gen_compare_short);
+
+ /* sort operator */
+#ifndef __OPTR_NONE__
+ qsort((void *)operator_mmi_cache_short, nvram_operator_short_count, sizeof(mmi_cache_short_entry), &nvram_gen_compare_short);
+#endif
+ return 0;
+}
+
+
+/*****************************************************************************
+* FUNCTION
+* nvram_sort_double
+* DESCRIPTION
+* sort one double_cache
+* PARAMETERS
+* none
+* RETURNS
+* none
+*****************************************************************************/
+int nvram_sort_double(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ /* sort common */
+ qsort((void *)common_mmi_cache_double, nvram_common_double_count, sizeof(mmi_cache_double_entry), &nvram_gen_compare_double);
+
+ /* sort custom */
+ qsort((void *)custom_mmi_cache_double, nvram_custom_double_count, sizeof(mmi_cache_double_entry), &nvram_gen_compare_double);
+
+#ifndef __OPTR_NONE__
+ qsort((void *)operator_mmi_cache_double, nvram_operator_double_count, sizeof(mmi_cache_double_entry), &nvram_gen_compare_double);
+#endif
+ return 0;
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_mmi_cache
+* DESCRIPTION
+* output mmi cache default value to nvram_mmi_cust_pack.h
+* PARAMETERS
+* project_name [IN]
+* broad_ver [IN]
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_mmi_cache(char *project_name, char *broad_ver)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *output;
+ int i, k;
+ int byte_max_len, short_max_len, double_max_len;
+ char output_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ int mode_result;
+ nvram_lid_enum last_custpack_lid;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_pathname, "%s\\nvram_mmi_cache_cust_pack.h", nvram_auto_gen_output_path);
+
+ printf("nvram_gen_mmi_cache milestone1\n");
+
+ /* check if the file exists. */
+ mode_result = access(output_pathname, 0);
+ if (mode_result == 0)
+ {
+ /* exists,but check if it can be written. */
+ mode_result = access(output_pathname, 2);
+ if (mode_result != 0)
+ {
+ fprintf(stderr, "error: nvram_mmi_cache_cust_pack.h exists,but it cannot be written.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+ else
+ {
+ /* file not exist*/
+ mode_result = access(nvram_auto_gen_output_path, 2);
+ if (mode_result != 0)
+ {
+ fprintf(stderr, "error: cannot create file in The project_BB folder\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+ output = fopen(output_pathname, "w+");
+ if (output == NULL)
+ {
+ fprintf(stderr, "error: cannot write to nvram_mmi_cache_cust_pack.h in The project_BB folder\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ fprintf(output, "/* This file is generated automatically by nvram_auto_gen.exe, please do not modify it here manually */\n");
+
+ printf("nvram_gen_mmi_cache milestone2\n");
+
+ nvram_common_byte_count = nvram_get_byte_entry_count(common_mmi_cache_byte);
+ if (nvram_common_byte_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds common_byte_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_common_short_count = nvram_get_short_entry_count(common_mmi_cache_short);
+ if (nvram_common_short_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds common_short_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_common_double_count = nvram_get_double_entry_count(common_mmi_cache_double);
+ if (nvram_common_double_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds common_double_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_custom_byte_count = nvram_get_byte_entry_count(custom_mmi_cache_byte);
+ if (nvram_custom_byte_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds custom_byte_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ nvram_custom_short_count = nvram_get_short_entry_count(custom_mmi_cache_short);
+ if (nvram_custom_short_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds custom_short_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ nvram_custom_double_count = nvram_get_double_entry_count(custom_mmi_cache_double);
+ if (nvram_custom_double_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds custom_double_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+#ifndef __OPTR_NONE__
+ nvram_operator_byte_count = nvram_get_byte_entry_count(operator_mmi_cache_byte);
+ if (nvram_operator_byte_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds operator_byte_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_operator_short_count = nvram_get_short_entry_count(operator_mmi_cache_short);
+ if (nvram_operator_short_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds operator_short_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_operator_double_count = nvram_get_double_entry_count(operator_mmi_cache_double);
+ if (nvram_operator_double_count < 0)
+ {
+ fprintf(stderr, "error: configuration exceeds operator_double_cache max count.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+#endif
+
+ printf("nvram_gen_mmi_cache milestone3\n");
+
+ nvram_sort_byte();
+ nvram_sort_short();
+ nvram_sort_double();
+ /*
+ fprintf(output, "nvram_common_byte_count : %d--------------------------------------------\n", nvram_common_byte_count);
+ for (i = 0; i < nvram_common_byte_count; i++)
+ {
+ fprintf(output, "%s, %s\n", common_mmi_cache_byte[i].id_str, common_mmi_cache_byte[i].value_str);
+ }
+ fprintf(output, "nvram_common_short_count : %d--------------------------------------------\n", nvram_common_short_count);
+ fprintf(output, "nvram_common_double_count : %d--------------------------------------------\n", nvram_common_double_count);
+ fprintf(output, "nvram_custom_byte_count : %d--------------------------------------------\n", nvram_custom_byte_count);
+ for (i = 0; i < nvram_custom_byte_count; i++)
+ {
+ fprintf(output, "%s, %s\n", custom_mmi_cache_byte[i].id_str, custom_mmi_cache_byte[i].value_str);
+ }
+ */
+
+ printf("nvram_gen_mmi_cache milestone4\n");
+
+#ifndef __OPTR_NONE__
+ nvram_op_byte_count = nvram_merge_byte(
+ common_mmi_cache_byte,
+ nvram_common_byte_count,
+ custom_mmi_cache_byte,
+ nvram_custom_byte_count,
+ nvram_op_byte);
+ if (nvram_op_byte_count < 0)
+ {
+ fprintf(stderr, "error: duplicate byte entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_op_short_count = nvram_merge_short(
+ common_mmi_cache_short,
+ nvram_common_short_count,
+ custom_mmi_cache_short,
+ nvram_custom_short_count,
+ nvram_op_short);
+ if (nvram_op_short_count < 0)
+ {
+ fprintf(stderr, "error: duplicate short entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_op_double_count = nvram_merge_double(
+ common_mmi_cache_double,
+ nvram_common_double_count,
+ custom_mmi_cache_double,
+ nvram_custom_double_count,
+ nvram_op_double);
+ if (nvram_op_double_count < 0)
+ {
+ fprintf(stderr, "error: duplicate double entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_byte_count = nvram_merge_byte(
+ nvram_op_byte,
+ nvram_op_byte_count,
+ operator_mmi_cache_byte,
+ nvram_operator_byte_count,
+ nvram_mmi_cache_byte);
+ if (nvram_byte_count < 0)
+ {
+ fprintf(stderr, "error: duplicate nvram_op_byte entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_short_count = nvram_merge_short(
+ nvram_op_short,
+ nvram_op_short_count,
+ operator_mmi_cache_short,
+ nvram_operator_short_count,
+ nvram_mmi_cache_short);
+ if (nvram_short_count < 0)
+ {
+ fprintf(stderr, "error: duplicate nvram_op_short entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ nvram_double_count = nvram_merge_double(
+ nvram_op_double,
+ nvram_op_double_count,
+ operator_mmi_cache_double,
+ nvram_operator_double_count,
+ nvram_mmi_cache_double);
+ if (nvram_double_count < 0)
+ {
+ fprintf(stderr, "error: duplicate nvram_op_double entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+#else /* __OPTR_NONE__ */
+ nvram_byte_count = nvram_merge_byte(
+ common_mmi_cache_byte,
+ nvram_common_byte_count,
+ custom_mmi_cache_byte,
+ nvram_custom_byte_count,
+ nvram_mmi_cache_byte);
+ if (nvram_byte_count < 0)
+ {
+ fprintf(stderr, "error: duplicate byte entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_short_count = nvram_merge_short(
+ common_mmi_cache_short,
+ nvram_common_short_count,
+ custom_mmi_cache_short,
+ nvram_custom_short_count,
+ nvram_mmi_cache_short);
+ if (nvram_short_count < 0)
+ {
+ fprintf(stderr, "error: duplicate short entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ nvram_double_count = nvram_merge_double(
+ common_mmi_cache_double,
+ nvram_common_double_count,
+ custom_mmi_cache_double,
+ nvram_custom_double_count,
+ nvram_mmi_cache_double);
+ if (nvram_double_count < 0)
+ {
+ fprintf(stderr, "error: duplicate double entries exist.\n");
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+#endif /* __OPTR_NONE__ */
+
+ /*
+ if (nvram_mmi_cache_byte[nvram_byte_count - 1].id != NVRAM_LAST_BYTE_ELEMENT - 1)
+ {
+ fprintf(stderr, "warning: there is byte enum id that does not config default value\n");
+ }
+ if (nvram_mmi_cache_short[nvram_short_count - 1].id != NVRAM_LAST_SHORT_ELEMENT - 1)
+ {
+ fprintf(stderr, "warning: there is short enum id that does not config default value\n");
+ }
+ if (nvram_mmi_cache_double[nvram_double_count - 1].id != NVRAM_LAST_DOUBLE_ELEMENT - 1)
+ {
+ fprintf(stderr, "warning: there is double enum id that does not config default value\n");
+ }
+ */
+
+ printf("nvram_gen_mmi_cache milestone5\n");
+
+ byte_max_len = 0;
+ short_max_len = 0;
+ double_max_len = 0;
+ for (i = 0; i < nvram_byte_count; i++)
+ {
+ if (strlen(nvram_mmi_cache_byte[i].value_str) > byte_max_len)
+ {
+ byte_max_len = strlen(nvram_mmi_cache_byte[i].value_str);
+ }
+ }
+ for (i = 0; i < nvram_short_count; i++)
+ {
+ if (strlen(nvram_mmi_cache_short[i].value1_str) > short_max_len)
+ {
+ short_max_len = strlen(nvram_mmi_cache_short[i].value1_str);
+ }
+ if (strlen(nvram_mmi_cache_short[i].value2_str) > short_max_len)
+ {
+ short_max_len = strlen(nvram_mmi_cache_short[i].value2_str);
+ }
+ }
+ for (i = 0; i < nvram_double_count; i++)
+ {
+ if (strlen(nvram_mmi_cache_double[i].value1_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value1_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value2_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value2_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value3_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value3_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value4_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value4_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value5_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value5_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value6_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value6_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value7_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value7_str);
+ }
+ if (strlen(nvram_mmi_cache_double[i].value8_str) > double_max_len)
+ {
+ double_max_len = strlen(nvram_mmi_cache_double[i].value8_str);
+ }
+ }
+
+
+ printf("nvram_gen_mmi_cache milestone6\n");
+
+ /* Begin output NVRAM_CACHE_BYTE_DEFAULT */
+ i = 0;
+ fprintf(output, "/* The count of byte configuaration: %d */\n", nvram_byte_count);
+ fprintf(output, "/* BYTEDATA enum Max index: %d */\n", NVRAM_LAST_BYTE_ELEMENT - 1);
+ fprintf(output, "const kal_uint8 NVRAM_CACHE_BYTE_DEFAULT[NVRAM_CACHE_SIZE] =\n");
+ fprintf(output, "{\n");
+ for (k = 0; k < BYTE_ENTRY_COUNT; k++)
+ {
+ int j;
+ if (i < nvram_byte_count)
+ {
+ if (nvram_mmi_cache_byte[i].id == k) /* enum <--->entry */
+ {
+ /* Begin to restore factory */
+ if (nvram_mmi_cache_byte[i].restore)
+ {
+ /* Get max length begin */
+ if(strlen(nvram_mmi_cache_byte[i].id_str) > nvram_max_length_byte_id_str)
+ {
+ nvram_max_length_byte_id_str = strlen(nvram_mmi_cache_byte[i].id_str);
+ }
+ /* Get max length end */
+
+ nvram_restore_cache_byte[nvram_mmi_cache_byte[i].app_id][nvram_restore_byte_idx[nvram_mmi_cache_byte[i].app_id]]
+ = i;
+ nvram_restore_byte_idx[nvram_mmi_cache_byte[i].app_id]++;
+ //cache_struct_idx++;
+ }
+ /* End to restore factory */
+ fprintf(output, " %s", nvram_mmi_cache_byte[i].value_str);
+ if (k != BYTE_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ for (j = 0; j < byte_max_len - strlen(nvram_mmi_cache_byte[i].value_str) + 4; j++)
+ {
+ fprintf(output, " ");
+ }
+ fprintf(output, "/* %3d : %s */\n", nvram_mmi_cache_byte[i].id, nvram_mmi_cache_byte[i].id_str);
+ i++;
+ }
+ else
+ {
+ fprintf(output, " 0xFF");
+ if (k != BYTE_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",/* unset */");
+ }
+ fprintf(output, "\n");
+ }
+ }
+ else
+ {
+ fprintf(output, " 0xFF");
+ if (k != BYTE_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ }
+ }
+ fprintf(output, "};\n\n\n");
+ /* End output NVRAM_CACHE_BYTE_DEFAULT */
+
+
+ /* Begin output NVRAM_CACHE_SHORT_DEFAULT */
+ i = 0;
+ fprintf(output, "/* The count of short configuaration: %d */\n", nvram_short_count);
+ fprintf(output, "/* SHORTDATA enum Max index: %d */\n", NVRAM_LAST_SHORT_ELEMENT - 1);
+
+ fprintf(output, "const kal_uint8 NVRAM_CACHE_SHORT_DEFAULT[NVRAM_CACHE_SIZE] =\n");
+ fprintf(output, "{\n");
+ for (k = 0; k < SHORT_ENTRY_COUNT; k++)
+ {
+ int j;
+ if (i < nvram_short_count)
+ {
+ if (nvram_mmi_cache_short[i].id == k)
+ {
+ /* Get max length begin */
+ if(strlen(nvram_mmi_cache_short[i].id_str) > nvram_max_length_short_id_str)
+ {
+ nvram_max_length_short_id_str = strlen(nvram_mmi_cache_short[i].id_str);
+ }
+ /* Get max length end */
+
+ /* Begin to restore factory */
+ if (nvram_mmi_cache_short[i].restore)
+ {
+ nvram_restore_cache_short[nvram_mmi_cache_short[i].app_id][nvram_restore_short_idx[nvram_mmi_cache_short[i].app_id]]
+ //= nvram_mmi_cache_short[i].id;
+ = i;
+ nvram_restore_short_idx[nvram_mmi_cache_short[i].app_id]++;
+ }
+ /* End to restore factory */
+ fprintf(output, " %s,", nvram_mmi_cache_short[i].value1_str);
+ for (j = 0; j < short_max_len - strlen(nvram_mmi_cache_short[i].value1_str) + 4; j++)
+ {
+ fprintf(output, " ");
+ }
+ fprintf(output, "/* %3d : %s */\n", nvram_mmi_cache_short[i].id, nvram_mmi_cache_short[i].id_str);
+ fprintf(output, " %s", nvram_mmi_cache_short[i].value2_str);
+ if (k != SHORT_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ i++;
+ }
+ else
+ {
+ fprintf(output, " 0xFF,/* unset */\n");
+ fprintf(output, " 0xFF");
+ if (k != SHORT_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ }
+ }
+ else
+ {
+ fprintf(output, " 0xFF,\n");
+ fprintf(output, " 0xFF");
+ if (k != SHORT_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ }
+
+ }
+
+ fprintf(output, "};\n\n\n");
+ /* End output NVRAM_CACHE_SHORT_DEFAULT */
+
+
+ /* Begin output NVRAM_CACHE_DOUBLE_DEFAULT */
+ i = 0;
+ fprintf(output, "/* The count of double configuaration: %d */\n", nvram_double_count);
+ fprintf(output, "/* DOUBLEDATA enum Max index: %d */\n", NVRAM_LAST_DOUBLE_ELEMENT - 1);
+
+ fprintf(output, "const kal_uint8 NVRAM_CACHE_DOUBLE_DEFAULT[NVRAM_CACHE_SIZE] =\n");
+ fprintf(output, "{\n");
+ for (k = 0; k < DOUBLE_ENTRY_COUNT; k++)
+ {
+ int j;
+ if (i < nvram_double_count)
+ {
+ if (nvram_mmi_cache_double[i].id == k)
+ {
+ /* Begin to restore factory */
+ if (nvram_mmi_cache_double[i].restore)
+ {
+ /* Get max length begin */
+ if(strlen(nvram_mmi_cache_double[i].id_str) > nvram_max_length_double_id_str)
+ {
+ nvram_max_length_double_id_str = strlen(nvram_mmi_cache_double[i].id_str);
+ }
+ /* Get max length end */
+
+ nvram_restore_cache_double[nvram_mmi_cache_double[i].app_id][nvram_restore_double_idx[nvram_mmi_cache_double[i].app_id]]
+ = i;
+ nvram_restore_double_idx[nvram_mmi_cache_double[i].app_id]++;
+ }
+ /* End to restore factory */
+ fprintf(output, " %s,", nvram_mmi_cache_double[i].value1_str);
+ for (j = 0; j < short_max_len - strlen(nvram_mmi_cache_double[i].value1_str) + 4; j++)
+ {
+ fprintf(output, " ");
+ }
+ fprintf(output, "/* %3d : %s */\n", nvram_mmi_cache_double[i].id, nvram_mmi_cache_double[i].id_str);
+ fprintf(output, " %s,\n", nvram_mmi_cache_double[i].value2_str);
+ fprintf(output, " %s,\n", nvram_mmi_cache_double[i].value3_str);
+ fprintf(output, " %s,\n", nvram_mmi_cache_double[i].value4_str);
+ fprintf(output, " %s,\n", nvram_mmi_cache_double[i].value5_str);
+ fprintf(output, " %s,\n", nvram_mmi_cache_double[i].value6_str);
+ fprintf(output, " %s,\n", nvram_mmi_cache_double[i].value7_str);
+ fprintf(output, " %s", nvram_mmi_cache_double[i].value8_str);
+ if (k != DOUBLE_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ i++;
+ }
+ else
+ {
+ fprintf(output,
+ " 0xFF,/* unset */\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF");
+ if (k != DOUBLE_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ }
+ }
+ else
+ {
+ fprintf(output, " 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF,\n 0xFF");
+ if (k != DOUBLE_ENTRY_COUNT - 1)
+ {
+ fprintf(output, ",");
+ }
+ fprintf(output, "\n");
+ }
+ }
+ fprintf(output, "};\n\n\n");
+ fclose(output);
+}
+
+void nvram_gen_mmi_cache_res_func(FILE *fh_restore_factory_c, FILE *fh_restore_dom_h)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int loop_app_idx;
+ int loop_app_cache_idx;
+ int loop_value_idx;
+ int loop_space;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ /* step 1: generate function name */
+ fprintf(fh_restore_factory_c,NVRAM_FUNCTION_HEAD, "nvram_restore_byte_cache()", "byte");
+ fprintf(fh_restore_factory_c, NVRAM_RESTORE_FUNCTION_NAME, "byte", "kal_uint8", "b", "kal_uint8");
+
+ /* Dom: byte (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_COMMENT, "BYTE -8bit");
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_BEGIN);
+ /* Dom: byte (end) */
+
+ /* step 2: generate function context */
+ for (loop_app_idx = 0; loop_app_idx < NVRAM_APP_TOTAL; loop_app_idx++)
+ {
+ if (nvram_restore_byte_idx[loop_app_idx])
+ {
+ fprintf(fh_restore_factory_c," case %s :\n", nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][0]].app_id_str);
+ }
+ else
+ {
+ continue;
+ }
+
+ for (loop_app_cache_idx = 0; loop_app_cache_idx < nvram_restore_byte_idx[loop_app_idx]; loop_app_cache_idx++)
+ {
+ /* Dom: byte (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_ID,
+ nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].id_str);
+
+ for (loop_space = 0; loop_space < nvram_max_length_byte_id_str - strlen(nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].id_str); loop_space++)
+ {
+ fprintf(fh_restore_dom_h, " ");
+ }
+
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_DESCRIPTION,
+ nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].description);
+ /* Dom: byte (end) */
+
+ if (nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].restore_id == NVRAM_CACHE_ID_RESERVED)
+ {
+ fprintf(fh_restore_factory_c," buffer[%s] = %s;\n",
+ nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].id_str,
+ nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].value_str);
+ }
+ else
+ {
+ fprintf(fh_restore_factory_c," b_buffer[%s] = b_buffer[%s];\n",
+ nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].id_str,
+ nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][loop_app_cache_idx]].restore_id_str);
+ }
+ }
+
+ fprintf(fh_restore_factory_c,NVRAM_RESTORE_FUNCTION_BREAK);
+ }
+ /* step 3: generate function end */
+ fprintf(fh_restore_factory_c, NVRAM_RESTORE_FUNCTION_TAIL, 1);
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_END, "BYTE", "BYTE");
+
+ /*
+ * generate restore function: cache short
+ *
+ */
+
+ /* step 1: generate function name */
+ fprintf(fh_restore_factory_c,NVRAM_FUNCTION_HEAD, "nvram_restore_short_cache()", "short");
+ fprintf(fh_restore_factory_c, NVRAM_RESTORE_FUNCTION_NAME, "short", "kal_uint16", "s", "kal_uint16");
+
+ /* Dom: short (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_COMMENT, "SHORT -16bit");
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_BEGIN);
+ /* Dom: short (end) */
+
+ /* step 2: generate function context */
+ for (loop_app_idx = 0; loop_app_idx < NVRAM_APP_TOTAL; loop_app_idx++)
+ {
+ if (nvram_restore_short_idx[loop_app_idx])
+ {
+ fprintf(fh_restore_factory_c," case %s :\n", nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][0]].app_id_str);
+ }
+ else
+ {
+ continue;
+ }
+
+ for (loop_app_cache_idx = 0; loop_app_cache_idx < nvram_restore_short_idx[loop_app_idx]; loop_app_cache_idx++)
+ {
+ /* Dom: short context (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_ID,
+ nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].id_str);
+
+ for (loop_space = 0; loop_space < nvram_max_length_short_id_str - strlen(nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].id_str); loop_space++)
+ {
+ fprintf(fh_restore_dom_h, " ");
+ }
+
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_DESCRIPTION,
+ nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].description);
+ /* Dom: short context (end) */
+
+ if (nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].restore_id == NVRAM_CACHE_ID_RESERVED)
+ {
+ fprintf(fh_restore_factory_c, NVRAM_AUTO_GEN_COMMENT, nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].description);
+
+ for (loop_value_idx = 0; loop_value_idx < sizeof(short); loop_value_idx++)
+ {
+ fprintf(fh_restore_factory_c," buffer[%d * %s + %d] = 0x%02X;\n",
+ sizeof(short),
+ nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].id_str,
+ loop_value_idx,
+ *(&(nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].value1) + loop_value_idx));
+ }
+
+ }
+ else
+ {
+ fprintf(fh_restore_factory_c," s_buffer[%s] = s_buffer[%s];\n",
+ nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].id_str,
+ nvram_mmi_cache_short[nvram_restore_cache_short[loop_app_idx][loop_app_cache_idx]].restore_id_str);
+ }
+ }
+
+ fprintf(fh_restore_factory_c,NVRAM_RESTORE_FUNCTION_BREAK);
+ }
+ /* step 3: generate function end */
+ fprintf(fh_restore_factory_c, NVRAM_RESTORE_FUNCTION_TAIL, 2);
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_END, "SHORT", "SHORT");
+
+ /*
+ * generate restore function: cache double
+ *
+ */
+
+ /* step 1: generate function name */
+ fprintf(fh_restore_factory_c,NVRAM_FUNCTION_HEAD, "nvram_restore_double_cache()", "double");
+ fprintf(fh_restore_factory_c, NVRAM_RESTORE_FUNCTION_NAME, "double", "double", "d", "double");
+ /* Dom: double (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_COMMENT, "DOUBLE -64bit");
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_BEGIN);
+ /* Dom: double (end) */
+
+ /* step 2: generate function context */
+ for (loop_app_idx = 0; loop_app_idx < NVRAM_APP_TOTAL; loop_app_idx++)
+ {
+ if (nvram_restore_double_idx[loop_app_idx])
+ {
+ fprintf(fh_restore_factory_c," case %s :\n", nvram_mmi_cache_byte[nvram_restore_cache_byte[loop_app_idx][0]].app_id_str);
+ }
+ else
+ {
+ continue;
+ }
+
+ for (loop_app_cache_idx = 0; loop_app_cache_idx < nvram_restore_double_idx[loop_app_idx]; loop_app_cache_idx++)
+ {
+ /* Dom: double context (begin) */
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_ID,
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].id_str);
+
+ for (loop_space = 0; loop_space < nvram_max_length_double_id_str - strlen(nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].id_str); loop_space++)
+ {
+ fprintf(fh_restore_dom_h, " ");
+ }
+
+ fprintf(fh_restore_dom_h, R_F_DOM_CONTENT_DESCRIPTION,
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].description);
+ /* Dom: double context (end) */
+
+ fprintf(fh_restore_factory_c, NVRAM_AUTO_GEN_COMMENT, nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].description);
+
+ if (nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].restore_id == NVRAM_CACHE_ID_RESERVED)
+ {
+ for (loop_value_idx = 0; loop_value_idx < sizeof(double); loop_value_idx++)
+ {
+ fprintf(fh_restore_factory_c," buffer[%d * %s + %d] = 0x%02X;\n",
+ sizeof(double),
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].id_str,
+ loop_value_idx,
+ *(&(nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].value1) + loop_value_idx));
+ }
+ }
+ else
+ {
+ fprintf(fh_restore_factory_c," d_buffer[%s] = d_buffer[%s];\n",
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].id_str,
+ nvram_mmi_cache_double[nvram_restore_cache_double[loop_app_idx][loop_app_cache_idx]].restore_id_str);
+ }
+ }
+
+ fprintf(fh_restore_factory_c,NVRAM_RESTORE_FUNCTION_BREAK);
+ }
+ /* step 3: generate function end */
+ fprintf(fh_restore_factory_c, NVRAM_RESTORE_FUNCTION_TAIL, 3);
+ fprintf(fh_restore_dom_h, R_F_DOM_ENUM_END, "DOUBLE", "DOUBLE");
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_mmi_cache
+* DESCRIPTION
+* output restore head file to nvram_restore_headfile.h
+* PARAMETERS
+* project_name [IN]
+* broad_ver [IN]
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_create_file(FILE **file_handle, char *file_path, char *file_name)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ int mode_result;
+ char file_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(file_pathname, "%s\\%s", file_path, file_name);
+
+ mode_result = access(file_pathname, 0);
+
+ if (mode_result == 0)
+ {
+ /* exists,but check if it can be written. */
+ mode_result = access(file_pathname, 2);
+ if (mode_result != 0)
+ {
+ fprintf(stderr, "error: %s exists,but it cannot be written.\n", file_name);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+ else
+ {
+ /* file not exist*/
+ mode_result = access(file_path, 2);
+ if (mode_result != 0)
+ {
+ fprintf(stderr, "error: cannot create file in folder: %s\n", file_path);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+ }
+
+ *file_handle = fopen(file_pathname, "w+");
+ if (file_handle == NULL)
+ {
+ fprintf(stderr, "error: cannot write to %s in folder: %s\n", file_name, file_path);
+ exit(NVRAM_EXIT_CODE_ERROR);
+ }
+
+ return;
+}
+
+void nvram_gen_close_file(FILE **file_handle)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ fclose(*file_handle);
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_restore_function
+* DESCRIPTION
+* output restore function to nvram_user_restore_factory.c
+* PARAMETERS
+* project_name [IN]
+* broad_ver [IN]
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_restore_function(char *project_name, char *broad_ver)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ FILE *fh_restore_factory_c;
+ FILE *fh_restore_dom_h;
+ char output_pathname[NVRAM_AUTO_GEN_MAX_PATH_LEN];
+ int loop_app_idx;
+ int loop_space;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ sprintf(output_pathname, "mmi_cache_restore.c");
+ nvram_gen_create_file(&fh_restore_factory_c,nvram_auto_gen_output_path,output_pathname);
+
+ sprintf(output_pathname,"mmi_cache_restore_dom.h");
+ nvram_gen_create_file(&fh_restore_dom_h,nvram_auto_gen_output_path,output_pathname);
+
+ /* generate head file */
+ fprintf(fh_restore_factory_c, COPYRIGHTS_HEADER, "custom_mmi_cache_restore.c");
+ fprintf(fh_restore_factory_c, "#ifndef NVRAM_NOT_PRESENT\n");
+ fprintf(fh_restore_factory_c, "#include \"kal_general_types.h\"\n");
+ fprintf(fh_restore_factory_c, "#include \"nvram_enums.h\"\n");
+ fprintf(fh_restore_factory_c, "#include \"custom_nvram_config.h\"\n");
+ fprintf(fh_restore_factory_c, "#include \"custom_mmi_default_value.h\"\n");
+
+ nvram_gen_mmi_cache_res_func(fh_restore_factory_c, fh_restore_dom_h);
+
+ fprintf(fh_restore_factory_c, "#endif /* NVRAM_NOT_PRESENT */");
+
+ nvram_gen_close_file(&fh_restore_factory_c);
+ nvram_gen_close_file(&fh_restore_dom_h);
+}
+
+#endif /* #if defined(NEPTUNE_MMI) */
+#endif /* NVRAM_NOT_PRESENT */
+
+/*****************************************************************************
+* FUNCTION
+* main
+* DESCRIPTION
+* main function.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+int main(int argc, char *argv[])
+{
+#if defined(NEPTUNE_MMI) && !defined(NVRAM_NOT_PRESENT)
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ if (argc > 1)
+ {
+ sprintf(nvram_auto_gen_output_path, "%s", argv[3]);
+
+ printf("nvram_gen_mmi_cache\n");
+ nvram_gen_mmi_cache(argv[1], argv[2]);
+
+ printf("nvram_gen_mmi_cache_res_func\n");
+ nvram_gen_restore_function(argv[1], argv[2]);
+
+ }
+ return 0;
+#else
+ printf("Old mmi cache mechanism is already phased out\n");
+ return 0;
+#endif
+}
+
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_gen_util.c b/mcu/tools/NVRAMStatistic/src/nvram_gen_util.c
new file mode 100644
index 0000000..2500552
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_gen_util.c
@@ -0,0 +1,1456 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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_gen_util.c
+ *
+ * Project:
+ * --------
+ * MAUI
+ *
+ * Description:
+ * ------------
+ * This file is intends for generating NVRAM information.
+ *
+ * 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!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#ifndef NVRAM_NOT_PRESENT
+/*
+ * Include
+ */
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <sys/io.h>
+#include "kal_public_api.h"
+
+#include "nvram_auto_gen.h"
+#if defined(__MMI_FMI__)
+#include "nvram_user_defs.h"
+#endif
+#include "nvram_defs.h" /* NVRAM_MSP_ALIGNMENT_REMAINDER */
+#include "custom_nvram_cat.h"
+#include "custom_nvram_config.h" /* __NVRAM_VENDOR_SUPPORT__ */
+#include "nvram_editor_data_item.h"
+#include "nvram_group_editor.h" //add for break group files from header file
+#ifdef __NVRAM_PSEUDO_MERGE__
+#include "nvram_pseudo_merge.h"
+#endif
+
+#include "nvram_internal.h"
+
+#include "custom_nvram_int_config.h"
+#ifdef __NV_CHKSUM_ENHANCE__
+#include "custom_nvram_sec.h" // add ,get checksum type/size.
+
+/* CUSTOM_CHK_ALGO_CONFIG configure*/
+extern nvram_checksum_config CUSTOM_CHK_ALGO_CONFIG;
+kal_uint32 get_checksum_size(nvram_ltable_entry_struct* ldi);
+#endif
+
+kal_uint32 custpack_total_to_verify = 0;
+
+#ifdef __NVRAM_VENDOR_SUPPORT__
+kal_uint32 nvram_vendor_reserve_size = NVRAM_MAX_VENDOR_LID_SIZE;
+#endif
+
+#ifdef __NVRAM_OTP__
+kal_uint32 otp_total_to_verify = 0;
+kal_uint32 otp_size_to_verify = 0;
+#endif
+
+kal_uint32 secupack_total_to_verify = 0;
+kal_uint32 secupack_size_to_verify = 0;
+kal_uint16 secupack_idx = 0;
+
+#if defined(__NVRAM_SECURE_DATA_STORAGE__)
+kal_uint32 sds_total_to_verify = 0;
+kal_uint32 sds_size_to_verify = 0;
+#endif
+
+kal_uint32 nvram_gen_backup_size = 0;
+kal_uint32 nvram_gen_backup_total = 0;
+
+boot_mode_type system_boot_mode;
+
+
+nvram_ltable_entry_struct *logical_data_item_table;
+
+kal_uint32 nvram_gen_total_lid;
+
+/* Fake free_ilm */
+void free_int_ilm(ilm_struct *ilm_ptr, kal_char* file_name, kal_uint32 line)
+{
+}
+
+#define IS_POWER_OF_2(v) ((v & (v - 1)) == 0)
+
+
+ltable_entry_struct logical_data_item_table_internal[] =
+{
+ {
+ NVRAM_EF_SYS_LID,
+ NVRAM_EF_SYS_TOTAL,
+ NVRAM_EF_SYS_SIZE,
+ NVRAM_NORMAL(NVRAM_EF_FF_DEFAULT),
+ NVRAM_CATEGORY_IMPORTANT_L1,
+ NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_MULTIPLE,
+ "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_NORMAL(NVRAM_EF_FF_DEFAULT),
+ NVRAM_CATEGORY_IMPORTANT,
+ NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_FAULT_ASSERT | NVRAM_ATTR_COMMITTED
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+ | NVRAM_ATTR_MSP | NVRAM_ATTR_MULTIPLE
+ #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_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_ZERO_DEFAULT),
+ NVRAM_CATEGORY_USER,
+ NVRAM_ATTR_AVERAGE | 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,
+ "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_NORMAL(NVRAM_EF_ZERO_DEFAULT),
+ NVRAM_CATEGORY_USER,
+ NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_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
+
+};
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_assign_entry
+* DESCRIPTION
+* construct table
+* PARAMETERS
+* position [IN]
+* ldi [IN]
+* RETURNS
+* none
+*****************************************************************************/
+void nvram_gen_assign_entry(nvram_ltable_entry_struct* ldi)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_int32 value;
+ kal_uint32 section_size;
+
+ kal_uint32 tbl_idx = 0, entry_idx = 0;
+ kal_uint32 nvram_checksum_size = 0;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ #ifdef __NV_CHKSUM_ENHANCE__
+ nvram_checksum_size = get_checksum_size(ldi); // get nvram_checksum_size , read CUSTOM_CHK_ALGO_CONFIG.
+ #else
+ nvram_checksum_size = NVRAM_CHKSUM_SIZE;
+ #endif
+
+ /* Step 1: Adjust attr / Category
+ Step 2: Verify
+ Step 3: Statistics */
+
+ //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
+ //***************************************************************************
+ if( (ldi->total_records < 2) && ( (ldi->attr & NVRAM_ATTR_MULTIREC_READ) || (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)))
+ {
+ fprintf(stderr,
+ "Can't Set the NVRAM_ATTR_MULTIREC_READ or NVRAM_ATTR_MULTI_DEFAULT for the lid with only one record, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+
+ if (ldi->default_value == (kal_uint8 const*)NVRAM_EF_FF_DEFAULT ||
+ ldi->default_value == (kal_uint8 const*)NVRAM_EF_ZERO_DEFAULT)
+ {
+ #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
+ if((ldi->attr & NVRAM_ATTR_GEN_DEFAULT) && !(NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)))
+ {
+ fprintf(stderr,
+ "Can't Set the NVRAM_ATTR_GEN_DEFAULT for the lid with Zero or FF default value, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+
+ if(NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) && !(ldi->attr & NVRAM_ATTR_GEN_DEFAULT))
+ {
+ fprintf(stderr,
+ "Must Set the NVRAM_ATTR_GEN_DEFAULT for L4 Category LID, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+
+ //***************************************************************************
+ // Adjust Attr/Category II
+ // MULTIPLE / BACKUP_RAW / BACKUP_FAT are mutually exclusive
+ //***************************************************************************
+ if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category))
+ {
+ if((ldi->attr &NVRAM_ATTR_RESERVE_BACKWARD) || (ldi->attr &NVRAM_ATTR_MULTIPLE))
+ {
+ fprintf(stderr,
+ "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_RESERVE_BACKWARD for Calibrate Lid, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ #if defined(__NVRAM_BACKUP_DISK_FAT__)
+
+ if((ldi->attr & NVRAM_ATTR_MULTIPLE) || (ldi->attr & NVRAM_ATTR_BACKUP_RAW))
+ {
+ fprintf(stderr,
+ "Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_RAW for Calibrat, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ if((ldi->attr & NVRAM_ATTR_BACKUP_FAT) == 0)
+ {
+ fprintf(stderr,
+ "Should set the NVRAM_ATTR_BACKUP_FAT for Calibrat, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+
+ #elif defined(__NVRAM_BACKUP_DISK_RAW__)
+ if((ldi->attr & NVRAM_ATTR_MULTIPLE) || (ldi->attr & NVRAM_ATTR_BACKUP_FAT))
+ {
+ fprintf(stderr,
+ "Can't Set the NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_BACKUP_FAT for Calibrat, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ if((ldi->attr & NVRAM_ATTR_BACKUP_RAW) == 0)
+ {
+ fprintf(stderr,
+ "Should set the NVRAM_ATTR_BACKUP_RAW for Calibrat, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ #else
+ #if !defined(__LOW_COST_SUPPORT_COMMON__) && !defined(__CCCIFS_SUPPORT__) && !defined(__FS_RAMDISK__)
+ if((ldi->attr & NVRAM_ATTR_MULTIPLE) == 0)
+ {
+ fprintf(stderr,
+ "Should set the NVRAM_ATTR_MULTIPLE for Calibrat under this scenario, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ #endif
+ if((ldi->attr & NVRAM_ATTR_BACKUP_RAW) || (ldi->attr & NVRAM_ATTR_BACKUP_FAT))
+ {
+ fprintf(stderr,
+ "Can't Set the NVRAM_ATTR_BACKUP_RAW/NVRAM_ATTR_BACKUP_FAT for Calibrat, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ #endif
+ }
+
+ //***************************************************************************
+ // Adjust Attr/Category III
+ // Just apply to smartphone
+ // 1: When AP side clean boot, nvram will reset all lid
+ // 2: When Modern side restore factory, nvram only reset data item in NVD_DATA
+ // and don't care about data item in folder A & B
+ // 3: So, turn off NVRAM_CATEGORY_FACTORY
+ //***************************************************************************
+#if defined(__CCCIFS_SUPPORT__)
+ if (NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category))
+ {
+ if((ldi->attr & NVRAM_ATTR_RESERVE_BACKWARD))
+ {
+ fprintf(stderr,
+ "Can't Set the NVRAM_ATTR_RESERVE_BACKWARD for Important/Impotant_L4, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ if((ldi->attr & NVRAM_ATTR_COMMITTED) == 0)
+ {
+ fprintf(stderr,
+ "Suggest Set the NVRAM_ATTR_COMMITTED for Important/Impotant_L4, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+#endif
+
+ //***************************************************************************
+ // Adjust Attr/Category IV
+ // OTP category cannot use with many attribute together. Because it cannot be reset
+ // OTP category also cannot use with other category together.
+ //***************************************************************************
+#ifdef __NVRAM_OTP__
+ if (NVRAM_IS_CATEGORY_OTP(ldi->category))
+ {
+ if( (ldi->attr & NVRAM_ATTR_WRITEPROTECT) || (ldi->attr & NVRAM_ATTR_MULTIPLE) || (ldi->attr & NVRAM_ATTR_MSP) || (ldi->attr & NVRAM_ATTR_OTA_RESET) )
+ {
+ fprintf(stderr,
+ "Can't Set NVRAM_ATTR_WRITEPROTECT/NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP/NVRAM_ATTR_OTA_RESET for OTP, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+#endif
+
+ //***************************************************************************
+ // Adjust Attr/Category V
+ // Add pseudo merge attribute
+ //***************************************************************************
+ /* Record data item will be restored (end) */
+#ifdef __NVRAM_PSEUDO_MERGE__
+ 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_checksum_size) * ldi->total_records < NVRAM_CLUSTER_SIZE))
+ {
+ if((ldi->attr & NVRAM_ATTR_PACKAGE) == 0)
+ {
+ fprintf(stderr,
+ "Should set the NVRAM_ATTR_PACKAGE for this lid %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+
+ if (NVRAM_IS_ATTR_PACKAGE(ldi->attr))
+ {
+ ldi->description = NULL;
+ if( (ldi->attr & NVRAM_ATTR_MULTIPLE) || (ldi->attr & NVRAM_ATTR_MSP))
+ {
+ fprintf(stderr,
+ "Can't Set NVRAM_ATTR_MULTIPLE/NVRAM_ATTR_MSP for PACKAGE Lid, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+ #endif
+
+ //***************************************************************************
+ // Adjust Attr/Category VI
+ // Add MSP, confidential, multiple with secupack item
+ //***************************************************************************
+
+ if (NVRAM_IS_CATEGORY_SECUPACK(ldi->category))
+ {
+ if(!(ldi->attr & NVRAM_ATTR_CONFIDENTIAL)
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+ || !(ldi->attr & NVRAM_ATTR_MSP)
+ #endif
+ )
+ {
+ fprintf(stderr,
+ "Should set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+
+ //***************************************************************************
+ // Adjust Attr/Category VII
+ // Add MSP, confidential, multiple with custom sensitve data
+ //***************************************************************************
+
+#ifdef __NVRAM_CUSTOM_SENSITIVE__
+ if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category))
+ {
+ if( !(ldi->attr & NVRAM_ATTR_MSP) || !(ldi->attr & NVRAM_ATTR_CONFIDENTIAL) || !(ldi->attr & NVRAM_ATTR_MULTIPLE))
+ {
+ fprintf(stderr,
+ "Should Set the NVRAM_ATTR_MSP/NVRAM_ATTR_CONFIDENTIAL/NVRAM_ATTR_MULTIPLE, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+#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->attr &= ~(NVRAM_ATTR_GEN_DEFAULT);
+ }
+#endif
+
+ //***************************************************************************
+ // Adjust Attr/Category VIII
+ // remove all attribute if the data is in custom disk
+ //***************************************************************************
+#ifdef __NVRAM_CUSTOM_DISK__
+ if (NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category))
+ {
+ if(ldi->attr != NVRAM_ATTR_AVERAGE)
+ {
+ fprintf(stderr,
+ "Can't set other attribute except NVRAM_ATTR_AVERAGE, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+#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
+
+ //***************************************************************************
+ // Check I
+ // cannot put the data into two categories that are mutually exclusive
+ //***************************************************************************
+
+ value = (ldi->category &
+ (NVRAM_CATEGORY_INTERNAL
+ | NVRAM_CATEGORY_CALIBRAT
+ | NVRAM_CATEGORY_IMPORTANT
+ | NVRAM_CATEGORY_IMPORTANT_L4
+ | NVRAM_CATEGORY_IMPORTANT_L1
+ #ifdef __NVRAM_CUSTOM_SENSITIVE__
+ | NVRAM_CATEGORY_CUSTOM_SENSITIVE
+ #endif
+ #ifdef __NVRAM_CUSTOM_DISK__
+ | NVRAM_CATEGORY_CUSTOM_DISK
+ #endif
+ ));
+
+ /* check if value is power of 2 */
+ if (!IS_POWER_OF_2(value))
+ {
+ fprintf(stderr,
+ "Category inernal & calibrate & important & sensitive can't be used at the same time!, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+
+ }
+
+
+ //***************************************************************************
+ // Check II
+ // cannot put the sds data with custom
+ //***************************************************************************
+#if defined(__NVRAM_SECURE_DATA_STORAGE__)
+ if (NVRAM_IS_CATEGORY_BACKUP_SDS(ldi->category))
+ {
+ if (NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) ||
+ NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category) ||
+ NVRAM_IS_CATEGORY_OTP(ldi->category))
+ {
+ fprintf(stderr,"Error: Sds use with wrong category LID:%s Desc:%s category %d\n",
+ ldi->str_LID, ldi->str_LID, ldi->category);
+
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+
+ if ((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))
+ {
+ fprintf(stderr,"Error: Sds use with wrong attribute LID:%s Desc:%s attribute %d\n",
+ ldi->str_LID, ldi->str_LID, ldi->attr);
+
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+
+
+ #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+ if (ldi->attr & NVRAM_ATTR_MSP)
+ {
+ /* 16 byte alignment */
+ section_size = ldi->size + nvram_checksum_size + NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_checksum_size);
+ }
+ else
+ #endif
+ {
+ section_size = ldi->size + nvram_checksum_size;
+ }
+
+ if (section_size * ldi->total_records > NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE)
+ {
+ fprintf(stderr,"Error: Data is too large to put into sds LID:%s Desc:%s %d %d\n",
+ ldi->str_LID, ldi->str_LID, ldi->size, ldi->total_records);
+
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+#endif
+
+
+ //***************************************************************************
+ // Check (III)
+ // Cannot use zero default or ff default with multi default
+ //***************************************************************************
+
+ if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+ {
+ if (strcmp(ldi->str_default_value, "NVRAM_EF_ZERO_DEFAULT") == 0 ||
+ strcmp(ldi->str_default_value, "NVRAM_EF_FF_DEFAULT") == 0)
+ {
+ fprintf(stderr,
+ "Cannot set ZERO_DEFAULT or FF_DEFAULT with multi_default!, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3);
+ }
+ }
+
+ //***************************************************************************
+ // Check (IV)
+ // The record size cannot bigger than the biggest control buffer
+ //***************************************************************************
+#ifndef __NVRAM_LARGE_RECORD_SIZE__
+
+#ifdef __NVRAM_BIND_TO_CHIP_CIPHER__
+ if (ldi->attr & NVRAM_ATTR_MSP)
+ {
+ /* 16 byte alignment */
+ section_size = ldi->size + nvram_checksum_size + NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_checksum_size);
+ }
+ else
+#endif
+ {
+ section_size = ldi->size + nvram_checksum_size;
+ }
+
+
+
+ if (section_size > NVRAM_CUSTOM_CFG_MAX_RECORD_SIZE)
+ {
+ fprintf(stderr,
+ "LID Size is too big!, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3);
+ }
+#endif
+
+ //***************************************************************************
+ // Check V
+ // Items in custpack cannot use zero default or ff default as the default value
+ //***************************************************************************
+ if (NVRAM_IS_CATEGORY_CUSTPACK(ldi->category))
+ {
+ if (strcmp(ldi->str_default_value, "NVRAM_EF_ZERO_DEFAULT") == 0 ||
+ strcmp(ldi->str_default_value, "NVRAM_EF_FF_DEFAULT") == 0)
+ {
+ fprintf(stderr,
+ "Cannot set ZERO_DEFAULT or FF_DEFAULT with custpack!, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3);
+
+ }
+ }
+
+ //***************************************************************************
+ // Check VI
+ // Build error check: CALIBRAT LID should not have NVRAM_ATTR_OTA_RESET attribute.
+ //***************************************************************************
+ if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) && (ldi->attr&NVRAM_ATTR_OTA_RESET))
+ {
+ fprintf(stderr,
+ "Error usage: NVRAM_ATTR_SW_VERNO_REST and NVRAM_CATEGORY_CALIBRAT should not use together!, %d, %s\n", ldi->LID, ldi->str_LID);
+ exit(3);
+
+ }
+
+ //***************************************************************************
+ // Statistics I
+ // calculate the custpack
+ //***************************************************************************
+ if (NVRAM_IS_CATEGORY_CUSTPACK(ldi->category))
+ {
+ custpack_total_to_verify++;
+ }
+ //***************************************************************************
+ // Statistics II
+ // calculate the secupack
+ //***************************************************************************
+
+ if (NVRAM_IS_CATEGORY_SECUPACK(ldi->category))
+ {
+ secupack_total_to_verify++;
+
+ if (ldi->attr & NVRAM_ATTR_MULTI_DEFAULT)
+ {
+ secupack_size_to_verify += ldi->size * ldi->total_records + nvram_checksum_size;
+ }
+ else
+ {
+ secupack_size_to_verify += ldi->size + nvram_checksum_size;
+ }
+ }
+
+ //***************************************************************************
+ // Statistics III
+ // calculate the otp
+ //***************************************************************************
+#ifdef __NVRAM_OTP__
+ if (NVRAM_IS_CATEGORY_OTP(ldi->category))
+ {
+ otp_total_to_verify++;
+ otp_size_to_verify += ldi->size * ldi->total_records;
+ }
+#endif /* __NVRAM_OTP__ */
+
+
+ //***************************************************************************
+ // Statistics IV
+ // calculate the vendor reserve size
+ //***************************************************************************
+
+#ifdef __NVRAM_VENDOR_SUPPORT__
+ if (is_customregion)
+ {
+ kal_uint32 section_size = ldi->size * ldi->total_records + nvram_checksum_size;
+ if (section_size < nvram_vendor_reserve_size)
+ {
+ nvram_vendor_reserve_size -= section_size;
+ }
+ else
+ {
+ fprintf(stderr,
+ "My dear, total size for vendor nvram shouldn't be larger than %d!\n", NVRAM_MAX_VENDOR_LID_SIZE);
+ exit(3); /* NVRAM_EXIT_CODE_ERROR */
+ }
+ }
+#endif /* __NVRAM_VENDOR_SUPPORT__ */
+
+ //***************************************************************************
+ // Statistics IV
+ // calculate the vendor reserve size
+ //***************************************************************************
+#if defined(__NVRAM_SECURE_DATA_STORAGE__)
+ if (NVRAM_IS_CATEGORY_BACKUP_SDS(ldi->category))
+ {
+ sds_total_to_verify++;
+ sds_size_to_verify += (ldi->size + nvram_checksum_size + NVRAM_MSP_ALIGNMENT_REMAINDER(ldi->size + nvram_checksum_size)) * ldi->total_records;
+ }
+#endif
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_assign_cat_entry
+ * DESCRIPTION
+ * PARAMETERS
+ * RETURNS
+ *****************************************************************************/
+static void nvram_gen_assign_cat_default_value(nvram_lid_enum position, nvram_cat_replace_setting* cat_item)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ if (cat_item->size != logical_data_item_table[position].size ||
+ cat_item->total_records != logical_data_item_table[position].total_records)
+ {
+ return;
+ }
+
+ logical_data_item_table[position].default_value = cat_item->default_value;
+
+ if (cat_item->is_multi_default)
+ {
+ logical_data_item_table[position].attr &= NVRAM_ATTR_MULTI_DEFAULT;
+ }
+ else
+ {
+ logical_data_item_table[position].attr &= ~NVRAM_ATTR_MULTI_DEFAULT;
+ }
+}
+
+int ltable_enum_cmp_local(nvram_ltable_entry_struct *ent_a, nvram_ltable_entry_struct *ent_b)
+{
+ return (int)(ent_a->LID - ent_b->LID);
+}
+
+/*****************************************************************************
+* FUNCTION
+* nvram_gen_construct_ltable
+* DESCRIPTION
+* To construct ltable.
+* PARAMETERS
+* None
+* RETURNS
+* None
+*****************************************************************************/
+void nvram_gen_construct_ltable(void)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ extern unsigned char nvram_ltable_begin, nvram_ltable_end;
+ kal_uint32 i = 0, tbl_idx = 0, tbl_size;
+ nvram_ltable_entry_struct *logical_data_item_table_bak;
+ size_t tbl_entry_size = sizeof(nvram_ltable_entry_struct);
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+
+ logical_data_item_table_bak = (nvram_ltable_entry_struct *)&nvram_ltable_begin;
+ tbl_size = (kal_uint32)(&nvram_ltable_end - &nvram_ltable_begin);
+ nvram_gen_total_lid = tbl_size/sizeof(nvram_ltable_entry_struct);
+ logical_data_item_table = (nvram_ltable_entry_struct *) malloc(tbl_size);
+ memcpy(logical_data_item_table, logical_data_item_table_bak, tbl_size);
+ qsort(logical_data_item_table, nvram_gen_total_lid, tbl_entry_size, ltable_enum_cmp_local);
+ printf("addr = %x, entry size: %d, real size: %d %s result size:%d\n", logical_data_item_table, sizeof(nvram_ltable_entry_struct), tbl_size, tbl_size%sizeof(nvram_ltable_entry_struct)?"!=":"=",nvram_gen_total_lid * sizeof(nvram_ltable_entry_struct));
+
+ do
+ {
+ printf("ltable[%d](0x%x) = %s(%d), size = %d, total_records = %d\n",
+ i, &logical_data_item_table[i], logical_data_item_table[i].str_LID, logical_data_item_table[i].LID, logical_data_item_table[i].size, logical_data_item_table[i].total_records);
+
+ nvram_gen_assign_entry(&logical_data_item_table[i]);
+
+ }while(++i < nvram_gen_total_lid);
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+}
+
+/*****************************************************************************
+ * FUNCTION
+ * nvram_gen_search_entry
+ * DESCRIPTION
+ * To construct ltable.
+ * PARAMETERS
+ * None
+ * RETURNS
+ * None
+ *****************************************************************************/
+nvram_ltable_entry_struct* nvram_gen_search_entry(nvram_lid_enum lid)
+{
+ /*----------------------------------------------------------------*/
+ /* Local Variables */
+ /*----------------------------------------------------------------*/
+ kal_uint32 i = 0;
+
+ /*----------------------------------------------------------------*/
+ /* Code Body */
+ /*----------------------------------------------------------------*/
+ do
+ {
+ if (logical_data_item_table[i].LID == lid)
+ {
+ return &logical_data_item_table[i];
+ }
+
+ }while(++i < nvram_gen_total_lid);
+
+ return NULL;
+}
+
+
+#endif /* NVRAM_NOT_PRESENT */
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_hash_check.c b/mcu/tools/NVRAMStatistic/src/nvram_hash_check.c
new file mode 100644
index 0000000..2a6afe3
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_hash_check.c
@@ -0,0 +1,132 @@
+/*****************************************************************************
+* 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) 2006
+*
+* 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_hash_check.c
+ *
+ * Project:
+ * --------
+ * UMOLYA
+ *
+ * Description:
+ * ------------
+ * This file is use to check LID hash info correct.
+ *
+ * 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!
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#include <string.h>
+#include "nvram_hash_check.h"
+#include "md5.h"
+
+//#define HASH_CHECK_DEBUG
+
+kal_bool nvram_hash_check(nvram_ltable_entry_struct *ldi) {
+#ifdef __NVRAM_LID_HASH_CHECK__
+ static kal_bool first_print = KAL_TRUE;
+ char strbuf[256] = {0};
+ unsigned char digest[17] = {0};
+ unsigned int hash;
+ MD5_CTX context = {0};
+
+ MD5_Init(&context);
+ sprintf(strbuf, "%d;%s;%s;%s;", ldi->LID, ldi->str_LID, ldi->fileprefix, ldi->fileverno);
+#ifdef HASH_CHECK_DEBUG
+ fprintf(stderr, "debug: %s\n", strbuf);
+#endif
+ MD5_Update(&context, strbuf, strlen(strbuf));
+ MD5_Final(digest, &context);
+#ifdef HASH_CHECK_DEBUG
+ fprintf(stderr, "debug: %02X %02X %02X %02X\n", digest[0], digest[1], digest[2], digest[3]);
+ fprintf(stderr, "debug: %02X %02X %02X %02X\n", digest[4], digest[5], digest[6], digest[7]);
+ fprintf(stderr, "debug: %02X %02X %02X %02X\n", digest[8], digest[9], digest[10], digest[11]);
+#endif
+ hash = (digest[4]<<4 | digest[5]>>4) << 24;
+ hash |= (digest[5]<<4 | digest[6]>>4) << 16;
+ hash |= (digest[6]<<4 | digest[7]>>4) << 8;
+ hash |= (digest[7]<<4 | digest[8]>>4);
+#ifdef HASH_CHECK_DEBUG
+ fprintf(stderr, "debug: 0x%08X\n", hash);
+#endif
+ if(hash != ldi->hash_key) {
+ if(first_print) {
+ fprintf(stderr, "error: Need register LID http://wiki.mediatek.inc/display/NVRAM/How+to+apply+LID+HASH+key\n");
+ fprintf(stderr, "error: This feature is just internal use. Please set NVRAM_LID_HASH_CHECK = FALSE for customer.\n");
+ first_print = KAL_FALSE;
+ }
+ fprintf(stderr, "error: %s (0x%08x) hash key is not match.\n", ldi->str_LID, ldi->hash_key);
+ fprintf(stderr, "debug: %d %s %s %s\n", ldi->LID, ldi->str_LID, ldi->fileprefix, ldi->fileverno);
+ return KAL_FALSE;
+ }
+#endif
+ return KAL_TRUE;
+}
diff --git a/mcu/tools/NVRAMStatistic/src/nvram_white_list.c b/mcu/tools/NVRAMStatistic/src/nvram_white_list.c
new file mode 100644
index 0000000..c4095ff
--- /dev/null
+++ b/mcu/tools/NVRAMStatistic/src/nvram_white_list.c
@@ -0,0 +1,18 @@
+#define ARRAY_ENT_NR(_array) (sizeof(_array)/sizeof(_array[0]))
+
+
+const char *g_nvram_white_list_for_multiple_attr[] =
+{
+ "NVRAM_EF_SYS_LID",
+ "NVRAM_EF_SML_LID",
+ "NVRAM_EF_SIM_LOCK_LID"
+};
+const int g_nr_nvram_white_list_for_multiple_attr = ARRAY_ENT_NR(g_nvram_white_list_for_multiple_attr);
+
+const char *g_nvram_white_list_for_write_protect_attr[] =
+{
+ "NVRAM_EF_SYS_LID",
+ "NVRAM_EF_IMEI_IMEISV_LID",
+ "NVRAM_EF_NVRAM_LOCK_LID"
+};
+const int g_nr_nvram_white_list_for_write_protect_attr = ARRAY_ENT_NR(g_nvram_white_list_for_write_protect_attr);